From a3b93a4dcfa8e7281cc9d0ef88d8a742c417dddc Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Tue, 10 Jan 2023 21:10:09 +0100 Subject: [PATCH 1/3] Better not to compare float directly --- src/mesh/Router.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 69ac1d5c9..b5965f25f 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -199,7 +199,7 @@ ErrorCode Router::send(MeshPacket *p) } // should have already been handled by sendLocal // Abort sending if we are violating the duty cycle - if (!config.lora.override_duty_cycle && myRegion->dutyCycle != 100) { + if (!config.lora.override_duty_cycle && myRegion->dutyCycle < 100) { float hourlyTxPercent = airTime->utilizationTXPercent(); if (hourlyTxPercent > myRegion->dutyCycle) { uint8_t silentMinutes = airTime->getSilentMinutes(hourlyTxPercent, myRegion->dutyCycle); From e13fb9919e20e640fe309944ca1fd5f4528d24e0 Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Tue, 10 Jan 2023 21:12:17 +0100 Subject: [PATCH 2/3] Send NAK only to the API upon duty cycle limit --- src/mesh/Router.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index b5965f25f..b3d43cf09 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -200,14 +200,18 @@ ErrorCode Router::send(MeshPacket *p) // Abort sending if we are violating the duty cycle if (!config.lora.override_duty_cycle && myRegion->dutyCycle < 100) { - float hourlyTxPercent = airTime->utilizationTXPercent(); - if (hourlyTxPercent > myRegion->dutyCycle) { - uint8_t silentMinutes = airTime->getSilentMinutes(hourlyTxPercent, myRegion->dutyCycle); - LOG_WARN("Duty cycle limit exceeded. Aborting send for now, you can send again in %d minutes.\n", silentMinutes); - Routing_Error err = Routing_Error_DUTY_CYCLE_LIMIT; - abortSendAndNak(err, p); - return err; - } + float hourlyTxPercent = airTime->utilizationTXPercent(); + if (hourlyTxPercent > myRegion->dutyCycle) { + uint8_t silentMinutes = airTime->getSilentMinutes(hourlyTxPercent, myRegion->dutyCycle); + LOG_WARN("Duty cycle limit exceeded. Aborting send for now, you can send again in %d minutes.\n", silentMinutes); + Routing_Error err = Routing_Error_DUTY_CYCLE_LIMIT; + if (getFrom(p) == nodeDB.getNodeNum()) { // only send NAK to API, not to the mesh + abortSendAndNak(err, p); + } else { + packetPool.release(p); + } + return err; + } } // PacketId nakId = p->decoded.which_ackVariant == SubPacket_fail_id_tag ? p->decoded.ackVariant.fail_id : 0; From ab9d0ba543be246ad7f52280550613a109661fb5 Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Tue, 10 Jan 2023 21:12:40 +0100 Subject: [PATCH 3/3] Report actual RoutingError --- src/mesh/Router.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index b3d43cf09..74487588b 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -138,7 +138,7 @@ void Router::sendAckNak(Routing_Error err, NodeNum to, PacketId idFrom, ChannelI void Router::abortSendAndNak(Routing_Error err, MeshPacket *p) { LOG_ERROR("Error=%d, returning NAK and dropping packet.\n", err); - sendAckNak(Routing_Error_NO_INTERFACE, getFrom(p), p->id, p->channel); + sendAckNak(err, getFrom(p), p->id, p->channel); packetPool.release(p); }