Modem State Machine

This week was an intense week. The week started with me demonstrating the modem to Dr. Shawn and with a short check of the modem’s code by him. He noticed that there was no obvious state machine in the code which prompted a rewrite of the code to include one. From that, I spent a day or two rewriting the code to incorporate the state machine and also the buffered commands that was required for a typical modem. Dr. Shawn then looked at the code once again and pointed out that the code was too long for a simple modem state machine. He then gave some advice on a few techniques that can be used to shorten and simplify the code ranging from directly using the numeric values of enums to avoiding unnecessary checks in the code. However since I did not have much time left, he told me to focus on getting a stable working modem first, making sure that stuff that is expected to work will work and stuff that is not supposed to work, doesn’t work before attempting to shorten the modem’s state machine code. Since the buffering part of the modem was not perfect anyways, I decided to rewrite the code once again, but this time with an emphasis on readability and cleanliness of the code.

I started again by carefully planning out the state machine of the modem before rewriting the code, this time at a slower pace, taking extra care not to copy-paste any code either by making use of fall-throughs in switch-cases or using functions to carry out reusable code. Even so for the functions, I made sure not to create any additional functions solely because a piece of code can be reused more than once unless there is better reason to do so which prompted a lot of planning and thinking on how best to structure the code. After the rewrite, and thanks to a trick or two from Dr. Shawn on how to simplify the code, it was great being able to see the code being cut down by ~200 lines which made the code a lot more readable. The next day, I demonstrated the modem together with showing the source code to Dr. Shawn. He also conducted his own tests on the modem to simulate the usage of the modem and thankfully there were no serious issues during testing. There were however, some limitations of the modem like the inability of it to receive multiple connections when listening on a single port so that would need to be documented. With a working modem done, I concluded my part of the project by documenting the functionalities and limitations of the modem.

This blog post concludes my journey with Aeste. From starting off with good old front-end C++ web development, to simple back-end RESTful APIs with a dash of front-end JavaScript, to drowning in firmware development for the company’s latest boards, it was an exciting and memorable journey to say the least. I would like to take this opportunity to thank the great people that I met at Aeste for making my time there all the more colourful, with all your unique experiences bringing different perspectives to life. Special thanks to Dr. Shawn too for giving this high-school kid the rare chance to contribute my small part to Aeste, and also especially for being patient with my ‘noobness’ in some of the work I did during my time there. At times, I sometimes wish that I would have done a better job if not for my lack of experience in many aspects, but hey, everyone has to start somewhere right!

You may also like...

Leave a Reply