lib/cosmos/packets/parsers/packet_parser.rb in cosmos-3.7.1 vs lib/cosmos/packets/parsers/packet_parser.rb in cosmos-3.8.0
- old
+ new
@@ -66,37 +66,19 @@
@parser.verify_num_parameters(3, 4, @usage)
end
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
+ PacketParser.finish_create_command(packet, commands, warnings)
end
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
+ PacketParser.finish_create_telemetry(packet, telemetry, latest_data, warnings)
end
- private
+ #private
def create_packet(target_name)
params = @parser.parameters
target_name = params[0].to_s.upcase if target_name == 'SYSTEM'
packet_name = params[1].to_s.upcase
@@ -106,18 +88,44 @@
raise @parser.error("Invalid endianness #{params[2]}. Must be BIG_ENDIAN or LITTLE_ENDIAN.", @usage)
end
Packet.new(target_name, packet_name, endianness, description)
end
- def check_for_duplicate(type, list, packet)
+ def self.check_for_duplicate(type, list, packet)
msg = nil
if list[packet.target_name]
if list[packet.target_name][packet.packet_name]
msg = "#{type} Packet #{packet.target_name} #{packet.packet_name} redefined."
Logger.instance.warn msg
end
end
msg
+ end
+
+ def self.finish_create_command(packet, commands, warnings)
+ warning = PacketParser.check_for_duplicate('Command', commands, packet)
+ warnings << warning if warning
+ commands[packet.target_name] ||= {}
+ packet
+ end
+
+ def self.finish_create_telemetry(packet, telemetry, latest_data, warnings)
+ warning = PacketParser.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
end
end # module Cosmos