From eaccdf4465db82234685f9384d45d6dd2f27f7cc Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 4 Jul 2025 11:49:25 -0500 Subject: [PATCH] show correct device id --- lib/aprsme/device_parser.ex | 25 ++++++++++---------- lib/aprsme_web/live/info_live/show.ex | 22 +++++++++++++++++ lib/aprsme_web/live/info_live/show.html.heex | 13 ++++++++-- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/lib/aprsme/device_parser.ex b/lib/aprsme/device_parser.ex index 0aec1e6..a703c28 100644 --- a/lib/aprsme/device_parser.ex +++ b/lib/aprsme/device_parser.ex @@ -9,21 +9,22 @@ defmodule Aprsme.DeviceParser do """ @spec extract_device_identifier(map()) :: String.t() | nil def extract_device_identifier(packet_data) do - cond do - Map.has_key?(packet_data, :destination) and not is_nil(packet_data[:destination]) -> - packet_data[:destination] + extract_from_destination(packet_data) || + extract_from_device_identifier(packet_data) || + extract_from_data_extended(packet_data) + end - Map.has_key?(packet_data, "destination") and not is_nil(packet_data["destination"]) -> - packet_data["destination"] + defp extract_from_destination(packet_data) do + get_field_value(packet_data, :destination) || get_field_value(packet_data, "destination") + end - Map.has_key?(packet_data, :device_identifier) and not is_nil(packet_data[:device_identifier]) -> - packet_data[:device_identifier] + defp extract_from_device_identifier(packet_data) do + get_field_value(packet_data, :device_identifier) || get_field_value(packet_data, "device_identifier") + end - Map.has_key?(packet_data, "device_identifier") and not is_nil(packet_data["device_identifier"]) -> - packet_data["device_identifier"] - - true -> - extract_from_data_extended(packet_data) + defp get_field_value(packet_data, key) do + if Map.has_key?(packet_data, key) and not is_nil(packet_data[key]) do + packet_data[key] end end diff --git a/lib/aprsme_web/live/info_live/show.ex b/lib/aprsme_web/live/info_live/show.ex index ef0be71..dbe544e 100644 --- a/lib/aprsme_web/live/info_live/show.ex +++ b/lib/aprsme_web/live/info_live/show.ex @@ -18,6 +18,7 @@ defmodule AprsmeWeb.InfoLive.Show do end packet = get_latest_packet(normalized_callsign) + packet = enrich_packet_with_device_info(packet) neighbors = get_neighbors(packet, normalized_callsign) socket = @@ -36,6 +37,7 @@ defmodule AprsmeWeb.InfoLive.Show do if packet_matches_callsign?(packet, socket.assigns.callsign) do # Refresh data when new packet arrives packet = get_latest_packet(socket.assigns.callsign) + packet = enrich_packet_with_device_info(packet) neighbors = get_neighbors(packet, socket.assigns.callsign) socket = @@ -62,6 +64,26 @@ defmodule AprsmeWeb.InfoLive.Show do |> List.first() end + defp enrich_packet_with_device_info(nil), do: nil + + defp enrich_packet_with_device_info(packet) do + device_identifier = Map.get(packet, :device_identifier) || Map.get(packet, "device_identifier") + + device = + if is_binary(device_identifier), do: Aprsme.DeviceIdentification.lookup_device_by_identifier(device_identifier) + + model = if device, do: device.model + vendor = if device, do: device.vendor + contact = if device, do: device.contact + class = if device, do: device.class + + packet + |> Map.put(:device_model, model) + |> Map.put(:device_vendor, vendor) + |> Map.put(:device_contact, contact) + |> Map.put(:device_class, class) + end + defp get_neighbors(nil, _callsign), do: [] defp get_neighbors(packet, callsign) do diff --git a/lib/aprsme_web/live/info_live/show.html.heex b/lib/aprsme_web/live/info_live/show.html.heex index 6c12a14..db06d6c 100644 --- a/lib/aprsme_web/live/info_live/show.html.heex +++ b/lib/aprsme_web/live/info_live/show.html.heex @@ -177,8 +177,17 @@
Device
- <%= if @packet.manufacturer && @packet.manufacturer != "" do %> - {@packet.manufacturer} {@packet.equipment_type || ""} + <%= if @packet.device_model || @packet.device_vendor do %> + {[ + @packet.device_model, + @packet.device_vendor, + @packet.device_contact + ] + |> Enum.reject(&is_nil/1) + |> Enum.join(" ")} + <%= if @packet.device_class do %> + ({@packet.device_class}) + <% end %> <% else %> {@packet.device_identifier || "Unknown"}