> The fundamental problem with the AT code is there is no queuing system
> implemented either to process messages taken off of the SIM or to send
> messages out through the SIM, and the current 'try for a
> while then die'
> mechanism is far from perfect.
>
I think its a bit more than that. Here are my suggestions;
* Separate the AT I/O into a reader thread and a writer thread.
* Make the writer thread event triggered. Define a set of events
like { OK, ERROR, SIMPIN, PINREADY, PROMPT, TIMEOUT, LINEERROR }
and so on. The writer thread should issue a command and wait for
an event, and then take the appropriate action.
* The reader thread reads characters from the port, parses the
character stream into tokens and signals an event from
the above set based on the token value.
* New messages are handled by the reader thread, decoded into
a Msg instance and placed on a List which is consumed by the
higher level at_read...() function.
You will need a rolling buffer struct for the read thread (something like
the strstreambuf from the C++ STL) and a function to wait on
multiple events (ie. Mutexes).
Using the SIM as a buffer has pros and cons. You'll need more code
to manage the device interaction (eg. to delete incoming messages
from the SIM having read them). For consistency, you should also
read messages from the SIM on start-up which means code to list
messages and process the results of the list. In my experience,
the less interaction with the devices, the more reliable the
application tends to be.
Hope this helps,