Fork of Semtech LoRaWAN stack

Fork of LoRaWAN-lib by canuck lehead

Branch:
v4.2.0
Revision:
20:92764fda7371
Parent:
19:838d3e8dffc6
Child:
21:4ccde8ee9ac8
diff -r 838d3e8dffc6 -r 92764fda7371 LoRaMac.cpp
--- a/LoRaMac.cpp	Thu Sep 15 19:47:38 2016 +0000
+++ b/LoRaMac.cpp	Mon Sep 19 09:45:15 2016 +0000
@@ -15,7 +15,7 @@
 
 License: Revised BSD License, see LICENSE.TXT file include in the project
 
-Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jäckle ( STACKFORCE )
+Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jäckle ( STACKFORCE )
 */
 #include "board.h"
 
@@ -41,6 +41,17 @@
 #define LORA_MAC_FRMPAYLOAD_OVERHEAD                13 // MHDR(1) + FHDR(7) + Port(1) + MIC(4)
 
 /*!
+ * Minimum number of available channels in Frequency Hopping Mode
+ */
+#define FRQ_HOP_CHNLS_MIN 50
+
+/*!
+ * Minimum number of available channels in Hybrid Mode
+ */
+#define HYBRD_CHNLS_MIN 4
+
+
+/*!
  * Device IEEE EUI
  */
 static uint8_t *LoRaMacDevEui;
@@ -2230,7 +2241,7 @@
     }
     else
     {
-        if( CountNbEnabled125kHzChannels( ChannelsMask ) < 50 )
+        if( CountNbEnabled125kHzChannels( ChannelsMask ) < FRQ_HOP_CHNLS_MIN )
         {// Limit tx power to max 21dBm
             resultTxPower = MAX( txPower, TX_POWER_20_DBM );
         }
@@ -2748,7 +2759,7 @@
             status &= 0xFD;  // Datarate KO
         }
 
-        if( CountNbEnabled125kHzChannels( channelsMask ) < 6 )
+        if( ( CountNbEnabled125kHzChannels( channelsMask ) > 0 ) && ( CountNbEnabled125kHzChannels( channelsMask ) < HYBRD_CHNLS_MIN ) )
         {
             status &= 0xFE; // Channel mask KO
         }
@@ -2764,6 +2775,7 @@
         if( ( status & 0x07 ) == 0x07 )
         {
             ChannelsDatarate = datarate;
+			ChannelsDefaultDatarate = datarate;
             ChannelsTxPower = txPower;
 
             ChannelsMask[0] = channelsMask[0];
@@ -3547,7 +3559,7 @@
 #endif
                 if( chanMaskState == true )
                 {
-                    if( ( CountNbEnabled125kHzChannels( mibSet->Param.ChannelsMask ) < 6 ) &&
+                    if( ( CountNbEnabled125kHzChannels( mibSet->Param.ChannelsMask ) < HYBRD_CHNLS_MIN ) &&
                         ( CountNbEnabled125kHzChannels( mibSet->Param.ChannelsMask ) > 0 ) )
                     {
                         status = LORAMAC_STATUS_PARAMETER_INVALID;