rsmp 0.3.5 → 0.3.9

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: d22d8796a378484c9c7a9d50b3bc48386db2e12893c5af07a1ef83825d2f1b0e
4
- data.tar.gz: ee6a4ebb4fcf094cb45e1f541e6f228e6ea9c3364fca6e1526e4fe46026751f2
3
+ metadata.gz: 0f137a9e58a8af4524954c33515926c1b6eb2dc8aa7e4fa9bfd00b22f6e5e4bb
4
+ data.tar.gz: a9710492f633d584e6ac0acdac9b8f5bf9b820dbe3ad14ca31295bc56b41e232
5
5
  SHA512:
6
- metadata.gz: a1a495ba2c110ebb42db60596516de255b9c9a9cb903fdd66bf77bd27a3f5d5b786b273436b522af3dbf57e983651676b9a9e67aee7387ba134ef89812261618
7
- data.tar.gz: 21f2e48b596dcca6296da89f687ec46d3845eaafb6cad497a16ac4fabca1cb5574da6df324256f4929b7207eeccd17697bd5021b328b4d265ff7d836d2a5e2c3
6
+ metadata.gz: cb33932006870bcedfbf3a8d07311c1a752ffccdb23c5d72303b80e47fef0f1b61a4a9fc01521afb8c02bfa32a039b54356687e2d912c03ae9c6238159fdc291
7
+ data.tar.gz: c7161ce4a72fbf33394336ad1d8a8db1aedb5148c8988c66fd7ea361b1afa8efddbccb34e376c47ac030ed30b785b118670f4005412752d490b66696213081f7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.3.5)
4
+ rsmp (0.3.9)
5
5
  async (~> 1.29.1)
6
6
  async-io (~> 1.32.1)
7
7
  colorize (~> 0.8.1)
@@ -13,7 +13,7 @@ module RSMP
13
13
  :rest,
14
14
  :not_connected ]
15
15
 
16
- def initialize node:, id:, grouped:
16
+ def initialize node:, id:, grouped: false
17
17
  @c_id = id
18
18
  @node = node
19
19
  @grouped = grouped
@@ -38,10 +38,23 @@ module RSMP
38
38
  Component.new id:id, node: self, grouped: type=='main'
39
39
  end
40
40
 
41
- def find_component component_id
41
+ def infer_component_type component_id
42
+ Component
43
+ end
44
+
45
+ def find_component component_id, build: true
42
46
  component = @components[component_id]
43
- raise UnknownComponent.new("Component #{component_id} not found") unless component
44
- component
47
+ return component if component
48
+ if build
49
+ inferred = infer_component_type component_id
50
+ component = inferred.new node: self, id: component_id
51
+ @components[ component_id] = component
52
+ class_name = component.class.name.split('::').last
53
+ log "Inferred #{class_name} component #{component_id}", level: :info
54
+ component
55
+ else
56
+ raise UnknownComponent.new("Component #{component_id} not found") unless component
57
+ end
45
58
  end
46
59
 
47
60
  end
@@ -125,17 +125,11 @@ module RSMP
125
125
  se = message.attribute("se")
126
126
  validate_aggregated_status(message,se) == false
127
127
  c_id = message.attributes["cId"]
128
- component = @components[c_id]
129
- if component == nil
130
- if @site_settings == nil || @site_settings['components'] == nil
131
- component = build_component(id:c_id, type:nil)
132
- @components[c_id] = component
133
- log "Adding component #{c_id} to site #{@site_id}", level: :info
134
- else
135
- reason = "component #{c_id} not found"
136
- dont_acknowledge message, "Ignoring #{message.type}:", reason
137
- return
138
- end
128
+ component = find_component c_id
129
+ unless component
130
+ reason = "component #{c_id} not found"
131
+ dont_acknowledge message, "Ignoring #{message.type}:", reason
132
+ return
139
133
  end
140
134
 
141
135
  component.set_aggregated_status_bools se
@@ -341,20 +335,12 @@ module RSMP
341
335
  @supervisor.notify_error e, options if @supervisor
342
336
  end
343
337
 
344
- def wait_for_alarm parent_task, options={}
345
- matching_alarm = nil
346
- message = collect(parent_task,options.merge(type: "Alarm", with_message: true, num: 1)) do |message|
347
- # TODO check components
348
- matching_alarm = nil
349
- alarm = message
338
+ def collect_alarms parent_task, options={}
339
+ collect(parent_task,options.merge(type: "Alarm")) do |alarm|
350
340
  next if options[:aCId] && options[:aCId] != alarm.attribute("aCId")
351
341
  next if options[:aSp] && options[:aSp] != alarm.attribute("aSp")
352
342
  next if options[:aS] && options[:aS] != alarm.attribute("aS")
353
- matching_alarm = alarm
354
- break
355
- end
356
- if item
357
- { message: message, status: matching_alarm }
343
+ true
358
344
  end
359
345
  end
360
346
 
data/lib/rsmp/tlc.rb CHANGED
@@ -5,7 +5,7 @@ module RSMP
5
5
  class TrafficController < Component
6
6
  attr_reader :pos, :cycle_time
7
7
 
8
- def initialize node:, id:, cycle_time:
8
+ def initialize node:, id:, cycle_time: 10
9
9
  super node: node, id: id, grouped: true
10
10
  @signal_groups = []
11
11
  @detector_logics = []
@@ -293,7 +293,8 @@ module RSMP
293
293
  def handle_s0002 status_code, status_name=nil
294
294
  case status_name
295
295
  when 'detectorlogicstatus'
296
- RSMP::Tlc.make_status @detector_logics.map { |dl| dl.forced ? '1' : '0' }.join
296
+ RSMP::Tlc.make_status @detector_logics.each { |dl| p dl.value }
297
+ RSMP::Tlc.make_status @detector_logics.map { |dl| dl.value ? '1' : '0' }.join
297
298
  end
298
299
  end
299
300
 
@@ -625,13 +626,15 @@ module RSMP
625
626
  class SignalGroup < Component
626
627
  attr_reader :plan, :state
627
628
 
628
- def initialize node:, id:, plan:
629
+ # plan is a string, with each character representing a signal phase at a particular second in the cycle
630
+ def initialize node:, id:, plan: nil
629
631
  super node: node, id: id, grouped: false
630
632
  @plan = plan
631
633
  move 0
632
634
  end
633
635
 
634
636
  def get_state pos
637
+ return 'a' unless @plan # if no plan, use phase a, which means disabled/dark
635
638
  if pos > @plan.length
636
639
  '.'
637
640
  else
@@ -701,7 +704,7 @@ module RSMP
701
704
  end
702
705
 
703
706
  class DetectorLogic < Component
704
- attr_reader :status, :forced, :value
707
+ attr_reader :forced, :value
705
708
 
706
709
  def initialize node:, id:
707
710
  super node: node, id: id, grouped: false
@@ -781,13 +784,20 @@ module RSMP
781
784
 
782
785
  def handle_m0008 arg
783
786
  @node.verify_security_code 2, arg['securityCode']
784
- force_detector_logic arg['status']=='True', arg['value']='True'
787
+ status = arg['status']=='True'
788
+ mode = arg['mode']=='True'
789
+ force_detector_logic status, mode
785
790
  arg
786
791
  end
787
792
 
788
- def force_detector_logic status, value
789
- @forced = status
793
+ def force_detector_logic forced, value
794
+ @forced = forced
790
795
  @value = value
796
+ if @forced
797
+ log "Forcing to #{value}", level: :info
798
+ else
799
+ log "Releasing", level: :info
800
+ end
791
801
  end
792
802
 
793
803
  end
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.9"
3
3
  end
data/test.rb ADDED
@@ -0,0 +1,27 @@
1
+ class A
2
+ def go &block
3
+ @block = block # block will be converted automatically to a Proc
4
+ indirect
5
+ end
6
+
7
+ def call
8
+ @block.call
9
+ end
10
+
11
+ def indirect
12
+ call
13
+ end
14
+
15
+ end
16
+
17
+ a = A.new
18
+
19
+ a.go do
20
+ break # this is ok. break causes the block to exit, and the encasing method to return - go() will exit
21
+ end
22
+
23
+ # this raises an error. the block we passed to go() will be called again, and it tries to break
24
+ # but we're not inside a method we can exit from
25
+
26
+
27
+ a.indirect
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.3.5
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-22 00:00:00.000000000 Z
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -231,6 +231,7 @@ files:
231
231
  - lib/rsmp/version.rb
232
232
  - lib/rsmp/wait.rb
233
233
  - rsmp.gemspec
234
+ - test.rb
234
235
  homepage: https://github.com/rsmp-nordic/rsmp
235
236
  licenses:
236
237
  - MIT
@@ -254,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
255
  - !ruby/object:Gem::Version
255
256
  version: '0'
256
257
  requirements: []
257
- rubygems_version: 3.2.15
258
+ rubygems_version: 3.2.26
258
259
  signing_key:
259
260
  specification_version: 4
260
261
  summary: RoadSide Message Protocol (RSMP) library.