rsmp 0.1.2 → 0.1.3

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: ce30f264a7328d7e272f655821ace2fc1a7a7e38a27a7d636f1cea859d10750d
4
- data.tar.gz: 34009cd95e04c16dd14ab05c38dc86b9edfd581c4ed3071c97b9385da4dd7a89
3
+ metadata.gz: 8ade1272155b959eee2f256b18425d9e1b14f3d4f2edeeebf73a1d29fbc4f78d
4
+ data.tar.gz: 3fafb63cb31a0e8a5db5c4d010d907b85ef8dbfd5100ae17bad6abe9926106d9
5
5
  SHA512:
6
- metadata.gz: 3c4024f635000e632061e7026a2d3d9c6f73bc56f4ec0c2758518f1734b148ab81edb1f305c81a31d501dfab6b84975793a12e0a662e634edc8e3e46dcf8dff4
7
- data.tar.gz: 3668868ba224b9fca05a2b00b847c53a4f31b31745779346c55380eebea138b8150c3be2b5fe022970e4e9f0d7be0e64ba1178cfbe7ffed0c2f813afa96a9827
6
+ metadata.gz: 3325ace5e118a54366f1333534f15f840c24d8dd272c2d7badef868b2ef23c4e029d1e2e9627af9fe9519222504c1e5a250f17957f7df0bc294c9a3e8a039459
7
+ data.tar.gz: 2820ddf6b3ab584e86f7a9a2ab0fb724092ae7ce550e8123715b412867cf926850fa76033cea0a5b5275b3943621ca53b170981201a46560aa852cda161b9900
data/CHANGELOG.md CHANGED
@@ -2,3 +2,12 @@
2
2
 
3
3
  ## 0.1.0
4
4
  Initial release.
5
+
6
+ ## 0.1.1
7
+ Refactoring.
8
+
9
+ ## 0.1.2
10
+ Refactoring.
11
+
12
+ ## 0.1.3
13
+ Refactoring.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.1.1)
4
+ rsmp (0.1.3)
5
5
  async (~> 1.23.0)
6
6
  async-io (~> 1.27.0)
7
7
  colorize (~> 0.8.1)
@@ -13,7 +13,6 @@ status_update_timeout: 1
13
13
 
14
14
  sites:
15
15
  AA+BBCCC=DDD: # rsmp simulator
16
- sxl: core
17
16
  RN+SI0001: # ruby rsmp site
18
17
 
19
18
  log:
data/lib/rsmp/message.rb CHANGED
@@ -11,7 +11,7 @@ module RSMP
11
11
  @@schemas = {}
12
12
 
13
13
  core_schema_path = File.join(schema_path,'core','rsmp.json')
14
- @@schemas['core'] = JSONSchemer.schema( Pathname.new(core_schema_path) )
14
+ @@schemas[nil] = JSONSchemer.schema( Pathname.new(core_schema_path) )
15
15
 
16
16
  tlc_schema_path = File.join(schema_path,'tlc','sxl.json')
17
17
  @@schemas['traffic_light_controller'] = JSONSchemer.schema( Pathname.new(tlc_schema_path) )
@@ -19,7 +19,7 @@ module RSMP
19
19
  @@schemas
20
20
  end
21
21
 
22
- def self.get_schema sxl = 'core'
22
+ def self.get_schema sxl=nil
23
23
  schema = @@schemas[sxl]
24
24
  raise SchemaError.new("Unknown schema #{sxl}") unless schema
25
25
  schema
@@ -28,14 +28,14 @@ module RSMP
28
28
  @@schemas = load_schemas
29
29
 
30
30
 
31
- def self.parse_attributes packet
32
- raise ArgumentError unless packet
33
- JSON.parse packet
31
+ def self.parse_attributes json
32
+ raise ArgumentError unless json
33
+ JSON.parse json
34
34
  rescue JSON::ParserError
35
- raise InvalidPacket, bin_to_chars(packet)
35
+ raise InvalidPacket, bin_to_chars(json)
36
36
  end
37
37
 
38
- def self.build attributes, packet
38
+ def self.build attributes, json
39
39
  validate_message_type attributes
40
40
  case attributes["type"]
41
41
  when "MessageAck"
@@ -67,7 +67,7 @@ module RSMP
67
67
  else
68
68
  message = Unknown.new attributes
69
69
  end
70
- message.json = packet
70
+ message.json = json
71
71
  message.direction = :in
72
72
  message
73
73
  end
@@ -129,9 +129,10 @@ module RSMP
129
129
  @attributes["mId"] ||= SecureRandom.uuid()
130
130
  end
131
131
 
132
- def validate
133
- unless Message.get_schema.valid? attributes
134
- errors = Message.get_schema.validate attributes
132
+ def validate sxl=nil
133
+ schema = Message.get_schema(sxl)
134
+ unless schema.valid? attributes
135
+ errors = schema.validate attributes
135
136
  error_string = errors.map do |item|
136
137
  [item['data_pointer'],item['type'],item['details']].compact.join(' ')
137
138
  end.join(", ")
@@ -153,10 +154,6 @@ module RSMP
153
154
 
154
155
  def generate_json
155
156
  @json = JSON.generate @attributes
156
-
157
- # wrap json with a form feed to create an rsmp packet,
158
- #as required by the rsmp specification
159
- @out = "#{@json}"
160
157
  end
161
158
 
162
159
  end
@@ -176,11 +173,6 @@ module RSMP
176
173
  }.merge attributes)
177
174
  end
178
175
 
179
- def validate
180
- super &&
181
- @attributes["RSMP"].is_a?(Array) && @attributes["RSMP"].size >= 1
182
- end
183
-
184
176
  def versions
185
177
  attribute("RSMP").map{ |item| item["vers"] }
186
178
  end
data/lib/rsmp/proxy.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RSMP
4
4
  class Proxy < Base
5
- attr_reader :site_ids, :state, :archive, :connection_info
5
+ attr_reader :site_ids, :state, :archive, :connection_info, :sxl
6
6
 
7
7
  def initialize options
8
8
  super options
@@ -11,6 +11,7 @@ module RSMP
11
11
  @socket = options[:socket]
12
12
  @ip = options[:ip]
13
13
  @connection_info = options[:info]
14
+ @sxl = nil
14
15
  clear
15
16
  end
16
17
 
@@ -73,11 +74,11 @@ module RSMP
73
74
  @reader = @task.async do |task|
74
75
  task.annotate "reader"
75
76
  @stream = Async::IO::Stream.new(@socket)
76
- @protocol = Async::IO::Protocol::Line.new(@stream,"\f") # rsmp messages are json terminated with a form-feed
77
+ @protocol = Async::IO::Protocol::Line.new(@stream,RSMP::WRAPPING_DELIMITER) # rsmp messages are json terminated with a form-feed
77
78
 
78
- while packet = @protocol.read_line
79
+ while json = @protocol.read_line
79
80
  beginning = Time.now
80
- message = process_packet packet
81
+ message = process_packet json
81
82
  duration = Time.now - beginning
82
83
  ms = (duration*1000).round(4)
83
84
  per_second = (1.0 / duration).round
@@ -169,7 +170,7 @@ module RSMP
169
170
  @awaiting_acknowledgement.clone.each_pair do |m_id, message|
170
171
  latest = message.timestamp + timeout
171
172
  if now > latest
172
- log "No acknowledgements for #{message.type} within #{timeout} seconds", level: :error
173
+ log "No acknowledgements for #{message.type} #{message.m_id_short} within #{timeout} seconds", level: :error
173
174
  stop
174
175
  return true
175
176
  end
@@ -199,11 +200,11 @@ module RSMP
199
200
 
200
201
  def send_message message, reason=nil
201
202
  raise IOError unless @protocol
202
- message.validate
203
203
  message.generate_json
204
+ message.validate sxl
204
205
  message.direction = :out
205
206
  expect_acknowledgement message
206
- @protocol.write_lines message.out
207
+ @protocol.write_lines message.json
207
208
  log_send message, reason
208
209
  rescue EOFError, IOError
209
210
  buffer_message message
@@ -230,15 +231,15 @@ module RSMP
230
231
  end
231
232
  end
232
233
 
233
- def process_packet packet
234
- attributes = Message.parse_attributes packet
235
- message = Message.build attributes, packet
234
+ def process_packet json
235
+ attributes = Message.parse_attributes json
236
+ message = Message.build attributes, json
236
237
  message.validate
237
238
  expect_version_message(message) unless @version_determined
238
239
  process_message message
239
240
  message
240
241
  rescue InvalidPacket => e
241
- warning "Received invalid package, must be valid JSON but got #{packet.size} bytes: #{e.message}"
242
+ warning "Received invalid package, must be valid JSON but got #{json.size} bytes: #{e.message}"
242
243
  nil
243
244
  rescue MalformedMessage => e
244
245
  warning "Received malformed message, #{e.message}", Malformed.new(attributes)
@@ -309,14 +310,14 @@ module RSMP
309
310
  site_ids_changed
310
311
  rsmp_version = check_rsmp_version message
311
312
  set_state :version_determined
312
- check_sxl_version
313
+ check_sxl_version message
313
314
  version_accepted message, rsmp_version
314
315
  end
315
316
 
316
317
  def site_ids_changed
317
318
  end
318
319
 
319
- def check_sxl_version
320
+ def check_sxl_version message
320
321
  end
321
322
 
322
323
  def acknowledge original
@@ -358,7 +359,7 @@ module RSMP
358
359
  version_response = Version.new({
359
360
  "RSMP"=>versions_hash,
360
361
  "siteId"=>[{"sId"=>@settings["site_id"]}],
361
- "SXL"=>"1.1"
362
+ "SXL"=>sxl_version
362
363
  })
363
364
  send_message version_response
364
365
  end
data/lib/rsmp/site.rb CHANGED
@@ -27,6 +27,7 @@ module RSMP
27
27
  { 'ip' => '127.0.0.1', 'port' => 12111 }
28
28
  ],
29
29
  'rsmp_versions' => ['3.1.1','3.1.2','3.1.3','3.1.4'],
30
+ 'sxl_version' => '1.0.7',
30
31
  'timer_interval' => 0.1,
31
32
  'watchdog_interval' => 1,
32
33
  'watchdog_timeout' => 2,
@@ -160,6 +161,5 @@ module RSMP
160
161
  proxy.stop
161
162
  end
162
163
  end
163
-
164
164
  end
165
165
  end
@@ -18,6 +18,10 @@ module RSMP
18
18
  end
19
19
  end
20
20
 
21
+ def add_component component
22
+ @components[component.c_id] = component
23
+ end
24
+
21
25
  def build_component id, settings={}
22
26
  Component.new id: id, node: self, grouped: true
23
27
  end
@@ -216,5 +216,16 @@ module RSMP
216
216
  @settings["watchdog_interval"] = interval
217
217
  end
218
218
 
219
+ def check_sxl_version message
220
+ super message
221
+ @site_sxl_version = message.attribute 'SXL'
222
+ end
223
+
224
+ def sxl_version
225
+ # a supervisor does not maintain it's own sxl version
226
+ # instead we use what the site requests
227
+ @site_sxl_version
228
+ end
229
+
219
230
  end
220
231
  end
@@ -215,6 +215,5 @@ module RSMP
215
215
 
216
216
  def aggregated_status_changed site_proxy, component
217
217
  end
218
-
219
218
  end
220
219
  end
@@ -13,6 +13,7 @@ module RSMP
13
13
  @port = options[:port]
14
14
  @status_subscriptions = {}
15
15
  @status_subscriptions_mutex = Mutex.new
16
+ @sxl = @site_settings['sxl']
16
17
  end
17
18
 
18
19
  def node
@@ -39,7 +40,7 @@ module RSMP
39
40
  @endpoint = Async::IO::Endpoint.tcp(@ip, @port)
40
41
  @socket = @endpoint.connect
41
42
  @stream = Async::IO::Stream.new(@socket)
42
- @protocol = Async::IO::Protocol::Line.new(@stream,"\f") # rsmp messages are json terminated with a form-feed
43
+ @protocol = Async::IO::Protocol::Line.new(@stream,RSMP::WRAPPING_DELIMITER) # rsmp messages are json terminated with a form-feed
43
44
  end
44
45
 
45
46
  def connection_complete
@@ -288,5 +289,8 @@ module RSMP
288
289
  send_message message
289
290
  end
290
291
 
292
+ def sxl_version
293
+ @site_settings['sxl_version']
294
+ end
291
295
  end
292
296
  end
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-12 00:00:00.000000000 Z
11
+ date: 2019-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -357,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
357
357
  - !ruby/object:Gem::Version
358
358
  version: '0'
359
359
  requirements: []
360
- rubygems_version: 3.0.3
360
+ rubygems_version: 3.0.6
361
361
  signing_key:
362
362
  specification_version: 4
363
363
  summary: RoadSide Message Protocol (RSMP) library.