Class: Cosmos::PacketConfig
- Defined in:
- lib/cosmos/packets/packet_config.rb
Constant Summary collapse
- COMMAND =
"Command"
- TELEMETRY =
"Telemetry"
Instance Attribute Summary collapse
-
#commands ⇒ Hash<String=>Packet>
readonly
Hash of all the command packets keyed by the packet name.
-
#latest_data ⇒ Hash<String=>Hash<String=>Array(Packet)>>
readonly
Hash of hashes keyed first by the target name and then by the item name.
-
#limits_groups ⇒ Hash<String=>Array(String, String, String)>
readonly
Hash of all the limits groups keyed by the group name.
-
#limits_sets ⇒ Array<Symbol>
readonly
The defined limits sets for all items in the packet.
-
#name ⇒ String
The name of this configuration.
-
#telemetry ⇒ Hash<String=>Packet>
readonly
Hash of all the telemetry packets keyed by the packet name.
-
#warnings ⇒ Array<String>
readonly
Array of strings listing all the warnings that were created while parsing the configuration file.
Instance Method Summary collapse
-
#initialize ⇒ PacketConfig
constructor
A new instance of PacketConfig.
-
#process_file(filename, process_target_name) ⇒ Object
Processes a COSMOS configuration file and uses the keywords to build up knowledge of the commands, telemetry, and limits groups.
Constructor Details
#initialize ⇒ PacketConfig
Returns a new instance of PacketConfig.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cosmos/packets/packet_config.rb', line 62 def initialize @name = nil @telemetry = {} @commands = {} @limits_groups = {} @limits_sets = [:DEFAULT] # Hash of Hashes. First index by target name and then item name. # Returns an array of packets with that target and item. @latest_data = {} @warnings = [] # Create unknown packets @commands['UNKNOWN'] @commands['UNKNOWN'] = {} @commands['UNKNOWN']['UNKNOWN'] = Packet.new('UNKNOWN', 'UNKNOWN', :BIG_ENDIAN) @telemetry['UNKNOWN'] @telemetry['UNKNOWN'] = {} @telemetry['UNKNOWN']['UNKNOWN'] = Packet.new('UNKNOWN', 'UNKNOWN', :BIG_ENDIAN) # Used during packet processing @current_cmd_or_tlm = nil @current_packet = nil @current_item = nil @current_limits_group = nil end |
Instance Attribute Details
#commands ⇒ Hash<String=>Packet> (readonly)
Returns Hash of all the command packets keyed by the packet name.
37 38 39 |
# File 'lib/cosmos/packets/packet_config.rb', line 37 def commands @commands end |
#latest_data ⇒ Hash<String=>Hash<String=>Array(Packet)>> (readonly)
Returns 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.
57 58 59 |
# File 'lib/cosmos/packets/packet_config.rb', line 57 def latest_data @latest_data end |
#limits_groups ⇒ Hash<String=>Array(String, String, String)> (readonly)
Returns Hash of all the limits groups keyed by the group name. The value is a three element array consisting of the target_name, packet_name, and item_name.
42 43 44 |
# File 'lib/cosmos/packets/packet_config.rb', line 42 def limits_groups @limits_groups end |
#limits_sets ⇒ Array<Symbol> (readonly)
Returns The defined limits sets for all items in the packet. This will always include :DEFAULT.
46 47 48 |
# File 'lib/cosmos/packets/packet_config.rb', line 46 def limits_sets @limits_sets end |
#name ⇒ String
Returns The name of this configuration. To be used by higher level classes to store information about the current PacketConfig.
29 30 31 |
# File 'lib/cosmos/packets/packet_config.rb', line 29 def name @name end |
Instance Method Details
#process_file(filename, process_target_name) ⇒ Object
Processes a COSMOS configuration file and uses the keywords to build up knowledge of the commands, telemetry, and limits groups.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/cosmos/packets/packet_config.rb', line 97 def process_file(filename, process_target_name) # Partial files are included into another file and thus aren't directly processed return if File.basename(filename)[0] == '_' # Partials start with underscore @converted_type = nil @converted_bit_size = nil @proc_text = '' @building_generic_conversion = false process_target_name = process_target_name.upcase parser = ConfigParser.new("http://cosmosrb.com/docs/cmdtlm") parser.parse_file(filename) do |keyword, params| if @building_generic_conversion case keyword # Complete a generic conversion when 'GENERIC_READ_CONVERSION_END', 'GENERIC_WRITE_CONVERSION_END' parser.verify_num_parameters(0, 0, keyword) @current_item.read_conversion = GenericConversion.new(@proc_text, @converted_type, @converted_bit_size) if keyword.include? "READ" @current_item.write_conversion = GenericConversion.new(@proc_text, @converted_type, @converted_bit_size) if keyword.include? "WRITE" @building_generic_conversion = false # Add the current config.line to the conversion being built else @proc_text << parser.line << "\n" end # case keyword else # not building generic conversion case keyword # Start a new packet when 'COMMAND' finish_packet() @current_packet = PacketParser.parse_command(parser, process_target_name, @commands, @warnings) @current_cmd_or_tlm = COMMAND when 'TELEMETRY' finish_packet() @current_packet = PacketParser.parse_telemetry(parser, process_target_name, @telemetry, @latest_data, @warnings) @current_cmd_or_tlm = TELEMETRY # Select an existing packet for editing when 'SELECT_COMMAND', 'SELECT_TELEMETRY' usage = "#{keyword} <TARGET NAME> <PACKET NAME>" finish_packet() parser.verify_num_parameters(2, 2, usage) target_name = process_target_name target_name = params[0].upcase if target_name == 'SYSTEM' packet_name = params[1].upcase @current_packet = nil if keyword.include?('COMMAND') @current_cmd_or_tlm = COMMAND if @commands[target_name] @current_packet = @commands[target_name][packet_name] end else @current_cmd_or_tlm = TELEMETRY if @telemetry[target_name] @current_packet = @telemetry[target_name][packet_name] end end raise parser.error("Packet not found", usage) unless @current_packet # Start the creation of a new limits group when 'LIMITS_GROUP' usage = "LIMITS_GROUP <GROUP NAME>" parser.verify_num_parameters(1, 1, usage) @current_limits_group = params[0].to_s.upcase @limits_groups[@current_limits_group] = [] unless @limits_groups.include?(@current_limits_group) # Add a telemetry item to the limits group when 'LIMITS_GROUP_ITEM' usage = "LIMITS_GROUP_ITEM <TARGET NAME> <PACKET NAME> <ITEM NAME>" parser.verify_num_parameters(3, 3, usage) @limits_groups[@current_limits_group] << [params[0].to_s.upcase, params[1].to_s.upcase, params[2].to_s.upcase] if @current_limits_group ####################################################################### # All the following keywords must have a current packet defined ####################################################################### when 'SELECT_ITEM', 'SELECT_PARAMETER', 'ITEM', 'PARAMETER', 'ID_ITEM', 'ID_PARAMETER', 'ARRAY_ITEM', 'ARRAY_PARAMETER', 'APPEND_ITEM', 'APPEND_PARAMETER', 'APPEND_ID_ITEM', 'APPEND_ID_PARAMETER', 'APPEND_ARRAY_ITEM', 'APPEND_ARRAY_PARAMETER', 'MACRO_APPEND_START', 'MACRO_APPEND_END', 'ALLOW_SHORT', 'HAZARDOUS', 'PROCESSOR', 'META', 'DISABLE_MESSAGES', 'HIDDEN', 'DISABLED' raise parser.error("No current packet for #{keyword}") unless @current_packet process_current_packet(parser, keyword, params) ####################################################################### # All the following keywords must have a current item defined ####################################################################### when 'STATE', 'READ_CONVERSION', 'WRITE_CONVERSION', 'POLY_READ_CONVERSION', 'POLY_WRITE_CONVERSION', 'SEG_POLY_READ_CONVERSION', 'SEG_POLY_WRITE_CONVERSION', 'GENERIC_READ_CONVERSION_START', 'GENERIC_WRITE_CONVERSION_START', 'REQUIRED', 'LIMITS', 'LIMITS_RESPONSE', 'UNITS', 'FORMAT_STRING', 'DESCRIPTION', 'MINIMUM_VALUE', 'MAXIMUM_VALUE', 'DEFAULT_VALUE', 'OVERFLOW' raise parser.error("No current item for #{keyword}") unless @current_item process_current_item(parser, keyword, params) else # blank config.lines will have a nil keyword and should not raise an exception raise parser.error("Unknown keyword '#{keyword}'") if keyword end # case keyword end # if building_generic_conversion end # Complete the last defined packet finish_packet() end |