gv_fsm 0.2.10 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf5e9e3cf0f82f27179188c0a3e994b2114278d723f4df2530b59a5ee87bdb72
4
- data.tar.gz: 6dda52c8b001d8043e888d139cca35939fb5682acb93c00f1e2a9a7373343b3b
3
+ metadata.gz: 104db8b7dc7c75c3680cea00e87170c3a3ab7a34c907b6022ecfe73cf7312b22
4
+ data.tar.gz: 2d59ec8faae9088a97d2dc8075adf426940b4ee51ee98ba8c42a150dca7a32b4
5
5
  SHA512:
6
- metadata.gz: 3fe7b3e14362c3a35692785df7fc35b1756575499b94de2c2441828096c5d479b15bfa5736ede6d7691908f646edb7f625b385b877a53d7423a27fab41adbf6b
7
- data.tar.gz: d99ed400cdc9ac9f13831952059e9b9ccd352bfd8b55f5fdc570b1667070cb6c1181ae4942e69c732eb6159639928e46f57debd3e05db969eaa99b9cc0e91a75
6
+ metadata.gz: 83ca0f6bebc31be22faa513940825133f78a3e4206eaf9457fd4ae9632b2987b8bf70efd9b752b3df894db78f4afd230b53b06ff8755c74fdf0d168f54e4c815
7
+ data.tar.gz: 952087a81fc23d362e05a275234c05a7917beb42f5c08323e1df2cf47168bceec52ae181f6ed51abba2d84e4a4ec9b0ec14bceeae413f37ba5f404d9dfe5813d
data/bin/gv_fsm CHANGED
@@ -48,6 +48,10 @@ op = OptionParser.new do |parser|
48
48
  sm.syslog = false
49
49
  end
50
50
 
51
+ parser.on("-k", "--sigint STATE", "Install SIGINT handler that points to STATE") do |state|
52
+ sm.sigint = state
53
+ end
54
+
51
55
  parser.on("-h", "--help", "Prints this help") do
52
56
  puts parser
53
57
  exit
@@ -73,6 +77,11 @@ unless sm.parse(ARGV[0]) then
73
77
  exit 3
74
78
  end
75
79
 
80
+ if sm.ino && sm.sigint then
81
+ STDERR.puts "ERROR: signal handler is not supported on Arduino!\n\n"
82
+ exit 4
83
+ end
84
+
76
85
  puts "Parsed #{sm.dotfile}"
77
86
  top = sm.topology
78
87
  puts "Graph topology:"
@@ -87,11 +96,18 @@ end
87
96
  puts "Generating C functions for states: #{sm.states_list.join(", ")}."
88
97
  puts " for transition: #{sm.transition_functions_list.join(", ")}."
89
98
 
99
+ if (sm.sigint) then
100
+ puts "Installed signal handler for SIGINT in state #{top[:sources][0]}:\n stable states have emergency transition to state #{sm.sigint}"
101
+ unless top[:sinks].include? sm.sigint then
102
+ puts "WARNING: the state #{sm.sigint} is not a source, please check topology"
103
+ end
104
+ end
90
105
 
91
106
  if options[:header] then
92
107
  name = sm.generate_h
93
108
  puts "Generated header #{name}"
94
109
  end
110
+
95
111
  if options[:source] then
96
112
  name = sm.generate_c
97
113
  puts "Generated source #{name}"
data/lib/gv_fsm.rb CHANGED
@@ -10,7 +10,7 @@ require File.expand_path("../version.rb", __FILE__)
10
10
  module GV_FSM
11
11
  class FSM
12
12
  attr_reader :states, :transitions, :dotfile, :prefix, :error
13
- attr_accessor :project_name, :description, :cname, :syslog, :ino
13
+ attr_accessor :project_name, :description, :cname, :syslog, :ino, :sigint
14
14
  include GV_FSM::Templates
15
15
 
16
16
  def initialize(filename = nil)
@@ -20,6 +20,7 @@ module GV_FSM
20
20
  @error = nil
21
21
  @matrix = nil
22
22
  @nodemap = {}
23
+ @sigint = nil
23
24
  parse(filename) if filename
24
25
  end
25
26
 
@@ -85,6 +86,10 @@ module GV_FSM
85
86
  @error = "Parsing error"
86
87
  return nil
87
88
  end
89
+ if (self.sigint && !states.find {|s| s[:id] == self.sigint}) then
90
+ @error = "Missing SIGINT state #{self.sigint}"
91
+ return nil
92
+ end
88
93
  return graph
89
94
  end
90
95
 
data/lib/templates.rb CHANGED
@@ -110,6 +110,17 @@ module GV_FSM
110
110
  <% end %>
111
111
  #include "<%= File::basename(@cname) %>.h"
112
112
 
113
+ <% if sigint then %>// Install signal handler:
114
+ // SIGINT requests a transition to state <%= self.sigint %>
115
+ #include <signal.h>
116
+ static int _exit_request = 0;
117
+ static void signal_handler(int signal) {
118
+ if (signal == SIGINT)
119
+ syslog(LOG_WARNING, "[FSM] SIGINT transition to <%= sigint %>");
120
+ _exit_request = 1;
121
+ }
122
+
123
+ <% end %>
113
124
  <% placeholder = "Your Code Here" %>
114
125
  // SEARCH FOR <%= placeholder %> FOR CODE INSERTION POINTS!
115
126
 
@@ -153,6 +164,7 @@ module GV_FSM
153
164
  // |_| \\__,_|_| |_|\\___|\\__|_|\\___/|_| |_|___/
154
165
  //
155
166
  <% dest = destinations.dup %>
167
+ <% topo = self.topology %>
156
168
  <% @states.each do |s| %>
157
169
  <% stable = true if dest[s[:id]].include? s[:id] %>
158
170
  <% dest[s[:id]].map! {|n| (@prefix+"STATE_"+n).upcase} %>
@@ -161,9 +173,13 @@ module GV_FSM
161
173
  end %>
162
174
  // Function to be executed in state <%= s[:id] %>
163
175
  // valid return states: <%= dest[s[:id]].join(", ") %>
176
+ <% if sigint && stable && topo[:sources][0] != s[:id] then %>
177
+ // SIGINT triggers an emergency transition to <%= self.sigint %>
178
+ <% end %>
164
179
  <%= @prefix %>state_t <%= s[:function] %>(<%= @prefix %>state_data_t *data) {
165
180
  <%= @prefix %>state_t next_state = <%= dest[s[:id]].first %>;
166
-
181
+ <% if sigint && topo[:sources][0] == s[:id] then %>signal(SIGINT, signal_handler);
182
+ <% end %>
167
183
  <% if log == :syslog then %>
168
184
  syslog(LOG_INFO, "[FSM] In state <%= s[:id] %>");
169
185
  <% elsif log == :ino then %>
@@ -186,6 +202,10 @@ module GV_FSM
186
202
  <% end %>
187
203
  next_state = <%= @prefix.upcase %>NO_CHANGE;
188
204
  }
205
+ <% if sigint && stable && topo[:sources][0] != s[:id] then %>
206
+ // SIGINT transition override
207
+ if (_exit_request) next_state = <%= (@prefix+"STATE_"+self.sigint ).upcase %>;
208
+ <% end %>
189
209
  return next_state;
190
210
  }
191
211
 
@@ -282,4 +302,4 @@ module GV_FSM
282
302
  <% end %>
283
303
  EOC
284
304
  end
285
- end
305
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GV_FSM
2
- VERSION = "0.2.10"
2
+ VERSION = "0.3.0"
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.2.10
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Bosetti