forked from things-nyc/arduino-lmic
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #385: correct TxParamSetupReq processing
- Loading branch information
1 parent
dd23e15
commit 2e2b4d9
Showing
6 changed files
with
96 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,8 +138,6 @@ bit_t LMICuslike_mapChannels(u1_t chpage, u2_t chmap) { | |
|| all channels 0..63 are turned off or on. MCMC_LADR_CHP_BANK | ||
|| is also special, in that it enables subbands. | ||
*/ | ||
u1_t base, top; | ||
|
||
if (chpage == MCMD_LinkADRReq_ChMaskCntl_USLIKE_BANK) { | ||
// each bit enables a bank of channels | ||
for (u1_t subband = 0; subband < 8; ++subband, chmap >>= 1) { | ||
|
@@ -149,60 +147,86 @@ bit_t LMICuslike_mapChannels(u1_t chpage, u2_t chmap) { | |
LMIC_disableSubBand(subband); | ||
} | ||
} | ||
} else { | ||
u1_t base, top; | ||
|
||
if (chpage < MCMD_LinkADRReq_ChMaskCntl_USLIKE_SPECIAL) { | ||
// operate on channels 0..15, 16..31, 32..47, 48..63 | ||
// note that the chpage hasn't been shifted right, so | ||
// it's really the base. | ||
base = chpage; | ||
top = base + 16; | ||
if (base == 64) { | ||
top = 72; | ||
} | ||
} else /* if (chpage == MCMD_LinkADRReq_ChMaskCntl_USLIKE_125ON || | ||
chpage == MCMD_LinkADRReq_ChMaskCntl_USLIKE_125OFF) */ { | ||
u1_t const en125 = chpage == MCMD_LinkADRReq_ChMaskCntl_USLIKE_125ON; | ||
|
||
// enable or disable all 125kHz channels | ||
for (u1_t chnl = 0; chnl < 64; ++chnl) { | ||
if (en125) | ||
LMIC_enableChannel(chnl); | ||
else | ||
LMIC_disableChannel(chnl); | ||
} | ||
|
||
// then apply mask to top 8 channels. | ||
base = 64; | ||
top = 72; | ||
} | ||
|
||
return LMIC.activeChannels125khz || LMIC.activeChannels500khz; | ||
} | ||
|
||
if (chpage < MCMD_LinkADRReq_ChMaskCntl_USLIKE_SPECIAL) { | ||
// operate on channels 0..15, 16..31, 32..47, 48..63 | ||
base = chpage << 4; | ||
top = base + 16; | ||
if (base == 64) { | ||
top = 72; | ||
} | ||
} else /* if (chpage == MCMD_LinkADRReq_ChMaskCntl_USLIKE_125ON || | ||
chpage == MCMD_LinkADRReq_ChMaskCntl_USLIKE_125OFF) */ { | ||
u1_t const en125 = chpage == MCMD_LinkADRReq_ChMaskCntl_USLIKE_125ON; | ||
|
||
// enable or disable all 125kHz channels | ||
for (u1_t chnl = 0; chnl < 64; ++chnl) { | ||
if (en125) | ||
LMIC_enableChannel(chnl); | ||
else | ||
LMIC_disableChannel(chnl); | ||
} | ||
|
||
// then apply mask to top 8 channels. | ||
base = 64; | ||
top = 72; | ||
} | ||
|
||
// apply chmap to channels in [base..top-1]. | ||
// Use enable/disable channel to keep activeChannel counts in sync. | ||
for (u1_t chnl = base; chnl < top; ++chnl, chmap >>= 1) { | ||
if (chmap & 0x0001) | ||
LMIC_enableChannel(chnl); | ||
else | ||
LMIC_disableChannel(chnl); | ||
// apply chmap to channels in [base..top-1]. | ||
// Use enable/disable channel to keep activeChannel counts in sync. | ||
for (u1_t chnl = base; chnl < top; ++chnl, chmap >>= 1) { | ||
if (chmap & 0x0001) | ||
LMIC_enableChannel(chnl); | ||
else | ||
LMIC_disableChannel(chnl); | ||
} | ||
} | ||
return LMIC.activeChannels125khz || LMIC.activeChannels500khz; | ||
|
||
LMICOS_logEventUint32("LMICuslike_mapChannels", (LMIC.activeChannels125khz << 16u)|(LMIC.activeChannels500khz << 0u)); | ||
return (LMIC.activeChannels125khz > 0) || (LMIC.activeChannels500khz > 0); | ||
} | ||
|
||
// US does not have duty cycling - return now as earliest TX time | ||
// but also do the channel hopping dance. | ||
ostime_t LMICuslike_nextTx(ostime_t now) { | ||
// TODO([email protected]): use a static const for US-like | ||
if (LMIC.datarate >= LMICuslike_getFirst500kHzDR()) { // 500kHz | ||
ASSERT(LMIC.activeChannels500khz>0); | ||
setNextChannel(64, 64 + 8, LMIC.activeChannels500khz); | ||
if (LMIC.activeChannels500khz > 0) { | ||
setNextChannel(64, 64 + 8, LMIC.activeChannels500khz); | ||
} else if (LMIC.activeChannels125khz > 0) { | ||
LMIC.datarate = lowerDR(LMICuslike_getFirst500kHzDR(), 1); | ||
setNextChannel(0, 64, LMIC.activeChannels125khz); | ||
LMICOS_logEvent("LMICuslike_nextTx: no 500k, choose 125k"); | ||
} else { | ||
LMICOS_logEvent("LMICuslike_nextTx: no channels at all (500)"); | ||
} | ||
} | ||
else { // 125kHz | ||
ASSERT(LMIC.activeChannels125khz>0); | ||
setNextChannel(0, 64, LMIC.activeChannels125khz); | ||
if (LMIC.activeChannels125khz > 0) { | ||
setNextChannel(0, 64, LMIC.activeChannels125khz); | ||
} else if (LMIC.activeChannels500khz > 0) { | ||
LMIC.datarate = LMICuslike_getFirst500kHzDR(); | ||
setNextChannel(64, 64 + 8, LMIC.activeChannels500khz); | ||
LMICOS_logEvent("LMICuslike_nextTx: no 125k, choose 500k"); | ||
} else { | ||
LMICOS_logEvent("LMICuslike_nextTx: no channels at all (125)"); | ||
} | ||
} | ||
return now; | ||
} | ||
|
||
bit_t LMICuslike_isDataRateFeasible(dr_t dr) { | ||
if (dr >= LMICuslike_getFirst500kHzDR()) { // 500kHz | ||
return LMIC.activeChannels500khz > 0; | ||
} else { | ||
return LMIC.activeChannels125khz > 6; | ||
} | ||
} | ||
|
||
#if !defined(DISABLE_JOIN) | ||
void LMICuslike_initJoinLoop(void) { | ||
// set an initial condition so that setNextChannel()'s preconds are met | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters