forked from pbosetti/gv_fsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.h
80 lines (67 loc) · 2.87 KB
/
example.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/******************************************************************************
Finite State Machine
Project: sm.dot
Description: <none given>
Generated by gv_fsm ruby gem, see https://rubygems.org/gems/gv_fsm
gv_fsm version 0.2.1
Generation date: 2020-08-31 12:03:07 +0200
Generated from: sm.dot
The finite state machine has:
5 states
5 transition functions
Functions and types have been generated with prefix "fsm_"
******************************************************************************/
#ifndef EXAMPLE_H
#define EXAMPLE_H
#include <stdlib.h>
// State data object
// By default set to void; override this typedef or load the proper
// header if you need
typedef void fsm_state_data_t;
// NOTHING SHALL BE CHANGED AFTER THIS LINE!
// List of states
typedef enum {
FSM_STATE_INIT = 0,
FSM_STATE_IDLE,
FSM_STATE_SETUP,
FSM_STATE_RUNNING,
FSM_STATE_STOP,
FSM_NUM_STATES,
FSM_NO_CHANGE
} fsm_state_t;
const char *state_names[] = {"init", "idle", "setup", "running", "stop"};
// State function and state transition prototypes
typedef fsm_state_t state_func_t(fsm_state_data_t *data);
typedef void transition_func_t(fsm_state_data_t *data);
// State functions
fsm_state_t fsm_do_init(fsm_state_data_t *data);
fsm_state_t fsm_do_idle(fsm_state_data_t *data);
fsm_state_t fsm_do_setup(fsm_state_data_t *data);
fsm_state_t fsm_do_running(fsm_state_data_t *data);
fsm_state_t fsm_do_stop(fsm_state_data_t *data);
// List of state functions
state_func_t *const fsm_state_table[FSM_NUM_STATES] = {
fsm_do_init, // in state init
fsm_do_idle, // in state idle
fsm_do_setup, // in state setup
fsm_do_running, // in state running
fsm_do_stop, // in state stop
};
// Transition functions
void fsm_init_to_idle(fsm_state_data_t *data);
void fsm_stay(fsm_state_data_t *data);
void fsm_to_setup(fsm_state_data_t *data);
void fsm_setup_to_running(fsm_state_data_t *data);
void fsm_to_idle(fsm_state_data_t *data);
// Table of transition functions
transition_func_t *const fsm_transition_table[FSM_NUM_STATES][FSM_NUM_STATES] = {
/* states: init , idle , setup , running , stop */
/* init */ {NULL , fsm_init_to_idle , NULL , NULL , NULL },
/* idle */ {NULL , fsm_stay , fsm_to_setup , NULL , NULL },
/* setup */ {NULL , NULL , NULL , fsm_setup_to_running, NULL },
/* running */ {NULL , fsm_to_idle , NULL , fsm_stay , NULL },
/* stop */ {NULL , NULL , NULL , NULL , NULL },
};
// state manager
fsm_state_t fsm_run_state(fsm_state_t cur_state, void *data);
#endif