1
\$\begingroup\$

I need to establish an ethernet connection between a host and mbed, where the host can send commands to the mbed (e.g. move forward, move backwards, stop, etc).

As there is no telling when these incoming commands might be received, would it be advisable to keep my Socket code in a separate thread, which polls socket.receive(..) in a while(true) loop, and then sets the state (based on the command received) of the main thread?

Alternatively is there a way to use an interrupt whenever there is data (i.e. a command) to be received?

What sort of issues might I run into with either of these methods?

\$\endgroup\$
2
\$\begingroup\$

Yes, good approach. I've done something similar here.

Alternatively, there is sigio where you can register an event when you can recv data. Note that you'll need to signal back from the sigio context to the main thread - you can do it using a Semaphore or via mbed-events.

\$\endgroup\$
  • \$\begingroup\$ Thanks. Which approach is most efficient? I have methods in another thread which are called ~1000/sec and I don't want to overload the CPU. \$\endgroup\$ – M-R Feb 6 '18 at 17:54
  • \$\begingroup\$ Not really sure... How timing sensitive are the other methods? I think measuring here would be the fastest way to find out. \$\endgroup\$ – Jan Jongboom Feb 7 '18 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.