Skip to content

Commit

Permalink
Fix #438: use clock error in FSK rx timing
Browse files Browse the repository at this point in the history
  • Loading branch information
terrillmoore committed Sep 9, 2019
1 parent 1d1ff10 commit 59cca34
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 61 deletions.
8 changes: 0 additions & 8 deletions src/lmic/lmic_as923.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,6 @@ ostime_t LMICas923_nextJoinState(void) {
}
#endif // !DISABLE_JOIN

// txDone handling for FSK.
void
LMICas923_txDoneFSK(ostime_t delay, osjobcb_t func) {
LMIC.rxtime = LMIC.txend + delay - PRERX_FSK*us2osticksRound(160);
LMIC.rxsyms = RXLEN_FSK;
os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
}

void
LMICas923_initJoinLoop(void) {
// LMIC.txParam is set to 0xFF by the central code at init time.
Expand Down
7 changes: 0 additions & 7 deletions src/lmic/lmic_bandplan_as923.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ void LMICas923_init(void);
#undef LMICbandplan_isFSK
#define LMICbandplan_isFSK() (/* RX datarate */LMIC.dndr == AS923_DR_FSK)

// txDone handling for FSK.
void
LMICas923_txDoneFSK(ostime_t delay, osjobcb_t func);

#undef LMICbandplan_txDoneFSK
#define LMICbandplan_txDoneFSK(delay, func) LMICas923_txDoneFSK(delay, func)

#define LMICbandplan_getInitialDrJoin() (AS923_DR_SF10)

void LMICas923_setBcnRxParams(void);
Expand Down
7 changes: 0 additions & 7 deletions src/lmic/lmic_bandplan_eu868.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ LMICeu868_isValidBeacon1(const uint8_t *d) {
#undef LMICbandplan_isFSK
#define LMICbandplan_isFSK() (/* RX datarate */LMIC.dndr == EU868_DR_FSK)

// txDone handling for FSK.
void
LMICeu868_txDoneFSK(ostime_t delay, osjobcb_t func);

#undef LMICbandplan_txDoneFSK
#define LMICbandplan_txDoneFSK(delay, func) LMICeu868_txDoneFSK(delay, func)

#define LMICbandplan_getInitialDrJoin() (EU868_DR_SF7)

void LMICeu868_setBcnRxParams(void);
Expand Down
7 changes: 0 additions & 7 deletions src/lmic/lmic_bandplan_in866.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ LMICin866_isValidBeacon1(const uint8_t *d) {
#undef LMICbandplan_isFSK
#define LMICbandplan_isFSK() (/* TX datarate */LMIC.dndr == IN866_DR_FSK)

// txDone handling for FSK.
void
LMICin866_txDoneFSK(ostime_t delay, osjobcb_t func);

#undef LMICbandplan_txDoneFSK
#define LMICbandplan_txDoneFSK(delay, func) LMICin866_txDoneFSK(delay, func)

#define LMICbandplan_getInitialDrJoin() (IN866_DR_SF7)

void LMICin866_setBcnRxParams(void);
Expand Down
7 changes: 0 additions & 7 deletions src/lmic/lmic_bandplan_kr920.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ LMICkr920_isValidBeacon1(const uint8_t *d) {
#undef LMICbandplan_isFSK
#define LMICbandplan_isFSK() (/* always false */ 0)

// txDone handling for FSK.
void
LMICkr920_txDoneFSK(ostime_t delay, osjobcb_t func);

#undef LMICbandplan_txDoneFSK
#define LMICbandplan_txDoneFSK(delay, func) LMICkr920_txDoneFSK(delay, func)

#define LMICbandplan_getInitialDrJoin() (KR920_DR_SF7)

void LMICkr920_setBcnRxParams(void);
Expand Down
8 changes: 0 additions & 8 deletions src/lmic/lmic_eu868.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,6 @@ ostime_t LMICeu868_nextJoinState(void) {
}
#endif // !DISABLE_JOIN

// Class A txDone handling for FSK.
void
LMICeu868_txDoneFSK(ostime_t delay, osjobcb_t func) {
LMIC.rxtime = LMIC.txend + delay - PRERX_FSK*us2osticksRound(160);
LMIC.rxsyms = RXLEN_FSK;
os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
}

// set the Rx1 dndr, rps.
void LMICeu868_setRx1Params(void) {
u1_t const txdr = LMIC.dndr;
Expand Down
29 changes: 29 additions & 0 deletions src/lmic/lmic_eu_like.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,33 @@ void LMICeulike_setRx1Freq(void) {
LMIC.freq = dlFreq;
#endif // !DISABLE_MCMD_DlChannelReq
}

// Class A txDone handling for FSK.
void
LMICeulike_txDoneFSK(ostime_t delay, osjobcb_t func) {
LMIC.rxsyms = RXLEN_FSK;

// If a clock error is specified, compensate for it by extending the
// receive window
delay -= PRERX_FSK * us2osticksRound(160);

if (LMIC.client.clockError != 0) {
// Calculate how much the clock will drift maximally after delay has
// passed. This indicates the amount of time we can be early
// _or_ late.
ostime_t drift = (int64_t)delay * LMIC.client.clockError / MAX_CLOCK_ERROR;

// Increase the receive window by twice the maximum drift (to
// compensate for a slow or a fast clock).
// decrease the rxtime to compensate for. Note that hsym is a
// *half* symbol time, so the factor 2 is hidden. First check if
// this would overflow (which can happen if the drift is very
// high, or the symbol time is low at high datarates).
delay -= drift;
}

LMIC.rxtime = LMIC.txend + delay;
os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
}

#endif // CFG_LMIC_EU_like
3 changes: 2 additions & 1 deletion src/lmic/lmic_eu_like.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ LMICeulike_isValidBeacon1(const uint8_t *d) {
#define LMICbandplan_isFSK() (0)

// provide a default LMICbandplan_txDoneDoFSK()
#define LMICbandplan_txDoneFSK(delay, func) do { } while (0)
void LMICeulike_txDoneFSK(ostime_t delay, osjobcb_t func);
#define LMICbandplan_txDoneFSK(delay, func) LMICeulike_txDoneFSK(delay, func)

#define LMICbandplan_joinAcceptChannelClear() LMICbandplan_initDefaultChannels(/* normal, not join */ 0)

Expand Down
8 changes: 0 additions & 8 deletions src/lmic/lmic_in866.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,6 @@ ostime_t LMICin866_nextJoinState(void) {
}
#endif // !DISABLE_JOIN

// Class A txDone handling for FSK.
void
LMICin866_txDoneFSK(ostime_t delay, osjobcb_t func) {
LMIC.rxtime = LMIC.txend + delay - PRERX_FSK*us2osticksRound(160);
LMIC.rxsyms = RXLEN_FSK;
os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
}

// set the Rx1 dndr, rps.
void LMICin866_setRx1Params(void) {
u1_t const txdr = LMIC.dndr;
Expand Down
8 changes: 0 additions & 8 deletions src/lmic/lmic_kr920.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,6 @@ ostime_t LMICkr920_nextJoinState(void) {
}
#endif // !DISABLE_JOIN

// // txDone handling for FSK.
// void
// LMICkr920_txDoneFSK(ostime_t delay, osjobcb_t func) {
// LMIC.rxtime = LMIC.txend + delay - PRERX_FSK*us2osticksRound(160);
// LMIC.rxsyms = RXLEN_FSK;
// os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
// }

// set the Rx1 dndr, rps.
void LMICkr920_setRx1Params(void) {
u1_t const txdr = LMIC.dndr;
Expand Down

0 comments on commit 59cca34

Please sign in to comment.