Class: OpenC3::PacketItemParser
- Defined in:
- lib/openc3/packets/parsers/packet_item_parser.rb
Overview
Parses a packet item definition and creates a new PacketItem
Direct Known Subclasses
Constant Summary collapse
- BIG_ARRAY_SIZE =
This number is a little arbitrary but there are definitely issues at 1 million and you really shouldn’t be doing anything this big anyway
100_000
Class Method Summary collapse
Instance Method Summary collapse
- #create_packet_item(packet, cmd_or_tlm) ⇒ Object
-
#initialize(parser, packet_config, warnings) ⇒ PacketItemParser
constructor
A new instance of PacketItemParser.
- #verify_parameters(cmd_or_tlm) ⇒ Object
Constructor Details
#initialize(parser, packet_config, warnings) ⇒ PacketItemParser
Returns a new instance of PacketItemParser.
44 45 46 47 48 49 |
# File 'lib/openc3/packets/parsers/packet_item_parser.rb', line 44 def initialize(parser, packet_config, warnings) @parser = parser @packet_config = packet_config @warnings = warnings @usage = get_usage() end |
Class Method Details
.parse(parser, packet_config, packet, cmd_or_tlm, warnings) ⇒ Object
36 37 38 39 40 |
# File 'lib/openc3/packets/parsers/packet_item_parser.rb', line 36 def self.parse(parser, packet_config, packet, cmd_or_tlm, warnings) parser = PacketItemParser.new(parser, packet_config, warnings) parser.verify_parameters(cmd_or_tlm) parser.create_packet_item(packet, cmd_or_tlm) end |
Instance Method Details
#create_packet_item(packet, cmd_or_tlm) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/openc3/packets/parsers/packet_item_parser.rb', line 70 def create_packet_item(packet, cmd_or_tlm) item_name = @parser.parameters[0].upcase if packet.items[item_name] msg = "#{packet.target_name} #{packet.packet_name} #{item_name} redefined." Logger.instance.warn msg @warnings << msg end if @parser.keyword.include?("STRUCTURE") item = PacketItem.new(item_name, get_bit_offset(), get_bit_size(true), :BLOCK, :BIG_ENDIAN, nil, :ERROR) # overflow else item = PacketItem.new(item_name, get_bit_offset(), get_bit_size(), get_data_type(), get_endianness(packet), get_array_size(), :ERROR) # overflow if cmd_or_tlm == PacketConfig::COMMAND item.range = get_range() item.default = get_default() end item.id_value = get_id_value(item) item.description = get_description() end if append? item = packet.append(item) else item = packet.define(item) end if @parser.keyword.include?("STRUCTURE") structure = lookup_packet(get_cmd_or_tlm(), get_target_name(), get_packet_name()) packet.structurize_item(item, structure) end item end |
#verify_parameters(cmd_or_tlm) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/openc3/packets/parsers/packet_item_parser.rb', line 51 def verify_parameters(cmd_or_tlm) if @parser.keyword.include?('ITEM') && cmd_or_tlm == PacketConfig::COMMAND raise @parser.error("ITEM types are only valid with TELEMETRY", @usage) elsif @parser.keyword.include?('PARAMETER') && cmd_or_tlm == PacketConfig::TELEMETRY raise @parser.error("PARAMETER types are only valid with COMMAND", @usage) end # The usage is formatted with brackets <XXX> around each option so # count the number of open brackets to determine the number of options = @usage.count("<") if @parser.keyword.include?('STRUCTURE') @parser.verify_num_parameters(, , @usage) else # The last two options (description and endianness) are optional @parser.verify_num_parameters( - 2, , @usage) end @parser.verify_parameter_naming(1) # Item name is the 1st parameter end |