From 3209e3337805f9c473de5456593aaadf57383929 Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Tue, 10 Sep 2019 18:47:23 -0400 Subject: [PATCH] Fix #448: AS923, AU915 enforce dwell time based on TxParam --- src/lmic/lmic_as923.c | 17 +++++++++++++++-- src/lmic/lmic_au921.c | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/lmic/lmic_as923.c b/src/lmic/lmic_as923.c index 419aec76..d66c10a7 100644 --- a/src/lmic/lmic_as923.c +++ b/src/lmic/lmic_as923.c @@ -370,6 +370,9 @@ LMICas923_initJoinLoop(void) { void LMICas923_updateTx(ostime_t txbeg) { u4_t freq = LMIC.channelFreq[LMIC.txChnl]; + u4_t dwellDelay; + u4_t globalDutyDelay; + // Update global/band specific duty cycle stats ostime_t airtime = calcAirTime(LMIC.rps, LMIC.dataLen); // Update channel/global duty cycle stats @@ -377,8 +380,18 @@ LMICas923_updateTx(ostime_t txbeg) { LMIC.freq = freq & ~(u4_t)3; LMIC.txpow = LMICas923_getMaxEIRP(LMIC.txParam); band->avail = txbeg + airtime * band->txcap; - if (LMIC.globalDutyRate != 0) - LMIC.globalDutyAvail = txbeg + (airtime << LMIC.globalDutyRate); + dwellDelay = globalDutyDelay = 0; + if (LMIC.globalDutyRate != 0) { + globalDutyDelay = (airtime << LMIC.globalDutyRate); + } + if (LMICas923_getUplinkDwellBit(LMIC.txParam)) { + dwellDelay = AS923_UPLINK_DWELL_TIME_osticks; + } + if (dwellDelay > globalDutyDelay) { + globalDutyDelay = dwellDelay; + } + if (globalDutyDelay != 0) + LMIC.globalDutyAvail = txbeg + globalDutyDelay; } diff --git a/src/lmic/lmic_au921.c b/src/lmic/lmic_au921.c index 0bb387bf..399d50fc 100644 --- a/src/lmic/lmic_au921.c +++ b/src/lmic/lmic_au921.c @@ -239,10 +239,23 @@ void LMICau921_updateTx(ostime_t txbeg) { LMIC.freq = AU921_500kHz_UPFBASE + (chnl - 64)*AU921_500kHz_UPFSTEP; } - // Update global duty cycle stats + // Update global duty cycle stat and deal with dwell time. + u4_t dwellDelay; + u4_t globalDutyDelay; + dwellDelay = globalDutyDelay = 0; + if (LMIC.globalDutyRate != 0) { ostime_t airtime = calcAirTime(LMIC.rps, LMIC.dataLen); - LMIC.globalDutyAvail = txbeg + (airtime << LMIC.globalDutyRate); + globalDutyDelay = txbeg + (airtime << LMIC.globalDutyRate); + } + if (LMICau921_getUplinkDwellBit(LMIC.txParam)) { + dwellDelay = AS923_UPLINK_DWELL_TIME_osticks; + } + if (dwellDelay > globalDutyDelay) { + globalDutyDelay = dwellDelay; + } + if (globalDutyDelay != 0) { + LMIC.globalDutyAvail = txbeg + globalDutyDelay; } }