Electronic – mbed Socket Thread

embeddedethernetmbedsocket

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?

Best Answer

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.

Related Topic