From 3ac596b33ce023c1f0b3cdfb83a8fd8387728800 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 | 6 ++++-- .../lora/providers/ActilityEnterpriseProvider.java | 9 +++++++-- .../adapter/lora/providers/ActilityWirelessProvider.java | 9 +++++++-- .../lora/providers/ActilityEnterpriseProviderTest.java | 3 +++ .../lora/providers/ActilityWirelessProviderTest.java | 6 ++++++ .../resources/payload/actilityEnterprise.uplink.json | 2 ++ .../test/resources/payload/actilityWireless.uplink.json | 2 ++ 7 files changed, 31 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..8a57d0af2d 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,13 @@ 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_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..f32eaac5df 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), + Optional.empty())) + .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..cc8d164dbf 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), + Optional.empty())) + .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..fe6bcc6c7a 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,8 @@ 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(13.99921); + assertThat(data.getLocation().getLongitude()).isEqualTo(23.99593); } } 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..0ba335b600 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,14 @@ 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(15.00092); + assertThat(data.getLocation().getLongitude()).isEqualTo(92.00992); } } diff --git a/adapters/lora/src/test/resources/payload/actilityEnterprise.uplink.json b/adapters/lora/src/test/resources/payload/actilityEnterprise.uplink.json index 58c98de7a5..c96c01c75f 100644 --- a/adapters/lora/src/test/resources/payload/actilityEnterprise.uplink.json +++ b/adapters/lora/src/test/resources/payload/actilityEnterprise.uplink.json @@ -17,6 +17,8 @@ "DevLrrCnt": 1, "Lrrid": "10000001", "Late": 0, + "DevLAT": 13.99921, + "DevLON": 23.99593, "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..86d5ba8d2d 100644 --- a/adapters/lora/src/test/resources/payload/actilityWireless.uplink.json +++ b/adapters/lora/src/test/resources/payload/actilityWireless.uplink.json @@ -18,6 +18,8 @@ "DevLrrCnt": "1", "Lrrid": "18035559", "Late": "0", + "DevLAT": "15.00092", + "DevLON": "92.00992", "LrrLAT": "53.108805", "LrrLON": "9.193430", "Lrrs": {