A finite-state machine can be implemented in a few minutes on the command line or in a bash script using
Assume we have the following state machine:
It has the following events and states:
- sensor closed
- sensor opened
The state transition table can be expressed in a csv file state-transition.csv:
With the state transition table,
csv-join can read in events, output the next state and keep track of this new state. Here is an example usage (input is marked '<', output '>'):
The input field and joining key in this case is a single field
event. As usual with csv-join any number of fields can be used to represent an event. The following example has the event represented by two fields: operation and result.
csv-join expects the state transition table to contain unique matches only (as per csv-join --unique).
The finite-state machine is only activated when the file/stream fields contain both 'state' and 'next_state'.