Method: OpenC3::Commands#identify
- Defined in:
- lib/openc3/packets/commands.rb
#identify(packet_data, target_names = nil) ⇒ Object
Identifies an unknown buffer of data as a defined command and sets the commands’s data to the given buffer. Identifying a command uses the fields marked as ID_PARAMETER to identify if the buffer passed represents the command defined. Incorrectly sized buffers are still processed but an error is logged.
Note: Subsequent requests for the command (using packet) will return an uninitialized copy of the command. Thus you must use the return value of this method.
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 |
# File 'lib/openc3/packets/commands.rb', line 97 def identify(packet_data, target_names = nil) identified_packet = nil target_names = target_names() unless target_names target_names.each do |target_name| target_name = target_name.to_s.upcase target_packets = nil begin target_packets = packets(target_name) rescue RuntimeError # No commands for this target next end target = System.targets[target_name] if target and target.cmd_unique_id_mode # Iterate through the packets and see if any represent the buffer target_packets.each do |packet_name, packet| if packet.identify?(packet_data) identified_packet = packet break end end else # Do a hash lookup to quickly identify the packet if target_packets.length > 0 packet = target_packets.first[1] key = packet.read_id_values(packet_data) hash = @config.cmd_id_value_hash[target_name] identified_packet = hash[key] identified_packet = hash['CATCHALL'.freeze] unless identified_packet end end if identified_packet identified_packet.received_count += 1 identified_packet = identified_packet.clone identified_packet.received_time = nil identified_packet.stored = false identified_packet.extra = nil identified_packet.buffer = packet_data break end end return identified_packet end |