SimRadio in separate thread

To use notifyLater when transmitting, fixes packetPool issues
This commit is contained in:
GUVWAF 2023-02-11 10:34:08 +01:00
parent 03f584a5ab
commit 97c1cf628a
2 changed files with 11 additions and 15 deletions

View File

@ -2,7 +2,7 @@
#include "MeshService.h" #include "MeshService.h"
#include "Router.h" #include "Router.h"
SimRadio::SimRadio() SimRadio::SimRadio() : NotifiedWorkerThread("SimRadio")
{ {
instance = this; instance = this;
} }
@ -53,10 +53,7 @@ void SimRadio::startTransmitTimer(bool withDelay)
if (!txQueue.empty()) { if (!txQueue.empty()) {
uint32_t delayMsec = !withDelay ? 1 : getTxDelayMsec(); uint32_t delayMsec = !withDelay ? 1 : getTxDelayMsec();
// LOG_DEBUG("xmit timer %d\n", delay); // LOG_DEBUG("xmit timer %d\n", delay);
delay(delayMsec); notifyLater(delayMsec, TRANSMIT_DELAY_COMPLETED, false);
onNotify(TRANSMIT_DELAY_COMPLETED);
} else {
LOG_DEBUG("TX QUEUE EMPTY!\n");
} }
} }
@ -66,8 +63,7 @@ void SimRadio::startTransmitTimerSNR(float snr)
if (!txQueue.empty()) { if (!txQueue.empty()) {
uint32_t delayMsec = getTxDelayMsecWeighted(snr); uint32_t delayMsec = getTxDelayMsecWeighted(snr);
// LOG_DEBUG("xmit timer %d\n", delay); // LOG_DEBUG("xmit timer %d\n", delay);
delay(delayMsec); notifyLater(delayMsec, TRANSMIT_DELAY_COMPLETED, false);
onNotify(TRANSMIT_DELAY_COMPLETED);
} }
} }
@ -142,11 +138,12 @@ void SimRadio::onNotify(uint32_t notification)
switch (notification) { switch (notification) {
case ISR_TX: case ISR_TX:
handleTransmitInterrupt(); handleTransmitInterrupt();
LOG_DEBUG("tx complete - starting timer\n"); // LOG_DEBUG("tx complete - starting timer\n");
startTransmitTimer(); startTransmitTimer();
break; break;
case ISR_RX: case ISR_RX:
LOG_DEBUG("rx complete - starting timer\n"); // LOG_DEBUG("rx complete - starting timer\n");
startTransmitTimer();
break; break;
case TRANSMIT_DELAY_COMPLETED: case TRANSMIT_DELAY_COMPLETED:
LOG_DEBUG("delay done\n"); LOG_DEBUG("delay done\n");
@ -170,8 +167,7 @@ void SimRadio::onNotify(uint32_t notification)
uint32_t xmitMsec = getPacketTime(txp); uint32_t xmitMsec = getPacketTime(txp);
airTime->logAirtime(TX_LOG, xmitMsec); airTime->logAirtime(TX_LOG, xmitMsec);
delay(xmitMsec); // Model the time it is busy sending notifyLater(xmitMsec, ISR_TX, false); // Model the time it is busy sending
completeSending();
} }
} }
} else { } else {
@ -242,8 +238,7 @@ void SimRadio::handleReceiveInterrupt(meshtastic_MeshPacket *p)
xmitMsec = getPacketTime(length); xmitMsec = getPacketTime(length);
// LOG_DEBUG("Payload size %d vs length (includes header) %d\n", p->decoded.payload.size, length); // LOG_DEBUG("Payload size %d vs length (includes header) %d\n", p->decoded.payload.size, length);
meshtastic_MeshPacket *mp = packetPool.allocCopy(*p); // keep a copy in packtPool meshtastic_MeshPacket *mp = packetPool.allocCopy(*p); // keep a copy in packetPool
mp->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // Mark that the payload is already decoded
printPacket("Lora RX", mp); printPacket("Lora RX", mp);

View File

@ -3,10 +3,11 @@
#include "MeshPacketQueue.h" #include "MeshPacketQueue.h"
#include "RadioInterface.h" #include "RadioInterface.h"
#include "api/WiFiServerAPI.h" #include "api/WiFiServerAPI.h"
#include "concurrency/NotifiedWorkerThread.h"
#include <RadioLib.h> #include <RadioLib.h>
class SimRadio : public RadioInterface class SimRadio : public RadioInterface, protected concurrency::NotifiedWorkerThread
{ {
enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED }; enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED };