2022-04-24 02:09 PM
Hi guys,
I'm struggling with modem communication on embedded system that does few other tasks in realtime. I'm using TCP stack built in modem (Fibocom G510).
This seem to be not complicated, but every time I'm doing it - I'm doing it diffrent way and I end up with pretty big and not perfect code, because there is always URC or condition that I have not thought of.
To establish TCP socket connection I have to:
- reset modem hardware
- wait for "SIM READY"
- enter pin (optional)
- wait for cellular network registration
- wait for 2G/3G/4G registration
- configure APN
- configure other things (optional)
- activate internet connection
- activate TCP connection
After everything is initialized and connected I have to handle many things, including URC (unsolicited result codes):
- cellular network connection lost (so AP and TCP connection is also lost)
- AP connection lost (so TCP connection is also lost)
- TCP connection lost
- maybe even SIM LOST scenario
- errors
- incoming data from TCP socket
- incoming SMS messages (optional)
And I also have to support timeouts.
Is there any way to avoid spaghetti state machine?
Is there any reference design for embedded modem driver that I can find on Github or some manufacturer website?
Solved! Go to Solution.
2022-04-25 03:08 AM
The golden rule is: Do not use blind delays!
eg,
https://www.avrfreaks.net/comment/2209136#comment-2209136
https://www.avrfreaks.net/comment/2212166#comment-2212166
and many. many more.
@kaamil1984 "Is there any way to avoid spaghetti state machine?"
A well-written State Machine should not be "spaghetti"!
You will probably need several state machines; eg,
"any reference design for embedded modem driver that I can find on Github"
Some here:
2022-04-25 03:08 AM
The golden rule is: Do not use blind delays!
eg,
https://www.avrfreaks.net/comment/2209136#comment-2209136
https://www.avrfreaks.net/comment/2212166#comment-2212166
and many. many more.
@kaamil1984 "Is there any way to avoid spaghetti state machine?"
A well-written State Machine should not be "spaghetti"!
You will probably need several state machines; eg,
"any reference design for embedded modem driver that I can find on Github"
Some here:
2022-04-25 04:12 AM
The main objective of the modem driver is to translate the operating system’s requests to the wireless device into the wireless device’s internal representation. Therefore the modem drivers code should be as generic as possible and it should be as small as possible.
2022-05-25 12:32 PM
Thanks guys,
Thanks @Andrew Neil for posting link that goes to attentive which is very interesting library.