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.
- Loading branch information
1 parent
bfe662a
commit 4a1839c
Showing
10 changed files
with
117 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
|
||
DEFINE_LMIC; | ||
|
||
#define LMIC_ENABLE_TRACE 1 | ||
//#define LMIC_ENABLE_TRACE 1 | ||
|
||
#ifndef LMIC_ENABLE_TRACE | ||
# define LMIC_ENABLE_TRACE 0 | ||
|
@@ -750,37 +750,60 @@ applyAdrRequests( | |
u1_t p1 = 0; | ||
u1_t p4 = 0; | ||
bit_t response_fit = 1; | ||
bit_t map_ok = 1; | ||
|
||
LMICbandplan_saveAdrState(&initialState); | ||
|
||
for (oidx = 0; oidx < olen && response_fit; ) { | ||
if (adrAns == MCMD_LinkADRAns_PowerACK | MCMD_LinkADRAns_DataRateACK | MCMD_LinkADRAns_ChannelACK) { | ||
// compute the changes | ||
if (adrAns == MCMD_LinkADRAns_PowerACK | MCMD_LinkADRAns_DataRateACK | MCMD_LinkADRAns_ChannelACK) { | ||
for (oidx = 0; oidx < olen; oidx += kAdrReqSize) { | ||
// can we advance? | ||
if (olen - oidx < kAdrReqSize) { | ||
// ignore the malformed one at the end | ||
break; | ||
} | ||
u2_t chmap = os_rlsbf2(&opts[oidx+2]);// list of enabled channels | ||
|
||
p1 = opts[oidx+1]; // txpow + DR, in case last | ||
p4 = opts[oidx+4]; // ChMaskCtl, NbTrans | ||
u1_t chpage = p4 & MCMD_LinkADRReq_Redundancy_ChMaskCntl_MASK; // channel page | ||
|
||
LMICbandplan_mapChannels(chpage, chmap); | ||
map_ok = LMICbandplan_mapChannels(chpage, chmap); | ||
ArduinoLMIC_putEventDatum("applyAdrRequests: mapChannels", (chpage << 16)|(chmap << 0)); | ||
} | ||
} | ||
|
||
oidx += kAdrReqSize; | ||
if (! map_ok) { | ||
adrAns &= ~MCMD_LinkADRAns_ChannelACK; | ||
LMICbandplan_restoreAdrState(&initialState); | ||
} | ||
|
||
// now put all the options | ||
for (oidx = 0; oidx < olen && response_fit; oidx += kAdrReqSize) { | ||
// can we advance? | ||
if (olen - oidx < kAdrReqSize) { | ||
// ignore the malformed one at the end | ||
break; | ||
} | ||
response_fit = put_mac_uplink_byte2(MCMD_LinkADRAns, adrAns); | ||
} | ||
|
||
// all done scanning options | ||
bit_t changes = LMICbandplan_compareAdrState(&initialState); | ||
|
||
// handle uplink repeat count | ||
u1_t uprpt = p4 & MCMD_LinkADRReq_Redundancy_NbTrans_MASK; // up repeat count | ||
if (LMIC.upRepeat != uprpt) { | ||
LMIC.upRepeat = uprpt; | ||
changes = 1; | ||
} | ||
// handle the final options | ||
if (adrAns == (MCMD_LinkADRAns_PowerACK | MCMD_LinkADRAns_DataRateACK | MCMD_LinkADRAns_ChannelACK)) { | ||
// handle uplink repeat count | ||
u1_t uprpt = p4 & MCMD_LinkADRReq_Redundancy_NbTrans_MASK; // up repeat count | ||
if (LMIC.upRepeat != uprpt) { | ||
LMIC.upRepeat = uprpt; | ||
changes = 1; | ||
} | ||
|
||
if (adrAns & MCMD_LinkADRAns_DataRateACK) { | ||
dr_t dr = (dr_t)(p1>>MCMD_LinkADRReq_DR_SHIFT); | ||
|
||
ArduinoLMIC_putEventDatum("applyAdrRequests: setDrTxPow", (adrAns << 16)|(dr << 8)|(p1 << 0)); | ||
|
||
// handle power changes here, too. | ||
changes |= setDrTxpow(DRCHG_NWKCMD, dr, pow2dBm(p1)); | ||
} | ||
|
@@ -798,6 +821,8 @@ scan_mac_cmds_link_adr( | |
bit_t *presponse_fit | ||
) | ||
{ | ||
ArduinoLMIC_putEventDatum("scan_mac_cmds_link_adr", olen); | ||
|
||
if (olen == 0) | ||
return 0; | ||
|
||
|
@@ -867,6 +892,15 @@ scan_mac_cmds( | |
|
||
response_fit = 1; | ||
cmd = opts[oidx]; | ||
|
||
/* compute length, and exit for illegal commands */ | ||
int const cmdlen = getMacCmdSize(cmd); | ||
if (cmdlen > olen - oidx) { | ||
// "the first unknown command terminates processing" | ||
olen = oidx; | ||
break; | ||
} | ||
|
||
switch( cmd ) { | ||
case MCMD_LinkCheckAns: { | ||
// TODO([email protected]) capture these, reliably.. | ||
|
@@ -1119,17 +1153,12 @@ scan_mac_cmds( | |
} /* end case */ | ||
} /* end switch */ | ||
|
||
/* compute length, and exit for illegal commands */ | ||
int const cmdlen = getMacCmdSize(cmd); | ||
if (cmdlen == 0) { | ||
// "the first unknown command terminates processing" | ||
// force olen to current oidx so we'll exit the while(). | ||
olen = oidx; | ||
} else if (! response_fit) { | ||
olen = oidx; | ||
} | ||
|
||
oidx += cmdlen; | ||
/* if we're out of spce for responses, skip to end. */ | ||
if (! response_fit) { | ||
olen = oidx; | ||
} else { | ||
oidx += cmdlen; | ||
} | ||
} /* end while */ | ||
|
||
return oidx; | ||
|
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 |
---|---|---|
|
@@ -80,12 +80,11 @@ bit_t LMICeulike_canMapChannels(u1_t chpage, u2_t chmap) { | |
} | ||
} | ||
|
||
// assumes that LMICeulike_canMapChannels passed. Return true if something changed. | ||
// chpage is 0 or 6; 6 turns all on; 0 selects channels 0..15 via mask. | ||
// assumes that LMICeulike_canMapChannels passed. Return true if this would | ||
// be a valid final configuration. | ||
// chpage is 0 or 0x60; 0x60 turns all on; 0 selects channels 0..15 via mask. | ||
// Assumes canMapChannels has already approved this change. | ||
bit_t LMICeulike_mapChannels(u1_t chpage, u2_t chmap) { | ||
u2_t const old_chmap = LMIC.channelMap; | ||
|
||
switch (chpage) { | ||
case MCMD_LinkADRReq_ChMaskCntl_EULIKE_DIRECT: | ||
LMIC.channelMap = chmap; | ||
|
@@ -106,7 +105,7 @@ bit_t LMICeulike_mapChannels(u1_t chpage, u2_t chmap) { | |
// do nothing. | ||
break; | ||
} | ||
return old_chmap != chmap; | ||
return LMIC.channelMap != 0; | ||
} | ||
|
||
#if !defined(DISABLE_JOIN) | ||
|
@@ -159,12 +158,12 @@ ostime_t LMICeulike_nextJoinState(uint8_t nDefaultChannels) { | |
LMIC.txChnl = 0; | ||
if ((++LMIC.txCnt % nDefaultChannels) == 0) { | ||
// Lower DR every nth try (having all default channels with same DR) | ||
// | ||
// TODO([email protected]) add new DR_REGIN_JOIN_MIN instead of LORAWAN_DR0; | ||
// then we can eliminate the LMIC_REGION_as923 below because we'll set | ||
// the failed flag here. This will cause the outer caller to take the | ||
// appropriate join path. Or add new LMICeulike_GetLowestJoinDR() | ||
// | ||
// | ||
// TODO([email protected]) add new DR_REGIN_JOIN_MIN instead of LORAWAN_DR0; | ||
// then we can eliminate the LMIC_REGION_as923 below because we'll set | ||
// the failed flag here. This will cause the outer caller to take the | ||
// appropriate join path. Or add new LMICeulike_GetLowestJoinDR() | ||
// | ||
if (LMIC.datarate == LORAWAN_DR0) | ||
failed = 1; // we have tried all DR - signal EV_JOIN_FAILED | ||
else | ||
|
@@ -185,12 +184,12 @@ ostime_t LMICeulike_nextJoinState(uint8_t nDefaultChannels) { | |
// Duty cycle is based on txend. | ||
ostime_t const time = LMICbandplan_nextJoinTime(os_getTime()); | ||
|
||
// TODO([email protected]): change delay to (0:1) secs + a known t0, but randomized; | ||
// TODO([email protected]): change delay to (0:1) secs + a known t0, but randomized; | ||
// starting adding a bias after 1 hour, 25 hours, etc.; and limit the duty | ||
// cycle on power up. For testability, add a way to set the join start time | ||
// externally (a test API) so we can check this feature. | ||
// See https://github.com/mcci-catena/arduino-lmic/issues/2 | ||
// Current code doesn't match LoRaWAN 1.0.2 requirements. | ||
// Current code doesn't match LoRaWAN 1.0.2 requirements. | ||
|
||
LMIC.txend = time + | ||
(isTESTMODE() | ||
|
@@ -206,12 +205,12 @@ ostime_t LMICeulike_nextJoinState(uint8_t nDefaultChannels) { | |
#endif // !DISABLE_JOIN | ||
|
||
void LMICeulike_saveAdrState(lmic_saved_adr_state_t *pStateBuffer) { | ||
memcpy( | ||
pStateBuffer->channelFreq, | ||
LMIC.channelFreq, | ||
sizeof(LMIC.channelFreq) | ||
); | ||
pStateBuffer->channelMap = LMIC.channelMap; | ||
os_copyMem( | ||
pStateBuffer->channelFreq, | ||
LMIC.channelFreq, | ||
sizeof(LMIC.channelFreq) | ||
); | ||
pStateBuffer->channelMap = LMIC.channelMap; | ||
} | ||
|
||
bit_t LMICeulike_compareAdrState(const lmic_saved_adr_state_t *pStateBuffer) { | ||
|
@@ -220,6 +219,15 @@ bit_t LMICeulike_compareAdrState(const lmic_saved_adr_state_t *pStateBuffer) { | |
return pStateBuffer->channelMap != LMIC.channelMap; | ||
} | ||
|
||
void LMICeulike_restoreAdrState(const lmic_saved_adr_state_t *pStateBuffer) { | ||
os_copyMem( | ||
LMIC.channelFreq, | ||
pStateBuffer->channelFreq, | ||
sizeof(LMIC.channelFreq) | ||
); | ||
LMIC.channelMap = pStateBuffer->channelMap; | ||
} | ||
|
||
void LMICeulike_setRx1Freq(void) { | ||
#if !defined(DISABLE_MCMD_DlChannelReq) | ||
uint32_t dlFreq = LMIC.channelDlFreq[LMIC.txChnl]; | ||
|
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