rsmp 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/config/supervisor.yaml +0 -1
- data/lib/rsmp/message.rb +12 -20
- data/lib/rsmp/proxy.rb +15 -14
- data/lib/rsmp/site.rb +1 -1
- data/lib/rsmp/site_base.rb +4 -0
- data/lib/rsmp/site_proxy.rb +11 -0
- data/lib/rsmp/supervisor.rb +0 -1
- data/lib/rsmp/supervisor_proxy.rb +5 -1
- data/lib/rsmp/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ade1272155b959eee2f256b18425d9e1b14f3d4f2edeeebf73a1d29fbc4f78d
|
4
|
+
data.tar.gz: 3fafb63cb31a0e8a5db5c4d010d907b85ef8dbfd5100ae17bad6abe9926106d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3325ace5e118a54366f1333534f15f840c24d8dd272c2d7badef868b2ef23c4e029d1e2e9627af9fe9519222504c1e5a250f17957f7df0bc294c9a3e8a039459
|
7
|
+
data.tar.gz: 2820ddf6b3ab584e86f7a9a2ab0fb724092ae7ce550e8123715b412867cf926850fa76033cea0a5b5275b3943621ca53b170981201a46560aa852cda161b9900
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/config/supervisor.yaml
CHANGED
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[
|
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
|
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
|
32
|
-
raise ArgumentError unless
|
33
|
-
JSON.parse
|
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(
|
35
|
+
raise InvalidPacket, bin_to_chars(json)
|
36
36
|
end
|
37
37
|
|
38
|
-
def self.build attributes,
|
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 =
|
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
|
-
|
134
|
-
|
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,
|
77
|
+
@protocol = Async::IO::Protocol::Line.new(@stream,RSMP::WRAPPING_DELIMITER) # rsmp messages are json terminated with a form-feed
|
77
78
|
|
78
|
-
while
|
79
|
+
while json = @protocol.read_line
|
79
80
|
beginning = Time.now
|
80
|
-
message = process_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.
|
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
|
234
|
-
attributes = Message.parse_attributes
|
235
|
-
message = Message.build attributes,
|
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 #{
|
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"=>
|
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
|
data/lib/rsmp/site_base.rb
CHANGED
data/lib/rsmp/site_proxy.rb
CHANGED
@@ -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
|
data/lib/rsmp/supervisor.rb
CHANGED
@@ -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,
|
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
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.
|
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
|
+
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.
|
360
|
+
rubygems_version: 3.0.6
|
361
361
|
signing_key:
|
362
362
|
specification_version: 4
|
363
363
|
summary: RoadSide Message Protocol (RSMP) library.
|