gv_fsm 0.2.6 → 0.2.7
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 +14 -1
- data/lib/gv_fsm.rb +20 -1
- data/lib/templates.rb +7 -2
- 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: 1706418c51873674098f304fe267d662d211728675db2ca78687efcb49b2ba95
|
4
|
+
data.tar.gz: 991b5f7b6d1173d4e08a9635ebbce25f654c88521a913ce7514a51e09cd1d3fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f2d8954ab0a5a009bd5cf6b31ca7d6927a680681e81dbd3a70d0aaa598234b8c71e91098c6e1aa011244ec05973611184b9c22bbbd28d32a1ff90e7e89350f9
|
7
|
+
data.tar.gz: 0b8d6e7a3fe3fe9434d3d58371b38edf5a82651cd9b9fdffec415c531ee0deaea6418ddce70520d19c20d4e83f044c9e51cb5bb53964827b9eaae762621d59e9
|
data/bin/gv_fsm
CHANGED
@@ -73,7 +73,20 @@ unless sm.parse(ARGV[0]) then
|
|
73
73
|
exit 3
|
74
74
|
end
|
75
75
|
|
76
|
-
puts "Parsed #{sm.dotfile}
|
76
|
+
puts "Parsed #{sm.dotfile}"
|
77
|
+
top = sm.topology
|
78
|
+
puts "Graph topology:"
|
79
|
+
puts " Pure source nodes: #{top[:sources].join(', ')}"
|
80
|
+
puts " Pure sink nodes: #{top[:sinks].empty? ? "<none>" : top[:sinks].join(', ')}"
|
81
|
+
|
82
|
+
if !(top[:sources].count == 1 and top[:sinks].count <= 1) then
|
83
|
+
puts "Topology error: there must be exactly one source and zero or one sink"
|
84
|
+
exit 4
|
85
|
+
end
|
86
|
+
|
87
|
+
puts "Generating C functions for states: #{sm.states_list.join(", ")}."
|
88
|
+
puts " for transition: #{sm.transition_functions_list.join(", ")}."
|
89
|
+
|
77
90
|
|
78
91
|
if options[:header] then
|
79
92
|
name = sm.generate_h
|
data/lib/gv_fsm.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'ruby-graphviz'
|
4
4
|
require 'erb'
|
5
|
+
require 'matrix'
|
5
6
|
|
6
7
|
require File.expand_path('../templates.rb', __FILE__)
|
7
8
|
require File.expand_path("../version.rb", __FILE__)
|
@@ -17,6 +18,8 @@ module GV_FSM
|
|
17
18
|
@syslog = true
|
18
19
|
@ino = false
|
19
20
|
@error = nil
|
21
|
+
@matrix = nil
|
22
|
+
@nodemap = {}
|
20
23
|
parse(filename) if filename
|
21
24
|
end
|
22
25
|
|
@@ -39,11 +42,14 @@ module GV_FSM
|
|
39
42
|
@error = "Graph is not directed"
|
40
43
|
return nil
|
41
44
|
end
|
42
|
-
|
45
|
+
n = g.node_count
|
46
|
+
if n == 0 then
|
43
47
|
@error = "Graph is empty"
|
44
48
|
return nil
|
45
49
|
end
|
50
|
+
@matrix = Matrix.zero(n, n)
|
46
51
|
@description = g.name
|
52
|
+
i = 0
|
47
53
|
g.each_node do |id|
|
48
54
|
n = g.get_node(id)
|
49
55
|
if n[:label].source.empty? or
|
@@ -52,9 +58,12 @@ module GV_FSM
|
|
52
58
|
else
|
53
59
|
label = n[:label].source
|
54
60
|
end
|
61
|
+
@nodemap[id] = i
|
62
|
+
i += 1
|
55
63
|
@states << {id: id, function: @prefix+label}
|
56
64
|
end
|
57
65
|
g.each_edge do |e|
|
66
|
+
@matrix[@nodemap[e.node_one], @nodemap[e.node_two]] += 1
|
58
67
|
from = e.node_one
|
59
68
|
to = e.node_two
|
60
69
|
unless e[:label] then
|
@@ -145,6 +154,16 @@ module GV_FSM
|
|
145
154
|
return fname
|
146
155
|
end
|
147
156
|
|
157
|
+
def topology
|
158
|
+
res = {matrix: @matrix}
|
159
|
+
# rows have the number of froms, columns the number of tos
|
160
|
+
res[:froms] = @matrix.row_vectors.map {|v| v.sum }
|
161
|
+
res[:tos] = @matrix.column_vectors.map {|v| v.sum }
|
162
|
+
res[:sinks] = res[:froms].each_index.select {|i| res[:froms][i] == 0}.map {|i| @nodemap.keys[i]}
|
163
|
+
res[:sources] = res[:tos].each_index.select {|i| res[:tos][i] == 0}.map {|i| @nodemap.keys[i]}
|
164
|
+
return res
|
165
|
+
end
|
166
|
+
|
148
167
|
end
|
149
168
|
|
150
169
|
end
|
data/lib/templates.rb
CHANGED
@@ -258,10 +258,11 @@ module GV_FSM
|
|
258
258
|
}
|
259
259
|
*/
|
260
260
|
<% else %>
|
261
|
+
<% nsinks = topology[:sinks].count %>
|
261
262
|
#ifdef TEST_MAIN
|
262
263
|
#include <unistd.h>
|
263
264
|
int main() {
|
264
|
-
<%= @prefix %>state_t cur_state = <%= @prefix.upcase %>
|
265
|
+
<%= @prefix %>state_t cur_state = <%= @prefix.upcase %>STATE_<%= @states.first[:id].upcase %>;
|
265
266
|
<% if @syslog then %>
|
266
267
|
openlog("SM", LOG_PID | LOG_PERROR, LOG_USER);
|
267
268
|
syslog(LOG_INFO, "Starting SM");
|
@@ -269,7 +270,11 @@ module GV_FSM
|
|
269
270
|
do {
|
270
271
|
cur_state = <%= @prefix %>run_state(cur_state, NULL);
|
271
272
|
sleep(1);
|
272
|
-
|
273
|
+
<% if nsinks == 1 %>
|
274
|
+
} while (cur_state != <%= @prefix.upcase %>STATE_<%= topology[:sinks][0].upcase %>);
|
275
|
+
<% else %>
|
276
|
+
} while (1);
|
277
|
+
<% end %>
|
273
278
|
return 0;
|
274
279
|
}
|
275
280
|
#endif
|
data/lib/version.rb
CHANGED