add parser test

This commit is contained in:
Graham McIntire 2023-01-26 14:04:20 -06:00
parent ed014503e6
commit c8fb68b160
3 changed files with 69 additions and 7 deletions

View file

@ -2,7 +2,7 @@ defmodule Parser do
@moduledoc """
Main parsing library
"""
use Bitwise
# import Bitwise
alias Parser.Types.{MicE, Position}
require Logger

12
mix.exs
View file

@ -20,7 +20,7 @@ defmodule Aprs.MixProject do
def application do
[
mod: {Aprs.Application, []},
extra_applications: [:logger, :runtime_tools]
extra_applications: [:hackney, :logger, :runtime_tools]
]
end
@ -48,19 +48,19 @@ defmodule Aprs.MixProject do
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 0.18.3"},
{:phoenix_live_dashboard, "~> 0.7.2"},
{:plug_cowboy, "~> 2.5"},
{:swoosh, "~> 1.3"},
{:timex, "~> 3.4"},
{:telemetry_metrics, "~> 0.6"},
{:telemetry_poller, "~> 1.0"},
{:plug_cowboy, "~> 2.5"},
{:esbuild, "~> 0.5", runtime: Mix.env() == :dev},
{:tailwind, "~> 0.1.8", runtime: Mix.env() == :dev},
{:sobelow, "~> 0.8", only: :dev},
{:dialyxir, "~> 1.0", only: [:dev], runtime: false},
{:credo, "~> 1.6.2", only: [:dev, :test], runtime: false},
{:floki, ">= 0.30.0", only: :test},
{:dialyxir, "~> 1.0", only: [:dev], runtime: false},
{:exvcr, "~> 0.13.4", only: [:test]},
{:mix_test_watch, "~> 1.1", only: [:dev, :test]}
{:floki, ">= 0.30.0", only: :test},
{:mix_test_watch, "~> 1.1", only: [:dev, :test]},
{:sobelow, "~> 0.8", only: :dev}
]
end

View file

@ -0,0 +1,62 @@
defmodule Parser.ParserTest do
use ExUnit.Case
test "timestamped position" do
aprs_message =
"KE7XXX>APRS,TCPIP*,qAC,NINTH:@211743z4444.67N/11111.68W_061/005g012t048r000p000P000h77b10015.DsVP\r\n"
{:ok, packet} = Parser.parse(aprs_message)
assert packet.data_type == :timestamped_position_with_message
end
test "mic_e convert digits" do
sut = Parser.parse_mic_e_digit("0")
assert sut == [0, 0, nil]
end
test "mic_e convert destination field" do
sut = Parser.parse_mic_e_destination("T7SYWP")
assert sut == %{
lat_degrees: 47,
lat_minutes: 39,
lat_fractional: 70,
lat_direction: :north,
lon_direction: :west,
longitude_offset: 100,
message_code: "M02",
message_description: "In Service"
}
end
test "mic_e convert information field" do
information_field = ~s(`\(_fn"Oj/]TEST=)
sut = Parser.parse_mic_e_information(information_field, 100)
assert sut ==
%{
dti: "`",
heading: 251,
lon_degrees: 112,
lon_fractional: 74,
lon_minutes: 7,
speed: 20,
symbol: "j",
table: "/",
message: "]TEST=",
manufacturer: "Kenwood DM-710"
}
end
test "mic_e" do
sut = Parser.parse_mic_e("T7SYWP", ~s(`\(_fn"Oj/))
assert %Parser.Types.MicE{} = sut
end
test "weird format" do
aprs_message =
~s(ON4AVM-11>APDI23,WIDE1-1,WIDE2-2,qAR,ON0LB-10:=S4`k!OZ,C# sT/A=000049DIXPRS 2.3.0b\n)
Parser.parse(aprs_message)
end
end