handle malformed packet
This commit is contained in:
parent
b809ffdd4a
commit
0aae76a6ab
2 changed files with 48 additions and 0 deletions
|
|
@ -256,6 +256,22 @@ defmodule Parser do
|
|||
Map.merge(result, compressed_cs)
|
||||
end
|
||||
|
||||
# Catch-all pattern for malformed position packets
|
||||
def parse_position_without_timestamp(aprs_messaging?, <<_dti::binary-size(1), rest::binary>> = data) do
|
||||
Logger.warning("Malformed position packet: #{inspect(data)}")
|
||||
|
||||
%{
|
||||
latitude: nil,
|
||||
longitude: nil,
|
||||
symbol_table_id: nil,
|
||||
symbol_code: nil,
|
||||
comment: rest,
|
||||
data_type: :malformed_position,
|
||||
aprs_messaging?: aprs_messaging?,
|
||||
raw_data: data
|
||||
}
|
||||
end
|
||||
|
||||
def parse_position_with_timestamp(
|
||||
aprs_messaging?,
|
||||
<<_dti::binary-size(1), time::binary-size(7), latitude::binary-size(8), sym_table_id::binary-size(1),
|
||||
|
|
|
|||
|
|
@ -279,4 +279,36 @@ defmodule Parser.ParserTest do
|
|||
assert result >= -180.0 and result <= 180.0
|
||||
end
|
||||
end
|
||||
|
||||
describe "malformed position packets" do
|
||||
test "handles malformed position packet gracefully" do
|
||||
# Test with the specific malformed packet that was causing issues
|
||||
malformed_packet = "KC3ARY>APDW16,KB3FCZ-2,WIDE1*,qAR,WA3YMM-1:!I:!&N:;\")# !"
|
||||
|
||||
{:ok, packet} = Parser.parse(malformed_packet)
|
||||
|
||||
assert packet.data_type == :position
|
||||
assert packet.sender == "KC3ARY"
|
||||
assert packet.destination == "APDW16"
|
||||
assert packet.data_extended.data_type == :malformed_position
|
||||
assert packet.data_extended.latitude == nil
|
||||
assert packet.data_extended.longitude == nil
|
||||
assert packet.data_extended.comment == "I:!&N:;\")# !"
|
||||
assert packet.data_extended.raw_data == "!I:!&N:;\")# !"
|
||||
end
|
||||
|
||||
test "handles other malformed position formats" do
|
||||
# Test with another type of malformed position data that's too short
|
||||
malformed_packet = "TEST>APRS,TCPIP*:!SHORT"
|
||||
|
||||
{:ok, packet} = Parser.parse(malformed_packet)
|
||||
|
||||
assert packet.data_type == :position
|
||||
assert packet.data_extended.data_type == :malformed_position
|
||||
assert packet.data_extended.latitude == nil
|
||||
assert packet.data_extended.longitude == nil
|
||||
assert packet.data_extended.comment == "SHORT"
|
||||
assert packet.data_extended.raw_data == "!SHORT"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue