gv_fsm 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/templates.rb +52 -34
  3. data/lib/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 450afef3dccacff09f92f297a5b5bcbdfb9d1c960bea0d546bcafe7123f5cebd
4
- data.tar.gz: 1fa684d748abecd8c8f17ac2a2b7ca17c83506003eb2cc143596668a32d0a1ea
3
+ metadata.gz: 2896e7f9617c0ed1a9917e78cd947d1da5ceef2d8554727a4db268a7f70e6229
4
+ data.tar.gz: 63d897002c102d5291ecbfd7b4c854f8c9fc029e01155ba573d13e2043621afb
5
5
  SHA512:
6
- metadata.gz: 98d883a1bff3afaae6fe1531a8f702b6600c97bd37fa4260b3eef02ecccfaf978ab3a9acc096a0c62d9d95c2b4450df105a5cc38f1a03f624984813c9ac5bcb9
7
- data.tar.gz: 20af124b281a5aeba975d5124c4a552480d03ea9d4cb13903f4c60f3408c28876adf12a040455dd48afb98ebed8dedb0ee65121e6e93e0d3c9d854a43e4fea57
6
+ metadata.gz: ae5be7ee072d06983c139320227c6b234d703b2556071df085cb3f6a3365d3d1c6a8cf38f9f6daac0b866ed5b77c4726933eee69eda7aa8d9ffe17b9f2c2ca0b
7
+ data.tar.gz: bd1129ccf730d930b42a8ba53f83eb2adeb6d66368ebd9aab6466c69e2b951d6b461d0e04579254153d2c753c390f16f023806040615e6ac52d53f3b2f60c71a
@@ -2,18 +2,23 @@
2
2
  module GV_FSM
3
3
  module Templates
4
4
  HEADER =<<~EOHEADER
5
- // Finite State Machine
6
- // Project: <%= @project_name or @dotfile %>
7
- // Description: <%= @description or "<none given>" %>
8
- //
9
- // Generated by gv_fsm ruby gem, see https://rubygems.org/gems/gv_fsm
10
- // gv_fsm version <%= GV_FSM::VERSION %>
11
- // Generation date: <%= Time.now %>
12
- // Generated from: <%= @dotfile %>
13
- // The finite state machine has:
14
- // <%= @states.count %> states
15
- // <%= @transitions.count %> transitions
16
- // <%= transition_functions_list.select {|e| e != 'NULL'}.count %> transition functions
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(void *data);
38
- typedef void transition_func_t(void *data);
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
- // state functions
52
+ // State functions
41
53
  <% @states.each do |s| %>
42
- state_t <%= s[:function] %>(void *data);
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
- <%= state_functions_list.join(",\n ")%>
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
- // transition functions
65
+ // Transition functions
52
66
  <% transition_functions_list.each do |t| %>
53
67
  <% next if t == "NULL" %>
54
- void <%= t %>(void *data);
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
- // To be executed in state <%= s[:id] %>
101
- state_t <%= s[:function] %>(void *data) {
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
- /* Your code here */
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
- // This function is called in transitions:
139
- <% transitions_paths[t].each do |e| %>
140
- // from <%= e[:from] %> to <%= e[:to] %>
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 %>(void *data) {
160
+ void <%= t %>(<%= @prefix %>state_data_t *data) {
143
161
  syslog(LOG_INFO, "[FSM] State transition <%= t %>");
144
- /* Your code here */
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, void *data) {
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;
@@ -1,3 +1,3 @@
1
1
  module GV_FSM
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gv_fsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Bosetti