kopia lustrzana https://github.com/meshtastic/firmware
SimRadio in separate thread
To use notifyLater when transmitting, fixes packetPool issuespull/2272/head
rodzic
03f584a5ab
commit
97c1cf628a
|
@ -2,7 +2,7 @@
|
|||
#include "MeshService.h"
|
||||
#include "Router.h"
|
||||
|
||||
SimRadio::SimRadio()
|
||||
SimRadio::SimRadio() : NotifiedWorkerThread("SimRadio")
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
@ -53,10 +53,7 @@ void SimRadio::startTransmitTimer(bool withDelay)
|
|||
if (!txQueue.empty()) {
|
||||
uint32_t delayMsec = !withDelay ? 1 : getTxDelayMsec();
|
||||
// LOG_DEBUG("xmit timer %d\n", delay);
|
||||
delay(delayMsec);
|
||||
onNotify(TRANSMIT_DELAY_COMPLETED);
|
||||
} else {
|
||||
LOG_DEBUG("TX QUEUE EMPTY!\n");
|
||||
notifyLater(delayMsec, TRANSMIT_DELAY_COMPLETED, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,8 +63,7 @@ void SimRadio::startTransmitTimerSNR(float snr)
|
|||
if (!txQueue.empty()) {
|
||||
uint32_t delayMsec = getTxDelayMsecWeighted(snr);
|
||||
// LOG_DEBUG("xmit timer %d\n", delay);
|
||||
delay(delayMsec);
|
||||
onNotify(TRANSMIT_DELAY_COMPLETED);
|
||||
notifyLater(delayMsec, TRANSMIT_DELAY_COMPLETED, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,11 +138,12 @@ void SimRadio::onNotify(uint32_t notification)
|
|||
switch (notification) {
|
||||
case ISR_TX:
|
||||
handleTransmitInterrupt();
|
||||
LOG_DEBUG("tx complete - starting timer\n");
|
||||
// LOG_DEBUG("tx complete - starting timer\n");
|
||||
startTransmitTimer();
|
||||
break;
|
||||
case ISR_RX:
|
||||
LOG_DEBUG("rx complete - starting timer\n");
|
||||
// LOG_DEBUG("rx complete - starting timer\n");
|
||||
startTransmitTimer();
|
||||
break;
|
||||
case TRANSMIT_DELAY_COMPLETED:
|
||||
LOG_DEBUG("delay done\n");
|
||||
|
@ -170,8 +167,7 @@ void SimRadio::onNotify(uint32_t notification)
|
|||
uint32_t xmitMsec = getPacketTime(txp);
|
||||
airTime->logAirtime(TX_LOG, xmitMsec);
|
||||
|
||||
delay(xmitMsec); // Model the time it is busy sending
|
||||
completeSending();
|
||||
notifyLater(xmitMsec, ISR_TX, false); // Model the time it is busy sending
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -242,8 +238,7 @@ void SimRadio::handleReceiveInterrupt(meshtastic_MeshPacket *p)
|
|||
xmitMsec = getPacketTime(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
|
||||
mp->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // Mark that the payload is already decoded
|
||||
meshtastic_MeshPacket *mp = packetPool.allocCopy(*p); // keep a copy in packetPool
|
||||
|
||||
printPacket("Lora RX", mp);
|
||||
|
||||
|
@ -268,4 +263,4 @@ int16_t SimRadio::readData(uint8_t *data, size_t len)
|
|||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
#include "MeshPacketQueue.h"
|
||||
#include "RadioInterface.h"
|
||||
#include "api/WiFiServerAPI.h"
|
||||
#include "concurrency/NotifiedWorkerThread.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 };
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue