Skip to content

Commit f8f9bbc

Browse files
committed
Fix #450 Fix #445: LMIC_clrTxData more carefully
1 parent 0c06144 commit f8f9bbc

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/lmic/lmic.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,9 +2744,20 @@ void LMIC_init (void) {
27442744

27452745

27462746
void LMIC_clrTxData (void) {
2747-
bit_t const txActive = LMIC.opmode & OP_TXDATA;
2748-
LMIC.opmode &= ~(OP_TXDATA|OP_TXRXPEND|OP_POLL);
2747+
u2_t opmode = LMIC.opmode;
2748+
bit_t const txActive = opmode & OP_TXDATA;
2749+
if (! txActive) {
2750+
return;
2751+
}
27492752
LMIC.pendTxLen = 0;
2753+
opmode &= ~(OP_TXDATA | OP_POLL);
2754+
if (! (opmode & OP_JOINING)) {
2755+
// in this case, we are joining, and the TX data
2756+
// is just pending.
2757+
opmode &= ~(OP_TXRXPEND);
2758+
}
2759+
2760+
LMIC.opmode = opmode;
27502761

27512762
if (txActive)
27522763
reportEventNoUpdate(EV_TXCANCELED);
@@ -2787,15 +2798,23 @@ dr_t LMIC_feasibleDataRateForFrame(dr_t dr, u1_t payloadSize) {
27872798
return dr;
27882799
}
27892800

2790-
static void adjustDrForFrame(u1_t len) {
2801+
static bit_t isTxPathBusy(void) {
2802+
return (LMIC.opmode & (OP_TXDATA|OP_JOINING)) != 0;
2803+
}
2804+
2805+
static bit_t adjustDrForFrameIfNotBusy(u1_t len) {
2806+
if (isTxPathBusy()) {
2807+
return 0;
2808+
}
27912809
dr_t newDr = LMIC_feasibleDataRateForFrame(LMIC.datarate, len);
27922810
if (newDr != LMIC.datarate) {
27932811
setDrTxpow(DRCHG_FRAMESIZE, newDr, KEEP_TXPOW);
27942812
}
2813+
return 1;
27952814
}
27962815

27972816
void LMIC_setTxData (void) {
2798-
adjustDrForFrame(LMIC.pendTxLen);
2817+
adjustDrForFrameIfNotBusy(LMIC.pendTxLen);
27992818
LMIC_setTxData_strict();
28002819
}
28012820

@@ -2812,7 +2831,7 @@ void LMIC_setTxData_strict (void) {
28122831

28132832
// send a message, attempting to adjust TX data rate
28142833
lmic_tx_error_t LMIC_setTxData2 (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed) {
2815-
adjustDrForFrame(dlen);
2834+
adjustDrForFrameIfNotBusy(dlen);
28162835
return LMIC_setTxData2_strict(port, data, dlen, confirmed);
28172836
}
28182837

@@ -2846,7 +2865,7 @@ lmic_tx_error_t LMIC_sendWithCallback (
28462865
u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed,
28472866
lmic_txmessage_cb_t *pCb, void *pUserData
28482867
) {
2849-
adjustDrForFrame(dlen);
2868+
adjustDrForFrameIfNotBusy(dlen);
28502869
return LMIC_sendWithCallback_strict(port, data, dlen, confirmed, pCb, pUserData);
28512870
}
28522871

0 commit comments

Comments
 (0)