Merge pull request #2184 from GUVWAF/trunk

Make Trunk happy
This commit is contained in:
GUVWAF 2023-01-21 13:27:30 +01:00 committed by GitHub
commit d8e644191b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,8 +3,8 @@
#include "NodeDB.h" #include "NodeDB.h"
#include "SPILock.h" #include "SPILock.h"
#include "configuration.h" #include "configuration.h"
#include "main.h"
#include "error.h" #include "error.h"
#include "main.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include <pb_decode.h> #include <pb_decode.h>
#include <pb_encode.h> #include <pb_encode.h>
@ -156,7 +156,7 @@ ErrorCode RadioLibInterface::send(MeshPacket *p)
packetPool.release(p); packetPool.release(p);
return ERRNO_DISABLED; return ERRNO_DISABLED;
#endif #endif
} }
QueueStatus RadioLibInterface::getQueueStatus() QueueStatus RadioLibInterface::getQueueStatus()
{ {
@ -169,18 +169,18 @@ QueueStatus RadioLibInterface::getQueueStatus()
return qs; return qs;
} }
bool RadioLibInterface::canSleep() bool RadioLibInterface::canSleep()
{ {
bool res = txQueue.empty(); bool res = txQueue.empty();
if (!res) // only print debug messages if we are vetoing sleep if (!res) // only print debug messages if we are vetoing sleep
LOG_DEBUG("radio wait to sleep, txEmpty=%d\n", res); LOG_DEBUG("radio wait to sleep, txEmpty=%d\n", res);
return res; return res;
} }
/** Attempt to cancel a previously sent packet. Returns true if a packet was found we could cancel */ /** Attempt to cancel a previously sent packet. Returns true if a packet was found we could cancel */
bool RadioLibInterface::cancelSending(NodeNum from, PacketId id) bool RadioLibInterface::cancelSending(NodeNum from, PacketId id)
{ {
auto p = txQueue.remove(from, id); auto p = txQueue.remove(from, id);
if (p) if (p)
packetPool.release(p); // free the packet we just removed packetPool.release(p); // free the packet we just removed
@ -188,17 +188,17 @@ QueueStatus RadioLibInterface::getQueueStatus()
bool result = (p != NULL); bool result = (p != NULL);
LOG_DEBUG("cancelSending id=0x%x, removed=%d\n", id, result); LOG_DEBUG("cancelSending id=0x%x, removed=%d\n", id, result);
return result; return result;
} }
/** radio helper thread callback. /** radio helper thread callback.
We never immediately transmit after any operation (either Rx or Tx). Instead we should wait a random multiple of We never immediately transmit after any operation (either Rx or Tx). Instead we should wait a random multiple of
'slotTimes' (see definition in RadioInterface.h) taken from a contention window (CW) to lower the chance of collision. 'slotTimes' (see definition in RadioInterface.h) taken from a contention window (CW) to lower the chance of collision.
The CW size is determined by setTransmitDelay() and depends either on the current channel utilization or SNR in case The CW size is determined by setTransmitDelay() and depends either on the current channel utilization or SNR in case
of a flooding message. After this, we perform channel activity detection (CAD) and reset the transmit delay if it is of a flooding message. After this, we perform channel activity detection (CAD) and reset the transmit delay if it is
currently active. currently active.
*/ */
void RadioLibInterface::onNotify(uint32_t notification) void RadioLibInterface::onNotify(uint32_t notification)
{ {
switch (notification) { switch (notification) {
case ISR_TX: case ISR_TX:
handleTransmitInterrupt(); handleTransmitInterrupt();
@ -243,10 +243,10 @@ QueueStatus RadioLibInterface::getQueueStatus()
default: default:
assert(0); // We expected to receive a valid notification from the ISR assert(0); // We expected to receive a valid notification from the ISR
} }
} }
void RadioLibInterface::setTransmitDelay() void RadioLibInterface::setTransmitDelay()
{ {
MeshPacket *p = txQueue.getFront(); MeshPacket *p = txQueue.getFront();
// We want all sending/receiving to be done by our daemon thread. // We want all sending/receiving to be done by our daemon thread.
// We use a delay here because this packet might have been sent in response to a packet we just received. // We use a delay here because this packet might have been sent in response to a packet we just received.
@ -263,39 +263,39 @@ QueueStatus RadioLibInterface::getQueueStatus()
LOG_DEBUG("rx_snr found. hop_limit:%d rx_snr:%f\n", p->hop_limit, p->rx_snr); LOG_DEBUG("rx_snr found. hop_limit:%d rx_snr:%f\n", p->hop_limit, p->rx_snr);
startTransmitTimerSNR(p->rx_snr); startTransmitTimerSNR(p->rx_snr);
} }
} }
void RadioLibInterface::startTransmitTimer(bool withDelay) void RadioLibInterface::startTransmitTimer(bool withDelay)
{ {
// If we have work to do and the timer wasn't already scheduled, schedule it now // If we have work to do and the timer wasn't already scheduled, schedule it now
if (!txQueue.empty()) { if (!txQueue.empty()) {
uint32_t delay = !withDelay ? 1 : getTxDelayMsec(); uint32_t delay = !withDelay ? 1 : getTxDelayMsec();
// LOG_DEBUG("xmit timer %d\n", delay); // LOG_DEBUG("xmit timer %d\n", delay);
notifyLater(delay, TRANSMIT_DELAY_COMPLETED, false); // This will implicitly enable notifyLater(delay, TRANSMIT_DELAY_COMPLETED, false); // This will implicitly enable
} }
} }
void RadioLibInterface::startTransmitTimerSNR(float snr) void RadioLibInterface::startTransmitTimerSNR(float snr)
{ {
// If we have work to do and the timer wasn't already scheduled, schedule it now // If we have work to do and the timer wasn't already scheduled, schedule it now
if (!txQueue.empty()) { if (!txQueue.empty()) {
uint32_t delay = getTxDelayMsecWeighted(snr); uint32_t delay = getTxDelayMsecWeighted(snr);
// LOG_DEBUG("xmit timer %d\n", delay); // LOG_DEBUG("xmit timer %d\n", delay);
notifyLater(delay, TRANSMIT_DELAY_COMPLETED, false); // This will implicitly enable notifyLater(delay, TRANSMIT_DELAY_COMPLETED, false); // This will implicitly enable
} }
} }
void RadioLibInterface::handleTransmitInterrupt() void RadioLibInterface::handleTransmitInterrupt()
{ {
// LOG_DEBUG("handling lora TX interrupt\n"); // LOG_DEBUG("handling lora TX interrupt\n");
// This can be null if we forced the device to enter standby mode. In that case // This can be null if we forced the device to enter standby mode. In that case
// ignore the transmit interrupt // ignore the transmit interrupt
if (sendingPacket) if (sendingPacket)
completeSending(); completeSending();
} }
void RadioLibInterface::completeSending() void RadioLibInterface::completeSending()
{ {
// We are careful to clear sending packet before calling printPacket because // We are careful to clear sending packet before calling printPacket because
// that can take a long time // that can take a long time
auto p = sendingPacket; auto p = sendingPacket;
@ -309,13 +309,14 @@ QueueStatus RadioLibInterface::getQueueStatus()
packetPool.release(p); packetPool.release(p);
// LOG_DEBUG("Done with send\n"); // LOG_DEBUG("Done with send\n");
} }
} }
void RadioLibInterface::handleReceiveInterrupt() void RadioLibInterface::handleReceiveInterrupt()
{ {
uint32_t xmitMsec; uint32_t xmitMsec;
// when this is called, we should be in receive mode - if we are not, just jump out instead of bombing. Possible Race Condition? // when this is called, we should be in receive mode - if we are not, just jump out instead of bombing. Possible Race
// Condition?
if (!isReceiving) { if (!isReceiving) {
LOG_DEBUG("*** WAS_ASSERT *** handleReceiveInterrupt called when not in receive mode\n"); LOG_DEBUG("*** WAS_ASSERT *** handleReceiveInterrupt called when not in receive mode\n");
return; return;
@ -381,11 +382,11 @@ QueueStatus RadioLibInterface::getQueueStatus()
deliverToReceiver(mp); deliverToReceiver(mp);
} }
} }
} }
/** start an immediate transmit */ /** start an immediate transmit */
void RadioLibInterface::startSend(MeshPacket * txp) void RadioLibInterface::startSend(MeshPacket *txp)
{ {
printPacket("Starting low level send", txp); printPacket("Starting low level send", txp);
if (disabled || !config.lora.tx_enabled) { if (disabled || !config.lora.tx_enabled) {
LOG_WARN("startSend is dropping tx packet because we are disabled\n"); LOG_WARN("startSend is dropping tx packet because we are disabled\n");
@ -411,4 +412,4 @@ QueueStatus RadioLibInterface::getQueueStatus()
// bits // bits
enableInterrupt(isrTxLevel0); enableInterrupt(isrTxLevel0);
} }
} }