From 64b77c33b530366487521ed1fd18e85a91665b7e646f3502050b1fecbc1884ed Mon Sep 17 00:00:00 2001 From: localhorst Date: Thu, 2 Jan 2025 14:44:59 +0100 Subject: [PATCH] cleanup and fix gnss location --- .../ttnMessageReceivedEventHandler.ts | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/server/src/eventHandler/ttnMessageReceivedEventHandler.ts b/server/src/eventHandler/ttnMessageReceivedEventHandler.ts index 05a94c6..19fb6fd 100644 --- a/server/src/eventHandler/ttnMessageReceivedEventHandler.ts +++ b/server/src/eventHandler/ttnMessageReceivedEventHandler.ts @@ -11,7 +11,7 @@ import { getLocationForWifiMemoized } from "../proxy/wigle"; const locationService = container.resolve(LocationService); const wifiScanService = container.resolve(WifiScanService); -const CalculateTtnGatewayLocation = async (event: TtnMessageReceivedEvent) => { +const CalculateTtnGatewayLocation = (event: TtnMessageReceivedEvent) => { // Get location based on TTN Gateways const virtualLocation = { latitude: undefined as number | undefined, @@ -105,25 +105,18 @@ const CalculateWifiLocation = async (event: TtnMessageReceivedEvent) => { }; }; -const CalculateGnssLocation = async (event: TtnMessageReceivedEvent) => { - // Default virtual location with undefined coordinates - const virtualLocation = { - latitude: undefined as number | undefined, - longitude: undefined as number | undefined, - }; - - if (virtualLocation.latitude === undefined || virtualLocation.longitude === undefined) { +const CalculateGnssLocation = (event: TtnMessageReceivedEvent) => { + // Get location based on reported GNSS + if (event.gnssLocation.latitude === undefined || event.gnssLocation.longitude === undefined) { console.log("No valid GNSS location received!"); } return { - gnss_latitude: virtualLocation.latitude, - gnss_longitude: virtualLocation.longitude, + gnss_latitude: event.gnssLocation.latitude, + gnss_longitude: event.gnssLocation.longitude, }; }; - - domainEventEmitter.on( TtnMessageReceivedEventName, async (event: TtnMessageReceivedEvent) => { @@ -137,7 +130,7 @@ domainEventEmitter.on( var ttn_gw_based_longitude: number | undefined = undefined; if (event.ttnGateways && event.ttnGateways.length > 0) { - const virtualLocation = await CalculateTtnGatewayLocation(event); + const virtualLocation = CalculateTtnGatewayLocation(event); ttn_gw_based_latitude = virtualLocation.ttn_latitude; ttn_gw_based_longitude = virtualLocation.ttn_longitude; } @@ -148,7 +141,7 @@ domainEventEmitter.on( wifi_based_longitude = virtualLocation.wifi_longitude; } - const virtualLocation = await CalculateGnssLocation(event); + const virtualLocation = CalculateGnssLocation(event); gnss_based_latitude = virtualLocation.gnss_latitude; gnss_based_longitude = virtualLocation.gnss_longitude;