Fork of Semtech LoRaWAN stack
Fork of LoRaWAN-lib by
Diff: LoRaMac.cpp
- Branch:
- v4.2.0
- Revision:
- 13:90a55bd536a1
- Parent:
- 12:d09ccf69cc93
- Child:
- 14:60c5d589a070
--- a/LoRaMac.cpp Mon Aug 29 14:28:26 2016 -0400 +++ b/LoRaMac.cpp Mon Aug 29 16:41:53 2016 -0400 @@ -1509,18 +1509,7 @@ #if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 ) // Re-enable default channels LC1, LC2, LC3 ChannelsMask[0] = ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) ); -#elif defined( USE_BAND_915 ) - // Re-enable default channels - ChannelsMask[0] = 0xFFFF; - ChannelsMask[1] = 0xFFFF; - ChannelsMask[2] = 0xFFFF; - ChannelsMask[3] = 0xFFFF; - ChannelsMask[4] = 0x00FF; - ChannelsMask[5] = 0x0000; -#elif defined( USE_BAND_915_HYBRID ) - // Re-enable default channels - ReenableChannels( ChannelsMask[4], ChannelsMask ); -#else +#elif !defined( USE_BAND_915 ) && !defined( USE_BAND_915_HYBRID ) #error "Please define a frequency band in the compiler options." #endif LoRaMacState &= ~MAC_TX_RUNNING; @@ -2665,19 +2654,34 @@ // Process accumulated Link ADR channel mask changes if( validLinkAdrCmds > 0 ) { + uint8_t drOkCounter = 0; + #if defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID ) for(uint8_t i=0; i< 6; i++) { for( uint8_t j = 0; j < 16; j++ ) { - if( ( ( channelsMask[i] & ( 1 << j ) ) != 0 ) && ( Channels[i * 16 + j].Frequency == 0 ) ) - {// Trying to enable an undefined channel - linkAdrStatus &= 0xFE; // Channel mask KO - break; + if( ( channelsMask[i] & ( 1 << j ) ) != 0 ) + { + if ( ( Channels[i * 16 + j].Frequency == 0 ) ) + { + linkAdrStatus &= 0xFE; // Channel mask KO + break; + } + else if( ( datarate >= Channels[i * 16 + j].DrRange.Fields.Min ) && + ( datarate <= Channels[i * 16 + j].DrRange.Fields.Max ) ) + { + drOkCounter++; + } } } } + if ( drOkCounter == 0 ) + { + linkAdrStatus &= 0xFD; // Datarate KO + } + if( CountNbEnabled125kHzChannels( channelsMask ) < 6 ) { linkAdrStatus &= 0xFE; // Channel mask KO