Skip to content

thesilex/MealyFSMGenerator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MealyFSMGenerator (Mealy)

version: 0.1.0

This mealy state machine generator will generates c code together with its unit test from draw.io graph. The generator is written in a modular way, so it can easily extended to support other languages and other input sources.

Key words used in the state machine generator are state, condition and transition function. It can describe the mealy state machine behavior: In state A, condition occurs, state machine should call a transition function and go to state B.


How to use:

Prerequisites

  • pip3 install bs4
  • sudo apt-get install python3-lxml

Step 1: Create the state machine graph.

State machine in draw.io can be created following the example given in below:

Example

Patterns to follow:

  1. States should start with unique number
  2. Condition should start with unique number
  3. Transition with single direction arrow should start from one state to another state.
  4. Each transition line should come with condition and transition function in a new line.
  5. Condition and transition function must be created on the transition line (not creating a text and move to the line).

Once the graph is generated, use drawio build-in export function to export the graph in xml format by:

File->Export As->xml

Make sure don't select compressed.

DontUseCompress

Step 2: Generate the code

By calling:

main.py -i <pathToXML> -n <StateMachineName>

After this step, you should be able to find the result in Result folder where you execute the main file.

Step 3: Execute Unit Test

In Result/unit_test/ folder, execute following command:

ceedling

You should not see any reported error.

The Unit test is based on ceedling which checks:

  1. If the state number is same as the one in the graph.
  2. If the condition number is same as the one in the graph.
  3. If the transition function is the same as the one in the graph.
  4. Size of the Transition table is not changed.
  5. The transition parameters (state, condition, next state, transition function) is same as the one in the graph.

By enabling this unit_test, any manual change (exception is filling in the function slots) to the generated files will trigger a unit test failure.


Result Folder

|
|--src                          # source folder
    |--fsmMgr                   # common code for all state machines
    |     |--MealyFSM.c         
    |     |--MealyFSM.h
    |--xxxSMFunc.c              # generated state machine code
    |--xxxSMFunc.h
    |--xxxSMTable.inc
|--unit_test                    # unit test folder
    |-- test                    # folder containing test files
         |-- test_xxx.c         # test file for the generated code
    |-- vendor                  # unit test plug-ins

## License

Licensed under MIT.

About

Finite state machine embedded C code generator from draw.io graph for Embedded C.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Python 92.6%
  • C 6.3%
  • Other 1.1%