Skip to content

Commit

Permalink
Test command endianness
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Jan 13, 2024
1 parent c7574b0 commit 059afb1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ COMMAND <%= target_name %> SETPARAMS BIG_ENDIAN "Sets numbered parameters"
<%= render "_ccsds_cmd.txt", locals: {id: 4} %>
# ERB syntax:
<% (1..5).each do |i| %>
APPEND_PARAMETER VALUE<%= i %> 16 UINT 0 5 1 "Value <%= i %> setting"
# The packet is BIG_ENDIAN (CCSDS) but these fields are LITTLE_ENDIAN
APPEND_PARAMETER VALUE<%= i %> 16 UINT 0 5 1 "Value <%= i %> setting" LITTLE_ENDIAN
RELATED_ITEM <%= target_name %> PARAMS VALUE<%= i %>
<% end %>
SCREEN <%= target_name %> PARAMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def write(packet)
when 'TIME_OFFSET'
@time_offset = packet.read('seconds')
when 'SETPARAMS'
# puts "SETPARAMS packet: #{packet.buffer.formatted}"
params_packet.value1 = packet.read('value1')
params_packet.value2 = packet.read('value2')
params_packet.value3 = packet.read('value3')
Expand Down
19 changes: 17 additions & 2 deletions openc3/spec/packets/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ module OpenC3
tf.puts ' APPEND_ID_PARAMETER item1 8 UINT 5 5 5 "Item1"'
tf.puts ' APPEND_PARAMETER item2 8 UINT 0 100 0 "Item2"'
tf.puts ' POLY_WRITE_CONVERSION 0 2'
tf.puts 'COMMAND tgt2 pkt6 BIG_ENDIAN "TGT2 PKT5 Description"'
tf.puts ' APPEND_ID_PARAMETER item1 16 UINT 6 6 6 "Item1"'
tf.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item2" LITTLE_ENDIAN'
tf.puts ' APPEND_PARAMETER item3 16 UINT MIN MAX 0 "Item2"'
tf.close

pc = PacketConfig.new
Expand Down Expand Up @@ -97,10 +101,11 @@ module OpenC3

it "returns all packets target TGT2" do
pkts = @cmd.packets("TGT2")
expect(pkts.length).to eql 3
expect(pkts.length).to eql 4
expect(pkts.keys).to include("PKT3")
expect(pkts.keys).to include("PKT4")
expect(pkts.keys).to include("PKT5")
expect(pkts.keys).to include("PKT6")
end
end

Expand Down Expand Up @@ -301,6 +306,16 @@ module OpenC3
expect(cmd.read("ITEM2", :RAW)).to eql 2
end

it "creates a command packet with mixed endianness" do
items = { "ITEM2" => 0xABCD, "ITEM3" => 0x6789 }
cmd = @cmd.build_cmd("TGT2", "PKT6", items)
cmd.enable_method_missing
expect(cmd.item1).to eql 6
expect(cmd.item2).to eql 0xABCD
expect(cmd.item3).to eql 0x6789
expect(cmd.buffer).to eql "\x00\x06\xCD\xAB\x67\x89"
end

it "complains about missing required parameters" do
expect { @cmd.build_cmd("tgt2", "pkt3") }.to raise_error(RuntimeError, "Required command parameter 'TGT2 PKT3 ITEM2' not given")
end
Expand Down Expand Up @@ -344,7 +359,7 @@ module OpenC3
expect(@cmd.format(pkt)).to eql "cmd_raw(\"TGT2 PKT4 with ITEM1 0, ITEM2 'HELLO WORLD'\")"

# If the string is too big it should truncate it
(1..2028).each { |i| string << 'A' }
(1..2028).each { |_i| string << 'A' }
pkt.write("ITEM2", string)
pkt.raw = false
result = @cmd.format(pkt)
Expand Down

0 comments on commit 059afb1

Please sign in to comment.