rsmp 0.20.4 → 0.20.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4c2f0ad26f341d78dba43980b9f873a75bf06d2233ffa3f27b30b3f7d83e297
4
- data.tar.gz: 84187fc4d5c836233397ff20ffff5cdf236435069d3edb436999fe5f8de1436b
3
+ metadata.gz: 77314f562ebf956079f50f9cabd90be180010d39d55ecc2b96aceeab7b6da553
4
+ data.tar.gz: 2c67e8fcca60ecdefec7edb539f56b7625046f3ef7e8d7a0801640c05f8f0535
5
5
  SHA512:
6
- metadata.gz: 1950948c8087db84fbf12069e4fcee10160efa8e4031ba618dcbdf04c130104df5f6e8467f0cfdb647615ab5de3b96fcb7cc9cfeaf5ec458bc0471e9f09676e2
7
- data.tar.gz: c9999221cc2b49d5320d2769230e8ba7c9e54bf5a4f4e37c7efdef599b7745f8d85dbb29c2ed7fc01304604e591a5303422e813e9dee978286760e3897705aa2
6
+ metadata.gz: 68a66a9531bff5c01cd743ae61a2b159bae2ce0dc6cfd393b5fa9deddda3838d771cfd1025a25ec8231a5d099d5e1976bbbc9418738ee0ba528875e3d8e63327
7
+ data.tar.gz: bac2a033fa66291905fa0ba5a66d79a9bb114900ff7d62f4ec696b7ba5271b8454793c1866f9607f0de0638c9950a09822640935541e9663ee01f74295469834
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.20.4)
4
+ rsmp (0.20.7)
5
5
  async (~> 2.6.2)
6
6
  async-io (~> 1.35.0)
7
7
  colorize (~> 0.8.1)
@@ -18,7 +18,7 @@ GEM
18
18
  cucumber (>= 4.0, < 9.0)
19
19
  rspec-expectations (~> 3.4)
20
20
  thor (~> 1.0)
21
- async (2.6.2)
21
+ async (2.6.3)
22
22
  console (~> 1.10)
23
23
  fiber-annotation
24
24
  io-event (~> 1.1)
@@ -28,7 +28,7 @@ GEM
28
28
  builder (3.2.4)
29
29
  childprocess (4.1.0)
30
30
  colorize (0.8.1)
31
- console (1.17.2)
31
+ console (1.21.0)
32
32
  fiber-annotation
33
33
  fiber-local
34
34
  contracts (0.17)
@@ -63,7 +63,7 @@ GEM
63
63
  fiber-annotation (0.2.0)
64
64
  fiber-local (1.0.0)
65
65
  hana (1.3.7)
66
- io-event (1.2.2)
66
+ io-event (1.2.3)
67
67
  json_schemer (0.2.25)
68
68
  ecma-re-validator (~> 0.3)
69
69
  hana (~> 1.3)
@@ -76,7 +76,7 @@ GEM
76
76
  multi_test (1.1.0)
77
77
  rake (13.0.6)
78
78
  regexp_parser (2.8.1)
79
- rsmp_schema (0.4.0)
79
+ rsmp_schema (0.4.5)
80
80
  json_schemer (~> 0.2.21)
81
81
  thor (~> 1.2.1)
82
82
  rspec (3.12.0)
@@ -39,22 +39,21 @@ module RSMP
39
39
  end
40
40
 
41
41
  def infer_component_type component_id
42
- Component
42
+ raise UnknownComponent.new("Component #{component_id} mising and cannot infer type")
43
43
  end
44
44
 
45
45
  def find_component component_id, build: true
46
46
  component = @components[component_id]
47
47
  return component if component
48
- if build && !component_id.empty?
49
- inferred = infer_component_type component_id
50
- component = inferred.new node: self, id: component_id
48
+ if build
49
+ inferred_type = infer_component_type component_id
50
+ component = inferred_type.new node: self, id: component_id
51
51
  @components[ component_id] = component
52
52
  class_name = component.class.name.split('::').last
53
53
  class_name << " component" unless (class_name == 'Component' || class_name == 'ComponentProxy')
54
- log "Adding component #{component_id} with the inferred type #{class_name}", level: :debug
54
+ log "Added component #{component_id} with the inferred type #{class_name}", level: :debug
55
55
  component
56
56
  else
57
- raise UnknownComponent.new("Component #{component_id} not found") unless component
58
57
  end
59
58
  end
60
59
 
data/lib/rsmp/proxy.rb CHANGED
@@ -403,8 +403,7 @@ module RSMP
403
403
  nil
404
404
  rescue SchemaError, RSMP::Schema::Error => e
405
405
  reason = "schema errors: #{e.message}"
406
- str = "Received invalid #{message.type}, #{reason}"
407
- log str, message: message, level: :warning
406
+ str = "Received invalid #{message.type}"
408
407
  notify_error e.exception(str), message: message
409
408
  dont_acknowledge message, str, reason
410
409
  message
@@ -67,8 +67,9 @@ module RSMP
67
67
  def connect_tcp
68
68
  @endpoint = Async::IO::Endpoint.tcp(@ip, @port)
69
69
 
70
+ error = nil
70
71
  # Async::IO::Endpoint#connect renames the current task. run in a subtask to avoid this see issue #22
71
- @task.async do |task|
72
+ result = @task.async do |task|
72
73
  task.annotate 'socket task'
73
74
  # this timeout is a workaround for connect hanging on windows if the other side is not present yet
74
75
  timeout = @site_settings.dig('timeouts','connect') || 1.1
@@ -77,7 +78,11 @@ module RSMP
77
78
  end
78
79
  delay = @site_settings.dig('intervals','after_connect')
79
80
  task.sleep delay if delay
81
+ rescue Errno::ECONNREFUSED => e # rescue to avoid log output
82
+ log "Connection refused", level: :warning
83
+ error = e
80
84
  end.wait
85
+ raise error if error # reraise any error outside task
81
86
 
82
87
  @stream = Async::IO::Stream.new(@socket)
83
88
  @protocol = Async::IO::Protocol::Line.new(@stream,WRAPPING_DELIMITER) # rsmp messages are json terminated with a form-feed
@@ -276,8 +281,8 @@ module RSMP
276
281
  component.handle_command command_code,arg
277
282
  end
278
283
  log "Received #{message.type}", message: message, level: :log
279
- rescue UnknownComponent => e
280
- log "Received #{message.type} with unknown component id '#{component_id}'", message: message, level: :warning
284
+ rescue UnknownComponent
285
+ log "Received #{message.type} with unknown component id '#{component_id}' and cannot infer type", message: message, level: :warning
281
286
  # If the component is unknown, we must set age=undefined for all items,
282
287
  # while still acknowledge the message.
283
288
  # See https://github.com/rsmp-nordic/rsmp_validator/issues/271
@@ -302,19 +307,32 @@ module RSMP
302
307
  end
303
308
 
304
309
  def process_status_request message, options={}
305
- component_id = message.attributes["cId"]
306
- component = @site.find_component component_id
307
- log "Received #{message.type}", message: message, level: :log
308
- sS = message.attributes["sS"].map do |arg|
309
- value, quality = component.get_status arg['sCI'], arg['n'], {sxl_version: sxl_version}
310
- { "s" => rsmpify_value(value), "q" => quality.to_s }.merge arg
310
+ sS = []
311
+ begin
312
+ component_id = message.attributes["cId"]
313
+ component = @site.find_component component_id
314
+ sS = message.attributes["sS"].map do |arg|
315
+ value, quality = component.get_status arg['sCI'], arg['n'], {sxl_version: sxl_version}
316
+ { "s" => rsmpify_value(value), "q" => quality.to_s }.merge arg
317
+ end
318
+ log "Received #{message.type}", message: message, level: :log
319
+
320
+ rescue UnknownComponent
321
+ log "Received #{message.type} with unknown component id '#{component_id}' and cannot infer type", message: message, level: :warning
322
+ # If the component is unknown, we must set q=undefined and s=nil for all items,
323
+ # while still acknowledge the message.
324
+ sS = message.attributes["sS"].map do |arg|
325
+ arg.dup.merge('q'=>'undefined','s'=>nil)
326
+ end
311
327
  end
328
+
312
329
  response = StatusResponse.new({
313
330
  "cId"=>component_id,
314
331
  "sTs"=>clock.to_s,
315
332
  "sS"=>sS,
316
333
  "mId" => options[:m_id]
317
334
  })
335
+
318
336
  set_nts_message_attributes response
319
337
  acknowledge message
320
338
  send_message response
@@ -538,7 +538,7 @@ module RSMP
538
538
 
539
539
  def switch_functional_position mode, timeout: nil, reverting: false, source:
540
540
  unless ['NormalControl','YellowFlash','Dark'].include? mode
541
- raise RSMP::MessageRejected.new "Invalid functional position '#{mode}', must be NormalControl, YellowFlash or Dark'"
541
+ raise RSMP::MessageRejected.new "Invalid functional position #{mode.inspect}, must be NormalControl, YellowFlash or Dark"
542
542
  end
543
543
  if reverting
544
544
  log "Reverting to functional position #{mode} after timeout", level: :info
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.20.4"
2
+ VERSION = "0.20.7"
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.20.4
4
+ version: 0.20.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-10 00:00:00.000000000 Z
11
+ date: 2023-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async