gv_fsm 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/templates.rb +52 -34
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2896e7f9617c0ed1a9917e78cd947d1da5ceef2d8554727a4db268a7f70e6229
|
4
|
+
data.tar.gz: 63d897002c102d5291ecbfd7b4c854f8c9fc029e01155ba573d13e2043621afb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae5be7ee072d06983c139320227c6b234d703b2556071df085cb3f6a3365d3d1c6a8cf38f9f6daac0b866ed5b77c4726933eee69eda7aa8d9ffe17b9f2c2ca0b
|
7
|
+
data.tar.gz: bd1129ccf730d930b42a8ba53f83eb2adeb6d66368ebd9aab6466c69e2b951d6b461d0e04579254153d2c753c390f16f023806040615e6ac52d53f3b2f60c71a
|
data/lib/templates.rb
CHANGED
@@ -2,18 +2,23 @@
|
|
2
2
|
module GV_FSM
|
3
3
|
module Templates
|
4
4
|
HEADER =<<~EOHEADER
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
/******************************************************************************
|
6
|
+
Finite State Machine
|
7
|
+
Project: <%= @project_name or @dotfile %>
|
8
|
+
Description: <%= @description or "<none given>" %>
|
9
|
+
|
10
|
+
Generated by gv_fsm ruby gem, see https://rubygems.org/gems/gv_fsm
|
11
|
+
gv_fsm version <%= GV_FSM::VERSION %>
|
12
|
+
Generation date: <%= Time.now %>
|
13
|
+
Generated from: <%= @dotfile %>
|
14
|
+
The finite state machine has:
|
15
|
+
<%= @states.count %> states
|
16
|
+
<%= @transitions.count %> transitions
|
17
|
+
<%= transition_functions_list.select {|e| e != 'NULL'}.count %> transition functions
|
18
|
+
<% if @prefix != '' %>
|
19
|
+
Functions and types have been generated with prefix "<%= @prefix %>"
|
20
|
+
<% end %>
|
21
|
+
******************************************************************************/
|
17
22
|
|
18
23
|
EOHEADER
|
19
24
|
|
@@ -22,6 +27,13 @@ module GV_FSM
|
|
22
27
|
#define <%= @cname.upcase %>_H
|
23
28
|
#include <stdlib.h>
|
24
29
|
|
30
|
+
// State data object
|
31
|
+
// By default set to void; override this typedef or load the proper
|
32
|
+
// header if you need
|
33
|
+
typedef void <%= @prefix %>state_data_t;
|
34
|
+
|
35
|
+
// NOTHING SHALL BE CHANGED AFTER THIS LINE!
|
36
|
+
|
25
37
|
// List of states
|
26
38
|
typedef enum {
|
27
39
|
<% @states.each_with_index do |s, i| %>
|
@@ -29,29 +41,31 @@ module GV_FSM
|
|
29
41
|
<% end %>
|
30
42
|
<%= @prefix.upcase %>NUM_STATES,
|
31
43
|
<%= @prefix.upcase %>NO_CHANGE
|
32
|
-
} state_t;
|
44
|
+
} <%= @prefix %>state_t;
|
33
45
|
|
34
46
|
const char *state_names[] = {<%= states_list.map {|sn| '"'+sn+'"'}.join(", ") %>};
|
35
47
|
|
36
48
|
// State function and state transition prototypes
|
37
|
-
typedef state_t state_func_t(
|
38
|
-
typedef void transition_func_t(
|
49
|
+
typedef <%= @prefix %>state_t state_func_t(<%= @prefix %>state_data_t *data);
|
50
|
+
typedef void transition_func_t(<%= @prefix %>state_data_t *data);
|
39
51
|
|
40
|
-
//
|
52
|
+
// State functions
|
41
53
|
<% @states.each do |s| %>
|
42
|
-
state_t <%= s[:function] %>(
|
54
|
+
<%= @prefix %>state_t <%= s[:function] %>(<%= @prefix %>state_data_t *data);
|
43
55
|
<% end %>
|
44
56
|
|
45
57
|
// List of state functions
|
46
58
|
state_func_t *const <%= @prefix %>state_table[<%= @prefix.upcase %>NUM_STATES] = {
|
47
|
-
|
59
|
+
<% @states.each do |s| %>
|
60
|
+
<%= s[:function] %>, // in state <%= s[:id] %>
|
61
|
+
<% end %>
|
48
62
|
};
|
49
63
|
|
50
64
|
<% if transition_functions_list.count > 0 then %>
|
51
|
-
//
|
65
|
+
// Transition functions
|
52
66
|
<% transition_functions_list.each do |t| %>
|
53
67
|
<% next if t == "NULL" %>
|
54
|
-
void <%= t %>(
|
68
|
+
void <%= t %>(<%= @prefix %>state_data_t *data);
|
55
69
|
<% end %>
|
56
70
|
|
57
71
|
// Table of transition functions
|
@@ -69,7 +83,7 @@ module GV_FSM
|
|
69
83
|
<% end %>
|
70
84
|
|
71
85
|
// state manager
|
72
|
-
state_t <%= @prefix %>run_state(state_t cur_state, void *data);
|
86
|
+
<%= @prefix %>state_t <%= @prefix %>run_state(<%= @prefix %>state_t cur_state, void *data);
|
73
87
|
|
74
88
|
#endif
|
75
89
|
EOH
|
@@ -78,6 +92,9 @@ module GV_FSM
|
|
78
92
|
#include <syslog.h>
|
79
93
|
#include "<%= @cname %>.h"
|
80
94
|
|
95
|
+
<% placeholder = "Your Code Here" %>
|
96
|
+
// SEARCH FOR <%= placeholder %> FOR CODE INSERTION POINTS!
|
97
|
+
|
81
98
|
// ____ _ _
|
82
99
|
// / ___|| |_ __ _| |_ ___
|
83
100
|
// \\___ \\| __/ _` | __/ _ \\
|
@@ -97,12 +114,12 @@ module GV_FSM
|
|
97
114
|
<% if dest[s[:id]].empty? or stable then
|
98
115
|
dest[s[:id]].unshift @prefix.upcase+"NO_CHANGE"
|
99
116
|
end %>
|
100
|
-
//
|
101
|
-
state_t <%= s[:function] %>(
|
102
|
-
state_t next_state = <%= dest[s[:id]].first %>;
|
117
|
+
// Function to be executed in state <%= s[:id] %>
|
118
|
+
<%= @prefix %>state_t <%= s[:function] %>(<%= @prefix %>state_data_t *data) {
|
119
|
+
<%= @prefix %>state_t next_state = <%= dest[s[:id]].first %>;
|
103
120
|
|
104
121
|
syslog(LOG_INFO, "[FSM] In state <%= s[:id] %>");
|
105
|
-
/*
|
122
|
+
/* <%= placeholder %> */
|
106
123
|
|
107
124
|
// valid return states: <%= dest[s[:id]].join(", ") %>
|
108
125
|
switch (next_state) {
|
@@ -135,13 +152,14 @@ module GV_FSM
|
|
135
152
|
|
136
153
|
<% transition_functions_list.each do |t| %>
|
137
154
|
<% next if t == "NULL" %>
|
138
|
-
|
139
|
-
|
140
|
-
|
155
|
+
<% tpaths = transitions_paths[t] %>
|
156
|
+
// This function is called in <%= tpaths.count %> transition<%= tpaths.count == 1 ? '' : 's' %>:
|
157
|
+
<% tpaths.each_with_index do |e, i| %>
|
158
|
+
// <%= i+1 %>. from <%= e[:from] %> to <%= e[:to] %>
|
141
159
|
<% end %>
|
142
|
-
void <%= t %>(
|
160
|
+
void <%= t %>(<%= @prefix %>state_data_t *data) {
|
143
161
|
syslog(LOG_INFO, "[FSM] State transition <%= t %>");
|
144
|
-
/*
|
162
|
+
/* <%= placeholder %> */
|
145
163
|
}
|
146
164
|
|
147
165
|
<% end %>
|
@@ -160,8 +178,8 @@ module GV_FSM
|
|
160
178
|
// |_| |_| |_|\\__,_|_| |_|\\__,_|\\__, |\\___|_|
|
161
179
|
// |___/
|
162
180
|
|
163
|
-
state_t <%= @prefix %>run_state(state_t cur_state,
|
164
|
-
state_t new_state = <%= @prefix %>state_table[cur_state](data);
|
181
|
+
<%= @prefix %>state_t <%= @prefix %>run_state(<%= @prefix %>state_t cur_state, <%= @prefix %>state_data_t *data) {
|
182
|
+
<%= @prefix %>state_t new_state = <%= @prefix %>state_table[cur_state](data);
|
165
183
|
<% if transition_functions_list.count > 0 then %>
|
166
184
|
transition_func_t *transition = <%= @prefix %>transition_table[cur_state][new_state];
|
167
185
|
if (transition)
|
@@ -174,11 +192,11 @@ module GV_FSM
|
|
174
192
|
#ifdef TEST_MAIN
|
175
193
|
#include <unistd.h>
|
176
194
|
int main() {
|
177
|
-
state_t cur_state = <%= @prefix.upcase %>STATE_INIT;
|
195
|
+
<%= @prefix %>state_t cur_state = <%= @prefix.upcase %>STATE_INIT;
|
178
196
|
openlog("SM", LOG_PID | LOG_PERROR, LOG_USER);
|
179
197
|
syslog(LOG_INFO, "Starting SM");
|
180
198
|
do {
|
181
|
-
cur_state = run_state(cur_state, NULL);
|
199
|
+
cur_state = <%= @prefix %>run_state(cur_state, NULL);
|
182
200
|
sleep(1);
|
183
201
|
} while (cur_state != <%= @prefix.upcase %>STATE_STOP);
|
184
202
|
return 0;
|
data/lib/version.rb
CHANGED