gv_fsm 0.2.2 → 0.2.3
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/gv_fsm.rb +2 -1
- data/lib/templates.rb +31 -17
- 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: 48a490d68d563a441424cfdd79c6c6051d30d4b6e55765239936aed794a898a5
|
4
|
+
data.tar.gz: fc16d72b89d439ae9b18f021e46a9cbf1c5caf4b48ed71a45bad2db72998005b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff52872fa8b822d0b63085cf1721bff88123d64112d3ba1103bdaf6da7e5eb1e801f5fed4526d029128b0853ab1527c45f1fc625d61cc37a9350c81709c5a578
|
7
|
+
data.tar.gz: 2d4c28d766e9c34bbe379af163f3302f53501870497df608142c7b67e9f02059846944d17ecac780c4d732a68be00eb790625ffbbd6d2d90b4040c764ea6dcea
|
data/lib/gv_fsm.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'ruby-graphviz'
|
4
4
|
require 'erb'
|
5
|
-
|
5
|
+
require 'pry'
|
6
6
|
require File.expand_path('../templates.rb', __FILE__)
|
7
7
|
require File.expand_path("../version.rb", __FILE__)
|
8
8
|
|
@@ -32,6 +32,7 @@ module GV_FSM
|
|
32
32
|
GraphViz.parse(filename) do |g|
|
33
33
|
g.each_node do |id|
|
34
34
|
n = g.get_node(id)
|
35
|
+
binding.pry
|
35
36
|
label = n[:label].source.empty? ? "do_#{id}" : n[:label].source
|
36
37
|
@states << {id: id, function: @prefix+label}
|
37
38
|
end
|
data/lib/templates.rb
CHANGED
@@ -47,7 +47,7 @@ module GV_FSM
|
|
47
47
|
} <%= @prefix %>state_t;
|
48
48
|
|
49
49
|
// State human-readable names
|
50
|
-
const char *state_names[]
|
50
|
+
extern const char *state_names[];
|
51
51
|
|
52
52
|
<% if transition_functions_list.count > 0 then %>
|
53
53
|
// State function and state transition prototypes
|
@@ -73,12 +73,7 @@ module GV_FSM
|
|
73
73
|
|
74
74
|
|
75
75
|
// List of state functions
|
76
|
-
|
77
|
-
state_func_t *const <%= @prefix %>state_table[<%= @prefix.upcase %>NUM_STATES] = {
|
78
|
-
<% @states.each do |s| %>
|
79
|
-
<%= (s[:function] + ',').ljust(fw+1) %> // in state <%= s[:id] %>
|
80
|
-
<% end %>
|
81
|
-
};
|
76
|
+
extern state_func_t *const <%= @prefix %>state_table[<%= @prefix.upcase %>NUM_STATES];
|
82
77
|
|
83
78
|
|
84
79
|
<% if transition_functions_list.count > 0 then %>
|
@@ -89,21 +84,13 @@ module GV_FSM
|
|
89
84
|
<% end %>
|
90
85
|
|
91
86
|
// Table of transition functions
|
92
|
-
transition_func_t *const <%= @prefix %>transition_table[<%= @prefix.upcase %>NUM_STATES][<%= @prefix.upcase %>NUM_STATES]
|
93
|
-
<% sl = states_list %>
|
94
|
-
<% fw = transition_functions_list.max {|a, b| a.length <=> b.length}.length %>
|
95
|
-
<% sw = states_list.max {|a, b| a.length <=> b.length}.length %>
|
96
|
-
/* <%= "states:".ljust(sw) %> <%= sl.map {|e| e.ljust(fw) }.join(", ") %> */
|
97
|
-
<% transitions_map.each_with_index do |l, i| %>
|
98
|
-
/* <%= sl[i].ljust(sw) %> */ {<%= l.map {|e| e.ljust(fw)}.join(", ") %>},
|
99
|
-
<% end %>
|
100
|
-
};
|
87
|
+
extern transition_func_t *const <%= @prefix %>transition_table[<%= @prefix.upcase %>NUM_STATES][<%= @prefix.upcase %>NUM_STATES];
|
101
88
|
<% else %>
|
102
89
|
// No transition functions
|
103
90
|
<% end %>
|
104
91
|
|
105
92
|
// state manager
|
106
|
-
<%= @prefix %>state_t <%= @prefix %>run_state(<%= @prefix %>state_t cur_state,
|
93
|
+
<%= @prefix %>state_t <%= @prefix %>run_state(<%= @prefix %>state_t cur_state, state_data_t *data);
|
107
94
|
|
108
95
|
<% if !@ino then %>
|
109
96
|
#endif
|
@@ -121,6 +108,33 @@ module GV_FSM
|
|
121
108
|
<% placeholder = "Your Code Here" %>
|
122
109
|
// SEARCH FOR <%= placeholder %> FOR CODE INSERTION POINTS!
|
123
110
|
|
111
|
+
// GLOBALS
|
112
|
+
// State human-readable names
|
113
|
+
const char *state_names[] = {<%= states_list.map {|sn| '"'+sn+'"'}.join(", ") %>};
|
114
|
+
|
115
|
+
// List of state functions
|
116
|
+
<% fw = state_functions_list.max {|a, b| a.length <=> b.length}.length %>
|
117
|
+
state_func_t *const <%= @prefix %>state_table[<%= @prefix.upcase %>NUM_STATES] = {
|
118
|
+
<% @states.each do |s| %>
|
119
|
+
<%= (s[:function] + ',').ljust(fw+1) %> // in state <%= s[:id] %>
|
120
|
+
<% end %>
|
121
|
+
};
|
122
|
+
<% if transition_functions_list.count > 0 then %>
|
123
|
+
|
124
|
+
// Table of transition functions
|
125
|
+
transition_func_t *const <%= @prefix %>transition_table[<%= @prefix.upcase %>NUM_STATES][<%= @prefix.upcase %>NUM_STATES] = {
|
126
|
+
<% sl = states_list %>
|
127
|
+
<% fw = transition_functions_list.max {|a, b| a.length <=> b.length}.length %>
|
128
|
+
<% sw = [states_list, "states:"].flatten.max {|a, b| a.length <=> b.length}.length %>
|
129
|
+
/* <%= "states:".ljust(sw) %> <%= sl.map {|e| e.ljust(fw) }.join(", ") %> */
|
130
|
+
<% transitions_map.each_with_index do |l, i| %>
|
131
|
+
/* <%= sl[i].ljust(sw) %> */ {<%= l.map {|e| e.ljust(fw)}.join(", ") %>},
|
132
|
+
<% end %>
|
133
|
+
};
|
134
|
+
<% else %>
|
135
|
+
// No transition functions
|
136
|
+
<% end %>
|
137
|
+
|
124
138
|
// ____ _ _
|
125
139
|
// / ___|| |_ __ _| |_ ___
|
126
140
|
// \\___ \\| __/ _` | __/ _ \\
|
data/lib/version.rb
CHANGED