Class: OpenC3::StreamingWebSocketApi
- Inherits:
-
CmdTlmWebSocketApi
- Object
- WebSocketApi
- CmdTlmWebSocketApi
- OpenC3::StreamingWebSocketApi
- Defined in:
- lib/openc3/script/web_socket_api.rb
Overview
Streaming API WebSocket
Constant Summary
Constants inherited from WebSocketApi
Class Method Summary collapse
-
.read_all(items: nil, packets: nil, start_time: nil, end_time:, scope: $openc3_scope, timeout: nil) ⇒ Object
Convenience method to read all data until end marker is received.
Instance Method Summary collapse
-
#add(items: nil, packets: nil, start_time: nil, end_time: nil, scope: $openc3_scope) ⇒ Object
Request to add data to the stream.
-
#initialize(url: nil, write_timeout: 10.0, read_timeout: 10.0, connect_timeout: 5.0, authentication: nil, scope: $openc3_scope) ⇒ StreamingWebSocketApi
constructor
A new instance of StreamingWebSocketApi.
-
#remove(items: nil, packets: nil, scope: $openc3_scope) ⇒ Object
Request to remove data from the stream.
Methods inherited from CmdTlmWebSocketApi
Methods inherited from WebSocketApi
#connect, #connected?, #disconnect, #generate_auth, #read, #read_message, #subscribe, #unsubscribe, #write, #write_action
Constructor Details
#initialize(url: nil, write_timeout: 10.0, read_timeout: 10.0, connect_timeout: 5.0, authentication: nil, scope: $openc3_scope) ⇒ StreamingWebSocketApi
Returns a new instance of StreamingWebSocketApi.
300 301 302 303 304 305 |
# File 'lib/openc3/script/web_socket_api.rb', line 300 def initialize(url: nil, write_timeout: 10.0, read_timeout: 10.0, connect_timeout: 5.0, authentication: nil, scope: $openc3_scope) @identifier = { channel: "StreamingChannel" } super(url: url, write_timeout: write_timeout, read_timeout: read_timeout, connect_timeout: connect_timeout, authentication: authentication, scope: scope) end |
Class Method Details
.read_all(items: nil, packets: nil, start_time: nil, end_time:, scope: $openc3_scope, timeout: nil) ⇒ Object
Convenience method to read all data until end marker is received. Warning: DATA IS STORED IN RAM. Do not use this with large queries
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/openc3/script/web_socket_api.rb', line 382 def self.read_all(items: nil, packets: nil, start_time: nil, end_time:, scope: $openc3_scope, timeout: nil) read_all_start_time = Time.now data = [] self.new do |api| api.add(items: items, packets: packets, start_time: start_time, end_time: end_time, scope: scope) while true batch = api.read if batch.length == 0 return data else data.concat(batch) end if timeout if (Time.now - read_all_start_time) > timeout return data end end end end end |
Instance Method Details
#add(items: nil, packets: nil, start_time: nil, end_time: nil, scope: $openc3_scope) ⇒ Object
Request to add data to the stream
arguments: scope: scope name start_time: 64-bit nanoseconds from unix epoch - If not present then realtime end_time: 64-bit nanoseconds from unix epoch - If not present stream forever items: [ [ MODE__CMDORTLM__TARGET__PACKET__ITEM__VALUETYPE__REDUCEDTYPE, item_key] ]
MODE - RAW, DECOM, REDUCED_MINUTE, REDUCED_HOUR, or REDUCED_DAY
CMDORTLM - CMD or TLM
TARGET - Target name
PACKET - Packet name
ITEM - Item Name
VALUETYPE - RAW, CONVERTED, FORMATTED, or WITH_UNITS
REDUCEDTYPE - MIN, MAX, AVG, STDDEV (only for reduced modes)
item_key is an optional shortened name to return the data as
packets: [ MODE__CMDORTLM__TARGET__PACKET__VALUETYPE ]
MODE - RAW, DECOM, REDUCED_MINUTE, REDUCED_HOUR, or REDUCED_DAY
CMDORTLM - CMD or TLM
TARGET - Target name
PACKET - Packet name
VALUETYPE - RAW, CONVERTED, FORMATTED, WITH_UNITS, or PURE (pure means all types as stored in log)
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/openc3/script/web_socket_api.rb', line 329 def add(items: nil, packets: nil, start_time: nil, end_time: nil, scope: $openc3_scope) data_hash = {} data_hash['action'] = 'add' if start_time if Time === start_time start_time = start_time.to_nsec_from_epoch end data_hash['start_time'] = start_time end if end_time if Time === end_time end_time = end_time.to_nsec_from_epoch end data_hash['end_time'] = end_time end data_hash['items'] = items if items data_hash['packets'] = packets if packets data_hash['scope'] = scope data_hash['token'] = @authentication.token write_action(data_hash) end |
#remove(items: nil, packets: nil, scope: $openc3_scope) ⇒ Object
Request to remove data from the stream
arguments: scope: scope name items: [ [ MODE__CMDORTLM__TARGET__PACKET__ITEM__VALUETYPE__REDUCEDTYPE] ]
MODE - RAW, DECOM, REDUCED_MINUTE, REDUCED_HOUR, or REDUCED_DAY
CMDORTLM - CMD or TLM
TARGET - Target name
PACKET - Packet name
ITEM - Item Name
VALUETYPE - RAW, CONVERTED, FORMATTED, or WITH_UNITS
REDUCEDTYPE - MIN, MAX, AVG, STDDEV (only for reduced modes)
packets: [ MODE__CMDORTLM__TARGET__PACKET__VALUETYPE ]
MODE - RAW, DECOM, REDUCED_MINUTE, REDUCED_HOUR, or REDUCED_DAY
CMDORTLM - CMD or TLM
TARGET - Target name
PACKET - Packet name
VALUETYPE - RAW, CONVERTED, FORMATTED, WITH_UNITS, or PURE (pure means all types as stored in log)
370 371 372 373 374 375 376 377 378 |
# File 'lib/openc3/script/web_socket_api.rb', line 370 def remove(items: nil, packets: nil, scope: $openc3_scope) data_hash = {} data_hash['action'] = 'remove' data_hash['items'] = items if items data_hash['packets'] = packets if packets data_hash['scope'] = scope data_hash['token'] = @authentication.token write_action(data_hash) end |