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.
Merge pull request #71 from mcci-catena/tanupoo-another-as923jp
- Loading branch information
Showing
8 changed files
with
159 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -971,6 +971,7 @@ static void schedRx12 (ostime_t delay, osjobcb_t func, u1_t dr) { | |
// (again note that hsym is half a sumbol time, so no /2 needed) | ||
LMIC.rxtime = LMIC.txend + delay + PAMBL_SYMS * hsym - LMIC.rxsyms * hsym; | ||
|
||
LMIC_X_DEBUG_PRINTF("%lu: sched Rx12 %lu\n", os_getTime(), LMIC.rxtime - RX_RAMPUP); | ||
os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func); | ||
} | ||
|
||
|
@@ -1035,18 +1036,32 @@ static bit_t processJoinAccept (void) { | |
return 1; | ||
} | ||
LMIC.opmode &= ~OP_TXRXPEND; | ||
ostime_t delay = LMICbandplan_nextJoinState(); | ||
int failed = LMICbandplan_nextJoinState(); | ||
EV(devCond, DEBUG, (e_.reason = EV::devCond_t::NO_JACC, | ||
e_.eui = MAIN::CDEV->getEui(), | ||
e_.info = LMIC.datarate|DR_PAGE, | ||
e_.info2 = osticks2ms(delay))); | ||
e_.info2 = failed)); | ||
// Build next JOIN REQUEST with next engineUpdate call | ||
// Optionally, report join failed. | ||
// Both after a random/chosen amount of ticks. | ||
os_setTimedCallback(&LMIC.osjob, os_getTime()+delay, | ||
(delay&1) != 0 | ||
// Both after a random/chosen amount of ticks. That time | ||
// is in LMIC.txend. The delay here is either zero or 1 | ||
// tick; onJoinFailed()/runEngineUpdate() are responsible | ||
// for honoring that. XXX([email protected]) The IBM 1.6 code | ||
// claimed to return a delay but really returns 0 or 1. | ||
// Once we update as923 to return failed after dr2, we | ||
// can take out this #if. | ||
#if CFG_region != LMIC_REGION_as923 | ||
os_setTimedCallback(&LMIC.osjob, os_getTime()+failed, | ||
failed | ||
? FUNC_ADDR(onJoinFailed) // one JOIN iteration done and failed | ||
: FUNC_ADDR(runEngineUpdate)); // next step to be delayed | ||
#else | ||
// in the join of AS923 v1.1 older, only DR2 is used. Therefore, | ||
// not much improvement when it handles two different behavior; | ||
// onJoinFailed or runEngineUpdate. | ||
os_setTimedCallback(&LMIC.osjob, os_getTime()+failed, | ||
FUNC_ADDR(onJoinFailed)); | ||
#endif | ||
return 1; | ||
} | ||
u1_t hdr = LMIC.frame[0]; | ||
|
@@ -1112,9 +1127,20 @@ static bit_t processJoinAccept (void) { | |
: EV::joininfo_t::ACCEPT))); | ||
|
||
ASSERT((LMIC.opmode & (OP_JOINING|OP_REJOIN))!=0); | ||
// | ||
// XXX([email protected]) OP_REJOIN confuses me, and I'm not sure why we're | ||
// adjusting DRs here. We've just recevied a join accept, and the | ||
// datarate therefore shouldn't be in play. | ||
// | ||
if( (LMIC.opmode & OP_REJOIN) != 0 ) { | ||
#if CFG_region != LMIC_REGION_as923 | ||
// TODO([email protected]) regionalize | ||
// Lower DR every try below current UP DR | ||
LMIC.datarate = lowerDR(LMIC.datarate, LMIC.rejoinCnt); | ||
#else | ||
// in the join of AS923 v1.1 or older, only DR2 (SF10) is used. | ||
LMIC.datarate = AS923_DR_SF10; | ||
#endif | ||
} | ||
LMIC.opmode &= ~(OP_JOINING|OP_TRACK|OP_REJOIN|OP_TXRXPEND|OP_PINGINI) | OP_NEXTCHNL; | ||
LMIC.txCnt = 0; | ||
|
@@ -1711,13 +1737,16 @@ static void engineUpdate (void) { | |
// Earliest possible time vs overhead to setup radio | ||
if( txbeg - (now + TX_RAMPUP) < 0 ) { | ||
// We could send right now! | ||
txbeg = now; | ||
txbeg = now; | ||
dr_t txdr = (dr_t)LMIC.datarate; | ||
#if !defined(DISABLE_JOIN) | ||
if( jacc ) { | ||
u1_t ftype; | ||
if( (LMIC.opmode & OP_REJOIN) != 0 ) { | ||
#if CFG_region != LMIC_REGION_as923 | ||
// in AS923 v1.1 or older, no need to change the datarate. | ||
txdr = lowerDR(txdr, LMIC.rejoinCnt); | ||
#endif | ||
ftype = HDR_FTYPE_REJOIN; | ||
} else { | ||
ftype = HDR_FTYPE_JREQ; | ||
|
@@ -1813,6 +1842,7 @@ static void engineUpdate (void) { | |
e_.eui = MAIN::CDEV->getEui(), | ||
e_.info = osticks2ms(txbeg-now), | ||
e_.info2 = LMIC.seqnoUp-1)); | ||
LMIC_X_DEBUG_PRINTF("%lu: next engine update in %lu\n", now, txbeg-TX_RAMPUP); | ||
os_setTimedCallback(&LMIC.osjob, txbeg-TX_RAMPUP, FUNC_ADDR(runEngineUpdate)); | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -91,6 +91,16 @@ void LMICeulike_updateTx(ostime_t txbeg) { | |
} | ||
|
||
#if !defined(DISABLE_JOIN) | ||
// | ||
// TODO([email protected]): | ||
// | ||
// The definition of this is a little strange. this seems to return a time, but | ||
// in reality it returns 0 if the caller should continue scanning through | ||
// channels, and 1 if the caller has scanned all channels on this session, | ||
// and therefore should reset to the beginning. The IBM 1.6 code is the | ||
// same way, so apparently I just carried this across. We should declare | ||
// as bool_t and change callers to use the result clearly as a flag. | ||
// | ||
ostime_t LMICeulike_nextJoinState(uint8_t nDefaultChannels) { | ||
u1_t failed = 0; | ||
|
||
|
@@ -100,22 +110,46 @@ 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() | ||
// | ||
if (LMIC.datarate == LORAWAN_DR0) | ||
failed = 1; // we have tried all DR - signal EV_JOIN_FAILED | ||
else | ||
{ | ||
// TODO([email protected]) - see above; please remove regional dependency from this file. | ||
#if CFG_region != LMIC_REGION_as923 | ||
LMICcore_setDrJoin(DRCHG_NOJACC, decDR((dr_t)LMIC.datarate)); | ||
#else | ||
// in the join of AS923 v1.1 or older, only DR2 is used. | ||
// no need to change the DR. | ||
LMIC.datarate = AS923_DR_SF10; | ||
#endif | ||
} | ||
} | ||
// Clear NEXTCHNL because join state engine controls channel hopping | ||
LMIC.opmode &= ~OP_NEXTCHNL; | ||
// Move txend to randomize synchronized concurrent joins. | ||
// 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; | ||
// 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. | ||
|
||
LMIC.txend = time + | ||
(isTESTMODE() | ||
// Avoid collision with JOIN ACCEPT @ SF12 being sent by GW (but we missed it) | ||
? DNW2_SAFETY_ZONE | ||
// Otherwise: randomize join (street lamp case): | ||
// SF12:255, SF11:127, .., SF7:8secs | ||
// | ||
: DNW2_SAFETY_ZONE + LMICcore_rndDelay(255 >> LMIC.datarate)); | ||
// 1 - triggers EV_JOIN_FAILED event | ||
return failed; | ||
|
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 |
---|---|---|
|
@@ -193,6 +193,16 @@ void LMICuslike_initJoinLoop(void) { | |
#endif // !DISABLE_JOIN | ||
|
||
#if !defined(DISABLE_JOIN) | ||
// | ||
// TODO([email protected]): | ||
// | ||
// The definition of this is a little strange. this seems to return a time, but | ||
// in reality it returns 0 if the caller should continue scanning through | ||
// channels, and 1 if the caller has scanned all channels on this session, | ||
// and therefore should reset to the beginning. The IBM 1.6 code is the | ||
// same way, so apparently I just carried this across. We should declare | ||
// as bool_t and change callers to use the result clearly as a flag. | ||
// | ||
ostime_t LMICuslike_nextJoinState(void) { | ||
// Try the following: | ||
// DR0 (SF10) on a random channel 0..63 | ||
|
@@ -227,6 +237,8 @@ ostime_t LMICuslike_nextJoinState(void) { | |
// 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. | ||
|
||
LMIC.txend = os_getTime() + | ||
(isTESTMODE() | ||
// Avoid collision with JOIN ACCEPT being sent by GW (but we missed it - GW is still busy) | ||
|
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
Oops, something went wrong.