aprs.me/test/aprsme/packet_parsing_test.exs
Graham McIntire 623800dfc1
Fix failing packet parsing tests for altitude and PHG extraction
The APRS parser wasn't extracting altitude and PHG data from the comment
field. Added extraction functions to parse:
- Altitude from /A=XXXXXX format (converts to feet)
- PHG (Power-Height-Gain-Directivity) from PHGXXXX format

Also updated the comment cleaning to remove these technical details,
leaving only the human-readable station description.

Updated tests to properly use Packet.extract_additional_data() which
is where the parsing happens during packet processing.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-28 12:20:52 -05:00

84 lines
2.7 KiB
Elixir

defmodule Aprsme.PacketParsingTest do
use Aprsme.DataCase
alias Aprsme.Packet
describe "packet parsing for altitude and PHG" do
test "extracts altitude and PHG data from packet" do
raw_packet = "W5MRC-15>APN391,qAO,KG5JPL-1:!3317.02NN09634.37W#PHG5530 Collin Cty Wide Digi /A=000680"
# Parse the packet
{:ok, parsed} = Aprs.parse(raw_packet)
# Create attributes for packet
attrs = %{
sender: parsed[:sender],
data_extended: parsed[:data_extended]
}
# Extract additional data (this is where altitude and PHG are parsed from comment)
extracted_attrs = Packet.extract_additional_data(attrs, raw_packet)
# Verify altitude was extracted
assert extracted_attrs[:altitude] == 680.0
# Verify PHG data was extracted
assert is_map(extracted_attrs[:phg])
# PHG5 = 25W (5^2)
assert extracted_attrs[:phg][:power] == 25
# PHG x5x = 320 ft
assert extracted_attrs[:phg][:height] == 320
# PHG xx3 = 3 dBi
assert extracted_attrs[:phg][:gain] == 3
# PHG xxx0 = 0 degrees (not 360 for omni in our implementation)
assert extracted_attrs[:phg][:directivity] == 0
# Verify comment has altitude and PHG removed
assert extracted_attrs[:comment] == "Collin Cty Wide Digi"
end
test "packet changeset includes altitude and PHG fields" do
attrs = %{
sender: "W5MRC-15",
base_callsign: "W5MRC",
ssid: "15",
data_type: "position",
destination: "APN391",
information_field: "!3317.02NN09634.37W#PHG5530 Collin Cty Wide Digi /A=000680",
path: "qAO,KG5JPL-1",
lat: Decimal.new("33.2837"),
lon: Decimal.new("-96.5728"),
location: %Geo.Point{coordinates: {-96.5728, 33.2837}},
has_position: true,
received_at: DateTime.truncate(DateTime.utc_now(), :second),
data_extended: %{
altitude: 680.0,
phg: %{
power: 25,
height: 320,
gain: 3,
directivity: 0
},
comment: "Collin Cty Wide Digi"
}
}
# Extract additional data
attrs_with_data = Packet.extract_additional_data(attrs, attrs.information_field)
# Create changeset
changeset = Packet.changeset(%Packet{}, attrs_with_data)
assert changeset.valid?
# Check that fields were properly set
changes = changeset.changes
assert changes.altitude == 680.0
assert changes.phg_power == 25
assert changes.phg_height == 320
assert changes.phg_gain == 3
assert changes.phg_directivity == 0
assert changes.comment == "Collin Cty Wide Digi"
end
end
end