Class: OpenC3::StreamingWebSocketApi

Inherits:
CmdTlmWebSocketApi show all
Defined in:
lib/openc3/script/web_socket_api.rb

Overview

Streaming API WebSocket

Constant Summary

Constants inherited from WebSocketApi

WebSocketApi::USER_AGENT

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CmdTlmWebSocketApi

#generate_url

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.



322
323
324
325
326
327
# File 'lib/openc3/script/web_socket_api.rb', line 322

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



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/openc3/script/web_socket_api.rb', line 404

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)


351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/openc3/script/web_socket_api.rb', line 351

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(include_bearer: false)
  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)


392
393
394
395
396
397
398
399
400
# File 'lib/openc3/script/web_socket_api.rb', line 392

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(include_bearer: false)
  write_action(data_hash)
end