Skip to content

Commit

Permalink
Merge pull request #707 from BallAerospace/warn_redefined
Browse files Browse the repository at this point in the history
Warn if ITEM or PARAMETER redefined
  • Loading branch information
jmthomas authored Jan 25, 2018
2 parents e905368 + 6988359 commit 00365fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/cosmos/packets/parsers/packet_item_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ def verify_parameters(cmd_or_tlm)
end

def create_packet_item(packet, cmd_or_tlm)
item = PacketItem.new(@parser.parameters[0],
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
item = PacketItem.new(item_name,
get_bit_offset(),
get_bit_size(),
get_data_type(),
Expand Down
27 changes: 27 additions & 0 deletions spec/packets/parsers/packet_item_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ module Cosmos
expect(packet.read("ITEM60")).to eql [0x00000001, 0x00000001]
tf.unlink
end

it "complains if an ITEM is redefined" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY TGT1 PKT1 BIG_ENDIAN "Description"'
tf.puts ' APPEND_ITEM ITEM1 16 UINT "Item 1"'
tf.puts ' APPEND_ITEM ITEM1 16 UINT "Another item"'
tf.close
@pc.process_file(tf.path, "TGT1")
packet = @pc.telemetry["TGT1"]["PKT1"]
packet.buffer = "\xDE\xAD\xBE\xEF"
expect(packet.read("ITEM1")).to eql 0xBEEF
expect(@pc.warnings).to include("TGT1 PKT1 ITEM1 redefined.")
tf.unlink
end
end

context "with keywords including PARAMETER" do
Expand Down Expand Up @@ -371,6 +385,19 @@ module Cosmos
end
end

it "complains if a PARAMETER is redefined" do
tf = Tempfile.new('unittest')
tf.puts 'COMMAND TGT1 PKT1 BIG_ENDIAN "Description"'
tf.puts ' APPEND_PARAMETER PARAM1 16 UINT MIN MAX 1 "Param 1"'
tf.puts ' APPEND_PARAMETER PARAM1 16 UINT MIN MAX 2 "Another param"'
tf.close
@pc.process_file(tf.path, "TGT1")
packet = @pc.commands["TGT1"]["PKT1"]
packet.buffer = "\xDE\xAD\xBE\xEF"
expect(packet.read("PARAM1")).to eql 0xBEEF
expect(@pc.warnings).to include("TGT1 PKT1 PARAM1 redefined.")
tf.unlink
end
end

end # describe "process_file"
Expand Down

0 comments on commit 00365fe

Please sign in to comment.