diff --git a/lib/aprs/is/is.ex b/lib/aprs/is/is.ex index 1164a19..6e0c762 100644 --- a/lib/aprs/is/is.ex +++ b/lib/aprs/is/is.ex @@ -356,13 +356,6 @@ defmodule Aprs.Is do {:error, :validation_error} -> Logger.error("Validation error while storing packet from #{inspect(parsed_message.sender)}") - Logger.debug("Packet attributes that failed: #{inspect(attrs)}") - - {:error, other_error} -> - Logger.error( - "Unknown error storing packet from #{inspect(parsed_message.sender)}: #{inspect(other_error)}" - ) - Logger.debug("Packet attributes that failed: #{inspect(attrs)}") end else @@ -380,16 +373,6 @@ defmodule Aprs.Is do # Broadcast to live clients AprsWeb.Endpoint.broadcast("aprs_messages", "packet", parsed_message) - # Logger.debug("BROADCAST: " <> inspect(parsed_message)) - - # Phoenix.PubSub.broadcast( - # Aprs.PubSub, - # "aprs_messages", - # {:packet, parsed_message} - # ) - - # IO.inspect(parsed_message) - # Logger.debug("SERVER:" <> message) {:error, :invalid_packet} -> Logger.debug("PARSE ERROR: invalid packet") @@ -401,10 +384,6 @@ defmodule Aprs.Is do {:error, error} -> Logger.debug("PARSE ERROR: " <> error) Aprs.Packets.store_bad_packet(message, %{message: error, type: "ParseError"}) - - x -> - Logger.debug("PARSE ERROR: " <> x) - Aprs.Packets.store_bad_packet(message, %{message: inspect(x), type: "ParseError"}) end end @@ -437,10 +416,6 @@ defmodule Aprs.Is do valid - %{lat: lat, lon: lon} when not is_nil(lat) and not is_nil(lon) -> - # Handle case where coordinates are at top level - are_valid_coords?(lat, lon) - _other -> Logger.debug("Unrecognized packet format: #{inspect(Map.keys(packet))}") false diff --git a/lib/aprs/packet_replay.ex b/lib/aprs/packet_replay.ex index 4e872a3..0d5a129 100644 --- a/lib/aprs/packet_replay.ex +++ b/lib/aprs/packet_replay.ex @@ -169,7 +169,7 @@ defmodule Aprs.PacketReplay do # Send notification to client that replay is starting Endpoint.broadcast(state.replay_topic, "replay_started", %{ - total_packets: Packets.get_historical_packet_count(replay_opts), + total_packets: Packets.get_historical_packet_count(Map.new(replay_opts)), start_time: state.start_time, end_time: state.end_time, replay_speed: state.replay_speed, @@ -177,7 +177,12 @@ defmodule Aprs.PacketReplay do }) # Get packets and start streaming - stream = Packets.stream_packets_for_replay(Keyword.put(replay_opts, :playback_speed, state.replay_speed)) + replay_opts_map = + replay_opts + |> Keyword.put(:playback_speed, state.replay_speed) + |> Map.new() + + stream = Packets.stream_packets_for_replay(replay_opts_map) # Schedule the first packet case stream |> Stream.take(1) |> Enum.to_list() do diff --git a/lib/parser.ex b/lib/parser.ex index 97f963d..ffa516c 100644 --- a/lib/parser.ex +++ b/lib/parser.ex @@ -28,8 +28,7 @@ defmodule Parser do information_field: data_trimmed, data_type: data_type, base_callsign: base_callsign, - # Ensure ssid is never nil - ssid: ssid || "0", + ssid: ssid, data_extended: data_extended, # Set received_at when creating packet received_at: DateTime.truncate(DateTime.utc_now(), :microsecond) diff --git a/lib/types/mic_e.ex b/lib/types/mic_e.ex index 15f1d41..eae7145 100644 --- a/lib/types/mic_e.ex +++ b/lib/types/mic_e.ex @@ -4,6 +4,29 @@ defmodule Parser.Types.MicE do """ @behaviour Access + @type direction :: :north | :south | :east | :west | :unknown + + @type t :: %__MODULE__{ + lat_degrees: number(), + lat_minutes: number(), + lat_fractional: number(), + lat_direction: direction(), + lon_direction: direction(), + longitude_offset: number(), + message_code: String.t() | nil, + message_description: String.t() | nil, + dti: String.t() | nil, + heading: number(), + lon_degrees: number(), + lon_minutes: number(), + lon_fractional: number(), + speed: number(), + manufacturer: String.t(), + message: String.t(), + symbol_table_id: String.t(), + symbol_code: String.t() + } + defstruct lat_degrees: 0, lat_minutes: 0, lat_fractional: 0, @@ -31,6 +54,7 @@ defmodule Parser.Types.MicE do Fetch a key from the MicE struct. Special handling for :latitude and :longitude which are calculated from components. """ + @spec fetch(t(), atom() | String.t()) :: {:ok, any()} | :error def fetch(mic_e, :latitude) do # Calculate decimal latitude from components if is_number(mic_e.lat_degrees) and is_number(mic_e.lat_minutes) do @@ -71,16 +95,19 @@ defmodule Parser.Types.MicE do @doc """ Gets a value and updates it with the given function. """ + @spec get_and_update(t(), atom() | String.t(), (any() -> {any(), any()} | :pop)) :: {any(), t()} def get_and_update(mic_e, key, fun) do value = get_value(mic_e, key) apply_update_function(mic_e, key, value, fun) end + @spec get_value(t(), atom() | String.t()) :: any() defp get_value(mic_e, :latitude), do: calculate_latitude(mic_e) defp get_value(mic_e, :longitude), do: calculate_longitude(mic_e) defp get_value(mic_e, key) when is_binary(key), do: get_string_key_value(mic_e, key) defp get_value(mic_e, key), do: Map.get(mic_e, key) + @spec calculate_latitude(t()) :: float() | nil defp calculate_latitude(mic_e) do if is_number(mic_e.lat_degrees) and is_number(mic_e.lat_minutes) do lat = mic_e.lat_degrees + mic_e.lat_minutes / 60.0 @@ -88,6 +115,7 @@ defmodule Parser.Types.MicE do end end + @spec calculate_longitude(t()) :: float() | nil defp calculate_longitude(mic_e) do if is_number(mic_e.lon_degrees) and is_number(mic_e.lon_minutes) do lon = mic_e.lon_degrees + mic_e.lon_minutes / 60.0 @@ -95,6 +123,7 @@ defmodule Parser.Types.MicE do end end + @spec get_string_key_value(t(), String.t()) :: any() defp get_string_key_value(mic_e, key) do atom_key = String.to_existing_atom(key) Map.get(mic_e, atom_key) @@ -103,6 +132,7 @@ defmodule Parser.Types.MicE do nil end + @spec apply_update_function(t(), atom() | String.t(), any(), (any() -> {any(), any()} | :pop)) :: {any(), t()} defp apply_update_function(mic_e, key, value, fun) do case fun.(value) do {get, update} -> {get, Map.put(mic_e, key, update)} @@ -113,6 +143,7 @@ defmodule Parser.Types.MicE do @doc """ Removes the given key from the struct with the default implementation. """ + @spec pop(t(), atom() | String.t()) :: {any(), t()} def pop(mic_e, key) when is_atom(key) do {Map.get(mic_e, key), Map.put(mic_e, key, nil)} end