From b6f6718f1ff0fac5e0938cead16ea4ad1453a738 Mon Sep 17 00:00:00 2001 From: StevenCellist <47155822+StevenCellist@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:43:56 +0100 Subject: [PATCH] [LoRaWAN] Add datarate into event structure (#885) * [LoRaWAN] Move TX power logic to function * Update keywords * [LoRaWAN] Add datarate into event structure --- .../LoRaWAN_End_Device_Reference.ino | 2 ++ src/protocols/LoRaWAN/LoRaWAN.cpp | 2 ++ src/protocols/LoRaWAN/LoRaWAN.h | 3 +++ 3 files changed, 7 insertions(+) diff --git a/examples/LoRaWAN/LoRaWAN_End_Device_Reference/LoRaWAN_End_Device_Reference.ino b/examples/LoRaWAN/LoRaWAN_End_Device_Reference/LoRaWAN_End_Device_Reference.ino index c31752e7..bf70f139 100644 --- a/examples/LoRaWAN/LoRaWAN_End_Device_Reference/LoRaWAN_End_Device_Reference.ino +++ b/examples/LoRaWAN/LoRaWAN_End_Device_Reference/LoRaWAN_End_Device_Reference.ino @@ -214,6 +214,8 @@ void loop() { Serial.println(event.confirmed); Serial.print(F("[LoRaWAN] Confirming:\t")); Serial.println(event.confirming); + Serial.print(F("[LoRaWAN] Datarate:\t")); + Serial.print(event.datarate); Serial.print(F("[LoRaWAN] Frequency:\t")); Serial.print(event.freq, 3); Serial.println(F(" MHz")); diff --git a/src/protocols/LoRaWAN/LoRaWAN.cpp b/src/protocols/LoRaWAN/LoRaWAN.cpp index a8f1fd2b..99c93549 100644 --- a/src/protocols/LoRaWAN/LoRaWAN.cpp +++ b/src/protocols/LoRaWAN/LoRaWAN.cpp @@ -904,6 +904,7 @@ int16_t LoRaWANNode::uplink(uint8_t* data, size_t len, uint8_t port, bool isConf event->dir = RADIOLIB_LORAWAN_CHANNEL_DIR_UPLINK; event->confirmed = isConfirmed; event->confirming = isConfirmingDown; + event->datarate = this->dataRates[RADIOLIB_LORAWAN_CHANNEL_DIR_UPLINK]; event->freq = currentChannels[event->dir].freq; event->power = this->txPwrCur; event->fcnt = this->fcntUp; @@ -1262,6 +1263,7 @@ int16_t LoRaWANNode::downlink(uint8_t* data, size_t* len, LoRaWANEvent_t* event) event->dir = RADIOLIB_LORAWAN_CHANNEL_DIR_DOWNLINK; event->confirmed = isConfirmedDown; event->confirming = isConfirmingUp; + event->datarate = this->dataRates[RADIOLIB_LORAWAN_CHANNEL_DIR_DOWNLINK]; event->freq = currentChannels[event->dir].freq; event->power = this->txPwrCur; event->fcnt = isAppDownlink ? this->aFcntDown : this->nFcntDown; diff --git a/src/protocols/LoRaWAN/LoRaWAN.h b/src/protocols/LoRaWAN/LoRaWAN.h index 6e4523d0..30ff2512 100644 --- a/src/protocols/LoRaWAN/LoRaWAN.h +++ b/src/protocols/LoRaWAN/LoRaWAN.h @@ -325,6 +325,9 @@ struct LoRaWANEvent_t { /*! \brief Whether the event is confirming a previous request (e.g., server downlink reply to confirmed uplink sent by user application)*/ bool confirming; + + /*! \brief Datarate */ + uint8_t datarate; /*! \brief Frequency in MHz */ float freq;