Module: Cosmos::Api

Includes:
Authorization, ApiShared, Extract
Included in:
AuthorizedApi, GemModel, Interface, LimitsResponse
Defined in:
lib/cosmos/api/api.rb,
lib/cosmos/api/cmd_api.rb,
lib/cosmos/api/tlm_api.rb,
lib/cosmos/api/config_api.rb,
lib/cosmos/api/limits_api.rb,
lib/cosmos/api/router_api.rb,
lib/cosmos/api/target_api.rb,
lib/cosmos/api/settings_api.rb,
lib/cosmos/api/interface_api.rb

Constant Summary collapse

SUBSCRIPTION_DELIMITER =

2x double underscore since __ is reserved

'____'
SETTINGS_KEY =
"cosmos__settings"

Constants included from ApiShared

Cosmos::ApiShared::DEFAULT_TLM_POLLING_RATE

Constants included from Extract

Extract::SCANNING_REGULAR_EXPRESSION

Instance Method Summary collapse

Instance Method Details

#_get_cnt(topic) ⇒ Object

PRIVATE - Shared by cmd_api and tlm_api



40
41
42
43
# File 'lib/cosmos/api/api.rb', line 40

def _get_cnt(topic)
  _, packet = Store.instance.read_topic_last(topic)
  packet ? packet["received_count"].to_i : 0
end

#_limits_group(group_name, action:, scope:, token:) ⇒ Object

PRIVATE implementation details



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/cosmos/api/limits_api.rb', line 340

def _limits_group(group_name, action:, scope:, token:)
  authorize(permission: 'tlm_set', scope: scope, token: token)
  group_name.upcase!
  group = get_limits_groups()[group_name]
  raise "LIMITS_GROUP #{group_name} undefined. Ensure your telemetry definition contains the line: LIMITS_GROUP #{group_name}" unless group

  Logger.info("Disabling Limits Group: #{group_name}")
  last_target_name = nil
  last_packet_name = nil
  packet = nil
  group.sort.each do |target_name, packet_name, item_name|
    if last_target_name != target_name || last_packet_name != packet_name
      if last_target_name && last_packet_name
        TargetModel.set_packet(last_target_name, last_packet_name, packet, scope: scope)
      end
      packet = TargetModel.packet(target_name, packet_name, scope: scope)
    end
    packet['items'].each do |item|
      if item['name'] == item_name
        if action == :enable
          item['limits']['enabled'] = true
        elsif action == :disable
          item['limits'].delete('enabled')
        end
        break
      end
    end
    last_target_name = target_name
    last_packet_name = packet_name
  end
  if last_target_name && last_packet_name
    TargetModel.set_packet(last_target_name, last_packet_name, packet, scope: scope)
  end
end

#_validate_tlm_type(type) ⇒ Object

PRIVATE



397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/cosmos/api/tlm_api.rb', line 397

def _validate_tlm_type(type)
  case type.intern
  when :RAW
    return ''
  when :CONVERTED
    return 'C'
  when :FORMATTED
    return 'F'
  when :WITH_UNITS
    return 'U'
  end
  return nil
end

#build_cmd_output_string(target_name, cmd_name, cmd_params, packet, raw) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/cosmos/api/cmd_api.rb', line 407

def build_cmd_output_string(target_name, cmd_name, cmd_params, packet, raw)
  if raw
    output_string = 'cmd_raw("'
  else
    output_string = 'cmd("'
  end
  output_string << target_name + ' ' + cmd_name
  if cmd_params.nil? or cmd_params.empty?
    output_string << '")'
  else
    params = []
    cmd_params.each do |key, value|
      next if Packet::RESERVED_ITEM_NAMES.include?(key)

      item = packet['items'].find { |item| item['name'] == key.to_s }

      begin
        item_type = item['data_type'].intern
      rescue
        item_type = nil
      end

      if value.is_a?(String)
        value = value.dup
        if item_type == :BLOCK or item_type == :STRING
          if !value.is_printable?
            value = "0x" + value.simple_formatted
          else
            value = value.inspect
          end
        else
          value = value.convert_to_value.to_s
        end
        if value.length > 256
          value = value[0..255] + "...'"
        end
        value.tr!('"', "'")
      elsif value.is_a?(Array)
        value = "[#{value.join(", ")}]"
      end
      params << "#{key} #{value}"
    end
    params = params.join(", ")
    output_string << ' with ' + params + '")'
  end
  return output_string
end

#cmd(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs) ⇒ Array<String, String, Hash>

Send a command packet to a target.

Accepts two different calling styles:

cmd("TGT CMD with PARAM1 val, PARAM2 val")
cmd('TGT','CMD','PARAM1'=>val,'PARAM2'=>val)

Favor the first syntax where possible as it is more succinct.

Parameters:

Returns:



59
60
61
62
# File 'lib/cosmos/api/cmd_api.rb', line 59

def cmd(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs)
  args << kwargs unless kwargs.empty?
  cmd_implementation(true, true, false, 'cmd', *args, scope: scope, token: token)
end

#cmd_implementation(range_check, hazardous_check, raw, method_name, *args, scope:, token:) ⇒ Object

PRIVATE implementation details



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/cosmos/api/cmd_api.rb', line 376

def cmd_implementation(range_check, hazardous_check, raw, method_name, *args, scope:, token:)
  case args.length
  when 1
    target_name, cmd_name, cmd_params = extract_fields_from_cmd_text(args[0], scope: scope)
  when 2, 3
    target_name = args[0]
    cmd_name    = args[1]
    if args.length == 2
      cmd_params = {}
    else
      cmd_params = args[2]
    end
  else
    # Invalid number of arguments
    raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{method_name}()"
  end
  authorize(permission: 'cmd', target_name: target_name, packet_name: cmd_name, scope: scope, token: token)
  packet = TargetModel.packet(target_name, cmd_name, type: :CMD, scope: scope)

  command = {
    'target_name' => target_name,
    'cmd_name' => cmd_name,
    'cmd_params' => cmd_params,
    'range_check' => range_check,
    'hazardous_check' => hazardous_check,
    'raw' => raw
  }
  Logger.info build_cmd_output_string(target_name, cmd_name, cmd_params, packet, raw) if !packet["messages_disabled"]
  CommandTopic.send_command(command, scope: scope)
end

#cmd_no_checks(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs) ⇒ Array<String, String, Hash>

Send a command packet to a target without performing any value range checks or hazardous checks both on the command itself and its parameters.

Accepts two different calling styles:

cmd_no_checks("TGT CMD with PARAM1 val, PARAM2 val")
cmd_no_checks('TGT','CMD','PARAM1'=>val,'PARAM2'=>val)

Favor the first syntax where possible as it is more succinct.

Parameters:

Returns:



109
110
111
112
# File 'lib/cosmos/api/cmd_api.rb', line 109

def cmd_no_checks(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs)
  args << kwargs unless kwargs.empty?
  cmd_implementation(false, false, false, 'cmd_no_checks', *args, scope: scope, token: token)
end

#cmd_no_hazardous_check(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs) ⇒ Array<String, String, Hash>

Send a command packet to a target without performing any hazardous checks both on the command itself and its parameters. Useful in scripts to prevent popping up warnings to the user.

Accepts two different calling styles:

cmd_no_hazardous_check("TGT CMD with PARAM1 val, PARAM2 val")
cmd_no_hazardous_check('TGT','CMD','PARAM1'=>val,'PARAM2'=>val)

Favor the first syntax where possible as it is more succinct.

Parameters:

Returns:



93
94
95
96
# File 'lib/cosmos/api/cmd_api.rb', line 93

def cmd_no_hazardous_check(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs)
  args << kwargs unless kwargs.empty?
  cmd_implementation(true, false, false, 'cmd_no_hazardous_check', *args, scope: scope, token: token)
end

#cmd_no_range_check(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs) ⇒ Array<String, String, Hash>

Send a command packet to a target without performing any value range checks on the parameters. Useful for testing to allow sending command parameters outside the allowable range as defined in the configuration.

Accepts two different calling styles:

cmd_no_range_check("TGT CMD with PARAM1 val, PARAM2 val")
cmd_no_range_check('TGT','CMD','PARAM1'=>val,'PARAM2'=>val)

Favor the first syntax where possible as it is more succinct.

Parameters:

Returns:



76
77
78
79
# File 'lib/cosmos/api/cmd_api.rb', line 76

def cmd_no_range_check(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs)
  args << kwargs unless kwargs.empty?
  cmd_implementation(false, true, false, 'cmd_no_range_check', *args, scope: scope, token: token)
end

#cmd_raw(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs) ⇒ Array<String, String, Hash>

Send a command packet to a target without running conversions.

Accepts two different calling styles:

cmd_raw("TGT CMD with PARAM1 val, PARAM2 val")
cmd_raw('TGT','CMD','PARAM1'=>val,'PARAM2'=>val)

Favor the first syntax where possible as it is more succinct.

Parameters:

Returns:



124
125
126
127
# File 'lib/cosmos/api/cmd_api.rb', line 124

def cmd_raw(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs)
  args << kwargs unless kwargs.empty?
  cmd_implementation(true, true, true, 'cmd_raw', *args, scope: scope, token: token)
end

#cmd_raw_no_checks(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs) ⇒ Array<String, String, Hash>

Send a command packet to a target without running conversions or performing any value range checks or hazardous checks both on the command itself and its parameters.

Accepts two different calling styles:

cmd_raw_no_checks("TGT CMD with PARAM1 val, PARAM2 val")
cmd_raw_no_checks('TGT','CMD','PARAM1'=>val,'PARAM2'=>val)

Favor the first syntax where possible as it is more succinct.

Parameters:

Returns:



174
175
176
177
# File 'lib/cosmos/api/cmd_api.rb', line 174

def cmd_raw_no_checks(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs)
  args << kwargs unless kwargs.empty?
  cmd_implementation(false, false, true, 'cmd_raw_no_checks', *args, scope: scope, token: token)
end

#cmd_raw_no_hazardous_check(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs) ⇒ Array<String, String, Hash>

Send a command packet to a target without running conversions or performing any hazardous checks both on the command itself and its parameters. Useful in scripts to prevent popping up warnings to the user.

Accepts two different calling styles:

cmd_raw_no_hazardous_check("TGT CMD with PARAM1 val, PARAM2 val")
cmd_raw_no_hazardous_check('TGT','CMD','PARAM1'=>val,'PARAM2'=>val)

Favor the first syntax where possible as it is more succinct.

Parameters:

Returns:



158
159
160
161
# File 'lib/cosmos/api/cmd_api.rb', line 158

def cmd_raw_no_hazardous_check(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs)
  args << kwargs unless kwargs.empty?
  cmd_implementation(true, false, true, 'cmd_raw_no_hazardous_check', *args, scope: scope, token: token)
end

#cmd_raw_no_range_check(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs) ⇒ Array<String, String, Hash>

Send a command packet to a target without performing any value range checks on the parameters or running conversions. Useful for testing to allow sending command parameters outside the allowable range as defined in the configuration.

Accepts two different calling styles:

cmd_raw_no_range_check("TGT CMD with PARAM1 val, PARAM2 val")
cmd_raw_no_range_check('TGT','CMD','PARAM1'=>val,'PARAM2'=>val)

Favor the first syntax where possible as it is more succinct.

Parameters:

Returns:



141
142
143
144
# File 'lib/cosmos/api/cmd_api.rb', line 141

def cmd_raw_no_range_check(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs)
  args << kwargs unless kwargs.empty?
  cmd_implementation(false, true, true, 'cmd_raw_no_range_check', *args, scope: scope, token: token)
end

#connect_interface(interface_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Connects an interface and starts its telemetry gathering thread

Parameters:

  • interface_name (String)

    The name of the interface



59
60
61
62
# File 'lib/cosmos/api/interface_api.rb', line 59

def connect_interface(interface_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system_set', interface_name: interface_name, scope: scope, token: token)
  InterfaceTopic.connect_interface(interface_name, scope: scope)
end

#connect_router(router_name, *params, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Connects a router and starts its command gathering thread

Parameters:

  • router_name (String)

    Name of router

  • params (Array)

    Parameters to pass to the router.



59
60
61
62
# File 'lib/cosmos/api/router_api.rb', line 59

def connect_router(router_name, *params, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system_set', router_name: router_name, scope: scope, token: token)
  RouterTopic.connect_router(router_name, scope: scope)
end

#delete_config(tool, name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



48
49
50
# File 'lib/cosmos/api/config_api.rb', line 48

def delete_config(tool, name, scope: $cosmos_scope, token: $cosmos_token)
  Store.instance.hdel("#{scope}__config__#{tool}", name)
end

#disable_limits(*args, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Disable limit checking for a telemetry item

Accepts two different calling styles:

disable_limits("TGT PKT ITEM")
disable_limits('TGT','PKT','ITEM')

Favor the first syntax where possible as it is more succinct.

Parameters:



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/cosmos/api/limits_api.rb', line 186

def disable_limits(*args, scope: $cosmos_scope, token: $cosmos_token)
  target_name, packet_name, item_name = tlm_process_args(args, 'disable_limits', scope: scope)
  authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  packet = TargetModel.packet(target_name, packet_name, scope: scope)
  found_item = nil
  packet['items'].each do |item|
    if item['name'] == item_name
      item['limits'].delete('enabled')
      found_item = item
      break
    end
  end
  raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist" unless found_item

  TargetModel.set_packet(target_name, packet_name, packet, scope: scope)
end

#disable_limits_group(group_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Disables limits for all the items in the group

Parameters:

  • group_name (String)

    Name of the group to disable



292
293
294
# File 'lib/cosmos/api/limits_api.rb', line 292

def disable_limits_group(group_name, scope: $cosmos_scope, token: $cosmos_token)
  _limits_group(group_name, action: :disable, scope: scope, token: token)
end

#disconnect_interface(interface_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Disconnects from an interface and kills its telemetry gathering thread

Parameters:

  • interface_name (String)

    The name of the interface



67
68
69
70
# File 'lib/cosmos/api/interface_api.rb', line 67

def disconnect_interface(interface_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system_set', interface_name: interface_name, scope: scope, token: token)
  InterfaceTopic.disconnect_interface(interface_name, scope: scope)
end

#disconnect_router(router_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Disconnects a router and kills its command gathering thread

Parameters:

  • router_name (String)

    Name of router



67
68
69
70
# File 'lib/cosmos/api/router_api.rb', line 67

def disconnect_router(router_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system_set', router_name: router_name, scope: scope, token: token)
  RouterTopic.disconnect_router(router_name, scope: scope)
end

#enable_limits(*args, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Enable limits checking for a telemetry item

Accepts two different calling styles:

enable_limits("TGT PKT ITEM")
enable_limits('TGT','PKT','ITEM')

Favor the first syntax where possible as it is more succinct.

Parameters:



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/cosmos/api/limits_api.rb', line 160

def enable_limits(*args, scope: $cosmos_scope, token: $cosmos_token)
  target_name, packet_name, item_name = tlm_process_args(args, 'enable_limits', scope: scope)
  authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  packet = TargetModel.packet(target_name, packet_name, scope: scope)
  found_item = nil
  packet['items'].each do |item|
    if item['name'] == item_name
      item['limits']['enabled'] = true
      found_item = item
      break
    end
  end
  raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist" unless found_item

  TargetModel.set_packet(target_name, packet_name, packet, scope: scope)
end

#enable_limits_group(group_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Enables limits for all the items in the group

Parameters:

  • group_name (String)

    Name of the group to enable



285
286
287
# File 'lib/cosmos/api/limits_api.rb', line 285

def enable_limits_group(group_name, scope: $cosmos_scope, token: $cosmos_token)
  _limits_group(group_name, action: :enable, scope: scope, token: token)
end

#get_all_cmd_info(scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<String, String, Numeric>

Get information on all command packets

Returns:



358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/cosmos/api/cmd_api.rb', line 358

def get_all_cmd_info(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', scope: scope, token: token)
  result = []
  TargetModel.names(scope: scope).each do | target_name |
    TargetModel.packets(target_name, type: :CMD, scope: scope).each do | packet |
      command_name = packet['packet_name']
      key = "#{scope}__COMMAND__{#{target_name}}__#{command_name}"
      result << [target_name, command_name, _get_cnt(key)]
    end
  end
  # Return the results sorted by target, packet
  result.sort_by { |a| [a[0], a[1]] }
end

#get_all_cmd_tlm_info(type, scope:, token:) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cosmos/api/api.rb', line 45

def get_all_cmd_tlm_info(type, scope:, token:)
  authorize(permission: 'system', scope: scope, token: token)
  result = []
  keys = []
  count = 0
  loop do
    count, part = Store.scan(0, :match => "#{scope}__#{type}__*", :count => 1000)
    keys.concat(part)
    break if count.to_i == 0
  end
  keys.each do |key|
    _, _, target, packet = key.gsub(/{|}/, '').split('__') # split off scope and type
    result << [target, packet, _get_cnt(key)]
  end
  # Return the results sorted by target, packet
  result.sort_by { |a| [a[0], a[1]] }
end

#get_all_commands(target_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Hash>

Returns an array of all the commands as a hash

Parameters:

  • target_name (String)

    Name of the target

Returns:

  • (Array<Hash>)

    Array of all commands as a hash

Since:

  • 5.0.0



211
212
213
214
# File 'lib/cosmos/api/cmd_api.rb', line 211

def get_all_commands(target_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'cmd_info', target_name: target_name, scope: scope, token: token)
  TargetModel.packets(target_name, type: :CMD, scope: scope)
end

#get_all_commands_list(target_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Hash>

Returns an array of all the command names and their descriptions

Parameters:

  • target_name (String)

    Name of the target

Returns:

  • (Array<Hash>)

    Array of all commands as a hash

Since:

  • 5.0.3



221
222
223
224
# File 'lib/cosmos/api/cmd_api.rb', line 221

def get_all_commands_list(target_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'cmd_info', target_name: target_name, scope: scope, token: token)
  TargetModel.all_packet_name_descriptions(target_name, type: :CMD, scope: scope)
end

#get_all_interface_info(scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Array<String, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric>>

Get information about all interfaces

Returns:



106
107
108
109
110
111
112
113
114
115
# File 'lib/cosmos/api/interface_api.rb', line 106

def get_all_interface_info(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', scope: scope, token: token)
  info = []
  InterfaceStatusModel.all(scope: scope).each do |int_name, int|
    info << [int['name'], int['state'], int['clients'], int['txsize'], int['rxsize'],
             int['txbytes'], int['rxbytes'], int['txcnt'], int['rxcnt']]
  end
  info.sort! { |a, b| a[0] <=> b[0] }
  info
end

#get_all_router_info(scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Array<String, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric, Numeric>>

Consolidate all router info into a single API call

Returns:



106
107
108
109
110
111
112
113
114
115
# File 'lib/cosmos/api/router_api.rb', line 106

def get_all_router_info(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', scope: scope, token: token)
  info = []
  RouterStatusModel.all(scope: scope).each do |router_name, router|
    info << [router['name'], router['state'], router['clients'], router['txsize'], router['rxsize'],\
             router['txbytes'], router['rxbytes'], router['rxcnt'], router['txcnt']]
  end
  info.sort! { |a, b| a[0] <=> b[0] }
  info
end

#get_all_settings(scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



37
38
39
# File 'lib/cosmos/api/settings_api.rb', line 37

def get_all_settings(scope: $cosmos_scope, token: $cosmos_token)
  Store.instance.hgetall(SETTINGS_KEY)
end

#get_all_target_info(scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Array<String, Numeric, Numeric>] Array of Arrays \[name, interface, cmd_cnt, tlm_cnt]

Get information about all targets

Returns:

  • (Array<Array<String, Numeric, Numeric>] Array of Arrays \[name, interface, cmd_cnt, tlm_cnt])

    Array<Array<String, Numeric, Numeric>] Array of Arrays [name, interface, cmd_cnt, tlm_cnt]



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cosmos/api/target_api.rb', line 52

def get_all_target_info(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', scope: scope, token: token)
  info = []
  get_target_list(scope: scope, token: token).each do |target_name|
    cmd_cnt = 0
    packets = TargetModel.packets(target_name, type: :CMD, scope: scope)
    packets.each do |packet|
      cmd_cnt += _get_cnt("#{scope}__COMMAND__{#{target_name}}__#{packet['packet_name']}")
    end
    tlm_cnt = 0
    packets = TargetModel.packets(target_name, type: :TLM, scope: scope)
    packets.each do |packet|
      tlm_cnt += _get_cnt("#{scope}__TELEMETRY__{#{target_name}}__#{packet['packet_name']}")
    end
    interface_name = ''
    InterfaceModel.all(scope: scope).each do |name, interface|
      if interface['target_names'].include? target_name
        interface_name = interface['name']
        break
      end
    end
    info << [target_name, interface_name, cmd_cnt, tlm_cnt]
  end
  info
end

#get_all_telemetry(target_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Hash>

Returns an array of all the telemetry packet hashes

Parameters:

  • target_name (String)

    Name of the target

Returns:

  • (Array<Hash>)

    Array of all telemetry packet hashes

Since:

  • 5.0.0



248
249
250
251
# File 'lib/cosmos/api/tlm_api.rb', line 248

def get_all_telemetry(target_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', target_name: target_name, scope: scope, token: token)
  TargetModel.packets(target_name, type: :TLM, scope: scope)
end

#get_all_telemetry_list(target_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Hash>

Returns an array of all telemetry packet’s name and descriptions

Parameters:

  • target_name (String)

    Name of the target

Returns:

  • (Array<Hash>)

    Array of all telemetry packet name and descriptions

Since:

  • 5.0.3



258
259
260
261
# File 'lib/cosmos/api/tlm_api.rb', line 258

def get_all_telemetry_list(target_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', target_name: target_name, scope: scope, token: token)
  TargetModel.all_packet_name_descriptions(target_name, type: :TLM, scope: scope)
end

#get_all_tlm_info(scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<String, String, Numeric>

Get information on all telemetry packets

Returns:



349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/cosmos/api/tlm_api.rb', line 349

def get_all_tlm_info(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', scope: scope, token: token)
  result = []
  TargetModel.names(scope: scope).each do | target_name |
    TargetModel.packets(target_name, scope: scope).each do | packet |
      packet_name = packet['packet_name']
      key = "#{scope}__TELEMETRY__{#{target_name}}__#{packet_name}"
      result << [target_name, packet_name, _get_cnt(key)]
    end
  end
  ['UNKNOWN'].each do | x |
    key = "#{scope}__TELEMETRY__{#{x}}__#{x}"
    result << [x, x, _get_cnt(key)]
  end
  # Return the result sorted by target, packet
  result.sort_by { |a| [a[0], a[1]] }
end

#get_cmd_buffer(target_name, command_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ String

Returns the raw buffer from the most recent specified command packet.

Parameters:

  • target_name (String)

    Target name of the command

  • command_name (String)

    Packet name of the command

Returns:

  • (String)

    last command buffer packet



194
195
196
197
198
199
200
201
202
203
204
# File 'lib/cosmos/api/cmd_api.rb', line 194

def get_cmd_buffer(target_name, command_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'cmd_info', target_name: target_name, packet_name: command_name, scope: scope, token: token)
  TargetModel.packet(target_name, command_name, type: :CMD, scope: scope)
  topic = "#{scope}__COMMAND__{#{target_name}}__#{command_name}"
  msg_id, msg_hash = Store.instance.read_topic_last(topic)
  if msg_id
    msg_hash['buffer'] = msg_hash['buffer'].b
    return msg_hash
  end
  return nil
end

#get_cmd_cnt(target_name, command_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Numeric

Get the transmit count for a command packet

Parameters:

  • target_name (String)

    Target name of the command

  • command_name (String)

    Packet name of the command

Returns:

  • (Numeric)

    Transmit count for the command



349
350
351
352
353
# File 'lib/cosmos/api/cmd_api.rb', line 349

def get_cmd_cnt(target_name, command_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', target_name: target_name, packet_name: command_name, scope: scope, token: token)
  TargetModel.packet(target_name, command_name, type: :CMD, scope: scope)
  _get_cnt("#{scope}__COMMAND__{#{target_name}}__#{command_name}")
end

#get_cmd_hazardous(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs) ⇒ Boolean

Returns whether the specified command is hazardous

Accepts two different calling styles:

get_cmd_hazardous("TGT CMD with PARAM1 val, PARAM2 val")
get_cmd_hazardous('TGT','CMD',{'PARAM1'=>val,'PARAM2'=>val})

Parameters:

Returns:

  • (Boolean)

    Whether the command is hazardous



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/cosmos/api/cmd_api.rb', line 257

def get_cmd_hazardous(*args, scope: $cosmos_scope, token: $cosmos_token, **kwargs)
  args << kwargs unless kwargs.empty?
  case args.length
  when 1
    target_name, command_name, params = extract_fields_from_cmd_text(args[0], scope: scope)
  when 2, 3
    target_name = args[0]
    command_name = args[1]
    if args.length == 2
      params = {}
    else
      params = args[2]
    end
  else
    # Invalid number of arguments
    raise "ERROR: Invalid number of arguments (#{args.length}) passed to get_cmd_hazardous()"
  end

  authorize(permission: 'cmd_info', target_name: target_name, packet_name: command_name, scope: scope, token: token)
  packet = TargetModel.packet(target_name, command_name, type: :CMD, scope: scope)
  return true if packet['hazardous']

  packet['items'].each do |item|
    next unless params.keys.include?(item['name']) && item['states']

    # States are an array of the name followed by a hash of 'value' and sometimes 'hazardous'
    item['states'].each do |name, hash|
      # To be hazardous the state must be marked hazardous
      # Check if either the state name or value matches the param passed
      if hash['hazardous'] && (name == params[item['name']] || hash['value'].to_f == params[item['name']].to_f)
        return true
      end
    end
  end

  false
end

#get_cmd_time(target_name = nil, command_name = nil, scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Target Name, Command Name, Time Seconds, Time Microseconds>

Returns the time the most recent command was sent

Parameters:

  • target_name (String) (defaults to: nil)

    Target name of the command. If not given then the most recent time from all commands will be returned

  • command_name (String) (defaults to: nil)

    Packet name of the command. If not given then then most recent time from the given target will be returned.

Returns:



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/cosmos/api/cmd_api.rb', line 315

def get_cmd_time(target_name = nil, command_name = nil, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'cmd_info', target_name: target_name, packet_name: command_name, scope: scope, token: token)
  if target_name and command_name
    time = Store.instance.get_cmd_item(target_name, command_name, 'RECEIVED_TIMESECONDS', type: :CONVERTED, scope: scope)
    [target_name, command_name, time.to_i, ((time.to_f - time.to_i) * 1_000_000).to_i]
  else
    if target_name.nil?
      targets = TargetModel.names(scope: scope)
    else
      targets = [target_name]
    end
    targets.each do |target_name|
      time = 0
      command_name = nil
      TargetModel.packets(target_name, type: :CMD, scope: scope).each do |packet|
        cur_time = Store.instance.get_cmd_item(target_name, packet["packet_name"], 'RECEIVED_TIMESECONDS', type: :CONVERTED, scope: scope)
        next unless cur_time

        if cur_time > time
          time = cur_time
          command_name = packet["packet_name"]
        end
      end
      target_name = nil unless command_name
      return [target_name, command_name, time.to_i, ((time.to_f - time.to_i) * 1_000_000).to_i]
    end
  end
end

#get_cmd_value(target_name, command_name, parameter_name, value_type = :CONVERTED, scope: $cosmos_scope, token: $cosmos_token) ⇒ Varies

Returns a value from the specified command

Parameters:

  • target_name (String)

    Target name of the command

  • command_name (String)

    Packet name of the command

  • parameter_name (String)

    Parameter name in the command

  • value_type (Symbol) (defaults to: :CONVERTED)

    How the values should be converted. Must be one of Packet::VALUE_TYPES

Returns:

  • (Varies)

    value



303
304
305
306
# File 'lib/cosmos/api/cmd_api.rb', line 303

def get_cmd_value(target_name, command_name, parameter_name, value_type = :CONVERTED, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'cmd_info', target_name: target_name, packet_name: command_name, scope: scope, token: token)
  Store.instance.get_cmd_item(target_name, command_name, parameter_name, type: value_type, scope: scope)
end

#get_command(target_name, packet_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Hash

Returns a hash of the given command

Parameters:

  • target_name (String)

    Name of the target

  • packet_name (String)

    Name of the packet

Returns:

  • (Hash)

    Command as a hash

Since:

  • 5.0.0



232
233
234
235
# File 'lib/cosmos/api/cmd_api.rb', line 232

def get_command(target_name, packet_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'cmd_info', target_name: target_name, scope: scope, token: token)
  TargetModel.packet(target_name, packet_name, type: :CMD, scope: scope)
end

#get_interface(interface_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Hash

Get information about an interface

Parameters:

  • interface_name (String)

    Interface name

Returns:

  • (Hash)

    Hash of all the interface information

Since:

  • 5.0.0



42
43
44
45
46
47
48
# File 'lib/cosmos/api/interface_api.rb', line 42

def get_interface(interface_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', interface_name: interface_name, scope: scope, token: token)
  interface = InterfaceModel.get(name: interface_name, scope: scope)
  raise "Interface '#{interface_name}' does not exist" unless interface

  interface.merge(InterfaceStatusModel.get(name: interface_name, scope: scope))
end

#get_interface_names(scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<String>

Returns All the interface names.

Returns:



51
52
53
54
# File 'lib/cosmos/api/interface_api.rb', line 51

def get_interface_names(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', scope: scope, token: token)
  InterfaceModel.names(scope: scope)
end

#get_item(target_name, packet_name, item_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Hash

Returns a telemetry packet item hash

Parameters:

  • target_name (String)

    Name of the target

  • packet_name (String)

    Name of the packet

  • item_name (String)

    Name of the packet

Returns:

  • (Hash)

    Telemetry packet item hash

Since:

  • 5.0.0



281
282
283
284
# File 'lib/cosmos/api/tlm_api.rb', line 281

def get_item(target_name, packet_name, item_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  TargetModel.packet_item(target_name, packet_name, item_name, scope: scope)
end

#get_limits(target_name, packet_name, item_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Hash{String => Array<Number, Number, Number, Number, Number, Number>}

Get a Hash of all the limits sets defined for an item. Hash keys are the limit set name in uppercase (note there is always a DEFAULT) and the value is an array of limit values: red low, yellow low, yellow high, red high, <green low, green high>. Green low and green high are optional.

For example: {‘DEFAULT’ => [-80, -70, 60, 80, -20, 20],

'TVAC' => [-25, -10, 50, 55] }

Returns:



212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/cosmos/api/limits_api.rb', line 212

def get_limits(target_name, packet_name, item_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  limits = {}
  item = TargetModel.packet_item(target_name, packet_name, item_name, scope: scope)
  item['limits'].each do |key, vals|
    next unless vals.is_a?(Hash)

    limits[key] = [vals['red_low'], vals['yellow_low'], vals['yellow_high'], vals['red_high']]
    limits[key].concat([vals['green_low'], vals['green_high']]) if vals['green_low']
  end
  return limits
end

#get_limits_events(offset = nil, count: 100, scope: $cosmos_scope, token: $cosmos_token) ⇒ Hash, Integer

Returns limits events starting at the provided offset. Passing nil for an offset will return the last received limits event and associated offset.

Parameters:

  • offset (Integer) (defaults to: nil)

    Offset to start reading limits events. Nil to return the last received limits event (if any).

  • count (Integer) (defaults to: 100)

    The total number of events returned. Default is 100.

Returns:

  • (Hash, Integer)

    Event hash followed by the offset. The offset can be used in subsequent calls to return events from where the last call left off.



331
332
333
334
# File 'lib/cosmos/api/limits_api.rb', line 331

def get_limits_events(offset = nil, count: 100, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', scope: scope, token: token)
  LimitsEventTopic.read(offset, count: count, scope: scope)
end

#get_limits_groups(scope: $cosmos_scope, token: $cosmos_token) ⇒ Hash{String => Array<Array<String, String, String>>]

Returns all limits_groups and their members

Returns:

Since:

  • 5.0.0 Returns hash with values



277
278
279
280
# File 'lib/cosmos/api/limits_api.rb', line 277

def get_limits_groups(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', scope: scope, token: token)
  TargetModel.limits_groups(scope: scope)
end

#get_limits_set(scope: $cosmos_scope, token: $cosmos_token) ⇒ String

Returns the active limits set that applies to all telemetry

Returns:

  • (String)

    The current limits set



318
319
320
321
# File 'lib/cosmos/api/limits_api.rb', line 318

def get_limits_set(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', scope: scope, token: token)
  LimitsEventTopic.current_set(scope: scope)
end

#get_limits_sets(scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<String>

Returns all defined limits sets

Returns:



299
300
301
302
# File 'lib/cosmos/api/limits_api.rb', line 299

def get_limits_sets(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', scope: scope, token: token)
  LimitsEventTopic.sets(scope: scope).keys
end

#get_oldest_logfile(scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/cosmos/api/tlm_api.rb', line 378

def get_oldest_logfile(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', scope: scope, token: token)
  _, list = S3Utilities.get_total_size_and_oldest_list('logs', "#{scope}/decom_logs", 1_000_000_000)
  # The list is a S3 structure containing the file paths
  # Request the path by calling the key method. Returns something like this:
  # DEFAULT/decom_logs/tlm/INST2/MECH/20220104/20220104165449021942700__20220104170449148642700__DEFAULT__INST2__MECH__rt__decom.bin
  # Thus we split and take the start date/time part of the filename
  if list and list[0]
    start = list[0].key.split('/')[-1].split('__')[0]
    # Format as YYYY-MM-DD HH:MM:SS for use by the frontend
    # utc_time = Time.utc(start[0,4], start[4,2], start[6,2], start[8,2], start[10,2], start[12,2])
    return "#{start[0,4]}-#{start[4,2]}-#{start[6,2]} #{start[8,2]}:#{start[10,2]}:#{start[12,2]}"
  else
    return Time.now.utc.to_s[0..18]
  end
end

#get_out_of_limits(scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Array<String, String, String, String>>

Return an array of arrays indicating all items in the packet that are out of limits

[[target name, packet name, item name, item limits state], ...]

Returns:



82
83
84
85
# File 'lib/cosmos/api/limits_api.rb', line 82

def get_out_of_limits(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', scope: scope, token: token)
  LimitsEventTopic.out_of_limits(scope: scope)
end

#get_overall_limits_state(ignored_items = nil, scope: $cosmos_scope, token: $cosmos_token) ⇒ String

Get the overall limits state which is the worse case of all limits items. For example if any limits are YELLOW_LOW or YELLOW_HIGH then the overall limits state is YELLOW. If a single limit item then turns RED_HIGH the overall limits state is RED.

Parameters:

  • ignored_items (Array<Array<String, String, String|nil>>) (defaults to: nil)

    Array of [TGT, PKT, ITEM] strings to ignore when determining overall state. Note, ITEM can be nil to indicate to ignore entire packet.

Returns:

  • (String)

    The overall limits state for the system, one of 'GREEN', 'YELLOW', 'RED'



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/cosmos/api/limits_api.rb', line 94

def get_overall_limits_state(ignored_items = nil, scope: $cosmos_scope, token: $cosmos_token)
  # We only need to check out of limits items so call get_out_of_limits() which authorizes
  out_of_limits = get_out_of_limits(scope: scope, token: token)
  overall = 'GREEN'
  limits_packet_stale = false # TODO: Calculate stale

  # Build easily matchable ignore list
  if ignored_items
    ignored_items.map! do |item|
      raise "Invalid ignored item: #{item}. Must be [TGT, PKT, ITEM] where ITEM can be nil." if item.length != 3

      item.join('__')
    end
  else
    ignored_items = []
  end

  out_of_limits.each do |target_name, packet_name, item_name, limits_state|
    # Ignore this item if we match one of the ignored items. Checking against /^#{item}/
    # allows us to detect matches against a TGT__PKT__ with no item defined.
    next if ignored_items.detect { |item| "#{target_name}__#{packet_name}__#{item_name}" =~ /^#{item}/ }

    case overall
      # If our overall state is currently blue or green we can go to any state
    when 'BLUE', 'GREEN', 'GREEN_HIGH', 'GREEN_LOW'
      overall = limits_state
    # If our overal state is yellow we can only go higher to red
    when 'YELLOW', 'YELLOW_HIGH', 'YELLOW_LOW'
      if limits_state == 'RED' || limits_state == 'RED_HIGH' || limits_state == 'RED_LOW'
        overall = limits_state
        break # Red is as high as we go so no need to look for more
      end
    end
  end
  overall = 'GREEN' if overall == 'GREEN_HIGH' || overall == 'GREEN_LOW' || overall == 'BLUE'
  overall = 'YELLOW' if overall == 'YELLOW_HIGH' || overall == 'YELLOW_LOW'
  overall = 'RED' if overall == 'RED_HIGH' || overall == 'RED_LOW'
  overall = 'STALE' if (overall == 'GREEN' || overall == 'BLUE') && limits_packet_stale
  return overall
end

#get_packet_derived_items(target_name, packet_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<String>

Get the list of derived telemetry items for a packet

Parameters:

  • target_name (String)

    Target name

  • packet_name (String)

    Packet name

Returns:

  • (Array<String>)

    All of the ignored telemetry items for a packet.



372
373
374
375
376
# File 'lib/cosmos/api/tlm_api.rb', line 372

def get_packet_derived_items(target_name, packet_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  packet = TargetModel.packet(target_name, packet_name, scope: scope)
  return packet['items'].select { |item| item['data_type'] == 'DERIVED' }.map { |item| item['name'] }
end

#get_packets(id, block: nil, count: 1000, scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<String, Array<Hash>] Array of the ID and array of all packets found

Get packets based on ID returned from subscribe_packet.

Parameters:

  • id (String)

    ID returned from subscribe_packets or last call to get_packets

  • block (Integer) (defaults to: nil)

    Number of milliseconds to block when requesting packets

  • count (Integer) (defaults to: 1000)

    Maximum number of packets to return from EACH packet stream

Returns:

  • (Array<String, Array<Hash>] Array of the ID and array of all packets found)

    Array<String, Array<Hash>] Array of the ID and array of all packets found



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/cosmos/api/tlm_api.rb', line 316

def get_packets(id, block: nil, count: 1000, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', scope: scope, token: token)
  # Split the list of topic, ID values and turn it into a hash for easy updates
  lookup = Hash[*id.split(SUBSCRIPTION_DELIMITER)]
  xread = Store.xread(lookup.keys, lookup.values, block: block, count: count)
  # Return the original ID and nil if we didn't get anything
  return [id, nil] if xread.empty?
  packets = []
  xread.each do |topic, data|
    data.each do |id, msg_hash|
      lookup[topic] = id # Store the new ID
      json_hash = JSON.parse(msg_hash['json_data'])
      msg_hash.delete('json_data')
      packets << msg_hash.merge(json_hash)
    end
  end
  return [lookup.to_a.join(SUBSCRIPTION_DELIMITER), packets]
end

#get_parameter(target_name, packet_name, param_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Hash

Returns a hash of the given command parameter

Parameters:

  • target_name (String)

    Name of the target

  • packet_name (String)

    Name of the packet

  • param_name (String)

    Name of the parameter

Returns:

  • (Hash)

    Command parameter as a hash

Since:

  • 5.0.0



244
245
246
247
# File 'lib/cosmos/api/cmd_api.rb', line 244

def get_parameter(target_name, packet_name, param_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'cmd_info', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  TargetModel.packet_item(target_name, packet_name, param_name, type: :CMD, scope: scope)
end

#get_router(router_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Hash

Get information about a router

Parameters:

  • router_name (String)

    Router name

Returns:

  • (Hash)

    Hash of all the router information



41
42
43
44
45
46
47
# File 'lib/cosmos/api/router_api.rb', line 41

def get_router(router_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', router_name: router_name, scope: scope, token: token)
  router = RouterModel.get(name: router_name, scope: scope)
  raise "Router '#{router_name}' does not exist" unless router

  router.merge(RouterStatusModel.get(name: router_name, scope: scope))
end

#get_router_names(scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<String>

Returns All the router names.

Returns:



50
51
52
53
# File 'lib/cosmos/api/router_api.rb', line 50

def get_router_names(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', scope: scope, token: token)
  RouterModel.names(scope: scope)
end

#get_saved_config(configuration_name = nil, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Get a saved configuration zip file



32
33
34
# File 'lib/cosmos/api/config_api.rb', line 32

def get_saved_config(configuration_name = nil, scope: $cosmos_scope, token: $cosmos_token)
  raise "Not supported by COSMOS 5"
end

#get_setting(name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



41
42
43
# File 'lib/cosmos/api/settings_api.rb', line 41

def get_setting(name, scope: $cosmos_scope, token: $cosmos_token)
  Store.instance.hget(SETTINGS_KEY, name)
end

#get_settings(*args, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/cosmos/api/settings_api.rb', line 45

def get_settings(*args, scope: $cosmos_scope, token: $cosmos_token)
  ret = []
  args.each do |name|
    ret << Store.instance.hget(SETTINGS_KEY, name)
  end
  return ret
end

#get_stale(with_limits_only: false, target_name: nil, staleness_sec: 30, scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Array<String, String>>

Get the list of stale packets for a specific target or pass nil to list all stale packets

Parameters:

  • with_limits_only (Boolean) (defaults to: false)

    Return only the stale packets that have limits items and thus affect the overall limits state of the system

  • target_name (String) (defaults to: nil)

    The target to find stale packets for or nil to list all stale packets in the system

  • staleness_sec (Integer) (defaults to: 30)

    The amount of time to pass before a packet is marked stale

Returns:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cosmos/api/limits_api.rb', line 54

def get_stale(with_limits_only: false, target_name: nil, staleness_sec: 30, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', target_name: target_name, scope: scope, token: token)
  stale_time = Time.now.sys.to_nsec_from_epoch - (staleness_sec * Time::NSEC_PER_SECOND)
  stale = []
  targets = []
  if target_name
    targets = [target_name]
  else
    targets = get_target_list()
  end
  targets.each do |target_name|
    get_all_telemetry(target_name, scope: scope).each do |packet|
      topic = "#{scope}__TELEMETRY__{#{target_name}}__#{packet['packet_name']}"
      _, msg_hash = Store.get_newest_message(topic)
      unless msg_hash && msg_hash['time'].to_i > stale_time
        next if with_limits_only && packet['items'].find { |item| item['limits'] }.nil?

        stale << [packet['target_name'], packet['packet_name']]
      end
    end
  end
  stale
end

#get_target(target_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Hash

Gets the full target hash

Parameters:

  • target_name (String)

    Target name

Returns:

  • (Hash)

    Hash of all the target properties

Since:

  • 5.0.0



44
45
46
47
# File 'lib/cosmos/api/target_api.rb', line 44

def get_target(target_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', target_name: target_name, scope: scope, token: token)
  TargetModel.get(name: target_name, scope: scope)
end

#get_target_list(scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<String>

Returns the list of all target names

Returns:



34
35
36
37
# File 'lib/cosmos/api/target_api.rb', line 34

def get_target_list(scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', scope: scope, token: token)
  TargetModel.names(scope: scope)
end

#get_telemetry(target_name, packet_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Hash

Returns a telemetry packet hash

Parameters:

  • target_name (String)

    Name of the target

  • packet_name (String)

    Name of the packet

Returns:

  • (Hash)

    Telemetry packet hash

Since:

  • 5.0.0



269
270
271
272
# File 'lib/cosmos/api/tlm_api.rb', line 269

def get_telemetry(target_name, packet_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  TargetModel.packet(target_name, packet_name, scope: scope)
end

#get_tlm_buffer(target_name, packet_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ String

Returns the raw buffer for a telemetry packet.

Parameters:

  • target_name (String)

    Name of the target

  • packet_name (String)

    Name of the packet

Returns:

  • (String)

    last telemetry packet buffer



189
190
191
192
193
194
195
196
197
198
199
# File 'lib/cosmos/api/tlm_api.rb', line 189

def get_tlm_buffer(target_name, packet_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  TargetModel.packet(target_name, packet_name, scope: scope)
  topic = "#{scope}__TELEMETRY__{#{target_name}}__#{packet_name}"
  msg_id, msg_hash = Store.instance.read_topic_last(topic)
  if msg_id
    msg_hash['buffer'] = msg_hash['buffer'].b
    return msg_hash
  end
  return nil
end

#get_tlm_cnt(target_name, packet_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Numeric

Get the receive count for a telemetry packet

Parameters:

  • target_name (String)

    Name of the target

  • packet_name (String)

    Name of the packet

Returns:

  • (Numeric)

    Receive count for the telemetry packet



340
341
342
343
344
# File 'lib/cosmos/api/tlm_api.rb', line 340

def get_tlm_cnt(target_name, packet_name, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  TargetModel.packet(target_name, packet_name, scope: scope)
  _get_cnt("#{scope}__TELEMETRY__{#{target_name}}__#{packet_name}")
end

#get_tlm_packet(target_name, packet_name, type: :CONVERTED, scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<String, Object, Symbol|nil>

Returns all the values (along with their limits state) for a packet.

Parameters:

  • target_name (String)

    Name of the target

  • packet_name (String)

    Name of the packet

  • type (Symbol) (defaults to: :CONVERTED)

    Types returned, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS

Returns:

  • (Array<String, Object, Symbol|nil>)

    Returns an Array consisting of [item name, item value, item limits state] where the item limits state can be one of Limits::LIMITS_STATES

Raises:

  • (ArgumentError)


207
208
209
210
211
212
213
214
215
216
# File 'lib/cosmos/api/tlm_api.rb', line 207

def get_tlm_packet(target_name, packet_name, type: :CONVERTED, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  packet = TargetModel.packet(target_name, packet_name, scope: scope)
  t = _validate_tlm_type(type)
  raise ArgumentError, "Unknown type '#{type}' for #{target_name} #{packet_name}" if t.nil?
  items = packet['items'].map { | item | item['name'] }
  cvt_items = items.map { | item | "#{target_name}__#{packet_name}__#{item}__#{type}" }
  current_values = CvtModel.get_tlm_values(cvt_items, scope: scope)
  items.zip(current_values).map { | item , values | [item, values[0], values[1]]}
end

#get_tlm_values(items, scope: $cosmos_scope, token: $cosmos_token) ⇒ Array<Object, Symbol>

Returns all the item values (along with their limits state). The items can be from any target and packet and thus must be fully qualified with their target and packet names.

Parameters:

  • items (Array<String>)

    Array of items consisting of 'tgt__pkt__item__type'

Returns:

  • (Array<Object, Symbol>)

    Array consisting of the item value and limits state given as symbols such as :RED, :YELLOW, :STALE

Since:

  • 5.0.0



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/cosmos/api/tlm_api.rb', line 227

def get_tlm_values(items, scope: $cosmos_scope, token: $cosmos_token)
  if !items.is_a?(Array) || !items[0].is_a?(String)
    raise ArgumentError, "items must be array of strings: ['TGT__PKT__ITEM__TYPE', ...]"
  end

  items.each_with_index do |item, index|
    target_name, packet_name, item_name, item_type = item.split('__')
    if packet_name == 'LATEST'
      _, packet_name, _ = tlm_process_args([target_name, packet_name, item_name], 'get_tlm_values', scope: scope) # Figure out which packet is LATEST
      items[index] = "#{target_name}__#{packet_name}__#{item_name}__#{item_type}" # Replace LATEST with the real packet name
    end
    authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  end
  CvtModel.get_tlm_values(items, scope: scope)
end

#inject_tlm(target_name, packet_name, item_hash = nil, log: true, type: :CONVERTED, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Injects a packet into the system as if it was received from an interface

Parameters:

  • target_name (String)

    Target name of the packet

  • packet_name (String)

    Packet name of the packet

  • item_hash (Hash) (defaults to: nil)

    Hash of item_name and value for each item you want to change from the current value table

  • type (Symbol) (defaults to: :CONVERTED)

    Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/cosmos/api/tlm_api.rb', line 118

def inject_tlm(target_name, packet_name, item_hash = nil, log: true, type: :CONVERTED, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  unless CvtModel::VALUE_TYPES.include?(type.intern)
    raise "Unknown type '#{type}' for #{target_name} #{packet_name}"
  end

  if item_hash
    # Check that the items exist ... exceptions are raised if not
    TargetModel.packet_items(target_name, packet_name, item_hash.keys, scope: scope)
  else
    # Check that the packet exists ... exceptions are raised if not
    TargetModel.packet(target_name, packet_name, scope: scope)
  end

  packet_hash = get_telemetry(target_name, packet_name, scope: scope, token: token)
  packet = Packet.from_json(packet_hash)
  if item_hash
    item_hash.each do |name, value|
      packet.write(name.to_s, value, type)
    end
  end
  packet.received_time = Time.now.sys
  # TODO: New packet so received_count is not correct
  packet.received_count += 1
  TelemetryTopic.write_packet(packet, scope: scope)
end

#limits_enabled?(*args, scope: $cosmos_scope, token: $cosmos_token) ⇒ Boolean

Whether the limits are enabled for the given item

Accepts two different calling styles:

limits_enabled?("TGT PKT ITEM")
limits_enabled?('TGT','PKT','ITEM')

Favor the first syntax where possible as it is more succinct.

Parameters:

Returns:

  • (Boolean)

    Whether limits are enable for the itme



145
146
147
148
149
# File 'lib/cosmos/api/limits_api.rb', line 145

def limits_enabled?(*args, scope: $cosmos_scope, token: $cosmos_token)
  target_name, packet_name, item_name = tlm_process_args(args, 'limits_enabled?', scope: scope)
  authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  return TargetModel.packet_item(target_name, packet_name, item_name, scope: scope)['limits']['enabled'] ? true : false
end

#list_configs(tool, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



36
37
38
# File 'lib/cosmos/api/config_api.rb', line 36

def list_configs(tool, scope: $cosmos_scope, token: $cosmos_token)
  Store.instance.hkeys("#{scope}__config__#{tool}")
end

#list_settings(scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



33
34
35
# File 'lib/cosmos/api/settings_api.rb', line 33

def list_settings(scope: $cosmos_scope, token: $cosmos_token)
  Store.instance.hkeys(SETTINGS_KEY)
end

#load_config(tool, name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



40
41
42
# File 'lib/cosmos/api/config_api.rb', line 40

def load_config(tool, name, scope: $cosmos_scope, token: $cosmos_token)
  Store.instance.hget("#{scope}__config__#{tool}", name)
end

#normalize_tlm(*args, type: :ALL, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Normalize a telemetry item in a packet to its default behavior. Called after override_tlm to restore standard processing.

Accepts two different calling styles:

normalize_tlm("TGT PKT ITEM")
normalize_tlm('TGT','PKT','ITEM')

Favor the first syntax where possible as it is more succinct.

Parameters:

  • args

    The args must either be a string or three strings (see the calling style in the description).

  • type (Symbol) (defaults to: :ALL)

    Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS Also takes :ALL which means to normalize all telemetry types



178
179
180
181
182
# File 'lib/cosmos/api/tlm_api.rb', line 178

def normalize_tlm(*args, type: :ALL, scope: $cosmos_scope, token: $cosmos_token)
  target_name, packet_name, item_name = tlm_process_args(args, __method__, scope: scope)
  authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  CvtModel.normalize(target_name, packet_name, item_name, type: type.intern, scope: scope)
end

#override_tlm(*args, type: :CONVERTED, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Override the current value table such that a particular item always returns the same value (for a given type) even when new telemetry packets are received from the target.

Accepts two different calling styles:

override_tlm("TGT PKT ITEM = 1.0")
override_tlm('TGT','PKT','ITEM', 10.0)

Favor the first syntax where possible as it is more succinct.

Parameters:

  • args

    The args must either be a string followed by a value or three strings followed by a value (see the calling style in the description).

  • type (Symbol) (defaults to: :CONVERTED)

    Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS



159
160
161
162
163
# File 'lib/cosmos/api/tlm_api.rb', line 159

def override_tlm(*args, type: :CONVERTED, scope: $cosmos_scope, token: $cosmos_token)
  target_name, packet_name, item_name, value = set_tlm_process_args(args, __method__, scope: scope)
  authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  CvtModel.override(target_name, packet_name, item_name, value, type: type.intern, scope: scope)
end

#save_config(tool, name, data, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



44
45
46
# File 'lib/cosmos/api/config_api.rb', line 44

def save_config(tool, name, data, scope: $cosmos_scope, token: $cosmos_token)
  Store.instance.hset("#{scope}__config__#{tool}", name, data)
end

#save_setting(name, data, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



53
54
55
56
# File 'lib/cosmos/api/settings_api.rb', line 53

def save_setting(name, data, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'admin', scope: scope, token: token)
  Store.instance.hset(SETTINGS_KEY, name, data)
end

#send_raw(interface_name, data, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Send a raw binary string to the specified interface.

Parameters:

  • interface_name (String)

    The interface to send the raw binary

  • data (String)

    The raw binary data



183
184
185
186
187
# File 'lib/cosmos/api/cmd_api.rb', line 183

def send_raw(interface_name, data, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'cmd_raw', interface_name: interface_name, scope: scope, token: token)
  get_interface(interface_name, scope: scope, token: token) # Check to make sure the interface exists
  InterfaceTopic.write_raw(interface_name, data, scope: scope)
end

#set_limits(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = :CUSTOM, persistence = nil, enabled = true, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Change the limits settings for a given item. By default, a new limits set called ‘CUSTOM’ is created to avoid overriding existing limits.



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/cosmos/api/limits_api.rb', line 227

def set_limits(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high,
               green_low = nil, green_high = nil, limits_set = :CUSTOM, persistence = nil, enabled = true,
               scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  if (red_low > yellow_low) || (yellow_low >= yellow_high) || (yellow_high > red_high)
    raise "Invalid limits specified. Ensure yellow limits are within red limits."
  end
  if (green_low && green_high) && ((yellow_low > green_low) || (green_low >= green_high) || (green_high > yellow_high))
    raise "Invalid limits specified. Ensure green limits are within yellow limits."
  end
  packet = TargetModel.packet(target_name, packet_name, scope: scope)
  found_item = nil
  packet['items'].each do |item|
    if item['name'] == item_name
      item['limits']['persistence_setting'] = persistence
      if enabled
        item['limits']['enabled'] = true
      else
        item['limits'].delete('enabled')
      end
      limits = {}
      limits['red_low'] = red_low
      limits['yellow_low'] = yellow_low
      limits['yellow_high'] = yellow_high
      limits['red_high'] = red_high
      limits['green_low'] = green_low if green_low && green_high
      limits['green_high'] = green_high if green_low && green_high
      item['limits'][limits_set] = limits
      found_item = item
      break
    end
  end
  raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist" unless found_item
  message = "Setting '#{target_name} #{packet_name} #{item_name}' limits to #{red_low} #{yellow_low} #{yellow_high} #{red_high}"
  message << " #{green_low} #{green_high}" if green_low && green_high
  message << " in set #{limits_set} with persistence #{persistence} as enabled #{enabled}"
  Logger.info(message)

  TargetModel.set_packet(target_name, packet_name, packet, scope: scope)

  event = { type: :LIMITS_SETTINGS, target_name: target_name, packet_name: packet_name,
            item_name: item_name, red_low: red_low, yellow_low: yellow_low, yellow_high: yellow_high, red_high: red_high,
            green_low: green_low, green_high: green_high, limits_set: limits_set, persistence: persistence, enabled: enabled,
            time_nsec: Time.now.to_nsec_from_epoch, message: message }
  LimitsEventTopic.write(event, scope: scope)
end

#set_limits_set(limits_set, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Changes the active limits set that applies to all telemetry

Parameters:

  • limits_set (String)

    The name of the limits set



307
308
309
310
311
312
313
# File 'lib/cosmos/api/limits_api.rb', line 307

def set_limits_set(limits_set, scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'tlm_set', scope: scope, token: token)
  message = "Setting Limits Set: #{limits_set}"
  Logger.info(message)
  LimitsEventTopic.write({ type: :LIMITS_SET, set: limits_set.to_s,
    time_nsec: Time.now.to_nsec_from_epoch, message: message }, scope: scope)
end

#set_tlm(*args, type: :CONVERTED, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Set a telemetry item in the current value table.

Note: If this is done while COSMOS is currently receiving telemetry, this value could get overwritten at any time. Thus this capability is best used for testing or for telemetry items that are not received regularly through the target interface.

Accepts two different calling styles:

set_tlm("TGT PKT ITEM = 1.0")
set_tlm('TGT','PKT','ITEM', 10.0)

Favor the first syntax where possible as it is more succinct.

Parameters:

  • args (String|Array<String>)

    See the description for calling style

  • type (Symbol) (defaults to: :CONVERTED)

    Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS



106
107
108
109
110
# File 'lib/cosmos/api/tlm_api.rb', line 106

def set_tlm(*args, type: :CONVERTED, scope: $cosmos_scope, token: $cosmos_token)
  target_name, packet_name, item_name, value = set_tlm_process_args(args, __method__, scope: scope)
  authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  CvtModel.set_item(target_name, packet_name, item_name, value, type: type.intern, scope: scope)
end

#set_tlm_process_args(args, function_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/cosmos/api/tlm_api.rb', line 444

def set_tlm_process_args(args, function_name, scope: $cosmos_scope, token: $cosmos_token)
  case args.length
  when 1
    target_name, packet_name, item_name, value = extract_fields_from_set_tlm_text(args[0])
  when 4
    target_name = args[0]
    packet_name = args[1]
    item_name = args[2]
    value = args[3]
  else
    # Invalid number of arguments
    raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{function_name}()"
  end
  # Determine if this item exists, it will raise appropriate errors if not
  TargetModel.packet_item(target_name, packet_name, item_name, scope: scope)

  return [target_name, packet_name, item_name, value]
end

#start_raw_logging_interface(interface_name = 'ALL', scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Starts raw logging for an interface

Parameters:

  • interface_name (String) (defaults to: 'ALL')

    The name of the interface



75
76
77
78
79
80
81
82
83
84
# File 'lib/cosmos/api/interface_api.rb', line 75

def start_raw_logging_interface(interface_name = 'ALL', scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system_set', interface_name: interface_name, scope: scope, token: token)
  if interface_name == 'ALL'
    get_interface_names().each do |interface_name|
      InterfaceTopic.start_raw_logging(interface_name, scope: scope)
    end
  else
    InterfaceTopic.start_raw_logging(interface_name, scope: scope)
  end
end

#start_raw_logging_router(router_name = 'ALL', scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Starts raw logging for a router

Parameters:

  • router_name (String) (defaults to: 'ALL')

    The name of the interface



75
76
77
78
79
80
81
82
83
84
# File 'lib/cosmos/api/router_api.rb', line 75

def start_raw_logging_router(router_name = 'ALL', scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system_set', router_name: router_name, scope: scope, token: token)
  if router_name == 'ALL'
    get_router_names().each do |router_name|
      RouterTopic.start_raw_logging(router_name, scope: scope)
    end
  else
    RouterTopic.start_raw_logging(router_name, scope: scope)
  end
end

#stop_raw_logging_interface(interface_name = 'ALL', scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Stop raw logging for an interface

Parameters:

  • interface_name (String) (defaults to: 'ALL')

    The name of the interface



89
90
91
92
93
94
95
96
97
98
# File 'lib/cosmos/api/interface_api.rb', line 89

def stop_raw_logging_interface(interface_name = 'ALL', scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system_set', interface_name: interface_name, scope: scope, token: token)
  if interface_name == 'ALL'
    get_interface_names().each do |interface_name|
      InterfaceTopic.stop_raw_logging(interface_name, scope: scope)
    end
  else
    InterfaceTopic.stop_raw_logging(interface_name, scope: scope)
  end
end

#stop_raw_logging_router(router_name = 'ALL', scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Stop raw logging for a router

Parameters:

  • router_name (String) (defaults to: 'ALL')

    The name of the interface



89
90
91
92
93
94
95
96
97
98
# File 'lib/cosmos/api/router_api.rb', line 89

def stop_raw_logging_router(router_name = 'ALL', scope: $cosmos_scope, token: $cosmos_token)
  authorize(permission: 'system_set', router_name: router_name, scope: scope, token: token)
  if router_name == 'ALL'
    get_router_names().each do |router_name|
      RouterTopic.stop_raw_logging(router_name, scope: scope)
    end
  else
    RouterTopic.stop_raw_logging(router_name, scope: scope)
  end
end

#subscribe_packets(packets, scope: $cosmos_scope, token: $cosmos_token) ⇒ String Also known as: subscribe_packet

Subscribe to a list of packets. An ID is returned which is passed to get_packets(id) to return packets.

Parameters:

Returns:

  • (String)

    ID which should be passed to get_packets



294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/cosmos/api/tlm_api.rb', line 294

def subscribe_packets(packets, scope: $cosmos_scope, token: $cosmos_token)
  if !packets.is_a?(Array) || !packets[0].is_a?(Array)
    raise ArgumentError, "packets must be nested array: [['TGT','PKT'],...]"
  end

  result = {}
  packets.each do |target_name, packet_name|
    authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
    topic = "#{scope}__DECOM__{#{target_name}}__#{packet_name}"
    id, _ = Store.read_topic_last(topic)
    result[topic] = id ? id : '0-0'
  end
  result.to_a.join(SUBSCRIPTION_DELIMITER)
end

#tlm(*args, type: :CONVERTED, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Request a telemetry item from a packet.

Accepts two different calling styles:

tlm("TGT PKT ITEM")
tlm('TGT','PKT','ITEM')

Favor the first syntax where possible as it is more succinct.

Parameters:

  • args (String|Array<String>)

    See the description for calling style

  • type (Symbol) (defaults to: :CONVERTED)

    Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS

Returns:

  • (Object)

    The telemetry value formatted as requested



65
66
67
68
69
# File 'lib/cosmos/api/tlm_api.rb', line 65

def tlm(*args, type: :CONVERTED, scope: $cosmos_scope, token: $cosmos_token)
  target_name, packet_name, item_name = tlm_process_args(args, 'tlm', scope: scope)
  authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
  CvtModel.get_item(target_name, packet_name, item_name, type: type.intern, scope: scope)
end

#tlm_formatted(*args, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Deprecated.

Use tlm with type: :FORMATTED



77
78
79
# File 'lib/cosmos/api/tlm_api.rb', line 77

def tlm_formatted(*args, scope: $cosmos_scope, token: $cosmos_token)
  tlm(*args, type: :FORMATTED, scope: scope, token: token)
end

#tlm_process_args(args, function_name, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/cosmos/api/tlm_api.rb', line 411

def tlm_process_args(args, function_name, scope: $cosmos_scope, token: $cosmos_token)
  case args.length
  when 1
    target_name, packet_name, item_name = extract_fields_from_tlm_text(args[0])
  when 3
    target_name = args[0]
    packet_name = args[1]
    item_name = args[2]
  else
    # Invalid number of arguments
    raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{function_name}()"
  end
  if packet_name == 'LATEST'
    latest = -1
    TargetModel.packets(target_name, scope: scope).each do |packet|
      item = packet['items'].find { |item| item['name'] == item_name }
      if item
        _, msg_hash = Store.instance.get_oldest_message("#{scope}__DECOM__{#{target_name}}__#{packet['packet_name']}")
        if msg_hash && msg_hash['time'] && msg_hash['time'].to_i > latest
          packet_name = packet['packet_name']
          latest = msg_hash['time'].to_i
        end
      end
    end
    raise "Item '#{target_name} LATEST #{item_name}' does not exist" if latest == -1
  else
    # Determine if this item exists, it will raise appropriate errors if not
    TargetModel.packet_item(target_name, packet_name, item_name, scope: scope)
  end

  return [target_name, packet_name, item_name]
end

#tlm_raw(*args, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Deprecated.

Use tlm with type: :RAW



72
73
74
# File 'lib/cosmos/api/tlm_api.rb', line 72

def tlm_raw(*args, scope: $cosmos_scope, token: $cosmos_token)
  tlm(*args, type: :RAW, scope: scope, token: token)
end

#tlm_variable(*args, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Deprecated.

Use tlm with type:



87
88
89
# File 'lib/cosmos/api/tlm_api.rb', line 87

def tlm_variable(*args, scope: $cosmos_scope, token: $cosmos_token)
  tlm(*args[0..-2], type: args[-1].intern, scope: scope, token: token)
end

#tlm_with_units(*args, scope: $cosmos_scope, token: $cosmos_token) ⇒ Object

Deprecated.

Use tlm with type: :WITH_UNITS



82
83
84
# File 'lib/cosmos/api/tlm_api.rb', line 82

def tlm_with_units(*args, scope: $cosmos_scope, token: $cosmos_token)
  tlm(*args, type: :WITH_UNITS, scope: scope, token: token)
end