From 6eca474a73b3c378209a29a64c74ee0a4e76e001 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 2 Apr 2019 16:34:58 -0400 Subject: [PATCH 1/6] Fix #89: add new LMIC event codes --- src/Arduino_LoRaWAN_lmic.h | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/Arduino_LoRaWAN_lmic.h b/src/Arduino_LoRaWAN_lmic.h index 37cccd2..e4ad584 100644 --- a/src/Arduino_LoRaWAN_lmic.h +++ b/src/Arduino_LoRaWAN_lmic.h @@ -1,5 +1,3 @@ -/* Arduino_LoRaWAN_lmic.h Tue Oct 25 2016 06:22:40 tmm */ - /* Module: Arduino_LoRaWAN_lmic.h @@ -7,28 +5,12 @@ Module: Arduino_LoRaWAN_lmic.h Function: Wrapper header file for LMIC internals. -Version: - V0.1.0 Tue Oct 25 2016 06:22:40 tmm Edit level 1 - Copyright notice: - This file copyright (C) 2016 by - - MCCI Corporation - 3520 Krums Corners Road - Ithaca, NY 14850 - - An unpublished work. All rights reserved. - - This file is proprietary information, and may not be disclosed or - copied without the prior permission of MCCI Corporation. + See accompanying LICENSE file. Author: Terry Moore, MCCI Corporation October 2016 -Revision history: - 0.1.0 Tue Oct 25 2016 06:22:40 tmm - Module created. - */ #ifndef _ARDUINO_LORAWAN_LMIC_H_ /* prevent multiple includes */ @@ -79,7 +61,8 @@ class Arduino_LoRaWAN::cLMIC "BEACON_TRACKED\0" "JOINING\0" "JOINED\0" "RFU1\0" \ "JOIN_FAILED\0" "REJOIN_FAILED\0" "TXCOMPLETE\0" \ "LOST_TSYNC\0" "RESET\0" "RXCOMPLETE\0" "LINK_DEAD\0" \ - "LINK_ALIVE\0" "SCAN_FOUND\0" "TXSTART\0" + "LINK_ALIVE\0" "SCAN_FOUND\0" "TXSTART\0" \ + "TXCANCELED\0" "RXSTART\0" "JOIN_TXCOMPLETE\0" /**** end of Arduino_LoRaWAN_lmic.h ****/ #endif /* _ARDUINO_LORAWAN_LMIC_H_ */ From 1040a38c2e0064e29c8dc8366035eb8161002623 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 2 Apr 2019 16:57:27 -0400 Subject: [PATCH 2/6] Fix #87: clean up tx completion --- src/lib/SendBuffer.cpp | 2 +- src/lib/arduino_lorawan_begin.cpp | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/lib/SendBuffer.cpp b/src/lib/SendBuffer.cpp index 89262a6..b13c870 100644 --- a/src/lib/SendBuffer.cpp +++ b/src/lib/SendBuffer.cpp @@ -65,7 +65,7 @@ bool Arduino_LoRaWAN::SendBuffer( uint8_t port ) { - if (this->m_fTxPending || LMIC.opmode & OP_TXRXPEND) + if (! this->GetTxReady()) { if (pDoneFn) (*pDoneFn)(pDoneCtx, false); diff --git a/src/lib/arduino_lorawan_begin.cpp b/src/lib/arduino_lorawan_begin.cpp index 50e5c84..1fb4ece 100644 --- a/src/lib/arduino_lorawan_begin.cpp +++ b/src/lib/arduino_lorawan_begin.cpp @@ -172,11 +172,7 @@ void Arduino_LoRaWAN::StandardEventProcessor( // we need to just reset. if (! this->GetOtaaProvisioningInfo(nullptr)) { - bool txPending = this->m_fTxPending; - this->m_fTxPending = false; - // notify client that TX is complete - if (txPending && this->m_pSendBufferDoneFn) - this->m_pSendBufferDoneFn(this->m_pSendBufferDoneCtx, false); + this->completeTx(false); } break; @@ -217,7 +213,6 @@ void Arduino_LoRaWAN::StandardEventProcessor( break; case EV_TXCOMPLETE: - this->m_fTxPending = false; // notify framework that RX may be available (because this happens // after every transmit). From 5c9c0ee1d96f6715daf2a5821140fdcf2c25e0f9 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 2 Apr 2019 17:01:47 -0400 Subject: [PATCH 3/6] Fix #91: remove redundant call to UpdateFCntDown() --- src/lib/arduino_lorawan_begin.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib/arduino_lorawan_begin.cpp b/src/lib/arduino_lorawan_begin.cpp index 1fb4ece..9c6bb39 100644 --- a/src/lib/arduino_lorawan_begin.cpp +++ b/src/lib/arduino_lorawan_begin.cpp @@ -155,6 +155,7 @@ void Arduino_LoRaWAN::StandardEventProcessor( uint32_t ev ) { + // update our idea of the downlink counter. this->UpdateFCntDown(LMIC.seqnoDn); switch(ev) @@ -281,11 +282,6 @@ void Arduino_LoRaWAN::NetRxComplete(void) ); } } - - // Try to save the Rx sequence number. - // For efficiency, client should look for changes - // since last save. - this->UpdateFCntDown(LMIC.seqnoDn); } /****************************************************************************\ From 05b0420a2cd33c88c765aec0f3e17ff5cf12b431 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 2 Apr 2019 17:02:42 -0400 Subject: [PATCH 4/6] clean up whitespace --- src/lib/arduino_lorawan_begin.cpp | 117 +++++++++++++++--------------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/src/lib/arduino_lorawan_begin.cpp b/src/lib/arduino_lorawan_begin.cpp index 9c6bb39..98dd5ce 100644 --- a/src/lib/arduino_lorawan_begin.cpp +++ b/src/lib/arduino_lorawan_begin.cpp @@ -3,13 +3,13 @@ Module: arduino_lorawan_begin.cpp Function: - Arduino_LoRaWAN::begin(); + Arduino_LoRaWAN::begin(); Copyright notice: - See LICENSE file accompanying this project. + See LICENSE file accompanying this project. Author: - Terry Moore, MCCI Corporation October 2016 + Terry Moore, MCCI Corporation October 2016 */ @@ -133,21 +133,21 @@ Arduino_LoRaWAN::cLMIC::GetEventName(uint32_t ev) Name: Arduino_LoRaWAN::StandardEventProcessor() Function: - Handle LMIC events. + Handle LMIC events. Definition: - private: void Arduino_LoRaWAN::StandardEventProcessor( - uint32_t ev - ); + private: void Arduino_LoRaWAN::StandardEventProcessor( + uint32_t ev + ); Description: - The simple events emitted from the LMIC core are processed, both - to arrange for completions and notificatoins for asynchronous events, - and to generate notifications to cause data to be pushed to the - platform's persistent storage. + The simple events emitted from the LMIC core are processed, both + to arrange for completions and notificatoins for asynchronous events, + and to generate notifications to cause data to be pushed to the + platform's persistent storage. Returns: - No explicit result. + No explicit result. */ @@ -179,9 +179,9 @@ void Arduino_LoRaWAN::StandardEventProcessor( case EV_JOINED: { - // announce that we have joined; allows for - // network-specific fixups, and saving keys. - this->NetJoin(); + // announce that we have joined; allows for + // network-specific fixups, and saving keys. + this->NetJoin(); SessionInfo Info; Info.V1.Tag = kSessionInfoTag_V1; Info.V1.Size = sizeof(Info); @@ -199,49 +199,48 @@ void Arduino_LoRaWAN::StandardEventProcessor( break; case EV_JOIN_FAILED: - // we failed the join. But we keep trying; client must - // do a reset to stop us. - // TODO(tmm@mcci.com): this->NetJoinFailed(), and/or + // we failed the join. But we keep trying; client must + // do a reset to stop us. + // TODO(tmm@mcci.com): this->NetJoinFailed(), and/or // an outcall break; case EV_REJOIN_FAILED: - // after we join, if ABP is enabled (LMIC_setLinkCheck(true)), - // if we don't get downlink messages for a while, we'll try to - // rejoin. This message indicated that the rejoin failed. - // TODO(tmm@mcci.com): this->NetRejoinFailed(), and/or - // an outcall + // after we join, if ABP is enabled (LMIC_setLinkCheck(true)), + // if we don't get downlink messages for a while, we'll try to + // rejoin. This message indicated that the rejoin failed. + // TODO(tmm@mcci.com): this->NetRejoinFailed(), and/or + // an outcall break; case EV_TXCOMPLETE: + // notify framework that RX may be available (because this happens + // after every transmit). + this->NetRxComplete(); - // notify framework that RX may be available (because this happens - // after every transmit). - this->NetRxComplete(); - - // notify framework that tx is complete + // notify framework that tx is complete this->NetTxComplete(); - // notify client that TX is complete; claim success unless - // LMIC.txrxFlags & TXRX_NACK + // notify client that TX is complete; claim success unless + // LMIC.txrxFlags & TXRX_NACK this->completeTx(! (LMIC.txrxFlags & TXRX_NACK)); break; case EV_LOST_TSYNC: - // only for class-B or class-C: we lost beacon time synch. + // only for class-B or class-C: we lost beacon time synch. break; case EV_RESET: - // the LoRaWAN MAC just got reset due to a pending frame rollover - // on FCntDn or actual rollover on FCntUp. + // the LoRaWAN MAC just got reset due to a pending frame rollover + // on FCntDn or actual rollover on FCntUp. break; case EV_RXCOMPLETE: // data received in ping slot // see TXCOMPLETE. - // follow protocol: - this->NetRxComplete(); + // follow protocol: + this->NetRxComplete(); break; case EV_LINK_DEAD: @@ -254,35 +253,35 @@ void Arduino_LoRaWAN::StandardEventProcessor( break; case EV_TXSTART: - this->NetSaveFCntUp(LMIC.seqnoUp); + this->NetSaveFCntUp(LMIC.seqnoUp); break; - default: - break; - } + default: + break; + } } void Arduino_LoRaWAN::NetRxComplete(void) - { - // notify client that RX is available - if (LMIC.dataLen != 0 || LMIC.dataBeg != 0) - { - uint8_t port; - port = 0; - if (LMIC.txrxFlags & TXRX_PORT) - port = LMIC.frame[LMIC.dataBeg - 1]; - - if (this->m_pReceiveBufferFn) - { - this->m_pReceiveBufferFn( - this->m_pReceiveBufferCtx, - port, - LMIC.frame + LMIC.dataBeg, - LMIC.dataLen - ); - } - } - } + { + // notify client that RX is available + if (LMIC.dataLen != 0 || LMIC.dataBeg != 0) + { + uint8_t port; + port = 0; + if (LMIC.txrxFlags & TXRX_PORT) + port = LMIC.frame[LMIC.dataBeg - 1]; + + if (this->m_pReceiveBufferFn) + { + this->m_pReceiveBufferFn( + this->m_pReceiveBufferCtx, + port, + LMIC.frame + LMIC.dataBeg, + LMIC.dataLen + ); + } + } + } /****************************************************************************\ | From 9a9f441cddd14dab9e384c39a5adb1237c0b8df4 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 2 Apr 2019 17:23:05 -0400 Subject: [PATCH 5/6] Fix #92: get correct tx complete status --- src/lib/arduino_lorawan_begin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/arduino_lorawan_begin.cpp b/src/lib/arduino_lorawan_begin.cpp index 98dd5ce..f3e8102 100644 --- a/src/lib/arduino_lorawan_begin.cpp +++ b/src/lib/arduino_lorawan_begin.cpp @@ -222,8 +222,8 @@ void Arduino_LoRaWAN::StandardEventProcessor( this->NetTxComplete(); // notify client that TX is complete; claim success unless - // LMIC.txrxFlags & TXRX_NACK - this->completeTx(! (LMIC.txrxFlags & TXRX_NACK)); + // it's confirmed and we didn't get an ACK. + this->completeTx(! LMIC.pendTxConf || (LMIC.txrxFlags & TXRX_ACK) != 0); break; case EV_LOST_TSYNC: From 915e0fbe666bd1e13d2db6468cd667b3c15c5b85 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 2 Apr 2019 17:23:33 -0400 Subject: [PATCH 6/6] Fix #93: add EV_TXCANCELED support --- src/lib/arduino_lorawan_begin.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/arduino_lorawan_begin.cpp b/src/lib/arduino_lorawan_begin.cpp index f3e8102..eec92f3 100644 --- a/src/lib/arduino_lorawan_begin.cpp +++ b/src/lib/arduino_lorawan_begin.cpp @@ -256,6 +256,10 @@ void Arduino_LoRaWAN::StandardEventProcessor( this->NetSaveFCntUp(LMIC.seqnoUp); break; + case EV_TXCANCELED: + this->completeTx(false); + break; + default: break; }