show correct device id
This commit is contained in:
parent
a78fb8a385
commit
eaccdf4465
3 changed files with 46 additions and 14 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -177,8 +177,17 @@
|
|||
<div>
|
||||
<dt class="text-xs font-medium text-gray-500">Device</dt>
|
||||
<dd class="mt-1 text-sm font-semibold text-gray-900">
|
||||
<%= 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 %>
|
||||
<span class="text-gray-500 font-mono">
|
||||
{@packet.device_identifier || "Unknown"}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue