gv_fsm 0.1.0 → 0.1.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/bin/gv_fsm +3 -0
- data/lib/gv_fsm.rb +10 -0
- data/lib/templates.rb +56 -8
- 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: 9cdb522af0bd9bac3a853e75ad379b063657a6bd21ceb2fcad80c427ca6c00ed
|
4
|
+
data.tar.gz: 350cd6c0dbdbe1e3ff03f8e26eda97b16be7764dc7f5c244a98b3e0997d50b3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b623ee5a2d45345ff3ab13db5605ffa978b30add3b0ca912588d531fbf81f13b3f5a3210b02bbcee29e736115a10b936201e57828635d81c9c2c82eec869e74
|
7
|
+
data.tar.gz: bc2584dfcc1025b41499bc66ff85113eb2b440031467e1ac74a44450717cc48850cc4c35cfe8594262b59ac6d3e0164c766f439aa9f8eaf6e36e6cdc790262d9
|
data/bin/gv_fsm
CHANGED
@@ -11,6 +11,7 @@ OptionParser.new do |parser|
|
|
11
11
|
Graphviz to Finite State Machine generator
|
12
12
|
Version: #{GV_FSM::VERSION}
|
13
13
|
See also https://github.com/pbosetti/gv_fsm
|
14
|
+
|
14
15
|
Usage: gv_fsm [options] scheme.dot
|
15
16
|
EOB
|
16
17
|
|
@@ -50,3 +51,5 @@ if options[:source] then
|
|
50
51
|
sm.generate_c
|
51
52
|
puts "Generated source #{sm.cname}.c"
|
52
53
|
end
|
54
|
+
|
55
|
+
|
data/lib/gv_fsm.rb
CHANGED
@@ -31,6 +31,7 @@ module GV_FSM
|
|
31
31
|
g.each_edge do |e|
|
32
32
|
from = e.node_one
|
33
33
|
to = e.node_two
|
34
|
+
next unless e[:label]
|
34
35
|
case e[:label].source
|
35
36
|
when ""
|
36
37
|
label = nil
|
@@ -82,6 +83,15 @@ module GV_FSM
|
|
82
83
|
return dest
|
83
84
|
end
|
84
85
|
|
86
|
+
def transitions_paths
|
87
|
+
path = {}
|
88
|
+
@transitions.each do |t|
|
89
|
+
path[t[:function]] = [] unless path[t[:function]]
|
90
|
+
path[t[:function]] << {from: t[:from], to: t[:to]}
|
91
|
+
end
|
92
|
+
return path
|
93
|
+
end
|
94
|
+
|
85
95
|
def generate_c(filename = @cname)
|
86
96
|
File.open("#{filename}.c", "w") do |f|
|
87
97
|
f.puts ERB.new(HEADER, 0, "<>").result(binding)
|
data/lib/templates.rb
CHANGED
@@ -41,17 +41,18 @@ module GV_FSM
|
|
41
41
|
state_t <%= s[:function] %>(void *data);
|
42
42
|
<% end %>
|
43
43
|
|
44
|
+
// List of state functions
|
45
|
+
state_func_t *const state_table[NUM_STATES] = {
|
46
|
+
<%= self.state_functions_list.join(",\n ")%>
|
47
|
+
};
|
48
|
+
|
49
|
+
<% if self.transition_functions_list.count > 0 then %>
|
44
50
|
// transition functions
|
45
51
|
<% self.transition_functions_list.each do |t| %>
|
46
52
|
<% next if t == "NULL" %>
|
47
53
|
void <%= t %>(void *data);
|
48
54
|
<% end %>
|
49
55
|
|
50
|
-
// List of state functions
|
51
|
-
state_func_t *const state_table[NUM_STATES] = {
|
52
|
-
<%= self.state_functions_list.join(",\n ")%>
|
53
|
-
};
|
54
|
-
|
55
56
|
// Table of transition functions
|
56
57
|
transition_func_t *const transition_table[NUM_STATES][NUM_STATES] = {
|
57
58
|
<% sl = self.states_list %>
|
@@ -62,6 +63,9 @@ module GV_FSM
|
|
62
63
|
/* <%= sl[i].ljust(sw) %> */ {<%= l.map {|e| e.ljust(fw)}.join(", ") %>},
|
63
64
|
<% end %>
|
64
65
|
};
|
66
|
+
<% else %>
|
67
|
+
// No transition functions
|
68
|
+
<% end %>
|
65
69
|
|
66
70
|
// state manager
|
67
71
|
state_t run_state(state_t cur_state, void *data);
|
@@ -73,7 +77,18 @@ module GV_FSM
|
|
73
77
|
#include <syslog.h>
|
74
78
|
#include "<%= self.cname %>.h"
|
75
79
|
|
76
|
-
//
|
80
|
+
// ____ _ _
|
81
|
+
// / ___|| |_ __ _| |_ ___
|
82
|
+
// \\___ \\| __/ _` | __/ _ \\
|
83
|
+
// ___) | || (_| | || __/
|
84
|
+
// |____/ \\__\\__,_|\\__\\___|
|
85
|
+
//
|
86
|
+
// __ _ _
|
87
|
+
// / _|_ _ _ __ ___| |_(_) ___ _ __ ___
|
88
|
+
// | |_| | | | '_ \\ / __| __| |/ _ \\| '_ \\/ __|
|
89
|
+
// | _| |_| | | | | (__| |_| | (_) | | | \\__ \\
|
90
|
+
// |_| \\__,_|_| |_|\\___|\\__|_|\\___/|_| |_|___/
|
91
|
+
//
|
77
92
|
<% dest = self.destinations.dup %>
|
78
93
|
<% self.states.each do |s| %>
|
79
94
|
<% stable = true if dest[s[:id]].include? s[:id] %>
|
@@ -81,6 +96,7 @@ module GV_FSM
|
|
81
96
|
<% if dest[s[:id]].empty? or stable then
|
82
97
|
dest[s[:id]].unshift "NO_CHANGE"
|
83
98
|
end %>
|
99
|
+
// To be executed in state <%= s[:id] %>
|
84
100
|
state_t <%= s[:function] %>(void *data) {
|
85
101
|
state_t next_state = <%= dest[s[:id]].first %>;
|
86
102
|
|
@@ -102,22 +118,54 @@ module GV_FSM
|
|
102
118
|
|
103
119
|
<% end %>
|
104
120
|
|
105
|
-
|
121
|
+
<% if self.transition_functions_list.count > 0 then %>
|
122
|
+
// _____ _ _ _
|
123
|
+
// |_ _| __ __ _ _ __ ___(_) |_(_) ___ _ __
|
124
|
+
// | || '__/ _` | '_ \\/ __| | __| |/ _ \\| '_ \\
|
125
|
+
// | || | | (_| | | | \\__ \\ | |_| | (_) | | | |
|
126
|
+
// |_||_| \\__,_|_| |_|___/_|\\__|_|\\___/|_| |_|
|
127
|
+
//
|
128
|
+
// __ _ _
|
129
|
+
// / _|_ _ _ __ ___| |_(_) ___ _ __ ___
|
130
|
+
// | |_| | | | '_ \\ / __| __| |/ _ \\| '_ \\/ __|
|
131
|
+
// | _| |_| | | | | (__| |_| | (_) | | | \\__ \\
|
132
|
+
// |_| \\__,_|_| |_|\\___|\\__|_|\\___/|_| |_|___/
|
133
|
+
//
|
134
|
+
|
106
135
|
<% self.transition_functions_list.each do |t| %>
|
107
136
|
<% next if t == "NULL" %>
|
137
|
+
// This function is called in transitions:
|
138
|
+
<% self.transitions_paths[t].each do |e| %>
|
139
|
+
// from <%= e[:from] %> to <%= e[:to] %>
|
140
|
+
<% end %>
|
108
141
|
void <%= t %>(void *data) {
|
109
142
|
syslog(LOG_INFO, "[FSM] State transition <%= t %>");
|
110
143
|
/* Your code here */
|
111
144
|
}
|
112
145
|
|
113
146
|
<% end %>
|
147
|
+
<% end %>
|
148
|
+
|
149
|
+
// ____ _ _
|
150
|
+
// / ___|| |_ __ _| |_ ___
|
151
|
+
// \\___ \\| __/ _` | __/ _ \\
|
152
|
+
// ___) | || (_| | || __/
|
153
|
+
// |____/ \\__\\__,_|\\__\\___|
|
154
|
+
//
|
155
|
+
//
|
156
|
+
// _ __ ___ __ _ _ __ __ _ __ _ ___ _ __
|
157
|
+
// | '_ ` _ \\ / _` | '_ \\ / _` |/ _` |/ _ \\ '__|
|
158
|
+
// | | | | | | (_| | | | | (_| | (_| | __/ |
|
159
|
+
// |_| |_| |_|\\__,_|_| |_|\\__,_|\\__, |\\___|_|
|
160
|
+
// |___/
|
114
161
|
|
115
|
-
// State manager
|
116
162
|
state_t run_state(state_t cur_state, void *data) {
|
117
163
|
state_t new_state = state_table[cur_state](data);
|
164
|
+
<% if self.transition_functions_list.count > 0 then %>
|
118
165
|
transition_func_t *transition = transition_table[cur_state][new_state];
|
119
166
|
if (transition)
|
120
167
|
transition(data);
|
168
|
+
<% end %>
|
121
169
|
return new_state == NO_CHANGE ? cur_state : new_state;
|
122
170
|
};
|
123
171
|
|
data/lib/version.rb
CHANGED