Fork of Semtech LoRaWAN stack
Fork of LoRaWAN-lib by
Diff: LoRaMac.cpp
- Branch:
- v4.2.0
- Revision:
- 24:69286d8b3962
- Parent:
- 23:80965acdd311
- Child:
- 25:8d0a79bd607b
--- a/LoRaMac.cpp Wed Oct 12 19:26:37 2016 +0000 +++ b/LoRaMac.cpp Thu Oct 13 19:40:56 2016 +0000 @@ -2280,62 +2280,65 @@ bool adrAckReq = false; int8_t datarate = ChannelsDatarate; int8_t txpower = ChannelsTxPower; - + if( adrEnabled == true ) { /* Request ADR Ack Request (including at lowest available datarate) */ adrAckReq = AdrAckCounter >= ADR_ACK_LIMIT ? true : false; - if( AdrAckCounter > (ADR_ACK_LIMIT + ADR_ACK_DELAY) ) + if( AdrAckCounter >= (ADR_ACK_LIMIT + ADR_ACK_DELAY) ) { // Step up power txpower = LORAMAC_DEFAULT_TX_POWER; - // isTx=true when preparing to transmit the next frame - if(isTx == true) - AdrAckCounter = 0; - -#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 ) - if( datarate > LORAMAC_TX_MIN_DATARATE ) - { - datarate--; - } - if( datarate == LORAMAC_TX_MIN_DATARATE ) - { - if( isTx == true ) - { - // Re-enable default channels LC1, LC2, LC3 - ChannelsMask[0] = ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) ); - } - } -#elif defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID ) - if( datarate > LORAMAC_TX_MIN_DATARATE ) + if( ( AdrAckCounter % ADR_ACK_DELAY ) == 0 ) { - datarate--; - } - else if( isTx == true ) - { +#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 ) + if( datarate > LORAMAC_TX_MIN_DATARATE ) + { + datarate--; + } + + if( datarate == LORAMAC_TX_MIN_DATARATE ) + { + if( isTx == true ) + { + // Re-enable default channels LC1, LC2, LC3 + ChannelsMask[0] = ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) ); + } + } +#elif defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID ) + if( datarate > LORAMAC_TX_MIN_DATARATE ) + { + if ( datarate == DR_8) + datarate = DR_4; + else + datarate--; + } + else if( isTx == true ) + { #if 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; + // Re-enable default channels + ChannelsMask[0] = 0xFFFF; + ChannelsMask[1] = 0xFFFF; + ChannelsMask[2] = 0xFFFF; + ChannelsMask[3] = 0xFFFF; + ChannelsMask[4] = 0x00FF; + ChannelsMask[5] = 0x0000; #else // defined( USE_BAND_915_HYBRID ) - // Re-enable default channels - ChannelsMask[0] = 0x00FF; - ChannelsMask[1] = 0x0000; - ChannelsMask[2] = 0x0000; - ChannelsMask[3] = 0x0000; - ChannelsMask[4] = 0x0001; - ChannelsMask[5] = 0x0000; + // Re-enable default channels + ChannelsMask[0] = 0x00FF; + ChannelsMask[1] = 0x0000; + ChannelsMask[2] = 0x0000; + ChannelsMask[3] = 0x0000; + ChannelsMask[4] = 0x0001; + ChannelsMask[5] = 0x0000; #endif - } + } #else #error "Please define a frequency band in the compiler options." #endif + } } } @@ -2346,6 +2349,7 @@ *txpowerOut = txpower; return adrAckReq; + } static LoRaMacStatus_t AddMacCommand( uint8_t cmd, uint8_t p1, uint8_t p2 )