gv_fsm 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b5c409a59baa14a81f425617228e69a99e08c6914aba00156516bb6d58f4b01
4
- data.tar.gz: 88f01660fdc03e5b7e439e8eb5c471990de71f0ab32cd5fd6d6a6e93879294ec
3
+ metadata.gz: 104db8b7dc7c75c3680cea00e87170c3a3ab7a34c907b6022ecfe73cf7312b22
4
+ data.tar.gz: 2d59ec8faae9088a97d2dc8075adf426940b4ee51ee98ba8c42a150dca7a32b4
5
5
  SHA512:
6
- metadata.gz: 68c7c63845e630d6b17e5d9ec7a7dac42bbd4045c9e6bd41f25bfcd8d1edc12e3b6dea3518179fe1bea72400a865e4a1fd0112980ea4625b3df3e2185cb651dd
7
- data.tar.gz: 8c47fdce73aafb70871ad87cddf1a5a359021b2e1cd1f619212186d1fda7b552b30858f958ad818ab4b6a491d47e27501bb7ccd50777d1d5686be17d9c9062af
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
 
@@ -48,7 +49,7 @@ module GV_FSM
48
49
  return nil
49
50
  end
50
51
  @matrix = Matrix.zero(n, n)
51
- @description = g.name
52
+ @description = g.name unless @description
52
53
  i = 0
53
54
  g.each_node do |id|
54
55
  n = g.get_node(id)
@@ -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
@@ -23,8 +23,8 @@ module GV_FSM
23
23
 
24
24
  HH =<<~EOH
25
25
  <% if !@ino then %>
26
- #ifndef <%= @cname.upcase %>_H
27
- #define <%= @cname.upcase %>_H
26
+ #ifndef <%= File::basename(@cname).upcase %>_H
27
+ #define <%= File::basename(@cname).upcase %>_H
28
28
  #include <stdlib.h>
29
29
  <% else %>
30
30
  #include <arduino.h>
@@ -92,7 +92,7 @@ module GV_FSM
92
92
  <% end %>
93
93
 
94
94
  // state manager
95
- <%= @prefix %>state_t <%= @prefix %>run_state(<%= @prefix %>state_t cur_state, state_data_t *data);
95
+ <%= @prefix %>state_t <%= @prefix %>run_state(<%= @prefix %>state_t cur_state, <%= @prefix %>state_data_t *data);
96
96
 
97
97
  <% if !@ino then %>
98
98
  #endif
@@ -108,8 +108,19 @@ module GV_FSM
108
108
  <% else %>
109
109
  <% if @syslog then log = :ino end %>
110
110
  <% end %>
111
- #include "<%= @cname %>.h"
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.8"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gv_fsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Bosetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-11 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-graphviz
@@ -48,7 +48,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: '0'
51
+ version: '2.7'
52
52
  required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="