Hello! I programed several times finite state machines to handle a gsm module. They worked fine, but I was never satisfied with the implementation.
For example, to send a UDP message to the server I have to:
0- initialize pins, uarts, etc
1- drive low a power pin
2- wait for the module to drive high the "on" pin
3- send AT and wait for OK
4- read simcard CCID
5- configure context (apn, user, password)
6- register and receive local IP address
7- configure my udp connection to my server
8- send message
9- wait for reply, ack or remote command and procecss the received data
10- wait for another message to be sent,
That implemented with only one big state machine was hundreds of code in a big switch(actual_state).
The firsts tasks are hardware related, the seconds are network task, then my application layer (send and process data). Everything is mixed, and I'm starting to think that must be a better way to implement.
Maybe a state machine to ensure that the module is powered on and operational (including sending periodically AT and receive the OK), another state machine to ensure that the module is connected (and maybe check RSSI), and a third state machine to handle the application data sending and receiving.
What do you think? I don't want to complicate things but my last implementation was hard to maintain even from me (the programmer)