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.
40 41 42 43 44 45 |
# File 'lib/openc3/packets/parsers/packet_item_parser.rb', line 40 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
32 33 34 35 36 |
# File 'lib/openc3/packets/parsers/packet_item_parser.rb', line 32 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
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 111 112 113 114 115 116 117 118 |
# File 'lib/openc3/packets/parsers/packet_item_parser.rb', line 75 def create_packet_item(packet, cmd_or_tlm) item_name = @parser.parameters[0].upcase if Packet::RESERVED_ITEM_NAMES.include?(item_name) raise @parser.error("#{item_name} is a reserved item name", @usage) end 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
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 |
# File 'lib/openc3/packets/parsers/packet_item_parser.rb', line 47 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 # ARRAY items cannot have brackets in their name because brackets are used # for array indexing in the UI and would cause confusion if @parser.keyword.include?('ARRAY') item_name = @parser.parameters[0] if item_name.include?('[') || item_name.include?(']') raise @parser.error("ARRAY items cannot have brackets in their name: #{item_name}", @usage) end end end |