Class: Cosmos::PacketParser

Inherits:
Object show all
Defined in:
lib/cosmos/packets/parsers/packet_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ PacketParser

Returns a new instance of PacketParser.

Parameters:



60
61
62
# File 'lib/cosmos/packets/parsers/packet_parser.rb', line 60

def initialize(parser)
  @parser = parser
end

Class Method Details

.check_item_data_types(packet) ⇒ Object

Parameters:

  • packet (Packet)

    Packet to check all default and range items for appropriate data types. Only applicable to COMMAND packets.



49
50
51
52
53
54
55
56
57
# File 'lib/cosmos/packets/parsers/packet_parser.rb', line 49

def self.check_item_data_types(packet)
  packet.sorted_items.each do |item|
    item.check_default_and_range_data_types()
  end
rescue => err
  # Add the target name and packet name to the error message so the user
  # can debug where the error occurred
  raise $!, "#{packet.target_name} #{packet.packet_name} #{$!}", $!.backtrace
end

.parse_command(parser, target_name, commands, warnings) ⇒ Object

Parameters:

  • parser (ConfigParser)

    Configuration parser

  • target_name (String)

    The name of the target to create the packet under. If the target name is 'SYSTEM' the keyword parameter will be used instead of this parameter.

  • commands (Hash)

    Hash of the currently defined commands

  • warnings (Array<String>)

    Any warning strings generated while parsing this command will be appened to this array



23
24
25
26
27
# File 'lib/cosmos/packets/parsers/packet_parser.rb', line 23

def self.parse_command(parser, target_name, commands, warnings)
  parser = PacketParser.new(parser)
  parser.verify_parameters()
  parser.create_command(target_name, commands, warnings)
end

.parse_telemetry(parser, target_name, telemetry, latest_data, warnings) ⇒ Object

Parameters:

  • parser (ConfigParser)

    Configuration parser

  • target_name (String)

    The name of the target to create the packet under. If the target name is 'SYSTEM' the keyword parameter will be used instead of this parameter.

  • telemetry (Hash)

    Hash of the currently defined telemetry packets

  • latest_data (Hash<String=>Hash<String=>Array(Packet)>>)

    Hash of hashes keyed first by the target name and then by the item name. This results in an array of packets containing that target and item. This structure is used to perform lookups when the packet and item are known but the packet is not.

  • warnings (Array<String>)

    Any warning strings generated while parsing this command will be appened to this array



41
42
43
44
45
# File 'lib/cosmos/packets/parsers/packet_parser.rb', line 41

def self.parse_telemetry(parser, target_name, telemetry, latest_data, warnings)
  parser = PacketParser.new(parser)
  parser.verify_parameters()
  parser.create_telemetry(target_name, telemetry, latest_data, warnings)
end

Instance Method Details

#create_command(target_name, commands, warnings) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/cosmos/packets/parsers/packet_parser.rb', line 69

def create_command(target_name, commands, warnings)
  packet = create_packet(target_name)
  warning = check_for_duplicate('Command', commands, packet)
  warnings << warning if warning
  commands[packet.target_name] ||= {}
  packet
end

#create_telemetry(target_name, telemetry, latest_data, warnings) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/cosmos/packets/parsers/packet_parser.rb', line 77

def create_telemetry(target_name, telemetry, latest_data, warnings)
  packet = create_packet(target_name)
  warning = check_for_duplicate('Telemetry', telemetry, packet)
  warnings << warning if warning

  # Add received time packet items
  item = packet.define_item('RECEIVED_TIMESECONDS', 0, 0, :DERIVED, nil, packet.default_endianness, :ERROR, '%0.6f', ReceivedTimeSecondsConversion.new)
  item.description = 'COSMOS Received Time (UTC, Floating point, Unix epoch)'
  item = packet.define_item('RECEIVED_TIMEFORMATTED', 0, 0, :DERIVED, nil, packet.default_endianness, :ERROR, nil, ReceivedTimeFormattedConversion.new)
  item.description = 'COSMOS Received Time (Local time zone, Formatted string)'
  item = packet.define_item('RECEIVED_COUNT', 0, 0, :DERIVED, nil, packet.default_endianness, :ERROR, nil, ReceivedCountConversion.new)
  item.description = 'COSMOS packet received count'

  unless telemetry[packet.target_name]
    telemetry[packet.target_name] = {}
    latest_data[packet.target_name] = {}
  end
  packet
end

#verify_parametersObject



64
65
66
67
# File 'lib/cosmos/packets/parsers/packet_parser.rb', line 64

def verify_parameters
  @usage = "#{@parser.keyword} <TARGET NAME> <PACKET NAME> <ENDIANNESS: BIG_ENDIAN/LITTLE_ENDIAN> <DESCRIPTION (Optional)>"
  @parser.verify_num_parameters(3, 4, @usage)
end