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: nil, 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: nil) ⇒ 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: nil) ⇒ 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, #wait_for_subscribed, #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.
366 367 368 369 370 371 |
# File 'lib/openc3/script/web_socket_api.rb', line 366 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: nil, 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
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/openc3/script/web_socket_api.rb', line 450 def self.read_all(items: nil, packets: nil, start_time: nil, end_time:, scope: nil, 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: nil) ⇒ 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 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, or PURE (pure means all types as stored in log)
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/openc3/script/web_socket_api.rb', line 395 def add(items: nil, packets: nil, start_time: nil, end_time: nil, scope: nil) scope ||= @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(include_bearer: false) write_action(data_hash) end |
#remove(items: nil, packets: nil, scope: nil) ⇒ 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 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, or PURE (pure means all types as stored in log)
437 438 439 440 441 442 443 444 445 446 |
# File 'lib/openc3/script/web_socket_api.rb', line 437 def remove(items: nil, packets: nil, scope: nil) scope ||= @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(include_bearer: false) write_action(data_hash) end |