The State Pattern solves many problems, untangles the code and saves one’s sanity.
Disclaimer: I love state machines . Thrown at the right problems they are quite useful.
Since we (potentially) have bee scales in different roles in different configurations doing very similar things I thought it would be useful to draw a little graph. Please comment.
The graph assumes the following:
There are 3 types of scales
- Solo - sends data directly to Kotori
- Node - sends data to a gateway
- Gateway - collects data from nodes and sends them to Kotori
Depending on the infrastructure at hand there are different radio hardware requirements for the three.
A gateway may or may not be a scale itself.
Each scale can be in one of theses modes:
- Normal - use deep sleep
- Maintenance - temporary, use light sleep
- Power - permanent, use light sleep
Power is for scales that are attached to net power and don’t need to save energy. The difference to maintenance is that it is switched from normal for a time only and will automatically fall back.
The graph is obviously not very detailed but I hope it gives a good overview. I’ve changed it three times will writing this post. I’m sure this is not the final version.