Method: Cosmos::CommandDecomTopic.get_cmd_item

Defined in:
lib/cosmos/topics/command_decom_topic.rb

.get_cmd_item(target_name, packet_name, param_name, type: :WITH_UNITS, scope: $cosmos_scope) ⇒ Object



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
# File 'lib/cosmos/topics/command_decom_topic.rb', line 46

def self.get_cmd_item(target_name, packet_name, param_name, type: :WITH_UNITS, scope: $cosmos_scope)
  msg_id, msg_hash = Topic.get_newest_message("#{scope}__DECOMCMD__{#{target_name}}__#{packet_name}")
  if msg_id
    # TODO: We now have these reserved items directly on command packets
    # Do we still calculate from msg_hash['time'] or use the times directly?
    #
    # if param_name == 'RECEIVED_TIMESECONDS' || param_name == 'PACKET_TIMESECONDS'
    #   Time.from_nsec_from_epoch(msg_hash['time'].to_i).to_f
    # elsif param_name == 'RECEIVED_TIMEFORMATTED' || param_name == 'PACKET_TIMEFORMATTED'
    #   Time.from_nsec_from_epoch(msg_hash['time'].to_i).formatted
    if param_name == 'RECEIVED_COUNT'
      msg_hash['received_count'].to_i
    else
      json = msg_hash['json_data']
      hash = JSON.parse(json)
      # Start from the most complex down to the basic raw value
      value = hash["#{param_name}__U"]
      return value if value && type == :WITH_UNITS

      value = hash["#{param_name}__F"]
      return value if value && (type == :WITH_UNITS || type == :FORMATTED)

      value = hash["#{param_name}__C"]
      return value if value && (type == :WITH_UNITS || type == :FORMATTED || type == :CONVERTED)

      return hash[param_name]
    end
  end
end