rsmp 0.9.0 → 0.9.1

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: dde978c380def64dfcad00d0a7c9845a7c57476828623664dcf2ace7f3f6b669
4
- data.tar.gz: 6dadc564b21089271b9921f876b95c899ad42c5bbc27b9250d34b47648447937
3
+ metadata.gz: 40f0ef33eec84edcea172dbc53cf139679e09afb1a717f3081a05c0c5abc94e0
4
+ data.tar.gz: 1d86aeb5a6c3e74757484d1db0e5f89fce122ea66799f275174baa2602d8ab0a
5
5
  SHA512:
6
- metadata.gz: 7bc25b5125c599a5c46db4c919e8bf6891ddad0631de6264dfe5df97eac5cdf85768f099df8f41bff26203fb6fb15d95f4b09c8e2d4b32e80b24b3065be88d1e
7
- data.tar.gz: 8b58da0f830cc4e4fa7f0906a2d691a3d1548b364c21e320c0f597ce4da873dd16b2db0d5e196c70f21fa9126c24a4e3f4c951586768cad0f99b78047ed7eb18
6
+ metadata.gz: a0c09b4ffe312e417095caf7ef426ce4d84649ac81b47d6f6247aa6b42cd689eb3940e23d13eaca8bd0736037571e389d543aeed92972e36de6948a1dd6aab42
7
+ data.tar.gz: cc6ec0019034ea0153448e744ec9cfcf78c3b772bcfcc70b5fc239fb68a295f58c0ca566f66fbe3632b6c0e723d3490cfbf5c5631454ce8c8527d7ac5c8c5bd9
@@ -1,14 +1,21 @@
1
1
  # This workflow runs RSpec tests
2
2
 
3
3
  name: RSpec
4
- on: [push, pull_request]
4
+ on: [push]
5
5
  jobs:
6
6
  test:
7
- runs-on: ubuntu-latest
7
+ timeout-minutes: 10
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ os: [ubuntu-latest, macos-latest, windows-latest, windows-2022]
12
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
13
+ ruby: ['3.0', '3.1']
14
+ runs-on: ${{ matrix.os }}
8
15
  steps:
9
16
  - uses: actions/checkout@v2
10
17
  - uses: ruby/setup-ruby@v1
11
18
  with:
12
- # ruby-version is not needed because we have a .ruby-version file
19
+ ruby-version: ${{ matrix.ruby }}
13
20
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
14
- - run: bundle exec rspec
21
+ - run: bundle exec rspec -f d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.9.0)
4
+ rsmp (0.9.1)
5
5
  async (~> 1.29.1)
6
6
  async-io (~> 1.32.2)
7
7
  colorize (~> 0.8.1)
@@ -64,9 +64,11 @@ GEM
64
64
  ecma-re-validator (0.4.0)
65
65
  regexp_parser (~> 2.2)
66
66
  ffi (1.15.5)
67
+ ffi (1.15.5-x64-mingw-ucrt)
68
+ ffi (1.15.5-x64-mingw32)
67
69
  fiber-local (1.0.0)
68
70
  hana (1.3.7)
69
- json_schemer (0.2.18)
71
+ json_schemer (0.2.19)
70
72
  ecma-re-validator (~> 0.3)
71
73
  hana (~> 1.3)
72
74
  regexp_parser (~> 2.0)
@@ -77,7 +79,7 @@ GEM
77
79
  multi_test (0.1.2)
78
80
  nio4r (2.5.8)
79
81
  rake (13.0.6)
80
- regexp_parser (2.2.0)
82
+ regexp_parser (2.2.1)
81
83
  rsmp_schemer (0.3.2)
82
84
  json_schemer (~> 0.2.18)
83
85
  rspec (3.10.0)
@@ -101,6 +103,9 @@ GEM
101
103
  uri_template (0.7.0)
102
104
 
103
105
  PLATFORMS
106
+ x64-mingw-ucrt
107
+ x64-mingw32
108
+ x86_64-darwin-19
104
109
  x86_64-darwin-20
105
110
  x86_64-darwin-21
106
111
  x86_64-linux
data/README.md CHANGED
@@ -13,16 +13,6 @@ $ gem install bundler
13
13
  $ bundle
14
14
  ```
15
15
 
16
- Install git submodules:
17
- The JSON Schema is is included as a git submodule. To install it:
18
-
19
- ```console
20
- $ git submodule init # initialize local submodule config
21
- $ git submodule update # fetch submodules
22
- ```
23
-
24
- Alternatively, you can pass --recurse-submodules to the git clone command, and it will automatically initialize and update each submodule in the repository.
25
-
26
16
  ## Usage
27
17
  ### Site and Supervisor
28
18
  The RSMP::Site and RSMP::Supervisor classes can be used to run a RSMP site.
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: --publish-quiet
data/lib/rsmp/cli.rb CHANGED
@@ -161,5 +161,10 @@ module RSMP
161
161
  RSMP::Convert::Export::JSONSchema.write sxl, options[:out]
162
162
  end
163
163
 
164
+ # avoid Thor returnin 0 on failures, see
165
+ # https://github.com/coinbase/salus/pull/380/files
166
+ def self.exit_on_failure?
167
+ true
168
+ end
164
169
  end
165
170
  end
@@ -1,5 +1,6 @@
1
1
  class Hash
2
2
  def deep_merge(other_hash)
3
+ return self unless other_hash
3
4
  self.merge(other_hash) do |key, old, fresh|
4
5
  if old.is_a?(Hash) && fresh.is_a?(Hash)
5
6
  old.deep_merge(fresh)
@@ -72,7 +72,7 @@ module RSMP
72
72
  else
73
73
  super message
74
74
  end
75
- rescue RSMP::RepeatedAlarmError, RSMP::RepeatedStatusError
75
+ rescue RSMP::RepeatedAlarmError, RSMP::RepeatedStatusError => e
76
76
  str = "Rejected #{message.type} message,"
77
77
  dont_acknowledge message, str, "#{e}"
78
78
  notify_error e.exception("#{str}#{e.message} #{message.json}")
@@ -71,10 +71,13 @@ module RSMP
71
71
  def connect_tcp
72
72
  @endpoint = Async::IO::Endpoint.tcp(@ip, @port)
73
73
 
74
- # Async::IO::Endpoint#connect renames the current task. run in a subtask to avoid this
74
+ # Async::IO::Endpoint#connect renames the current task. run in a subtask to avoid this see issue #22
75
75
  @task.async do |task|
76
76
  task.annotate 'socket task'
77
- @socket = @endpoint.connect
77
+ # this timeout is a workaround for #connect hanging on windows if the other side is not present yet
78
+ task.with_timeout 1.1 do
79
+ @socket = @endpoint.connect
80
+ end
78
81
  end.wait
79
82
 
80
83
  @stream = Async::IO::Stream.new(@socket)
data/lib/rsmp/task.rb CHANGED
@@ -29,7 +29,7 @@ module RSMP
29
29
  end
30
30
 
31
31
  # get the status of our task, or nil of no task
32
- def status
32
+ def task_status
33
33
  @task.status if @task
34
34
  end
35
35
 
@@ -49,6 +49,8 @@ module RSMP
49
49
 
50
50
  @inputs = '0'*@num_inputs
51
51
  @input_activations = '0'*@num_inputs
52
+ @input_forced = '0'*@num_inputs
53
+ @input_forced_values = '0'*@num_inputs
52
54
  @input_results = '0'*@num_inputs
53
55
 
54
56
  @day_time_table = {}
@@ -167,6 +169,10 @@ module RSMP
167
169
 
168
170
  plan = "P#{@plan}"
169
171
 
172
+ # create folders if needed
173
+ FileUtils.mkdir_p File.dirname(@live_output)
174
+
175
+ # append a line with the current state to the file
170
176
  File.open @live_output, 'w' do |file|
171
177
  file.puts "#{modes} #{plan.rjust(2)} #{@cycle_counter.to_s.rjust(3)} #{str}\r"
172
178
  end
@@ -228,18 +234,27 @@ module RSMP
228
234
  end
229
235
  end
230
236
 
237
+ def recompute_input idx
238
+ if @input_forced[idx] == '1'
239
+ @input_results[idx] = @input_forced_values[idx]
240
+ elsif @input_activations[idx]=='1'
241
+ @input_results[idx] = '1'
242
+ else
243
+ @input_results[idx] = bool_to_digit( @inputs[idx]=='1' )
244
+ end
245
+ end
246
+
231
247
  def handle_m0006 arg
232
248
  @node.verify_security_code 2, arg['securityCode']
233
249
  input = arg['input'].to_i
234
250
  idx = input - 1
235
251
  return unless idx>=0 && input<@num_inputs # TODO should NotAck
236
- @input_activations[idx] = (arg['status']=='True' ? '1' : '0')
237
- result = @input_activations[idx]=='1' || @inputs[idx]=='1'
238
- @input_results[idx] = (result ? '1' : '0')
252
+ @input_activations[idx] = bool_string_to_digit arg['status']
253
+ recompute_input idx
239
254
  if @input_activations[idx]
240
- log "Activate input #{idx}", level: :info
255
+ log "Activating input #{idx+1}", level: :info
241
256
  else
242
- log "Deactivate input #{idx}", level: :info
257
+ log "Deactivating input #{idx+1}", level: :info
243
258
  end
244
259
  end
245
260
 
@@ -302,8 +317,39 @@ module RSMP
302
317
  @node.verify_security_code 2, arg['securityCode']
303
318
  end
304
319
 
320
+ def bool_string_to_digit bool
321
+ case bool
322
+ when 'True'
323
+ '1'
324
+ when 'False'
325
+ '0'
326
+ else
327
+ raise RSMP::MessageRejected.new "Invalid boolean '#{bool}', must be 'True' or 'False'"
328
+ end
329
+ end
330
+
331
+ def bool_to_digit bool
332
+ bool ? '1' : '0'
333
+ end
334
+
305
335
  def handle_m0019 arg
306
336
  @node.verify_security_code 2, arg['securityCode']
337
+ input = arg['input'].to_i
338
+ idx = input - 1
339
+ unless idx>=0 && input<@num_inputs # TODO should NotAck
340
+ log "Can't force input #{idx+1}, only have #{@num_inputs} inputs", level: :warning
341
+ return
342
+ end
343
+ @input_forced[idx] = bool_string_to_digit arg['status']
344
+ if @input_forced[idx]
345
+ @input_forced_values[idx] = bool_string_to_digit arg['inputValue']
346
+ end
347
+ recompute_input idx
348
+ if @input_forced[idx]
349
+ log "Forcing input #{idx+1} to #{@input_forced_values[idx]}, #{@input_results}", level: :info
350
+ else
351
+ log "Releasing input #{idx+1}", level: :info
352
+ end
307
353
  end
308
354
 
309
355
  def handle_m0020 arg
@@ -336,7 +382,7 @@ module RSMP
336
382
 
337
383
  def set_input i, value
338
384
  return unless i>=0 && i<@num_inputs
339
- @inputs[i] = (arg['value'] ? '1' : '0')
385
+ @inputs[i] = bool_to_digit arg['value']
340
386
  end
341
387
 
342
388
  def set_fixed_time_control status
@@ -402,7 +448,7 @@ module RSMP
402
448
  def handle_s0002 status_code, status_name=nil
403
449
  case status_name
404
450
  when 'detectorlogicstatus'
405
- TrafficControllerSite.make_status @detector_logics.map { |dl| dl.value ? '1' : '0' }.join
451
+ TrafficControllerSite.make_status @detector_logics.map { |dl| bool_to_digit(dl.value) }.join
406
452
  end
407
453
  end
408
454
 
@@ -557,7 +603,7 @@ module RSMP
557
603
  def handle_s0021 status_code, status_name=nil
558
604
  case status_name
559
605
  when 'detectorlogics'
560
- TrafficControllerSite.make_status @detector_logics.map { |logic| logic.forced=='True' ? '1' : '0'}.join
606
+ TrafficControllerSite.make_status @detector_logics.map { |logic| bool_to_digit(logic.forced)}.join
561
607
  end
562
608
  end
563
609
 
@@ -611,7 +657,7 @@ module RSMP
611
657
  def handle_s0029 status_code, status_name=nil
612
658
  case status_name
613
659
  when 'status'
614
- TrafficControllerSite.make_status ''
660
+ TrafficControllerSite.make_status @input_forced
615
661
  end
616
662
  end
617
663
 
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
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.0
4
+ version: 0.9.1
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-01-31 00:00:00.000000000 Z
11
+ date: 2022-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -201,6 +201,7 @@ files:
201
201
  - bin/setup
202
202
  - config/supervisor.yaml
203
203
  - config/tlc.yaml
204
+ - cucumber.yml
204
205
  - documentation/classes_and_modules.md
205
206
  - documentation/collecting_message.md
206
207
  - documentation/message_distribution.md