Team Walter / LoRaWAN-lib

Files at this revision

API Documentation at this revision

Comitter:
ubhat
Date:
Tue Jul 17 22:48:35 2018 +0000
Parent:
6:d7a34ded7c87
Commit message:
Fix bug where FCnt get incremented twice in the case of ADRACKReq with D/L ACK

Changed in this revision

LoRaMac.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r d7a34ded7c87 -r 2426a05fe29e LoRaMac.cpp
--- a/LoRaMac.cpp	Wed May 18 11:19:24 2016 +0000
+++ b/LoRaMac.cpp	Tue Jul 17 22:48:35 2018 +0000
@@ -131,6 +131,8 @@
  */
 static uint32_t UpLinkCounter = 1;
 
+static bool UpLinkCounterFlag = false;
+
 /*!
  * LoRaMAC frame counter. Each time a packet is received the counter is incremented.
  * Only the 16 LSB bits are received
@@ -1379,7 +1381,7 @@
                 }
             }
             if( ( LoRaMacFlags.Bits.MlmeReq == 1 ) || ( ( LoRaMacFlags.Bits.McpsReq == 1 ) ) )
-            {
+            {                
                 if( ( ChannelsNbRepCounter >= ChannelsNbRep ) || ( LoRaMacFlags.Bits.McpsInd == 1 ) )
                 {
                     ChannelsNbRepCounter = 0;
@@ -1388,6 +1390,7 @@
                     if( IsUpLinkCounterFixed == false )
                     {
                         UpLinkCounter++;
+                        UpLinkCounterFlag = true;
                     }
 
                     LoRaMacState &= ~MAC_TX_RUNNING;
@@ -1402,12 +1405,13 @@
         }
 
         if( LoRaMacFlags.Bits.McpsInd == 1 )
-        {
+        {            
             if( ( McpsConfirm.AckReceived == true ) || ( AckTimeoutRetriesCounter > AckTimeoutRetries ) )
             {
                 AckTimeoutRetry = false;
                 NodeAckRequested = false;
-                if( IsUpLinkCounterFixed == false )
+                //if( ( IsUpLinkCounterFixed == false ) )
+                if( ( IsUpLinkCounterFixed == false ) && ( UpLinkCounterFlag == false ) )
                 {
                     UpLinkCounter++;
                 }
@@ -1416,6 +1420,8 @@
                 LoRaMacState &= ~MAC_TX_RUNNING;
             }
         }
+        
+        UpLinkCounterFlag = false;
 
         if( ( AckTimeoutRetry == true ) && ( ( LoRaMacState & MAC_TX_DELAYED ) == 0 ) )
         {