Skip to content

Commit 59cca34

Browse files
committed
Fix #438: use clock error in FSK rx timing
1 parent 1d1ff10 commit 59cca34

10 files changed

+31
-61
lines changed

src/lmic/lmic_as923.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,6 @@ ostime_t LMICas923_nextJoinState(void) {
361361
}
362362
#endif // !DISABLE_JOIN
363363

364-
// txDone handling for FSK.
365-
void
366-
LMICas923_txDoneFSK(ostime_t delay, osjobcb_t func) {
367-
LMIC.rxtime = LMIC.txend + delay - PRERX_FSK*us2osticksRound(160);
368-
LMIC.rxsyms = RXLEN_FSK;
369-
os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
370-
}
371-
372364
void
373365
LMICas923_initJoinLoop(void) {
374366
// LMIC.txParam is set to 0xFF by the central code at init time.

src/lmic/lmic_bandplan_as923.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ void LMICas923_init(void);
7474
#undef LMICbandplan_isFSK
7575
#define LMICbandplan_isFSK() (/* RX datarate */LMIC.dndr == AS923_DR_FSK)
7676

77-
// txDone handling for FSK.
78-
void
79-
LMICas923_txDoneFSK(ostime_t delay, osjobcb_t func);
80-
81-
#undef LMICbandplan_txDoneFSK
82-
#define LMICbandplan_txDoneFSK(delay, func) LMICas923_txDoneFSK(delay, func)
83-
8477
#define LMICbandplan_getInitialDrJoin() (AS923_DR_SF10)
8578

8679
void LMICas923_setBcnRxParams(void);

src/lmic/lmic_bandplan_eu868.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ LMICeu868_isValidBeacon1(const uint8_t *d) {
6161
#undef LMICbandplan_isFSK
6262
#define LMICbandplan_isFSK() (/* RX datarate */LMIC.dndr == EU868_DR_FSK)
6363

64-
// txDone handling for FSK.
65-
void
66-
LMICeu868_txDoneFSK(ostime_t delay, osjobcb_t func);
67-
68-
#undef LMICbandplan_txDoneFSK
69-
#define LMICbandplan_txDoneFSK(delay, func) LMICeu868_txDoneFSK(delay, func)
70-
7164
#define LMICbandplan_getInitialDrJoin() (EU868_DR_SF7)
7265

7366
void LMICeu868_setBcnRxParams(void);

src/lmic/lmic_bandplan_in866.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ LMICin866_isValidBeacon1(const uint8_t *d) {
5858
#undef LMICbandplan_isFSK
5959
#define LMICbandplan_isFSK() (/* TX datarate */LMIC.dndr == IN866_DR_FSK)
6060

61-
// txDone handling for FSK.
62-
void
63-
LMICin866_txDoneFSK(ostime_t delay, osjobcb_t func);
64-
65-
#undef LMICbandplan_txDoneFSK
66-
#define LMICbandplan_txDoneFSK(delay, func) LMICin866_txDoneFSK(delay, func)
67-
6861
#define LMICbandplan_getInitialDrJoin() (IN866_DR_SF7)
6962

7063
void LMICin866_setBcnRxParams(void);

src/lmic/lmic_bandplan_kr920.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ LMICkr920_isValidBeacon1(const uint8_t *d) {
6161
#undef LMICbandplan_isFSK
6262
#define LMICbandplan_isFSK() (/* always false */ 0)
6363

64-
// txDone handling for FSK.
65-
void
66-
LMICkr920_txDoneFSK(ostime_t delay, osjobcb_t func);
67-
68-
#undef LMICbandplan_txDoneFSK
69-
#define LMICbandplan_txDoneFSK(delay, func) LMICkr920_txDoneFSK(delay, func)
70-
7164
#define LMICbandplan_getInitialDrJoin() (KR920_DR_SF7)
7265

7366
void LMICkr920_setBcnRxParams(void);

src/lmic/lmic_eu868.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,6 @@ ostime_t LMICeu868_nextJoinState(void) {
247247
}
248248
#endif // !DISABLE_JOIN
249249

250-
// Class A txDone handling for FSK.
251-
void
252-
LMICeu868_txDoneFSK(ostime_t delay, osjobcb_t func) {
253-
LMIC.rxtime = LMIC.txend + delay - PRERX_FSK*us2osticksRound(160);
254-
LMIC.rxsyms = RXLEN_FSK;
255-
os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
256-
}
257-
258250
// set the Rx1 dndr, rps.
259251
void LMICeu868_setRx1Params(void) {
260252
u1_t const txdr = LMIC.dndr;

src/lmic/lmic_eu_like.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,33 @@ void LMICeulike_setRx1Freq(void) {
250250
LMIC.freq = dlFreq;
251251
#endif // !DISABLE_MCMD_DlChannelReq
252252
}
253+
254+
// Class A txDone handling for FSK.
255+
void
256+
LMICeulike_txDoneFSK(ostime_t delay, osjobcb_t func) {
257+
LMIC.rxsyms = RXLEN_FSK;
258+
259+
// If a clock error is specified, compensate for it by extending the
260+
// receive window
261+
delay -= PRERX_FSK * us2osticksRound(160);
262+
263+
if (LMIC.client.clockError != 0) {
264+
// Calculate how much the clock will drift maximally after delay has
265+
// passed. This indicates the amount of time we can be early
266+
// _or_ late.
267+
ostime_t drift = (int64_t)delay * LMIC.client.clockError / MAX_CLOCK_ERROR;
268+
269+
// Increase the receive window by twice the maximum drift (to
270+
// compensate for a slow or a fast clock).
271+
// decrease the rxtime to compensate for. Note that hsym is a
272+
// *half* symbol time, so the factor 2 is hidden. First check if
273+
// this would overflow (which can happen if the drift is very
274+
// high, or the symbol time is low at high datarates).
275+
delay -= drift;
276+
}
277+
278+
LMIC.rxtime = LMIC.txend + delay;
279+
os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
280+
}
281+
253282
#endif // CFG_LMIC_EU_like

src/lmic/lmic_eu_like.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ LMICeulike_isValidBeacon1(const uint8_t *d) {
5656
#define LMICbandplan_isFSK() (0)
5757

5858
// provide a default LMICbandplan_txDoneDoFSK()
59-
#define LMICbandplan_txDoneFSK(delay, func) do { } while (0)
59+
void LMICeulike_txDoneFSK(ostime_t delay, osjobcb_t func);
60+
#define LMICbandplan_txDoneFSK(delay, func) LMICeulike_txDoneFSK(delay, func)
6061

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

src/lmic/lmic_in866.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,6 @@ ostime_t LMICin866_nextJoinState(void) {
212212
}
213213
#endif // !DISABLE_JOIN
214214

215-
// Class A txDone handling for FSK.
216-
void
217-
LMICin866_txDoneFSK(ostime_t delay, osjobcb_t func) {
218-
LMIC.rxtime = LMIC.txend + delay - PRERX_FSK*us2osticksRound(160);
219-
LMIC.rxsyms = RXLEN_FSK;
220-
os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
221-
}
222-
223215
// set the Rx1 dndr, rps.
224216
void LMICin866_setRx1Params(void) {
225217
u1_t const txdr = LMIC.dndr;

src/lmic/lmic_kr920.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,6 @@ ostime_t LMICkr920_nextJoinState(void) {
223223
}
224224
#endif // !DISABLE_JOIN
225225

226-
// // txDone handling for FSK.
227-
// void
228-
// LMICkr920_txDoneFSK(ostime_t delay, osjobcb_t func) {
229-
// LMIC.rxtime = LMIC.txend + delay - PRERX_FSK*us2osticksRound(160);
230-
// LMIC.rxsyms = RXLEN_FSK;
231-
// os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
232-
// }
233-
234226
// set the Rx1 dndr, rps.
235227
void LMICkr920_setRx1Params(void) {
236228
u1_t const txdr = LMIC.dndr;

0 commit comments

Comments
 (0)