This is not a question for beginners.
I am implementing a functional interface to an asynchronous serial device connected to the Serial1 port on a mega.
To ensure clarity, I want to implement a series of functions thus:
{param} CallInterface({param1},{param2},...) {
sendRequestPacket();
....{await Response or timeout}....
return Response;
}
Obviously, when "awaiting Response" we are blocking the operational thread and have to allow an additional thread processor access in order to retrieve and parse the response.
On a multithreaded platform, this would be trivial to implement using semaphores and other multi-threading techniques, but on Arduino,AVR the solution is possibly less obvious, or not.
So, the question is, what is the best and most effective way to implement a pattern such as this on the Arduino platform?
Obviously, when "awaiting Response" we are blocking the operational thread
... actually, that is not obvious ... you could use non-blocking codeCallInterface
, to which the response is to be delivered, and anupdate()
method to the object implementing the interface, in order for it to catch the response and deliver it to the callback.