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_ */ 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..eec92f3 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. */ @@ -155,6 +155,7 @@ void Arduino_LoRaWAN::StandardEventProcessor( uint32_t ev ) { + // update our idea of the downlink counter. this->UpdateFCntDown(LMIC.seqnoDn); switch(ev) @@ -172,19 +173,15 @@ 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; 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); @@ -202,50 +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: - this->m_fTxPending = false; + // 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 - this->completeTx(! (LMIC.txrxFlags & TXRX_NACK)); + // notify client that TX is complete; claim success unless + // it's confirmed and we didn't get an ACK. + this->completeTx(! LMIC.pendTxConf || (LMIC.txrxFlags & TXRX_ACK) != 0); 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: @@ -258,40 +253,39 @@ void Arduino_LoRaWAN::StandardEventProcessor( break; case EV_TXSTART: - this->NetSaveFCntUp(LMIC.seqnoUp); + this->NetSaveFCntUp(LMIC.seqnoUp); + break; + + case EV_TXCANCELED: + this->completeTx(false); 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 - ); - } - } - - // Try to save the Rx sequence number. - // For efficiency, client should look for changes - // since last save. - this->UpdateFCntDown(LMIC.seqnoDn); - } + { + // 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 + ); + } + } + } /****************************************************************************\ |