LoRaWAN MAC layer implementation

Dependents:   LoRaWAN-demo-72_tjm LoRaWAN-demo-72_jlc LoRaWAN-demo-elmo frdm_LoRa_Connect_Woodstream_Demo_tjm ... more

LoRAWAN-lib is a port of the GitHub LoRaMac-node LoRaWAN MAC layer implementation.

This library depends on the SX1276Lib or SX1272Lib radio drivers depending on the used mbed component shield.

This library depends also on some cryptographic helper functions as well as helper functions for the timers management. These can be found on the example projects under the system directory.

The example projects are:

  1. LoRaWAN-demo-72
  2. LoRaWAN-demo-76
  3. LoRaWAN-demo-NAMote72

The LoRaWAN specification specifies different ISM bands operating parameters. These are all implemented under the LoRaMac-board.h file.

In order to select which band to use, please change line 24 of board.h file provided on the examples projects as follows:


EU868

board.h

#define USE_BAND_868


US915

board.h

#define USE_BAND_915


US915 - Hybrid

board.h

#define USE_BAND_915_HYBRID


CN780

board.h

#define USE_BAND_780


EU433

board.h

#define USE_BAND_433

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
--- 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 ) )
         {