rsmp 0.29.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ module RSMP
15
15
  @signal_groups = []
16
16
  @detector_logics = []
17
17
  @plans = signal_plans
18
- @cycle_time = cycle_time
18
+ @cycle_time = cycle_time || 10
19
19
  @num_traffic_situations = 1
20
20
 
21
21
  if inputs
@@ -107,10 +107,7 @@ module RSMP
107
107
 
108
108
  def timer now
109
109
  # TODO use monotone timer, to avoid jumps in case the user sets the system time
110
- time = Time.now.to_i
111
- return if time == @time_int
112
- @time_int = time
113
- move_cycle_counter
110
+ return unless move_cycle_counter
114
111
  check_functional_position_timeout
115
112
  move_startup_sequence if @startup_sequence_active
116
113
 
@@ -118,17 +115,20 @@ module RSMP
118
115
  @signal_priorities.each {|priority| priority.timer }
119
116
 
120
117
  output_states
121
- prune_priorities
122
118
  end
123
119
 
124
120
  def signal_priority_changed priority, state
125
- #puts "priority #{priority.id} -> #{state}"
126
121
  end
127
122
 
123
+ # remove all stale priority requests
128
124
  def prune_priorities
129
- # TODO spec states that update must be send one time when it reaches the state 'completed',
130
- # and then be removed. so we need to know when it has been sent
131
- @signal_priorities.delete_if {|priority| priority.state=='completed' && priority.age >= 1.5 }
125
+ @signal_priorities.delete_if {|priority| priority.prune? }
126
+ end
127
+
128
+ # this method is called by the supervisor proxy each time status updates have been send
129
+ # we can then prune our priority request list
130
+ def status_updates_sent
131
+ prune_priorities
132
132
  end
133
133
 
134
134
  def get_priority_list
@@ -143,7 +143,9 @@ module RSMP
143
143
 
144
144
  def move_cycle_counter
145
145
  counter = Time.now.to_i % @cycle_time
146
+ changed = counter != @cycle_counter
146
147
  @cycle_counter = counter
148
+ changed
147
149
  end
148
150
 
149
151
  def check_functional_position_timeout
@@ -251,10 +253,20 @@ module RSMP
251
253
 
252
254
  def handle_m0001 arg, options={}
253
255
  @node.verify_security_code 2, arg['securityCode']
256
+
257
+ # timeout is specified in minutes, but we take 1 to mean 1s
258
+ # this is not according to the curent rsmp spec, but is done
259
+ # to speed up testing
260
+ timeout = arg['timeout'].to_i
261
+ if timeout == 1
262
+ timeout = 1
263
+ else
264
+ timeout *= 60
265
+ end
266
+
254
267
  switch_functional_position arg['status'],
255
- timeout: arg['timeout'].to_i*60,
268
+ timeout: timeout,
256
269
  source: 'forced'
257
-
258
270
  end
259
271
 
260
272
  def handle_m0002 arg, options={}
@@ -510,17 +522,19 @@ module RSMP
510
522
  eta = arg['eta']
511
523
  vehicleType = arg['vehicleType']
512
524
  @signal_priorities << SignalPriority.new(node:self, id:id, level:level, eta:eta, vehicleType:vehicleType)
513
- log "Priority request for signal group #{signal_group.c_id} received with id #{id}", level: :info
525
+ log "Priority request #{id} for signal group #{signal_group.c_id} received.", level: :info
514
526
  end
515
527
  when 'update'
516
528
  if priority
517
- log "Priority Request #{id} updated", level: :info
529
+ log "Updating Priority Request #{id}", level: :info
530
+
518
531
  else
519
532
  raise MessageRejected.new("Cannot update priority request #{id}, not found")
520
533
  end
521
534
  when 'cancel'
522
535
  if priority
523
- @signal_priorities.delete priority
536
+ priority.cancel
537
+ log "Priority request with id #{id} cancelled.", level: :info
524
538
  else
525
539
  raise MessageRejected.new("Cannot cancel priority request #{id}, not found")
526
540
  end
@@ -18,7 +18,10 @@ module RSMP
18
18
  unless main
19
19
  raise ConfigurationError.new "TLC must have a main component"
20
20
  end
21
+ end
21
22
 
23
+ def site_type_name
24
+ "TLC"
22
25
  end
23
26
 
24
27
  def start
@@ -88,7 +91,7 @@ module RSMP
88
91
  begin
89
92
  timer(@clock.now)
90
93
  rescue StandardError => e
91
- notify_error e, level: :internal
94
+ distribute_error e, level: :internal
92
95
  ensure
93
96
  # adjust sleep duration to avoid drift. so wake up always happens on the
94
97
  # same fractional second.
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.29.0"
2
+ VERSION = "0.32.0"
3
3
  end
data/lib/rsmp.rb CHANGED
@@ -17,15 +17,16 @@ require 'rsmp/logging'
17
17
  require 'rsmp/node'
18
18
  require 'rsmp/supervisor'
19
19
  require 'rsmp/components'
20
- require 'rsmp/collect/notifier'
21
- require 'rsmp/collect/listener'
20
+ require 'rsmp/collect/distributor'
21
+ require 'rsmp/collect/receiver'
22
+ require 'rsmp/collect/queue'
22
23
  require 'rsmp/collect/collector'
23
24
  require 'rsmp/collect/state_collector'
24
25
  require 'rsmp/collect/filter'
25
- require 'rsmp/collect/query'
26
- require 'rsmp/collect/status_query'
27
- require 'rsmp/collect/command_query'
28
- require 'rsmp/collect/alarm_query'
26
+ require 'rsmp/collect/matcher'
27
+ require 'rsmp/collect/status_matcher'
28
+ require 'rsmp/collect/command_matcher'
29
+ require 'rsmp/collect/alarm_matcher'
29
30
  require 'rsmp/collect/status_collector'
30
31
  require 'rsmp/collect/command_response_collector'
31
32
  require 'rsmp/collect/aggregated_status_collector'
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.29.0
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-19 00:00:00.000000000 Z
11
+ date: 2024-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -200,18 +200,19 @@ files:
200
200
  - lib/rsmp/collect/ack_collector.rb
201
201
  - lib/rsmp/collect/aggregated_status_collector.rb
202
202
  - lib/rsmp/collect/alarm_collector.rb
203
- - lib/rsmp/collect/alarm_query.rb
203
+ - lib/rsmp/collect/alarm_matcher.rb
204
204
  - lib/rsmp/collect/collector.rb
205
- - lib/rsmp/collect/command_query.rb
205
+ - lib/rsmp/collect/command_matcher.rb
206
206
  - lib/rsmp/collect/command_response_collector.rb
207
+ - lib/rsmp/collect/distributor.rb
207
208
  - lib/rsmp/collect/filter.rb
208
- - lib/rsmp/collect/listener.rb
209
+ - lib/rsmp/collect/matcher.rb
209
210
  - lib/rsmp/collect/message_matchers.rb
210
- - lib/rsmp/collect/notifier.rb
211
- - lib/rsmp/collect/query.rb
211
+ - lib/rsmp/collect/queue.rb
212
+ - lib/rsmp/collect/receiver.rb
212
213
  - lib/rsmp/collect/state_collector.rb
213
214
  - lib/rsmp/collect/status_collector.rb
214
- - lib/rsmp/collect/status_query.rb
215
+ - lib/rsmp/collect/status_matcher.rb
215
216
  - lib/rsmp/component.rb
216
217
  - lib/rsmp/component_base.rb
217
218
  - lib/rsmp/component_proxy.rb
@@ -1,23 +0,0 @@
1
- # Receives items from a Notifier, as long as it's
2
- # installed as a listener.
3
-
4
- module RSMP
5
- class Listener
6
- include Inspect
7
-
8
- def initialize notifier, options={}
9
- @notifier = notifier
10
- end
11
-
12
- def change_notifier notifier
13
- @notifier.remove_listener self if @notifier
14
- @notifier = notifier
15
- end
16
-
17
- def notify message
18
- end
19
-
20
- def notify_error error, options={}
21
- end
22
- end
23
- end
@@ -1,65 +0,0 @@
1
- # Distributes messages to listeners
2
-
3
- module RSMP
4
- module Notifier
5
- attr_reader :listeners
6
-
7
- include Inspect
8
-
9
- def inspect
10
- "#<#{self.class.name}:#{self.object_id}, #{inspector(:@listeners)}>"
11
- end
12
-
13
- def initialize_distributor
14
- @listeners = []
15
- @defer_notify = false
16
- @notify_queue = []
17
- end
18
-
19
- def clear_deferred_notify &block
20
- @notify_queue = []
21
- end
22
-
23
- def deferred_notify &block
24
- was, @defer_notify = @defer_notify, true
25
- yield
26
- dequeue_notify
27
- ensure
28
- @defer_notify = was
29
- @notify_queue = []
30
- end
31
-
32
- def dequeue_notify
33
- @notify_queue.each { |message| notify_without_defer message }
34
- ensure
35
- @notify_queue = []
36
- end
37
-
38
- def add_listener listener
39
- raise ArgumentError unless listener
40
- @listeners << listener unless @listeners.include? listener
41
- end
42
-
43
- def remove_listener listener
44
- raise ArgumentError unless listener
45
- @listeners.delete listener
46
- end
47
-
48
- def notify message
49
- raise ArgumentError unless message
50
- if @defer_notify
51
- @notify_queue << message
52
- else
53
- notify_without_defer message
54
- end
55
- end
56
-
57
- def notify_without_defer message
58
- @listeners.each { |listener| listener.notify message }
59
- end
60
-
61
- def distribute_error error, options={}
62
- @listeners.each { |listener| listener.notify_error error, options }
63
- end
64
- end
65
- end