Module: Cosmos::Api

Includes:
Extract
Included in:
BackgroundTask, CmdTlmServer, Interface, LimitsResponse
Defined in:
lib/cosmos/tools/cmd_tlm_server/api.rb

Constant Summary

Constants included from Extract

Extract::SCANNING_REGULAR_EXPRESSION

Instance Method Summary collapse

Instance Method Details

#cmd(*args) ⇒ 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:



108
109
110
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 108

def cmd(*args)
  cmd_implementation(true, true, false, 'cmd', *args)
end

#cmd_no_checks(*args) ⇒ 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:



155
156
157
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 155

def cmd_no_checks(*args)
  cmd_implementation(false, false, false, 'cmd_no_checks', *args)
end

#cmd_no_hazardous_check(*args) ⇒ 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:



140
141
142
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 140

def cmd_no_hazardous_check(*args)
  cmd_implementation(true, false, false, 'cmd_no_hazardous_check', *args)
end

#cmd_no_range_check(*args) ⇒ 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:



124
125
126
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 124

def cmd_no_range_check(*args)
  cmd_implementation(false, true, false, 'cmd_no_range_check', *args)
end

#cmd_raw(*args) ⇒ 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:



169
170
171
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 169

def cmd_raw(*args)
  cmd_implementation(true, true, true, 'cmd_raw', *args)
end

#cmd_raw_no_checks(*args) ⇒ 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:



216
217
218
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 216

def cmd_raw_no_checks(*args)
  cmd_implementation(false, false, true, 'cmd_raw_no_checks', *args)
end

#cmd_raw_no_hazardous_check(*args) ⇒ 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:



201
202
203
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 201

def cmd_raw_no_hazardous_check(*args)
  cmd_implementation(true, false, true, 'cmd_raw_no_hazardous_check', *args)
end

#cmd_raw_no_range_check(*args) ⇒ 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:



185
186
187
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 185

def cmd_raw_no_range_check(*args)
  cmd_implementation(false, true, true, 'cmd_raw_no_range_check', *args)
end

#connect_interface(interface_name, *params) ⇒ Object

Connects to an interface and starts its telemetry gathering thread. If optional parameters are given, the interface is recreated with new parameters.

Parameters:

  • interface_name (String)

    The name of the interface

  • params (Array)

    Parameters to pass to the interface.



760
761
762
763
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 760

def connect_interface(interface_name, *params)
  CmdTlmServer.interfaces.connect(interface_name, *params)
  nil
end

#connect_router(router_name, *params) ⇒ Object

Connects a router and starts its command gathering thread. If optional parameters are given, the router is recreated with new parameters.

Parameters:

  • router_name (String)

    The name of the router

  • params (Array)

    Parameters to pass to the router.



802
803
804
805
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 802

def connect_router(router_name, *params)
  CmdTlmServer.routers.connect(router_name, *params)
  nil
end

#disable_limits(*args) ⇒ 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:



623
624
625
626
627
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 623

def disable_limits(*args)
  target_name, packet_name, item_name = tlm_process_args(args, 'disable_limits')
  System.limits.disable(target_name, packet_name, item_name)
  nil
end

#disable_limits_group(group_name) ⇒ Object

Disables limit checking for all the items in the given group.

Parameters:

  • group_name (String)

    Name of the group to disable



675
676
677
678
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 675

def disable_limits_group(group_name)
  System.limits.disable_group(group_name)
  nil
end

#disconnect_interface(interface_name) ⇒ Object

Disconnects from an interface and kills its telemetry gathering thread

Parameters:

  • interface_name (String)

    The name of the interface



768
769
770
771
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 768

def disconnect_interface(interface_name)
  CmdTlmServer.interfaces.disconnect(interface_name)
  nil
end

#disconnect_router(router_name) ⇒ Object

Disconnects a router and kills its command gathering thread

Parameters:

  • router_name (String)

    The name of the router



810
811
812
813
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 810

def disconnect_router(router_name)
  CmdTlmServer.routers.disconnect(router_name)
  nil
end

#enable_limits(*args) ⇒ 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:



608
609
610
611
612
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 608

def enable_limits(*args)
  target_name, packet_name, item_name = tlm_process_args(args, 'enable_limits')
  System.limits.enable(target_name, packet_name, item_name)
  nil
end

#enable_limits_group(group_name) ⇒ Object

Enables limit checking for all the items in the given group.

Parameters:

  • group_name (String)

    Name of the group to enable



669
670
671
672
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 669

def enable_limits_group(group_name)
  System.limits.enable_group(group_name)
  nil
end

#get_cmd_hazardous(target_name, command_name, params = {}) ⇒ Boolean

Returns whether the specified command is hazardous

Parameters:

  • params (Hash) (defaults to: {})

    Command parameter hash to test whether a particular parameter setting makes the command hazardous

  • target_name (String)

    Name of the target

  • command_name (String)

    Name of the command

Returns:

  • (Boolean)

    Whether the command is hazardous



274
275
276
277
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 274

def get_cmd_hazardous(target_name, command_name, params = {})
  hazardous, _ = System.commands.cmd_hazardous?(target_name, command_name, params)
  return hazardous
end

#get_cmd_list(target_name) ⇒ Array<Array<String, String>>

Returns the list of all the command names and their descriptions from the given target.

Parameters:

  • target_name (String)

    Name of the target

Returns:

  • (Array<Array<String, String>>)

    Array containing [command name, command description] for all commands in the target



235
236
237
238
239
240
241
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 235

def get_cmd_list(target_name)
  list = []
  System.commands.packets(target_name).each do |name, command|
    list << [name, command.description]
  end
  return list.sort
end

#get_cmd_log_filename(packet_log_writer_name = 'DEFAULT') ⇒ String

Returns The command packet log filename.

Parameters:

  • packet_log_writer_name (String) (defaults to: 'DEFAULT')

    The name of the packet log writer which is writing the command packet log

Returns:

  • (String)

    The command packet log filename



825
826
827
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 825

def get_cmd_log_filename(packet_log_writer_name = 'DEFAULT')
  CmdTlmServer.packet_logging.cmd_filename(packet_log_writer_name)
end

#get_cmd_param_list(target_name, command_name) ⇒ Array<Array<String, Object, nil|Array, nil|String, nil|String, nil|String, Boolean>] Array containing \[name, default, states, description, units_full, units, required] for all parameters in the command

Returns the list of all the parameters for the given command.

Parameters:

  • command_name (String)

    Name of the command

  • target_name (String)

    Name of the target

Returns:

  • (Array<Array<String, Object, nil|Array, nil|String, nil|String, nil|String, Boolean>] Array containing \[name, default, states, description, units_full, units, required] for all parameters in the command)

    Array<Array<String, Object, nil|Array, nil|String, nil|String, nil|String, Boolean>] Array containing [name, default, states, description, units_full, units, required] for all parameters in the command



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 251

def get_cmd_param_list(target_name, command_name)
  list = []
  System.commands.params(target_name, command_name).each do |parameter|
    if parameter.format_string
      unless parameter.default.kind_of?(Array)
        list << [parameter.name, sprintf(parameter.format_string, parameter.default), parameter.states, parameter.description, parameter.units_full, parameter.units, parameter.required]
      else
        list << [parameter.name, "[]", parameter.states, parameter.description, parameter.units_full, parameter.units, parameter.required]
      end
    else
      list << [parameter.name, parameter.default, parameter.states, parameter.description, parameter.units_full, parameter.units, parameter.required]
    end
  end
  return list
end

#get_cmd_time(target_name = nil, command_name = nil) ⇒ 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:



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
343
344
345
346
347
348
349
350
351
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 317

def get_cmd_time(target_name = nil, command_name = nil)
  last_command = nil
  if target_name
    if command_name
      last_command = System.commands.packet(target_name, command_name)
    else
      System.commands.packets(target_name).each do |packet_name, command|
        last_command = command if !last_command and command.received_time
        if command.received_time and command.received_time > last_command.received_time
          last_command = command
        end
      end
    end
  else
    commands = System.commands.all
    commands.each do |target_name, target_commands|
      target_commands.each do |packet_name, command|
        last_command = command if !last_command and command.received_time
        if command.received_time and command.received_time > last_command.received_time
          last_command = command
        end
      end
    end
  end

  if last_command
    if last_command.received_time
      return [last_command.target_name, last_command.packet_name, last_command.received_time.tv_sec, last_command.received_time.tv_usec]
    else
      return [last_command.target_name, last_command.packet_name, nil, nil]
    end
  else
    return [nil, nil, nil, nil]
  end
end

#get_cmd_value(target_name, command_name, parameter_name, value_type = :CONVERTED) ⇒ 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



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 287

def get_cmd_value(target_name, command_name, parameter_name, value_type = :CONVERTED)
  packet = System.commands.packet(target_name, command_name)
  # Virtually support RECEIVED_TIMEFORMATTED, RECEIVED_TIMESECONDS, RECEIVED_COUNT
  case parameter_name.to_s.upcase
  when 'RECEIVED_TIMEFORMATTED'
    if packet.received_time
      return packet.received_time.formatted
    else
      return 'No Packet Received Time'
    end
  when 'RECEIVED_TIMESECONDS'
    if packet.received_time
      return packet.received_time.to_f
    else
      return 0.0
    end
  when 'RECEIVED_COUNT'
    return packet.received_count
  else
    return packet.read(parameter_name, value_type.intern)
  end
end

#get_interface_namesArray<String>

Returns All the interface names.

Returns:



750
751
752
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 750

def get_interface_names
  CmdTlmServer.interfaces.names
end

#get_limits(target_name, packet_name, item_name, limits_set = nil) ⇒ Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information

Get the limits for a telemetry item

Parameters:

  • target_name (String)

    Target Name

  • packet_name (String)

    Packet Name

  • item_name (String)

    Item Name

  • limits_set (String or Symbol or nil) (defaults to: nil)

    Desired Limits set. nil = current limits set

Returns:

  • (Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information)

    Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information



648
649
650
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 648

def get_limits(target_name, packet_name, item_name, limits_set = nil)
  System.limits.get(target_name, packet_name, item_name, limits_set)
end

#get_limits_event(id, non_block = false) ⇒ Object



725
726
727
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 725

def get_limits_event(id, non_block = false)
  CmdTlmServer.get_limits_event(id, non_block)
end

#get_limits_groupsHash(String, Array)

Returns The defined limits groups.

Returns:



664
665
666
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 664

def get_limits_groups
  return System.limits.groups.keys
end

#get_limits_setString

Returns the active limits set that applies to all telemetry

Returns:

  • (String)

    The current limits set



697
698
699
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 697

def get_limits_set
  return System.limits_set.to_s
end

#get_limits_setsArray<Symbol>

Returns all defined limits sets

Returns:



683
684
685
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 683

def get_limits_sets
  return System.limits.sets
end

#get_out_of_limitsArray<Array<String, String, String, Symbol>>

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:



575
576
577
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 575

def get_out_of_limits
  return System.limits.out_of_limits
end

#get_overall_limits_state(ignored_items = nil) ⇒ Symbol

Returns The overall limits state for the system.

Returns:

  • (Symbol)

    The overall limits state for the system



580
581
582
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 580

def get_overall_limits_state (ignored_items = nil)
  return System.limits.overall_limits_state(ignored_items)
end

#get_packet_data(id, non_block = false) ⇒ Object



741
742
743
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 741

def get_packet_data(id, non_block = false)
  CmdTlmServer.get_packet_data(id, non_block)
end

#get_router_namesArray<String>

Returns All the router names.

Returns:



792
793
794
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 792

def get_router_names
  CmdTlmServer.routers.names
end

#get_server_message_log_filenameString

Returns The server message log filename.

Returns:

  • (String)

    The server message log filename



929
930
931
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 929

def get_server_message_log_filename
  CmdTlmServer.message_log.filename
end

#get_stale(with_limits_only = false, target = nil) ⇒ 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 (String) (defaults to: nil)

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

Returns:



639
640
641
642
643
644
645
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 639

def get_stale(with_limits_only = false, target = nil)
  stale = []
  System.telemetry.stale(with_limits_only, target).each do |packet|
    stale << [packet.target_name, packet.packet_name]
  end
  stale
end

#get_target_listArray<String>

Returns the list of all target names

Returns:



708
709
710
711
712
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 708

def get_target_list
  list = []
  System.targets.each_key {|target_name| list << target_name }
  return list.sort
end

#get_tlm_details(item_array) ⇒ Array<Hash>

Returns an array of Hashes with all the attributes of the item.

Parameters:

  • item_array (Array<Array(String String String)>)

    An array consisting of [target name, packet name, item name]

  • value_types (Symbol|Array<Symbol>)

    How to convert the items before returning. A single symbol of Packet::VALUE_TYPES can be passed which will convert all items the same way. Or an array of symbols can be passed to control how each item is converted.

Returns:

  • (Array<Hash>)

    Array of hashes describing the items. All the attributes in PacketItem and StructItem are present in the Hash.



562
563
564
565
566
567
568
569
570
571
572
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 562

def get_tlm_details(item_array)
  if !item_array.is_a?(Array) || !item_array[0].is_a?(Array)
    raise ArgumentError, "item_array must be nested array: [['TGT','PKT','ITEM'],...]"
  end
  details = []
  item_array.each do |target_name, packet_name, item_name|
    _, item = System.telemetry.packet_and_item(target_name, packet_name, item_name)
    details << item.to_hash
  end
  details
end

#get_tlm_item_list(target_name, packet_name) ⇒ Array<String, Hash, String>

Returns the item names and their states and descriptions for a particular packet.

Parameters:

  • target_name (String)

    Name of the target

  • packet_name (String)

    Name of the packet

Returns:



548
549
550
551
552
553
554
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 548

def get_tlm_item_list(target_name, packet_name)
  list = []
  System.telemetry.items(target_name, packet_name).each do |item|
    list << [item.name, item.states, item.description]
  end
  list
end

#get_tlm_list(target_name) ⇒ Array<String, String>

Returns the sorted packet names and their descriptions for a particular target.

Parameters:

  • target_name (String)

    Name of the target

Returns:

  • (Array<String, String>)

    Array of [packet name, packet description] sorted by packet name



532
533
534
535
536
537
538
539
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 532

def get_tlm_list(target_name)
  list = []
  packets = System.telemetry.packets(target_name)
  packets.each do |packet_name, packet|
    list << [packet_name, packet.description]
  end
  list.sort
end

#get_tlm_log_filename(packet_log_writer_name = 'DEFAULT') ⇒ String

Returns The telemetry packet log filename.

Parameters:

  • packet_log_writer_name (String) (defaults to: 'DEFAULT')

    The name of the packet log writer which is writing the telemetry packet log

Returns:

  • (String)

    The telemetry packet log filename



832
833
834
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 832

def get_tlm_log_filename(packet_log_writer_name = 'DEFAULT')
  CmdTlmServer.packet_logging.tlm_filename(packet_log_writer_name)
end

#get_tlm_packet(target_name, packet_name, value_type = :CONVERTED) ⇒ 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

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

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

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



490
491
492
493
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 490

def get_tlm_packet(target_name, packet_name, value_type = :CONVERTED)
  packet = System.telemetry.packet(target_name, packet_name)
  return packet.read_all_with_limits_states(value_type.to_s.intern)
end

#get_tlm_values(item_array, value_types = :CONVERTED) ⇒ Array< Array<Object>, Array<Symbol>, Array<Array<Numeric>>, String>

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:

  • item_array (Array<Array(String String String)>)

    An array consisting of [target name, packet name, item name]

  • value_types (Symbol|Array<Symbol>) (defaults to: :CONVERTED)

    How to convert the items before returning. A single symbol of Packet::VALUE_TYPES can be passed which will convert all items the same way. Or an array of symbols can be passed to control how each item is converted.

Returns:

  • (Array< Array<Object>, Array<Symbol>, Array<Array<Numeric>>, String>)

    Array consisting of an Array of item values, an Array of item limits state given as symbols such as :RED, :YELLOW, :STALE, an Array of Arrays including the limits setting such as red low, yellow low, yellow high, red high and optionally green low and high, and the overall limits state which is one of Limits::LIMITS_STATES.



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 506

def get_tlm_values(item_array, value_types = :CONVERTED)
  if !item_array.is_a?(Array) || (!item_array[0].is_a?(Array) and !item_array.empty?)
    raise ArgumentError, "item_array must be nested array: [['TGT','PKT','ITEM'],...]"
  end
  return [[], [], [], System.limits_set] if item_array.empty?
  if value_types.is_a?(Array)
    elem = value_types[0]
  else
    elem = value_types
  end
  # Due to JSON round tripping from scripts, value_types can be a String
  # so we must check for both Symbol and String
  if !elem.is_a?(Symbol) && !elem.is_a?(String)
    raise ArgumentError, "value_types must be a single symbol or array of symbols specifying the conversion method (:RAW, :CONVERTED, :FORMATTED, :WITH_UNITS)"
  end
  array = System.telemetry.values_and_limits_states(item_array, value_types)
  array << System.limits_set
  return array
end

#initializeObject

Sets api_requests to 0 and initializes the whitelist of allowable API method calls



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 20

def initialize
  @api_whitelist = [
    'cmd',
    'cmd_no_range_check',
    'cmd_no_hazardous_check',
    'cmd_no_checks',
    'cmd_raw',
    'cmd_raw_no_range_check',
    'cmd_raw_no_hazardous_check',
    'cmd_raw_no_checks',
    'send_raw',
    'get_cmd_list',
    'get_cmd_param_list',
    'get_cmd_hazardous',
    'get_cmd_value',
    'get_cmd_time',
    'tlm',
    'tlm_raw',
    'tlm_formatted',
    'tlm_with_units',
    'tlm_variable',
    'set_tlm',
    'set_tlm_raw',
    'get_tlm_packet',
    'get_tlm_values',
    'get_tlm_list',
    'get_tlm_item_list',
    'get_tlm_details',
    'get_out_of_limits',
    'get_overall_limits_state',
    'limits_enabled?',
    'enable_limits',
    'disable_limits',
    'get_stale',
    'get_limits',
    'set_limits',
    'get_limits_groups',
    'enable_limits_group',
    'disable_limits_group',
    'get_limits_sets',
    'set_limits_set',
    'get_limits_set',
    'get_target_list',
    'subscribe_limits_events',
    'unsubscribe_limits_events',
    'get_limits_event',
    'subscribe_packet_data',
    'unsubscribe_packet_data',
    'get_packet_data',
    'get_interface_names',
    'connect_interface',
    'disconnect_interface',
    'interface_state',
    'map_target_to_interface',
    'get_router_names',
    'connect_router',
    'disconnect_router',
    'router_state',
    'get_cmd_log_filename',
    'get_tlm_log_filename',
    'start_logging',
    'stop_logging',
    'start_cmd_log',
    'start_tlm_log',
    'stop_cmd_log',
    'stop_tlm_log',
    'start_raw_logging_interface',
    'stop_raw_logging_interface',
    'start_raw_logging_router',
    'stop_raw_logging_router',
    'get_server_message_log_filename',
    'start_new_server_message_log']
end

#interface_state(interface_name) ⇒ String

Returns The state of the interface which is one of ‘CONNECTED’, ‘ATTEMPTING’ or ‘DISCONNECTED’.

Parameters:

  • interface_name (String)

    The name of the interface

Returns:

  • (String)

    The state of the interface which is one of 'CONNECTED', 'ATTEMPTING' or 'DISCONNECTED'.



776
777
778
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 776

def interface_state(interface_name)
  CmdTlmServer.interfaces.state(interface_name)
end

#limits_enabled?(*args) ⇒ 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



594
595
596
597
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 594

def limits_enabled?(*args)
  target_name, packet_name, item_name = tlm_process_args(args, 'limits_enabled?')
  return System.limits.enabled?(target_name, packet_name, item_name)
end

#map_target_to_interface(target_name, interface_name) ⇒ Object

Associates a target and all its commands and telemetry with a particular interface. All the commands will go out over and telemetry be received from that interface.

Parameters:

  • target_name (String)

    The name of the target

  • interface_name (String)

    The name of the interface



786
787
788
789
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 786

def map_target_to_interface(target_name, interface_name)
  CmdTlmServer.interfaces.map_target(target_name, interface_name)
  nil
end

#router_state(router_name) ⇒ String

Returns The state of the router which is one of ‘CONNECTED’, ‘ATTEMPTING’ or ‘DISCONNECTED’.

Parameters:

  • router_name (String)

    The name of the router

Returns:

  • (String)

    The state of the router which is one of 'CONNECTED', 'ATTEMPTING' or 'DISCONNECTED'.



818
819
820
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 818

def router_state(router_name)
  CmdTlmServer.routers.state(router_name)
end

#send_raw(interface_name, data) ⇒ 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



224
225
226
227
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 224

def send_raw(interface_name, data)
  CmdTlmServer.commanding.send_raw(interface_name, data)
  nil
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) ⇒ Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information

Set the limits for a telemetry item

Parameters:

  • target_name (String)

    Target Name

  • packet_name (String)

    Packet Name

  • item_name (String)

    Item Name

  • red_low (Float)

    Red Low Limit

  • yellow_low (Float)

    Yellow Low Limit

  • yellow_high (Float)

    Yellow High Limit

  • red_high (Float)

    Red High Limit

  • green_low (Float) (defaults to: nil)

    Green Low Limit

  • green_high (Float) (defaults to: nil)

    Green High Limit

  • limits_set (String or Symbol or nil) (defaults to: :CUSTOM)

    Desired Limits set. nil = current limits set, recommend using :CUSTOM

  • persistence (Integer) (defaults to: nil)

    The number of samples the value must be out of limits before detecting a limits change. nil = Leave unchanged

  • enabled (Boolean) (defaults to: true)

    If limits monitoring is enabled for this item

Returns:

  • (Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information)

    Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information



653
654
655
656
657
658
659
660
661
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 653

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)
  result = System.limits.set(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low, green_high, limits_set, persistence, enabled)
  if result[0] != nil
    limits_settings = [target_name, packet_name, item_name].concat(result)
    CmdTlmServer.instance.post_limits_event(:LIMITS_SETTINGS, limits_settings)
    Logger.info("Limits Settings Changed: #{limits_settings}")
  end
  result
end

#set_limits_set(limits_set) ⇒ Object

Changes the active limits set that applies to all telemetry

Parameters:

  • limits_set (String)

    The name of the limits set



690
691
692
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 690

def set_limits_set(limits_set)
  System.limits_set = limits_set if System.limits_set != limits_set.to_s.upcase.intern
end

#set_tlm(*args) ⇒ Object

Set a telemetry item in a packet to a particular value and then verifies the value is within the acceptable limits. This method uses any conversions that apply to the item when setting the value.

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

    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).



452
453
454
455
456
457
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 452

def set_tlm(*args)
  target_name, packet_name, item_name, value = set_tlm_process_args(args, 'set_tlm')
  System.telemetry.set_value(target_name, packet_name, item_name, value, :CONVERTED)
  System.telemetry.packet(target_name, packet_name).check_limits(System.limits_set, true)
  nil
end

#set_tlm_raw(*args) ⇒ Object

Set a telemetry item in a packet to a particular value and then verifies the value is within the acceptable limits. No conversions are applied.

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_raw("TGT PKT ITEM = 1.0")
set_tlm_raw('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).



476
477
478
479
480
481
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 476

def set_tlm_raw(*args)
  target_name, packet_name, item_name, value = set_tlm_process_args(args, 'set_tlm_raw')
  System.telemetry.set_value(target_name, packet_name, item_name, value, :RAW)
  System.telemetry.packet(target_name, packet_name).check_limits(System.limits_set, true)
  nil
end

#start_cmd_log(packet_log_writer_name = 'ALL', label = nil) ⇒ Object

Start command packet logging.

Parameters:

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

    The name of the packet log writer which is writing the command logs

  • label (String) (defaults to: nil)

    Optional label to apply to the command packet log filename



862
863
864
865
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 862

def start_cmd_log(packet_log_writer_name = 'ALL', label = nil)
  CmdTlmServer.packet_logging.start_cmd(packet_log_writer_name, label)
  nil
end

#start_logging(packet_log_writer_name = 'ALL', label = nil) ⇒ Object

Start both command and telemetry packet logging.

Parameters:

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

    The name of the packet log writer which is writing both the command and telemetry logs

  • label (String) (defaults to: nil)

    Optional label to apply to both the command and telemetry packet log filename



842
843
844
845
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 842

def start_logging(packet_log_writer_name = 'ALL', label = nil)
  CmdTlmServer.packet_logging.start(packet_log_writer_name, label)
  nil
end

#start_new_server_message_logObject

Starts a new server message log



934
935
936
937
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 934

def start_new_server_message_log
  CmdTlmServer.message_log.start
  nil
end

#start_raw_logging_interface(interface_name = 'ALL') ⇒ Object

Starts raw logging for an interface

Parameters:

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

    The name of the interface



899
900
901
902
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 899

def start_raw_logging_interface(interface_name = 'ALL')
  CmdTlmServer.interfaces.start_raw_logging(interface_name)
  nil
end

#start_raw_logging_router(router_name = 'ALL') ⇒ Object

Starts raw logging for a router

Parameters:

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

    The name of the router



915
916
917
918
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 915

def start_raw_logging_router(router_name = 'ALL')
  CmdTlmServer.routers.start_raw_logging(router_name)
  nil
end

#start_tlm_log(packet_log_writer_name = 'ALL', label = nil) ⇒ Object

Start telemetry packet logging.

Parameters:

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

    The name of the packet log writer which is writing the telemetry logs

  • label (String) (defaults to: nil)

    Optional label to apply to the telemetry packet log filename



873
874
875
876
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 873

def start_tlm_log(packet_log_writer_name = 'ALL', label = nil)
  CmdTlmServer.packet_logging.start_tlm(packet_log_writer_name, label)
  nil
end

#stop_cmd_log(packet_log_writer_name = 'ALL') ⇒ Object

Stop command packet logging.

Parameters:

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

    The name of the packet log writer which is writing the command log



882
883
884
885
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 882

def stop_cmd_log(packet_log_writer_name = 'ALL')
  CmdTlmServer.packet_logging.stop_cmd(packet_log_writer_name)
  nil
end

#stop_logging(packet_log_writer_name = 'ALL') ⇒ Object

Stop both command and telemetry packet logging.

Parameters:

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

    The name of the packet log writer which is writing both the command and telemetry logs



851
852
853
854
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 851

def stop_logging(packet_log_writer_name = 'ALL')
  CmdTlmServer.packet_logging.stop(packet_log_writer_name)
  nil
end

#stop_raw_logging_interface(interface_name = 'ALL') ⇒ Object

Stop raw logging for an interface

Parameters:

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

    The name of the interface



907
908
909
910
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 907

def stop_raw_logging_interface(interface_name = 'ALL')
  CmdTlmServer.interfaces.stop_raw_logging(interface_name)
  nil
end

#stop_raw_logging_router(router_name = 'ALL') ⇒ Object

Stops raw logging for a router

Parameters:

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

    The name of the router



923
924
925
926
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 923

def stop_raw_logging_router(router_name = 'ALL')
  CmdTlmServer.routers.stop_raw_logging(router_name)
  nil
end

#stop_tlm_log(packet_log_writer_name = 'ALL') ⇒ Object

Stop telemetry packet logging.

Parameters:

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

    The name of the packet log writer which is writing the telemetry log



891
892
893
894
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 891

def stop_tlm_log(packet_log_writer_name = 'ALL')
  CmdTlmServer.packet_logging.stop_tlm(packet_log_writer_name)
  nil
end

#subscribe_limits_events(queue_size = CmdTlmServer::DEFAULT_LIMITS_EVENT_QUEUE_SIZE) ⇒ Object



715
716
717
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 715

def subscribe_limits_events(queue_size = CmdTlmServer::DEFAULT_LIMITS_EVENT_QUEUE_SIZE)
  CmdTlmServer.subscribe_limits_events(queue_size)
end

#subscribe_packet_data(packets, queue_size = CmdTlmServer::DEFAULT_PACKET_DATA_QUEUE_SIZE) ⇒ Object



730
731
732
733
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 730

def subscribe_packet_data(packets,
                          queue_size = CmdTlmServer::DEFAULT_PACKET_DATA_QUEUE_SIZE)
  CmdTlmServer.subscribe_packet_data(packets, queue_size)
end

#tlm(*args) ⇒ Numeric

Request a converted 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:

Returns:

  • (Numeric)

    The converted telemetry value without formatting or units



364
365
366
367
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 364

def tlm(*args)
  target_name, packet_name, item_name = tlm_process_args(args, 'tlm')
  System.telemetry.value(target_name, packet_name, item_name, :CONVERTED)
end

#tlm_formatted(*args) ⇒ String

Request a formatted telemetry item from a packet.

Accepts two different calling styles:

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

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

Parameters:

Returns:

  • (String)

    The converted telemetry value with formatting but without units



396
397
398
399
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 396

def tlm_formatted(*args)
  target_name, packet_name, item_name = tlm_process_args(args, 'tlm_formatted')
  System.telemetry.value(target_name, packet_name, item_name, :FORMATTED)
end

#tlm_raw(*args) ⇒ Numeric

Request a raw telemetry item from a packet.

Accepts two different calling styles:

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

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

Parameters:

Returns:

  • (Numeric)

    The unconverted telemetry value without formatting or units



380
381
382
383
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 380

def tlm_raw(*args)
  target_name, packet_name, item_name = tlm_process_args(args, 'tlm_raw')
  System.telemetry.value(target_name, packet_name, item_name, :RAW)
end

#tlm_variable(*args) ⇒ Object

Request a telemetry item from a packet with the specified conversion applied. This method is equivalent to calling the other tlm_xxx methods.

Accepts two different calling styles:

tlm_variable("TGT PKT ITEM", :RAW)
tlm_variable('TGT','PKT','ITEM', :RAW)

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

Parameters:

  • args

    The args must either be a string followed by a symbol or three strings followed by a symbol (see the calling style in the description). The symbol must be one of Packet::VALUE_TYPES.

Returns:

  • (Object)

    The converted telemetry value



429
430
431
432
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 429

def tlm_variable(*args)
  target_name, packet_name, item_name, value_type = tlm_variable_process_args(args, 'tlm_variable')
  System.telemetry.value(target_name, packet_name, item_name, value_type)
end

#tlm_with_units(*args) ⇒ String

Request a telemetry item with units from a packet.

Accepts two different calling styles:

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

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

Parameters:

Returns:

  • (String)

    The converted, formatted telemetry value with units



411
412
413
414
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 411

def tlm_with_units(*args)
  target_name, packet_name, item_name = tlm_process_args(args, 'tlm_with_units')
  System.telemetry.value(target_name, packet_name, item_name, :WITH_UNITS)
end

#unsubscribe_limits_events(id) ⇒ Object



720
721
722
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 720

def unsubscribe_limits_events(id)
  CmdTlmServer.unsubscribe_limits_events(id)
end

#unsubscribe_packet_data(id) ⇒ Object



736
737
738
# File 'lib/cosmos/tools/cmd_tlm_server/api.rb', line 736

def unsubscribe_packet_data(id)
  CmdTlmServer.unsubscribe_packet_data(id)
end