Re:State Machines
by nova on Tuesday May 15, 2012 @04:37AM
(#3975597)
I like the approach of "Practical UML Statecharts in C/C++", at least the simple one. More or less, keep the state on a function pointer, each state is represented by a function which gets incoming messages or events and returns the next state. I used it for a RS485 protocol running on a microcontroller quite successfully.
[ Parent
| on HN ]
Re:State Machines
by pierrebouchet on Tuesday May 15, 2012 @05:56AM
(#3975768)
There is also the HSM (hierarchical state machine) extension of this concept (by the same author, not sure it's in the same book) where a given state either handles an event or returns a pointer to a "superstate" that handles it.
This kind of "behavioral inheritance" allows for a much more compact code.
Compact and efficient state machines are immensely useful when working with small microcontrollers that don't even run an OS.