rsmp 0.8.2 → 0.8.6

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: 49e4aee9252ad888e831e5ce0738eff5bba57fdd6f2ec2220d7e74936e0e8177
4
- data.tar.gz: 5866b23cb324d0732de17f995abec6304f50673e9cfcaa7b440dea6858102cd8
3
+ metadata.gz: 437183789b08f12b23264bc2716b84fd6c2298c2abab58dfb0b64529d004ac7d
4
+ data.tar.gz: 5595afbb4edb5d3e66320cae10c92c98a13fd56848095bb8ec4bb3615a097b05
5
5
  SHA512:
6
- metadata.gz: 0ff9a48cde72b3fb3963c421a321c4bd08c0edfb9afcd7b4b919e2e92aa37624259a5124c81f4bd0189cc6a3596414edc75a305fb19b0c348fadc4e836bdf7cf
7
- data.tar.gz: 490aa51f0a4a5b9a6a197c0f6bbe11b8ae16934e5eecd76a486b6e4e34786ebbb334d4ddabf7340c9f13d4946cad4e162db49205a3fbf04fa064938bf6029e0f
6
+ metadata.gz: f3cdc4723d2d4616cc703d18aca6432c354bdbd7e4084c443a5f17aa8c420463d567813e73dc3fb454f02461b773149970932ee1d6d84f0434d8eaf21324a0ff
7
+ data.tar.gz: b90f7f2c8edc5722e0044cb31107779caabc4a9acbfce8bb713dd9a7d84e7272dd96fb2aad293c7d30e2350701758fe5300cfed776a774a754798cf8ac91037c
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.3
1
+ 3.1.0
data/Gemfile.lock CHANGED
@@ -1,27 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.8.2)
4
+ rsmp (0.8.6)
5
5
  async (~> 1.29.1)
6
- async-io (~> 1.32.1)
6
+ async-io (~> 1.32.2)
7
7
  colorize (~> 0.8.1)
8
8
  rsmp_schemer
9
- thor (~> 1.0.1)
9
+ thor (~> 1.2.1)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (6.1.4)
15
- concurrent-ruby (~> 1.0, >= 1.0.2)
16
- i18n (>= 1.6, < 2)
17
- minitest (>= 5.1)
18
- tzinfo (~> 2.0)
19
- zeitwerk (~> 2.3)
20
- aruba (1.1.2)
14
+ aruba (2.0.0)
21
15
  bundler (>= 1.17, < 3.0)
22
16
  childprocess (>= 2.0, < 5.0)
23
17
  contracts (>= 0.16.0, < 0.18.0)
24
- cucumber (>= 2.4, < 7.0)
18
+ cucumber (>= 4.0, < 8.0)
25
19
  rspec-expectations (~> 3.4)
26
20
  thor (~> 1.0)
27
21
  async (1.29.2)
@@ -33,68 +27,56 @@ GEM
33
27
  builder (3.2.4)
34
28
  childprocess (4.1.0)
35
29
  colorize (0.8.1)
36
- concurrent-ruby (1.1.9)
37
30
  console (1.14.0)
38
31
  fiber-local
39
32
  contracts (0.17)
40
- cucumber (6.1.0)
33
+ cucumber (7.1.0)
41
34
  builder (~> 3.2, >= 3.2.4)
42
- cucumber-core (~> 9.0, >= 9.0.1)
43
- cucumber-create-meta (~> 4.0, >= 4.0.0)
44
- cucumber-cucumber-expressions (~> 12.1, >= 12.1.1)
45
- cucumber-gherkin (~> 18.1, >= 18.1.0)
46
- cucumber-html-formatter (~> 13.0, >= 13.0.0)
47
- cucumber-messages (~> 15.0, >= 15.0.0)
48
- cucumber-wire (~> 5.0, >= 5.0.1)
35
+ cucumber-core (~> 10.1, >= 10.1.0)
36
+ cucumber-create-meta (~> 6.0, >= 6.0.1)
37
+ cucumber-cucumber-expressions (~> 14.0, >= 14.0.0)
38
+ cucumber-gherkin (~> 22.0, >= 22.0.0)
39
+ cucumber-html-formatter (~> 17.0, >= 17.0.0)
40
+ cucumber-messages (~> 17.1, >= 17.1.1)
41
+ cucumber-wire (~> 6.2, >= 6.2.0)
49
42
  diff-lcs (~> 1.4, >= 1.4.4)
50
43
  mime-types (~> 3.3, >= 3.3.1)
51
44
  multi_test (~> 0.1, >= 0.1.2)
52
45
  sys-uname (~> 1.2, >= 1.2.2)
53
- cucumber-core (9.0.1)
54
- cucumber-gherkin (~> 18.1, >= 18.1.0)
55
- cucumber-messages (~> 15.0, >= 15.0.0)
56
- cucumber-tag-expressions (~> 3.0, >= 3.0.1)
57
- cucumber-create-meta (4.0.0)
58
- cucumber-messages (~> 15.0, >= 15.0.0)
46
+ cucumber-core (10.1.1)
47
+ cucumber-gherkin (~> 22.0, >= 22.0.0)
48
+ cucumber-messages (~> 17.1, >= 17.1.1)
49
+ cucumber-tag-expressions (~> 4.1, >= 4.1.0)
50
+ cucumber-create-meta (6.0.4)
51
+ cucumber-messages (~> 17.1, >= 17.1.1)
59
52
  sys-uname (~> 1.2, >= 1.2.2)
60
- cucumber-cucumber-expressions (12.1.1)
61
- cucumber-gherkin (18.1.1)
62
- cucumber-messages (~> 15.0, >= 15.0.0)
63
- cucumber-html-formatter (13.0.0)
64
- cucumber-messages (~> 15.0, >= 15.0.0)
65
- cucumber-messages (15.0.0)
66
- protobuf-cucumber (~> 3.10, >= 3.10.8)
67
- cucumber-tag-expressions (3.0.1)
68
- cucumber-wire (5.0.1)
69
- cucumber-core (~> 9.0, >= 9.0.1)
70
- cucumber-cucumber-expressions (~> 12.1, >= 12.1.1)
71
- cucumber-messages (~> 15.0, >= 15.0.0)
72
- diff-lcs (1.4.4)
73
- ecma-re-validator (0.3.0)
74
- regexp_parser (~> 2.0)
75
- ffi (1.15.3)
53
+ cucumber-cucumber-expressions (14.0.0)
54
+ cucumber-gherkin (22.0.0)
55
+ cucumber-messages (~> 17.1, >= 17.1.1)
56
+ cucumber-html-formatter (17.0.0)
57
+ cucumber-messages (~> 17.1, >= 17.1.0)
58
+ cucumber-messages (17.1.1)
59
+ cucumber-tag-expressions (4.1.0)
60
+ cucumber-wire (6.2.1)
61
+ cucumber-core (~> 10.1, >= 10.1.0)
62
+ cucumber-cucumber-expressions (~> 14.0, >= 14.0.0)
63
+ diff-lcs (1.5.0)
64
+ ecma-re-validator (0.4.0)
65
+ regexp_parser (~> 2.2)
66
+ ffi (1.15.5)
76
67
  fiber-local (1.0.0)
77
68
  hana (1.3.7)
78
- i18n (1.8.10)
79
- concurrent-ruby (~> 1.0)
80
69
  json_schemer (0.2.18)
81
70
  ecma-re-validator (~> 0.3)
82
71
  hana (~> 1.3)
83
72
  regexp_parser (~> 2.0)
84
73
  uri_template (~> 0.7)
85
- middleware (0.1.0)
86
- mime-types (3.3.1)
74
+ mime-types (3.4.1)
87
75
  mime-types-data (~> 3.2015)
88
- mime-types-data (3.2021.0225)
89
- minitest (5.14.4)
76
+ mime-types-data (3.2022.0105)
90
77
  multi_test (0.1.2)
91
78
  nio4r (2.5.8)
92
- protobuf-cucumber (3.10.8)
93
- activesupport (>= 3.2)
94
- middleware
95
- thor
96
- thread_safe
97
- rake (13.0.3)
79
+ rake (13.0.6)
98
80
  regexp_parser (2.2.0)
99
81
  rsmp_schemer (0.3.2)
100
82
  json_schemer (~> 0.2.18)
@@ -104,37 +86,33 @@ GEM
104
86
  rspec-mocks (~> 3.10.0)
105
87
  rspec-core (3.10.1)
106
88
  rspec-support (~> 3.10.0)
107
- rspec-expectations (3.10.1)
89
+ rspec-expectations (3.10.2)
108
90
  diff-lcs (>= 1.2.0, < 2.0)
109
91
  rspec-support (~> 3.10.0)
110
92
  rspec-mocks (3.10.2)
111
93
  diff-lcs (>= 1.2.0, < 2.0)
112
94
  rspec-support (~> 3.10.0)
113
- rspec-support (3.10.2)
95
+ rspec-support (3.10.3)
114
96
  sys-uname (1.2.2)
115
97
  ffi (~> 1.1)
116
- thor (1.0.1)
117
- thread_safe (0.3.6)
98
+ thor (1.2.1)
118
99
  timecop (0.9.4)
119
100
  timers (4.3.3)
120
- tzinfo (2.0.4)
121
- concurrent-ruby (~> 1.0)
122
101
  uri_template (0.7.0)
123
- zeitwerk (2.4.2)
124
102
 
125
103
  PLATFORMS
126
104
  x86_64-darwin-20
127
105
  x86_64-darwin-21
128
106
 
129
107
  DEPENDENCIES
130
- aruba (~> 1.1.2)
131
- bundler (~> 2.2.21)
132
- cucumber (~> 6.1.0)
133
- rake (~> 13.0.3)
108
+ aruba (~> 2.0.0)
109
+ bundler (~> 2.3.6)
110
+ cucumber (~> 7.1.0)
111
+ rake (~> 13.0.6)
134
112
  rsmp!
135
113
  rspec (~> 3.10.0)
136
- rspec-expectations (~> 3.10.1)
114
+ rspec-expectations (~> 3.10.2)
137
115
  timecop (~> 0.9.4)
138
116
 
139
117
  BUNDLED WITH
140
- 2.2.32
118
+ 2.3.6
data/config/tlc.yaml CHANGED
@@ -20,17 +20,18 @@ signal_plans:
20
20
  dynamic_bands:
21
21
  1: 0
22
22
  2: 5
23
- states:
24
- A1: '123efg'
25
- A2: '123efg'
26
- B1: '123efg'
27
- B2: '123efg'
28
- 2:
29
23
  states:
30
24
  A1: '111NBB'
31
25
  A2: '11NBBB'
32
26
  B1: 'BBB11N'
33
27
  B2: 'BBB1NB'
28
+ 2:
29
+ states:
30
+ A1: 'NNNNBB'
31
+ A2: 'NNNNBN'
32
+ B1: 'BBNNNN'
33
+ B2: 'BNNNNN'
34
+ startup_sequence: 'efg'
34
35
  intervals:
35
36
  timer: 0.1
36
37
  watchdog: 0.1
@@ -48,3 +49,4 @@ log:
48
49
  level: false
49
50
  debug: true
50
51
  json: true
52
+ live_output: tmp/tlc.state
@@ -157,7 +157,7 @@ task.wait # wait for collection task to complete (or time out)
157
157
  ```
158
158
 
159
159
  ### With collection
160
- If you provide `:collect` options, it will be used to construct a StatusUpdateCollector for collecting the relevant status messages. When collection completes the collector is returned in the `:collector` key:
160
+ If you provide `:collect` options, it will be used to construct a StatusCollector for collecting the relevant status messages. When collection completes the collector is returned in the `:collector` key:
161
161
 
162
162
  ```ruby
163
163
  options = {
@@ -2,7 +2,7 @@ module RSMP
2
2
  # Class for waiting for an aggregated status response
3
3
  class AggregatedStatusCollector < Collector
4
4
  def initialize proxy, options={}
5
- required = { type: ['AggregatedStatus','MessageNotAck'], title: 'aggregated status' }
5
+ required = { type: 'AggregatedStatus', title: 'aggregated status' }
6
6
  super proxy, options.merge(required)
7
7
  end
8
8
  end
@@ -6,8 +6,8 @@ module RSMP
6
6
  class Collector < Listener
7
7
  attr_reader :condition, :messages, :status, :error, :task
8
8
 
9
- def initialize proxy, options={}
10
- super proxy, options
9
+ def initialize notifier, options={}
10
+ super notifier, options
11
11
  @options = {
12
12
  cancel: {
13
13
  schema_error: true,
@@ -18,7 +18,15 @@ module RSMP
18
18
  @outgoing = options[:outgoing] == nil ? false : options[:outgoing]
19
19
  @condition = Async::Notification.new
20
20
  @title = options[:title] || [@options[:type]].flatten.join('/')
21
- @task = options[:task]
21
+ if options[:task]
22
+ @task = options[:task]
23
+ else
24
+ # if notifier is a Proxy, or some other object that implements task(),
25
+ # then try to get the task that way
26
+ if notifier.respond_to? 'task'
27
+ @task = notifier.task
28
+ end
29
+ end
22
30
  reset
23
31
  end
24
32
 
@@ -43,12 +51,12 @@ module RSMP
43
51
  @status == :collecting
44
52
  end
45
53
 
46
- # Is collection active?
54
+ # Is collection complete?
47
55
  def ok?
48
56
  @status == :ok
49
57
  end
50
58
 
51
- # Has collection time out?
59
+ # Has collection timed out?
52
60
  def timeout?
53
61
  @status == :timeout
54
62
  end
@@ -73,6 +81,13 @@ module RSMP
73
81
  @outgoing == true
74
82
  end
75
83
 
84
+ # if an errors caused collection to abort, then raise it
85
+ # return self, so this can be tucked on to calls that return a collector
86
+ def ok!
87
+ raise @error if @error
88
+ self
89
+ end
90
+
76
91
  # Collect message
77
92
  # Will return once all messages have been collected, or timeout is reached
78
93
  def collect &block
@@ -86,9 +101,8 @@ module RSMP
86
101
  # Collect message
87
102
  # Returns the collected messages, or raise an exception in case of a time out.
88
103
  def collect! &block
89
- if collect(&block) == :timeout
90
- raise RSMP::TimeoutError.new describe_progress
91
- end
104
+ collect(&block)
105
+ ok!
92
106
  @messages
93
107
  end
94
108
 
@@ -104,6 +118,7 @@ module RSMP
104
118
  end
105
119
  @status
106
120
  rescue Async::TimeoutError
121
+ @error = RSMP::TimeoutError.new describe_progress
107
122
  @status = :timeout
108
123
  end
109
124
 
@@ -112,7 +127,7 @@ module RSMP
112
127
  # If timeout is reached, an exceptioin is raised.
113
128
  def wait!
114
129
  wait
115
- raise RSMP::TimeoutError.new(describe_progress) if timeout?
130
+ raise @error if timeout?
116
131
  @messages
117
132
  end
118
133
 
@@ -192,8 +207,8 @@ module RSMP
192
207
  @condition.signal
193
208
  end
194
209
 
195
- # The proxy experienced some error.
196
- # Check if this should cause us to cancel.
210
+ # An error occured upstream.
211
+ # Check if we should cancel.
197
212
  def notify_error error, options={}
198
213
  case error
199
214
  when RSMP::SchemaError
@@ -3,7 +3,7 @@ module RSMP
3
3
  class CommandResponseCollector < StateCollector
4
4
  def initialize proxy, want, options={}
5
5
  super proxy, want, options.merge(
6
- type: ['CommandResponse','MessageNotAck'],
6
+ type: 'CommandResponse',
7
7
  title:'command response'
8
8
  )
9
9
  end
@@ -1,8 +1,12 @@
1
1
  module RSMP
2
2
  # Base class for waiting for status updates or responses
3
- class StatusUpdateOrResponseCollector < StateCollector
3
+ class StatusCollector < StateCollector
4
4
  def initialize proxy, want, options={}
5
- super proxy, want, options.merge(outgoing: false)
5
+ super proxy, want, options.merge(title: 'status response')
6
+
7
+ @options[:type] ||= []
8
+ @options[:type] << 'StatusUpdate' unless options[:updates] == false
9
+ @options[:type] << 'StatusResponse' unless options[:reponses] == false
6
10
  end
7
11
 
8
12
  def build_query want
data/lib/rsmp/node.rb CHANGED
@@ -15,7 +15,6 @@ module RSMP
15
15
  @clock = Clock.new
16
16
  @error_queue = Async::Queue.new
17
17
  @ignore_errors = []
18
- options[:collector]
19
18
  @collect = options[:collect]
20
19
  end
21
20
 
data/lib/rsmp/proxy.rb CHANGED
@@ -52,12 +52,6 @@ module RSMP
52
52
  node.clock
53
53
  end
54
54
 
55
- def collect options, &block
56
- collector = RSMP::Collector.new self, options.merge(task: @task)
57
- collector.collect &block
58
- collector
59
- end
60
-
61
55
  def run
62
56
  start
63
57
  @reader.wait if @reader
@@ -578,26 +572,21 @@ module RSMP
578
572
  node.site_id
579
573
  end
580
574
 
581
- def wait_for_acknowledgement parent_task, options={}, m_id
582
- collect(parent_task,options.merge({
583
- type: ['MessageAck','MessageNotAck'],
584
- num: 1
585
- })) do |message|
586
- if message.is_a?(MessageNotAck)
587
- if message.attribute('oMId') == m_id
588
- # set result to an exception, but don't raise it.
589
- # this will be returned by the task and stored as the task result
590
- # when the parent task call wait() on the task, the exception
591
- # will be raised in the parent task, and caught by rspec.
592
- # rspec will then show the error and record the test as failed
593
- m_id_short = RSMP::Message.shorten_m_id m_id, 8
594
- result = RSMP::MessageRejected.new "Aggregated status request #{m_id_short} was rejected with '#{message.attribute('rea')}'"
595
- next true # done, no more messages wanted
596
- end
597
- elsif message.is_a?(MessageAck)
598
- next true if message.attribute('oMId') == m_id
575
+ def send_and_optionally_collect message, options, &block
576
+ collect_options = options[:collect] || options[:collect!]
577
+ if collect_options
578
+ task = @task.async do |task|
579
+ collector = yield collect_options # call block to create collector
580
+ collector.collect
581
+ collector.ok! if options[:collect!] # raise any errors if the bang version was specified
582
+ collector
599
583
  end
600
- false
584
+
585
+ send_message message, validate: options[:validate]
586
+ { sent: message, collector: task.wait }
587
+ else
588
+ send_message message, validate: options[:validate]
589
+ return { sent: message }
601
590
  end
602
591
  end
603
592
  end
data/lib/rsmp/site.rb CHANGED
@@ -9,9 +9,9 @@ module RSMP
9
9
  attr_reader :rsmp_versions, :site_settings, :logger, :proxies
10
10
 
11
11
  def initialize options={}
12
+ super options
12
13
  initialize_components
13
14
  handle_site_settings options
14
- super options
15
15
  @proxies = []
16
16
  @sleep_condition = Async::Notification.new
17
17
  @proxies_condition = Async::Notification.new
@@ -95,7 +95,8 @@ module RSMP
95
95
  ip: supervisor_settings['ip'],
96
96
  port: supervisor_settings['port'],
97
97
  logger: @logger,
98
- archive: @archive
98
+ archive: @archive,
99
+ collect: @collect
99
100
  })
100
101
  @proxies << proxy
101
102
  @proxies_condition.signal
@@ -101,8 +101,11 @@ module RSMP
101
101
  "cId" => component,
102
102
  "mId" => m_id
103
103
  })
104
- send_and_collect_if_needed message, options do |task|
105
- collect_aggregated_status task, options[:collect].merge(m_id: m_id, num:1)
104
+ send_and_optionally_collect message, options do |collect_options|
105
+ AggregatedStatusCollector.new(
106
+ self,
107
+ collect_options.merge(task:@task,m_id: m_id, num:1)
108
+ )
106
109
  end
107
110
  end
108
111
 
@@ -174,8 +177,12 @@ module RSMP
174
177
  "sS" => request_list,
175
178
  "mId" => m_id
176
179
  })
177
- send_and_collect_if_needed message, options do |task|
178
- collect_status_responses task, status_list, options[:collect].merge(m_id: m_id)
180
+ send_and_optionally_collect message, options do |collect_options|
181
+ StatusCollector.new(
182
+ self,
183
+ status_list,
184
+ collect_options.merge(task:@task,m_id: m_id)
185
+ )
179
186
  end
180
187
  end
181
188
 
@@ -186,17 +193,6 @@ module RSMP
186
193
  acknowledge message
187
194
  end
188
195
 
189
- def send_and_collect_if_needed message, options, &block
190
- if options[:collect]
191
- task = @task.async { |task| yield task }
192
- send_message message, validate: options[:validate]
193
- { sent: message, collector: task.wait }
194
- else
195
- send_message message, validate: options[:validate]
196
- return { sent: message }
197
- end
198
- end
199
-
200
196
  def subscribe_to_status component_id, status_list, options={}
201
197
  validate_ready 'subscribe to status'
202
198
  m_id = options[:m_id] || RSMP::Message.make_m_id
@@ -215,8 +211,12 @@ module RSMP
215
211
  "sS" => subscribe_list,
216
212
  'mId' => m_id
217
213
  })
218
- send_and_collect_if_needed message, options do |task|
219
- collect_status_updates task, status_list, options[:collect].merge(m_id: m_id)
214
+ send_and_optionally_collect message, options do |collect_options|
215
+ StatusCollector.new(
216
+ self,
217
+ status_list,
218
+ collect_options.merge(task:@task,m_id: m_id)
219
+ )
220
220
  end
221
221
  end
222
222
 
@@ -261,8 +261,12 @@ module RSMP
261
261
  "arg" => command_list,
262
262
  "mId" => m_id
263
263
  })
264
- send_and_collect_if_needed message, options do |task|
265
- collect_command_responses task, command_list, options[:collect].merge(m_id: m_id)
264
+ send_and_optionally_collect message, options do |collect_options|
265
+ CommandResponseCollector.new(
266
+ self,
267
+ command_list,
268
+ collect_options.merge(task:@task,m_id: m_id)
269
+ )
266
270
  end
267
271
  end
268
272
 
@@ -339,37 +343,13 @@ module RSMP
339
343
  distribute_error e, options
340
344
  end
341
345
 
342
- def collect_alarms parent_task, options={}
343
- collect(parent_task,options.merge(type: "Alarm")) do |alarm|
346
+ def collect_alarms options={}
347
+ collect(@task,options.merge(type: "Alarm")) do |alarm|
344
348
  next if options[:aCId] && options[:aCId] != alarm.attribute("aCId")
345
349
  next if options[:aSp] && options[:aSp] != alarm.attribute("aSp")
346
350
  next if options[:aS] && options[:aS] != alarm.attribute("aS")
347
- true
351
+ :keep
348
352
  end
349
353
  end
350
-
351
- def collect_status_updates task, status_list, options
352
- collector = StatusUpdateCollector.new(self, status_list, options.merge(task:task))
353
- collector.collect
354
- collector
355
- end
356
-
357
- def collect_status_responses task, status_list, options
358
- collector = StatusResponseCollector.new(self, status_list, options.merge(task:task))
359
- collector.collect
360
- collector
361
- end
362
-
363
- def collect_command_responses task, command_list, options
364
- collector = CommandResponseCollector.new(self, command_list, options.merge(task:task))
365
- collector.collect
366
- collector
367
- end
368
-
369
- def collect_aggregated_status task, options
370
- collector = AggregatedStatusCollector.new(self, options.merge(task:task))
371
- collector.collect
372
- collector
373
- end
374
354
  end
375
355
  end
@@ -138,16 +138,8 @@ module RSMP
138
138
  "mId" => m_id,
139
139
  })
140
140
 
141
- if options[:collect]
142
- result = nil
143
- task = @task.async do |task|
144
- wait_for_acknowledgement task, options[:collect], m_id
145
- end
146
- send_message message, validate: options[:validate]
147
- return message, task.wait
148
- else
149
- send_message message, validate: options[:validate]
150
- message
141
+ send_and_optionally_collect message, options do |collect_options|
142
+ Collector.new self, collect_options.merge(task:@task, type: 'MessageAck')
151
143
  end
152
144
  end
153
145
 
@@ -6,25 +6,33 @@ module RSMP
6
6
  # plan is a string, with each character representing a signal phase at a particular second in the cycle
7
7
  def initialize node:, id:
8
8
  super node: node, id: id, grouped: false
9
- move 0
10
9
  end
11
10
 
12
- def get_state pos
11
+ def timer
12
+ @state = get_state
13
+ end
14
+
15
+ def get_state
16
+ return 'a' if node.main.dark_mode
17
+ return 'c' if node.main.yellow_flash
18
+
19
+ cycle_counter = node.main.cycle_counter
20
+
21
+ if node.main.startup_sequence_active
22
+ @state = node.main.startup_state || 'a'
23
+ end
24
+
13
25
  default = 'a' # phase a means disabled/dark
14
26
  plan = node.main.current_plan
15
27
  return default unless plan
16
28
  return default unless plan.states
17
29
  states = plan.states[c_id]
18
30
  return default unless states
19
- state = states[pos]
31
+ state = states[cycle_counter]
20
32
  return default unless state =~ /[a-hA-G0-9N-P]/ # valid signal group states
21
33
  state
22
34
  end
23
35
 
24
- def move pos
25
- @state = get_state pos
26
- end
27
-
28
36
  def handle_command command_code, arg
29
37
  case command_code
30
38
  when 'M0010', 'M0011'
@@ -5,9 +5,12 @@ module RSMP
5
5
  # and keeps track of signal plans, detector logics, inputs, etc. which do
6
6
  # not have dedicated components.
7
7
  class TrafficController < Component
8
- attr_reader :pos, :cycle_time, :plan
8
+ attr_reader :pos, :cycle_time, :plan, :cycle_counter,
9
+ :yellow_flash, :dark_mode,
10
+ :startup_sequence_active, :startup_sequence, :startup_sequence_pos
9
11
 
10
- def initialize node:, id:, cycle_time: 10, signal_plans:
12
+ def initialize node:, id:, cycle_time: 10, signal_plans:,
13
+ startup_sequence:, live_output:nil
11
14
  super node: node, id: id, grouped: true
12
15
  @signal_groups = []
13
16
  @detector_logics = []
@@ -15,13 +18,15 @@ module RSMP
15
18
  @cycle_time = cycle_time
16
19
  @num_traffic_situations = 1
17
20
  @num_inputs = 8
21
+ @startup_sequence = startup_sequence
22
+ @live_output = live_output
18
23
  reset
19
24
  end
20
25
 
21
26
  def reset
22
- @pos = 0
23
- @plan = 0
24
- @dark_mode = false
27
+ @cycle_counter = 0
28
+ @plan = 1
29
+ @dark_mode = true
25
30
  @yellow_flash = false
26
31
  @booting = false
27
32
  @control_mode = 'control'
@@ -40,6 +45,12 @@ module RSMP
40
45
  @inputs = '0'*@num_inputs
41
46
  @input_activations = '0'*@num_inputs
42
47
  @input_results = '0'*@num_inputs
48
+
49
+ @day_time_table = {}
50
+ @startup_sequence_active = false
51
+ @startup_sequence_initiated_at = nil
52
+ @startup_sequence_pos = 0
53
+ @time_int = nil
43
54
  end
44
55
 
45
56
  def clock
@@ -64,46 +75,83 @@ module RSMP
64
75
  end
65
76
 
66
77
  def timer now
67
- # TODO
68
- # We should use a monotone timer, to avoid jumps
69
- # in case the user sets the system time
70
- pos = Time.now.to_i % @cycle_time
71
- if pos != @pos
72
- @pos = pos
73
- move pos
74
- end
78
+ # TODO use monotone timer, to avoid jumps in case the user sets the system time
79
+ @signal_groups.each { |group| group.timer }
80
+ time = Time.now.to_i
81
+ return if time == @time_int
82
+ @time_int = time
83
+ move_cycle_counter
84
+ move_startup_sequence if @startup_sequence_active
85
+ output_states
86
+ end
87
+
88
+ def move_cycle_counter
89
+ counter = Time.now.to_i % @cycle_time
90
+ @cycle_counter = counter
91
+ end
92
+
93
+ def startup_state
94
+ return unless @startup_sequence_active
95
+ return unless @startup_sequence_pos
96
+ @startup_sequence[ @startup_sequence_pos ]
75
97
  end
76
98
 
77
- def move pos
78
- @signal_groups.each do |group|
79
- group.move pos
99
+ def initiate_startup_sequence
100
+ log "Initiating startup sequence", level: :info
101
+ @startup_sequence_active = true
102
+ @startup_sequence_initiated_at = nil
103
+ @startup_sequence_pos = nil
104
+ end
105
+
106
+ def end_startup_sequence
107
+ @startup_sequence_active = false
108
+ @startup_sequence_initiated_at = nil
109
+ @startup_sequence_pos = nil
110
+
111
+ @yellow_flash = false
112
+ @dark_mode = false
113
+ end
114
+
115
+ def move_startup_sequence
116
+ was = @startup_sequence_pos
117
+ if @startup_sequence_initiated_at == nil
118
+ @startup_sequence_initiated_at = Time.now.to_i + 1
119
+ @startup_sequence_pos = 0
120
+ else
121
+ @startup_sequence_pos = Time.now.to_i - @startup_sequence_initiated_at
122
+ end
123
+ if @startup_sequence_pos >= @startup_sequence.size
124
+ end_startup_sequence
80
125
  end
81
- #output_states
82
126
  end
83
127
 
84
128
  def output_states
129
+ return unless @live_output
85
130
  str = @signal_groups.map do |group|
86
131
  s = "#{group.c_id}:#{group.state}"
87
132
  if group.state =~ /^[1-9]$/
88
133
  s.colorize(:green)
89
134
  elsif group.state =~ /^[NOP]$/
90
135
  s.colorize(:yellow)
91
- elsif group.state =~ /^[a]$/
92
- s.colorize(color: :black)
136
+ elsif group.state =~ /^[ae]$/
137
+ s.colorize(:black)
138
+ elsif group.state =~ /^[f]$/
139
+ s.colorize(:yellow)
140
+ elsif group.state =~ /^[g]$/
141
+ s.colorize(:red)
93
142
  else
94
143
  s.colorize(:red)
95
144
  end
96
145
  end.join ' '
97
146
  plan = "P#{@plan}"
98
- print "#{plan.rjust(4)} #{pos.to_s.rjust(4)} #{str}\r"
147
+
148
+ File.open @live_output, 'w' do |file|
149
+ file.puts "#{plan.rjust(4)} #{pos.to_s.rjust(4)} #{str}\r"
150
+ end
99
151
  end
100
152
 
101
153
  def format_signal_group_status
102
- if @yellow_flash
103
- 'c' * @signal_groups.size
104
- else
105
- @signal_groups.map { |group| group.state }.join
106
- end
154
+ @signal_groups.map { |group| group.state }.join
107
155
  end
108
156
 
109
157
  def handle_command command_code, arg
@@ -214,6 +262,18 @@ module RSMP
214
262
 
215
263
  def handle_m0017 arg
216
264
  @node.verify_security_code 2, arg['securityCode']
265
+ arg['status'].split(',').each do |item|
266
+ elems = item.split('-')
267
+ nr = elems[0].to_i
268
+ plan = elems[1].to_i
269
+ hour = elems[2].to_i
270
+ min = elems[3].to_i
271
+ if nr<0 || nr>12
272
+ raise InvalidMessage.new "time table id must be between 0 and 12, got #{nr}"
273
+ end
274
+ #p "nr: #{nr}, plan #{plan} at #{hour}:#{min}"
275
+ @day_time_table[nr] = {plan: plan, hour: hour, min:min}
276
+ end
217
277
  end
218
278
 
219
279
  def handle_m0018 arg
@@ -276,6 +336,7 @@ module RSMP
276
336
  log "Switching to mode #{mode}", level: :info
277
337
  case mode
278
338
  when 'NormalControl'
339
+ initiate_startup_sequence if @yellow_flash || @dark_mode
279
340
  @yellow_flash = false
280
341
  @dark_mode = false
281
342
  when 'YellowFlash'
@@ -308,9 +369,9 @@ module RSMP
308
369
  when 'signalgroupstatus'
309
370
  TrafficControllerSite.make_status format_signal_group_status
310
371
  when 'cyclecounter'
311
- TrafficControllerSite.make_status @pos.to_s
372
+ TrafficControllerSite.make_status @cycle_counter.to_s
312
373
  when 'basecyclecounter'
313
- TrafficControllerSite.make_status @pos.to_s
374
+ TrafficControllerSite.make_status @cycle_counter.to_s
314
375
  when 'stage'
315
376
  TrafficControllerSite.make_status 0.to_s
316
377
  end
@@ -511,7 +572,10 @@ module RSMP
511
572
  def handle_s0027 status_code, status_name=nil
512
573
  case status_name
513
574
  when 'status'
514
- TrafficControllerSite.make_status '00-00-00-00'
575
+ status = @day_time_table.map do |i,item|
576
+ "#{i}-#{item[:plan]}-#{item[:hour]}-#{item[:min]}"
577
+ end.join(',')
578
+ TrafficControllerSite.make_status status
515
579
  end
516
580
  end
517
581
 
@@ -5,11 +5,16 @@ module RSMP
5
5
  attr_accessor :main, :signal_plans
6
6
 
7
7
  def initialize options={}
8
+ # setup options before calling super initializer,
9
+ # since build of components depend on options
8
10
  @sxl = 'traffic_light_controller'
9
11
  @security_codes = options[:site_settings]['security_codes']
10
12
  @interval = options[:site_settings].dig('intervals','timer') || 1
13
+ @startup_sequence = options[:site_settings]['startup_sequence'] || 'efg'
11
14
  build_plans options[:site_settings].dig('signal_plans')
15
+
12
16
  super options
17
+
13
18
  unless @main
14
19
  raise ConfigurationError.new "TLC must have a main component"
15
20
  end
@@ -37,7 +42,9 @@ module RSMP
37
42
  when 'main'
38
43
  @main = TrafficController.new node: self, id: id,
39
44
  cycle_time: settings['cycle_time'],
40
- signal_plans: @signal_plans
45
+ startup_sequence: @startup_sequence,
46
+ signal_plans: @signal_plans,
47
+ live_output: @site_settings['live_output']
41
48
  when 'signal_group'
42
49
  group = SignalGroup.new node: self, id: id
43
50
  @main.add_signal_group group
@@ -52,6 +59,7 @@ module RSMP
52
59
  def start_action
53
60
  super
54
61
  start_timer
62
+ @main.initiate_startup_sequence
55
63
  end
56
64
 
57
65
  def start_timer
@@ -134,6 +142,7 @@ module RSMP
134
142
  when :restart
135
143
  log "Restarting TLC", level: :info
136
144
  restart
145
+ initiate_startup_sequence
137
146
  end
138
147
  end
139
148
  end
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.6"
3
3
  end
data/lib/rsmp.rb CHANGED
@@ -25,9 +25,7 @@ require 'rsmp/collect/filter'
25
25
  require 'rsmp/collect/query'
26
26
  require 'rsmp/collect/status_query'
27
27
  require 'rsmp/collect/command_query'
28
- require 'rsmp/collect/status_update_or_response_collector'
29
- require 'rsmp/collect/status_response_collector'
30
- require 'rsmp/collect/status_update_collector'
28
+ require 'rsmp/collect/status_collector'
31
29
  require 'rsmp/collect/command_response_collector'
32
30
  require 'rsmp/collect/aggregated_status_collector'
33
31
  require 'rsmp/component'
data/rsmp.gemspec CHANGED
@@ -31,16 +31,16 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_dependency "async", "~> 1.29.1"
34
- spec.add_dependency "async-io", "~> 1.32.1"
34
+ spec.add_dependency "async-io", "~> 1.32.2"
35
35
  spec.add_dependency "colorize", "~> 0.8.1"
36
- spec.add_dependency "thor", "~> 1.0.1"
36
+ spec.add_dependency "thor", "~> 1.2.1"
37
37
  spec.add_dependency "rsmp_schemer"
38
38
 
39
- spec.add_development_dependency "bundler", "~> 2.2.21"
40
- spec.add_development_dependency "rake", "~> 13.0.3"
39
+ spec.add_development_dependency "bundler", "~> 2.3.6"
40
+ spec.add_development_dependency "rake", "~> 13.0.6"
41
41
  spec.add_development_dependency "rspec", "~> 3.10.0"
42
- spec.add_development_dependency "rspec-expectations", "~> 3.10.1"
42
+ spec.add_development_dependency "rspec-expectations", "~> 3.10.2"
43
43
  spec.add_development_dependency "timecop", "~> 0.9.4"
44
- spec.add_development_dependency "cucumber", "~> 6.1.0"
45
- spec.add_development_dependency "aruba" , "~> 1.1.2"
44
+ spec.add_development_dependency "cucumber", "~> 7.1.0"
45
+ spec.add_development_dependency "aruba" , "~> 2.0.0"
46
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-10 00:00:00.000000000 Z
11
+ date: 2022-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.32.1
33
+ version: 1.32.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.32.1
40
+ version: 1.32.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: colorize
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.0.1
61
+ version: 1.2.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.0.1
68
+ version: 1.2.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rsmp_schemer
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 2.2.21
89
+ version: 2.3.6
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 2.2.21
96
+ version: 2.3.6
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 13.0.3
103
+ version: 13.0.6
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 13.0.3
110
+ version: 13.0.6
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 3.10.1
131
+ version: 3.10.2
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 3.10.1
138
+ version: 3.10.2
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: timecop
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -156,28 +156,28 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 6.1.0
159
+ version: 7.1.0
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 6.1.0
166
+ version: 7.1.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: aruba
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 1.1.2
173
+ version: 2.0.0
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 1.1.2
180
+ version: 2.0.0
181
181
  description: Easy RSMP site and supervisor communication.
182
182
  email:
183
183
  - zf0f@kk.dk
@@ -217,10 +217,8 @@ files:
217
217
  - lib/rsmp/collect/notifier.rb
218
218
  - lib/rsmp/collect/query.rb
219
219
  - lib/rsmp/collect/state_collector.rb
220
+ - lib/rsmp/collect/status_collector.rb
220
221
  - lib/rsmp/collect/status_query.rb
221
- - lib/rsmp/collect/status_response_collector.rb
222
- - lib/rsmp/collect/status_update_collector.rb
223
- - lib/rsmp/collect/status_update_or_response_collector.rb
224
222
  - lib/rsmp/component.rb
225
223
  - lib/rsmp/components.rb
226
224
  - lib/rsmp/convert/export/json_schema.rb
@@ -271,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
269
  - !ruby/object:Gem::Version
272
270
  version: '0'
273
271
  requirements: []
274
- rubygems_version: 3.2.32
272
+ rubygems_version: 3.3.3
275
273
  signing_key:
276
274
  specification_version: 4
277
275
  summary: RoadSide Message Protocol (RSMP) library.
@@ -1,11 +0,0 @@
1
- module RSMP
2
- # Class for waiting for specific status responses
3
- class StatusResponseCollector < StatusUpdateOrResponseCollector
4
- def initialize proxy, want, options={}
5
- super proxy, want, options.merge(
6
- type: ['StatusResponse','MessageNotAck'],
7
- title: 'status response'
8
- )
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module RSMP
2
- # Class for waiting for specific status responses
3
- class StatusUpdateCollector < StatusUpdateOrResponseCollector
4
- def initialize proxy, want, options={}
5
- super proxy, want, options.merge(
6
- type: ['StatusUpdate','MessageNotAck'],
7
- title:'status update'
8
- )
9
- end
10
- end
11
- end