Avoid switching to rx on each packet

master
sh123 2023-11-17 12:23:45 +02:00
rodzic b89a13680e
commit cf99eb014d
3 zmienionych plików z 58 dodań i 25 usunięć

Wyświetl plik

@ -52,9 +52,14 @@ private:
void onRigTaskRxPacket(); void onRigTaskRxPacket();
void onRigTaskTxPacket(); void onRigTaskTxPacket();
void onRigTaskStartRx();
void onRigTaskStartTx();
static void rigTask(void *self); static void rigTask(void *self);
static ICACHE_RAM_ATTR void onRigIsrRxPacket(); static ICACHE_RAM_ATTR void onRigIsrRxPacket();
void startRx();
static bool startRxTimer(void *param);
void onAprsisDataAvailable(); void onAprsisDataAvailable();
void sendSignalReportEvent(int rssi, float snr); void sendSignalReportEvent(int rssi, float snr);
@ -150,7 +155,9 @@ private:
// radio task commands // radio task commands
enum RadioTaskBits { enum RadioTaskBits {
Receive = 0x01, Receive = 0x01,
Transmit = 0x02 Transmit = 0x02,
StartReceive = 0x04,
StartTransmit = 0x10
}; };
private: private:
@ -169,6 +176,7 @@ private:
// peripherals, radio // peripherals, radio
static TaskHandle_t rigTaskHandle_; static TaskHandle_t rigTaskHandle_;
Timer<1> startRxTimer_;
static volatile bool rigIsRxActive_; static volatile bool rigIsRxActive_;
static volatile bool rigIsRxIsrEnabled_; static volatile bool rigIsRxIsrEnabled_;
bool rigIsImplicitMode_; bool rigIsImplicitMode_;

Wyświetl plik

@ -367,6 +367,7 @@ void Service::loop()
if (config_.TlmEnable) { if (config_.TlmEnable) {
telemetryTimer_.tick(); telemetryTimer_.tick();
} }
startRxTimer_.tick();
} }
ICACHE_RAM_ATTR void Service::onRigIsrRxPacket() { ICACHE_RAM_ATTR void Service::onRigIsrRxPacket() {
@ -388,9 +389,30 @@ void Service::rigTask(void *self) {
else if (commandBits & RadioTaskBits::Transmit) { else if (commandBits & RadioTaskBits::Transmit) {
static_cast<Service*>(self)->onRigTaskTxPacket(); static_cast<Service*>(self)->onRigTaskTxPacket();
} }
if (commandBits & RadioTaskBits::StartReceive) {
static_cast<Service*>(self)->onRigTaskStartRx();
}
else if (commandBits & RadioTaskBits::StartTransmit) {
static_cast<Service*>(self)->onRigTaskStartTx();
}
} }
} }
void Service::onRigTaskStartRx() {
LOG_TRACE("onRigTaskStartRx");
if (config_.PttEnable) {
digitalWrite(config_.PttPin, LOW);
}
if (isHalfDuplex()) {
setFreq(config_.LoraFreqRx);
}
int state = rig_->startReceive();
if (state != RADIOLIB_ERR_NONE) {
LOG_ERROR("Start receive error: ", state);
}
rigIsRxIsrEnabled_ = true;
}
void Service::onRigTaskRxPacket() { void Service::onRigTaskRxPacket() {
int packetSize = rig_->getPacketLength(); int packetSize = rig_->getPacketLength();
LOG_TRACE("onRigTaskRxPacket", packetSize); LOG_TRACE("onRigTaskRxPacket", packetSize);
@ -411,15 +433,21 @@ void Service::onRigTaskRxPacket() {
rigIsRxActive_ = false; rigIsRxActive_ = false;
} }
void Service::onRigTaskTxPacket() { void Service::onRigTaskStartTx() {
rigIsRxIsrEnabled_ = false; LOG_TRACE("onRigTaskStartTx");
if (isHalfDuplex()) { if (rigIsRxIsrEnabled_) {
setFreq(config_.LoraFreqTx); rigIsRxIsrEnabled_ = false;
} if (isHalfDuplex()) {
if (config_.PttEnable) { setFreq(config_.LoraFreqTx);
digitalWrite(config_.PttPin, HIGH); }
if (config_.PttEnable) {
digitalWrite(config_.PttPin, HIGH);
}
delay(config_.PttTxDelayMs); delay(config_.PttTxDelayMs);
} }
}
void Service::onRigTaskTxPacket() {
while (rigTxQueueIndex_.size() > 0) { while (rigTxQueueIndex_.size() > 0) {
int txPacketSize = rigTxQueueIndex_.shift(); int txPacketSize = rigTxQueueIndex_.shift();
LOG_TRACE("onRigTaskTxPacket", txPacketSize); LOG_TRACE("onRigTaskTxPacket", txPacketSize);
@ -435,18 +463,7 @@ void Service::onRigTaskTxPacket() {
} }
vTaskDelay(1); vTaskDelay(1);
} }
if (config_.PttEnable) { startRxTimer_.in(config_.PttTxTailMs, &startRxTimer);
delay(config_.PttTxTailMs);
digitalWrite(config_.PttPin, LOW);
}
if (isHalfDuplex()) {
setFreq(config_.LoraFreqRx);
}
int state = rig_->startReceive();
if (state != RADIOLIB_ERR_NONE) {
LOG_ERROR("Start receive error: ", state);
}
rigIsRxIsrEnabled_ = true;
} }
void Service::sendPeriodicBeacon() void Service::sendPeriodicBeacon()
@ -528,6 +545,16 @@ bool Service::sendModemTelemetryTimer(void *param)
return true; return true;
} }
bool Service::startRxTimer(void *param)
{
static_cast<Service*>(param)->startRx();
return true;
}
void Service::startRx() {
xTaskNotify(rigTaskHandle_, RadioTaskBits::StartReceive, eSetBits);
}
void Service::sendModemTelemetry() void Service::sendModemTelemetry()
{ {
float batVoltage = 2 * analogRead(config_.TlmBatMonPin) * (3.3 / 4096.0) + config_.TlmBatMonCal; float batVoltage = 2 * analogRead(config_.TlmBatMonPin) * (3.3 / 4096.0) + config_.TlmBatMonCal;
@ -591,10 +618,6 @@ void Service::performFrequencyCorrection() {
void Service::setFreq(long loraFreq) const { void Service::setFreq(long loraFreq) const {
rig_->setFrequency((float)loraFreq / 1e6); rig_->setFrequency((float)loraFreq / 1e6);
int state = rig_->startReceive();
if (state != RADIOLIB_ERR_NONE) {
LOG_ERROR("Start receive error:", state);
}
} }
void Service::processIncomingRawPacketAsServer(const byte *packet, int packetLength) { void Service::processIncomingRawPacketAsServer(const byte *packet, int packetLength) {
@ -650,6 +673,8 @@ void Service::processIncomingRawPacketAsServer(const byte *packet, int packetLen
bool Service::onRigTxBegin() bool Service::onRigTxBegin()
{ {
LOG_TRACE("onRigTxBegin"); LOG_TRACE("onRigTxBegin");
startRxTimer_.cancel();
xTaskNotify(rigTaskHandle_, RadioTaskBits::StartTransmit, eSetBits);
rigCurrentTxPacketSize_ = 0; rigCurrentTxPacketSize_ = 0;
return true; return true;
} }

Wyświetl plik

@ -17,7 +17,7 @@
#include "loraprs_service.h" #include "loraprs_service.h"
const int CfgPollDelayMs = 20; // main loop delay const int CfgPollDelayMs = 10; // main loop delay
/* /*
* Initialize config from config.h options. * Initialize config from config.h options.