From b076994a426fa2cf556769fa0ce7bf8848afce31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harri=20Sm=C3=A5tt?= Date: Fri, 29 Sep 2023 15:02:34 +0300 Subject: [PATCH] Implement LoRa Actility triangulated device location support --- .../adapter/lora/providers/ActilityBaseProvider.java | 7 +++++-- .../lora/providers/ActilityEnterpriseProvider.java | 9 +++++++-- .../adapter/lora/providers/ActilityWirelessProvider.java | 9 +++++++-- .../lora/providers/ActilityEnterpriseProviderTest.java | 4 ++++ .../lora/providers/ActilityWirelessProviderTest.java | 7 +++++++ .../resources/payload/actilityEnterprise.uplink.json | 3 +++ .../test/resources/payload/actilityWireless.uplink.json | 3 +++ 7 files changed, 36 insertions(+), 6 deletions(-) diff --git a/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityBaseProvider.java b/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityBaseProvider.java index 0bf13ccedc..2296896e1a 100644 --- a/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityBaseProvider.java +++ b/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityBaseProvider.java @@ -30,11 +30,14 @@ abstract class ActilityBaseProvider extends JsonBasedLoraProvider { protected static final String FIELD_ACTILITY_CHANNEL = "Channel"; protected static final String FIELD_ACTILITY_FPORT = "FPort"; + protected static final String FIELD_ACTILITY_DEV_ALTITUDE = "DevAlt"; + protected static final String FIELD_ACTILITY_DEV_LATITUDE = "DevLAT"; + protected static final String FIELD_ACTILITY_DEV_LONGITUDE = "DevLON"; protected static final String FIELD_ACTILITY_FRAME_COUNT_UPLINK = "FCntUp"; - protected static final String FIELD_ACTILITY_LATITUTDE = "LrrLAT"; - protected static final String FIELD_ACTILITY_LONGITUDE = "LrrLON"; protected static final String FIELD_ACTILITY_LRR = "Lrr"; protected static final String FIELD_ACTILITY_LRR_ID = "Lrrid"; + protected static final String FIELD_ACTILITY_LRR_LATITUDE = "LrrLAT"; + protected static final String FIELD_ACTILITY_LRR_LONGITUDE = "LrrLON"; protected static final String FIELD_ACTILITY_LRR_RSSI = "LrrRSSI"; protected static final String FIELD_ACTILITY_LRR_SNR = "LrrSNR"; protected static final String FIELD_ACTILITY_LRRS = "Lrrs"; diff --git a/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityEnterpriseProvider.java b/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityEnterpriseProvider.java index 4d8ab846f8..f8c2ddea38 100644 --- a/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityEnterpriseProvider.java +++ b/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityEnterpriseProvider.java @@ -54,6 +54,11 @@ protected LoraMetaData extractMetaData(final JsonObject rootObject) { LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_CHANNEL, String.class) .map(this::getFrequency) .ifPresent(data::setFrequency); + Optional.ofNullable(LoraUtils.newLocation( + LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_DEV_LONGITUDE, Double.class), + LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_DEV_LATITUDE, Double.class), + LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_DEV_ALTITUDE, Double.class))) + .ifPresent(data::setLocation); LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_LRRS, JsonObject.class) .map(lrrs -> lrrs.getValue(FIELD_ACTILITY_LRR)) @@ -70,8 +75,8 @@ protected LoraMetaData extractMetaData(final JsonObject rootObject) { .ifPresent(s -> gwId.ifPresent(id -> { if (id.equals(s)) { Optional.ofNullable(LoraUtils.newLocation( - LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_LONGITUDE, Double.class), - LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_LATITUTDE, Double.class), + LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_LRR_LONGITUDE, Double.class), + LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_LRR_LATITUDE, Double.class), Optional.empty())) .ifPresent(gateway::setLocation); } diff --git a/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityWirelessProvider.java b/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityWirelessProvider.java index 7b5cca5b31..e5b0314210 100644 --- a/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityWirelessProvider.java +++ b/adapters/lora/src/main/java/org/eclipse/hono/adapter/lora/providers/ActilityWirelessProvider.java @@ -58,6 +58,11 @@ protected LoraMetaData extractMetaData(final JsonObject rootObject) { LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_CHANNEL, String.class) .map(this::getFrequency) .ifPresent(data::setFrequency); + Optional.ofNullable(LoraUtils.newLocationFromString( + LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_DEV_LONGITUDE, String.class), + LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_DEV_LATITUDE, String.class), + LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_DEV_ALTITUDE, String.class))) + .ifPresent(data::setLocation); LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_LRRS, JsonObject.class) .map(lrrs -> lrrs.getValue(FIELD_ACTILITY_LRR)) @@ -74,8 +79,8 @@ protected LoraMetaData extractMetaData(final JsonObject rootObject) { .ifPresent(s -> gwId.ifPresent(id -> { if (id.equals(s)) { Optional.ofNullable(LoraUtils.newLocationFromString( - LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_LONGITUDE, String.class), - LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_LATITUTDE, String.class), + LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_LRR_LONGITUDE, String.class), + LoraUtils.getChildObject(rootObject, FIELD_ACTILITY_LRR_LATITUDE, String.class), Optional.empty())) .ifPresent(gateway::setLocation); } diff --git a/adapters/lora/src/test/java/org/eclipse/hono/adapter/lora/providers/ActilityEnterpriseProviderTest.java b/adapters/lora/src/test/java/org/eclipse/hono/adapter/lora/providers/ActilityEnterpriseProviderTest.java index e3c796ac4a..764be37aa6 100644 --- a/adapters/lora/src/test/java/org/eclipse/hono/adapter/lora/providers/ActilityEnterpriseProviderTest.java +++ b/adapters/lora/src/test/java/org/eclipse/hono/adapter/lora/providers/ActilityEnterpriseProviderTest.java @@ -51,5 +51,9 @@ protected void assertMetaDataForUplinkMessage(final UplinkLoraMessage loraMessag assertThat(data.getFunctionPort()).isEqualTo(2); assertThat(data.getFrameCount()).isEqualTo(57); assertThat(data.getFrequency()).isEqualTo(868.5); + + assertThat(data.getLocation().getLatitude()).isEqualTo(61.499146); + assertThat(data.getLocation().getLongitude()).isEqualTo(23.765516); + assertThat(data.getLocation().getAltitude()).isEqualTo(0.000001); } } diff --git a/adapters/lora/src/test/java/org/eclipse/hono/adapter/lora/providers/ActilityWirelessProviderTest.java b/adapters/lora/src/test/java/org/eclipse/hono/adapter/lora/providers/ActilityWirelessProviderTest.java index d74a14be14..22afc2a777 100644 --- a/adapters/lora/src/test/java/org/eclipse/hono/adapter/lora/providers/ActilityWirelessProviderTest.java +++ b/adapters/lora/src/test/java/org/eclipse/hono/adapter/lora/providers/ActilityWirelessProviderTest.java @@ -44,8 +44,15 @@ protected void assertMetaDataForUplinkMessage(final UplinkLoraMessage loraMessag assertThat(data.getGatewayInfo().get(0).getGatewayId()).isEqualTo("18035559"); assertThat(data.getGatewayInfo().get(0).getRssi()).isEqualTo(-48); assertThat(data.getGatewayInfo().get(0).getSnr()).isEqualTo(3.0); + assertThat(data.getGatewayInfo().get(0).getLocation().getLatitude()).isEqualTo(53.108805); + assertThat(data.getGatewayInfo().get(0).getLocation().getLongitude()).isEqualTo(9.193430); assertThat(data.getGatewayInfo().get(1).getGatewayId()).isEqualTo("18035560"); assertThat(data.getGatewayInfo().get(1).getRssi()).isEqualTo(-49); assertThat(data.getGatewayInfo().get(1).getSnr()).isEqualTo(4.0); + assertThat(data.getGatewayInfo().get(1).getLocation()).isNull(); + + assertThat(data.getLocation().getLatitude()).isEqualTo(61.499146); + assertThat(data.getLocation().getLongitude()).isEqualTo(23.765516); + assertThat(data.getLocation().getAltitude()).isEqualTo(0.000001); } } diff --git a/adapters/lora/src/test/resources/payload/actilityEnterprise.uplink.json b/adapters/lora/src/test/resources/payload/actilityEnterprise.uplink.json index 58c98de7a5..5bf0caa31c 100644 --- a/adapters/lora/src/test/resources/payload/actilityEnterprise.uplink.json +++ b/adapters/lora/src/test/resources/payload/actilityEnterprise.uplink.json @@ -17,6 +17,9 @@ "DevLrrCnt": 1, "Lrrid": "10000001", "Late": 0, + "DevLAT": 61.499146, + "DevLON": 23.765516, + "DevAlt": 0.000001, "LrrLAT": 27.831039, "LrrLON": -97.534576, "Lrrs": { diff --git a/adapters/lora/src/test/resources/payload/actilityWireless.uplink.json b/adapters/lora/src/test/resources/payload/actilityWireless.uplink.json index 5625f6e6f4..38cd42552a 100644 --- a/adapters/lora/src/test/resources/payload/actilityWireless.uplink.json +++ b/adapters/lora/src/test/resources/payload/actilityWireless.uplink.json @@ -18,6 +18,9 @@ "DevLrrCnt": "1", "Lrrid": "18035559", "Late": "0", + "DevLAT": "61.499146", + "DevLON": "23.765516", + "DevAlt": "0.000001", "LrrLAT": "53.108805", "LrrLON": "9.193430", "Lrrs": {