rsmp 0.28.1 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,19 +10,35 @@ class RSMP::TLC::SignalPriority
10
10
  set_state 'received'
11
11
  end
12
12
 
13
+ def prune?
14
+ @state == 'stale' || @state == 'completed'
15
+ end
16
+
17
+ def cancel
18
+ if @state == 'activated'
19
+ set_state 'completed'
20
+ end
21
+ end
22
+
13
23
  def set_state state
14
24
  @state = state
15
25
  @updated = node.clock.now
16
- node.signal_priority_changed self, @state
26
+ @node.signal_priority_changed self, @state
17
27
  end
18
28
 
19
29
  def timer
20
30
  @age = @node.clock.now - @updated
21
31
  case @state
22
32
  when 'received'
23
- set_state 'activated' if @age >= 0.5
33
+ if @age >= 0.5
34
+ @node.log "Priority request #{@id} activated.", level: :info
35
+ set_state 'activated'
36
+ end
24
37
  when 'activated'
25
- set_state 'completed' if @age >= 0.5
38
+ if @age >= 1
39
+ @node.log "Priority request #{@id} became stale.", level: :info
40
+ set_state 'stale'
41
+ end
26
42
  end
27
43
  end
28
44
  end
@@ -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
@@ -88,7 +88,7 @@ module RSMP
88
88
  begin
89
89
  timer(@clock.now)
90
90
  rescue StandardError => e
91
- notify_error e, level: :internal
91
+ distribute_error e, level: :internal
92
92
  ensure
93
93
  # adjust sleep duration to avoid drift. so wake up always happens on the
94
94
  # same fractional second.
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.28.1"
2
+ VERSION = "0.31.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'
data/rsmp.gemspec CHANGED
@@ -30,16 +30,16 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_dependency "async", "~> 2.10.0"
34
- spec.add_dependency "async-io", "~> 1.42.0"
33
+ spec.add_dependency "async", "~> 2.12.0"
34
+ spec.add_dependency "async-io", "~> 1.43.0"
35
35
  spec.add_dependency "colorize", "~> 1.1"
36
- spec.add_dependency "rsmp_schema", "~> 0.6.0"
36
+ spec.add_dependency "rsmp_schema", "~> 0.7.0"
37
37
 
38
38
  spec.add_development_dependency "bundler", "~> 2.5.7"
39
39
  spec.add_development_dependency "rake", "~> 13.2.0"
40
40
  spec.add_development_dependency "rspec", "~> 3.13.0"
41
- spec.add_development_dependency "rspec-expectations", "~> 3.13.0"
42
- spec.add_development_dependency "timecop", "~> 0.9.8"
41
+ spec.add_development_dependency "rspec-expectations", "~> 3.13.1"
42
+ spec.add_development_dependency "timecop", "~> 0.9.9"
43
43
  spec.add_development_dependency "cucumber", "~> 9.2.0"
44
44
  spec.add_development_dependency "aruba" , "~> 2.2.0"
45
45
  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.28.1
4
+ version: 0.31.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-12 00:00:00.000000000 Z
11
+ date: 2024-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.10.0
19
+ version: 2.12.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.10.0
26
+ version: 2.12.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: async-io
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.42.0
33
+ version: 1.43.0
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.42.0
40
+ version: 1.43.0
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: 0.6.0
61
+ version: 0.7.0
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: 0.6.0
68
+ version: 0.7.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -114,28 +114,28 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 3.13.0
117
+ version: 3.13.1
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 3.13.0
124
+ version: 3.13.1
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: timecop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.9.8
131
+ version: 0.9.9
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: 0.9.8
138
+ version: 0.9.9
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: cucumber
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -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