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\$

1 Answer 1

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\$
2
  • \$\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\$ Commented Feb 6, 2018 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\$ Commented Feb 7, 2018 at 8:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.