rsmp 0.9.1 → 0.9.2

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: 40f0ef33eec84edcea172dbc53cf139679e09afb1a717f3081a05c0c5abc94e0
4
- data.tar.gz: 1d86aeb5a6c3e74757484d1db0e5f89fce122ea66799f275174baa2602d8ab0a
3
+ metadata.gz: 9fa8cde971466041262bd390c93f4f976cb0942ca6d78aadd2707e87e90fddb2
4
+ data.tar.gz: f7970833a69ea2ed5741a5b7f6d3619bfca25df8343f0b6a02a304dc7a74fce7
5
5
  SHA512:
6
- metadata.gz: a0c09b4ffe312e417095caf7ef426ce4d84649ac81b47d6f6247aa6b42cd689eb3940e23d13eaca8bd0736037571e389d543aeed92972e36de6948a1dd6aab42
7
- data.tar.gz: cc6ec0019034ea0153448e744ec9cfcf78c3b772bcfcc70b5fc239fb68a295f58c0ca566f66fbe3632b6c0e723d3490cfbf5c5631454ce8c8527d7ac5c8c5bd9
6
+ metadata.gz: d3a857d4b29b9b1e2f9bbf0181ed86586ade1b15eedbbbd79fbc4ca0a3f65b5e67c8f96224b55a87a3c05622a75353fc7fb29d61e1ecfb8af464c99873cc0bae
7
+ data.tar.gz: 499d7c02e691e0a3aa0fdf2f1f000f30bbda8bc9240836f00c6e8ca0114298666a92ffd20953d57887f359bec45ca983cf12624fc0b49eee952eb24eea8b80ca
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.9.1)
4
+ rsmp (0.9.2)
5
5
  async (~> 1.29.1)
6
6
  async-io (~> 1.32.2)
7
7
  colorize (~> 0.8.1)
@@ -13,8 +13,8 @@ module RSMP
13
13
  end
14
14
 
15
15
  def compute_state
16
- return 'a' if node.main.dark_mode
17
- return 'c' if node.main.yellow_flash
16
+ return 'a' if node.main.dark?
17
+ return 'c' if node.main.yellow_flash?
18
18
 
19
19
  cycle_counter = node.main.cycle_counter
20
20
 
@@ -6,7 +6,7 @@ module RSMP
6
6
  # not have dedicated components.
7
7
  class TrafficController < Component
8
8
  attr_reader :pos, :cycle_time, :plan, :cycle_counter,
9
- :yellow_flash, :dark_mode,
9
+ :functional_position,
10
10
  :startup_sequence_active, :startup_sequence, :startup_sequence_pos
11
11
 
12
12
  def initialize node:, id:, cycle_time: 10, signal_plans:,
@@ -24,15 +24,16 @@ module RSMP
24
24
  end
25
25
 
26
26
  def reset_modes
27
- @dark_mode = true
28
- @yellow_flash = false
27
+ @function_position = 'NormalControl'
28
+ @previous_functional_position = nil
29
+ @functional_position_timeout = nil
30
+
29
31
  @booting = false
30
32
  @is_starting = false
31
33
  @control_mode = 'control'
32
34
  @manual_control = false
33
35
  @fixed_time_control = false
34
36
  @isolated_control = false
35
- @yellow_flash = false
36
37
  @all_red = false
37
38
  @police_key = 0
38
39
  end
@@ -60,6 +61,18 @@ module RSMP
60
61
  @time_int = nil
61
62
  end
62
63
 
64
+ def dark?
65
+ @function_position == 'Dark'
66
+ end
67
+
68
+ def yellow_flash?
69
+ @function_position == 'YellowFlash'
70
+ end
71
+
72
+ def normal_control?
73
+ @function_position == 'NormalControl'
74
+ end
75
+
63
76
  def clock
64
77
  node.clock
65
78
  end
@@ -87,6 +100,7 @@ module RSMP
87
100
  return if time == @time_int
88
101
  @time_int = time
89
102
  move_cycle_counter
103
+ check_functional_position_timeout
90
104
  move_startup_sequence if @startup_sequence_active
91
105
 
92
106
  @signal_groups.each { |group| group.timer }
@@ -99,6 +113,15 @@ module RSMP
99
113
  @cycle_counter = counter
100
114
  end
101
115
 
116
+ def check_functional_position_timeout
117
+ return unless @functional_position_timeout
118
+ if clock.now >= @functional_position_timeout
119
+ switch_functional_position @previous_functional_position, reverting: true
120
+ @functional_position_timeout = nil
121
+ @previous_functional_position = nil
122
+ end
123
+ end
124
+
102
125
  def startup_state
103
126
  return unless @startup_sequence_active
104
127
  return unless @startup_sequence_pos
@@ -108,7 +131,6 @@ module RSMP
108
131
  def initiate_startup_sequence
109
132
  log "Initiating startup sequence", level: :info
110
133
  reset_modes
111
- @dark_mode = false
112
134
  @startup_sequence_active = true
113
135
  @startup_sequence_initiated_at = nil
114
136
  @startup_sequence_pos = nil
@@ -118,8 +140,6 @@ module RSMP
118
140
  @startup_sequence_active = false
119
141
  @startup_sequence_initiated_at = nil
120
142
  @startup_sequence_pos = nil
121
- @yellow_flash = false
122
- @dark_mode = false
123
143
  end
124
144
 
125
145
  def move_startup_sequence
@@ -157,15 +177,16 @@ module RSMP
157
177
  end.join ' '
158
178
 
159
179
  modes = '.'*9
160
- modes[0] = 'B' if @booting
161
- modes[1] = 'S' if @startup_sequence_active
162
- modes[2] = 'D' if @dark_mode
163
- modes[3] = 'Y' if @yellow_flash
164
- modes[4] = 'M' if @manual_control
165
- modes[5] = 'F' if @fixed_time_control
166
- modes[6] = 'R' if @all_red
167
- modes[7] = 'I' if @isolated_control
168
- modes[8] = 'P' if @police_key != 0
180
+ modes[0] = 'N' if @function_position == 'NormalControl'
181
+ modes[1] = 'Y' if @function_position == 'YellowFlash'
182
+ modes[2] = 'D' if @function_position == 'Dark'
183
+ modes[3] = 'B' if @booting
184
+ modes[4] = 'S' if @startup_sequence_active
185
+ modes[5] = 'M' if @manual_control
186
+ modes[6] = 'F' if @fixed_time_control
187
+ modes[7] = 'R' if @all_red
188
+ modes[8] = 'I' if @isolated_control
189
+ modes[9] = 'P' if @police_key != 0
169
190
 
170
191
  plan = "P#{@plan}"
171
192
 
@@ -197,7 +218,7 @@ module RSMP
197
218
 
198
219
  def handle_m0001 arg
199
220
  @node.verify_security_code 2, arg['securityCode']
200
- switch_mode arg['status']
221
+ switch_functional_position arg['status'], timeout: arg['timeout'].to_i*60
201
222
  end
202
223
 
203
224
  def handle_m0002 arg
@@ -376,8 +397,8 @@ module RSMP
376
397
  arg['second'],
377
398
  'UTC'
378
399
  )
379
- @node.clock.set time
380
- log "Clock set to #{time}, (adjustment is #{@node.clock.adjustment}s)", level: :info
400
+ clock.set time
401
+ log "Clock set to #{time}, (adjustment is #{clock.adjustment}s)", level: :info
381
402
  end
382
403
 
383
404
  def set_input i, value
@@ -400,20 +421,24 @@ module RSMP
400
421
  @plan = plan_nr
401
422
  end
402
423
 
403
- def switch_mode mode
404
- log "Switching to mode #{mode}", level: :info
405
- case mode
406
- when 'NormalControl'
407
- initiate_startup_sequence if @yellow_flash || @dark_mode
408
- @yellow_flash = false
409
- @dark_mode = false
410
- when 'YellowFlash'
411
- @yellow_flash = true
412
- @dark_mode = false
413
- when 'Dark'
414
- @yellow_flash = false
415
- @dark_mode = true
424
+ def switch_functional_position mode, timeout: nil, reverting: false
425
+ unless ['NormalControl','YellowFlash','Dark'].include? mode
426
+ raise RSMP::MessageRejected.new "Invalid functional position '#{mode}', must be NormalControl, YellowFlash or Dark'"
427
+ end
428
+ if reverting
429
+ log "Reverting to functional position #{mode} after timeout", level: :info
430
+ elsif timeout && timeout > 0
431
+ log "Switching to functional position #{mode} with timeout #{timeout}min", level: :info
432
+ @previous_functional_position = @function_position
433
+ now = clock.now
434
+ @functional_position_timeout = now + timeout
435
+ else
436
+ log "Switching to functional position #{mode}", level: :info
437
+ end
438
+ if mode == 'NormalControl'
439
+ initiate_startup_sequence if @function_position != 'NormalControl'
416
440
  end
441
+ @function_position = mode
417
442
  mode
418
443
  end
419
444
 
@@ -491,7 +516,7 @@ module RSMP
491
516
  when 'intersection'
492
517
  TrafficControllerSite.make_status @intersection
493
518
  when 'status'
494
- TrafficControllerSite.make_status !@dark_mode
519
+ TrafficControllerSite.make_status @function_position != 'Dark'
495
520
  end
496
521
  end
497
522
 
@@ -527,7 +552,7 @@ module RSMP
527
552
  when 'intersection'
528
553
  TrafficControllerSite.make_status @intersection
529
554
  when 'status'
530
- TrafficControllerSite.make_status @yellow_flash
555
+ TrafficControllerSite.make_status TrafficControllerSite.to_rmsp_bool( @function_position == 'YellowFlash' )
531
556
  end
532
557
  end
533
558
 
@@ -723,7 +748,7 @@ module RSMP
723
748
  when 'checksum'
724
749
  TrafficControllerSite.make_status '1'
725
750
  when 'timestamp'
726
- now = @node.clock.to_s
751
+ now = clock.to_s
727
752
  TrafficControllerSite.make_status now
728
753
  end
729
754
  end
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  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.9.1
4
+ version: 0.9.2
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-02-21 00:00:00.000000000 Z
11
+ date: 2022-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async