@@ -367,6 +367,7 @@ void Service::loop()
367367 if (config_.TlmEnable ) {
368368 telemetryTimer_.tick ();
369369 }
370+ startRxTimer_.tick ();
370371}
371372
372373ICACHE_RAM_ATTR void Service::onRigIsrRxPacket () {
@@ -388,9 +389,30 @@ void Service::rigTask(void *self) {
388389 else if (commandBits & RadioTaskBits::Transmit) {
389390 static_cast <Service*>(self)->onRigTaskTxPacket ();
390391 }
392+ if (commandBits & RadioTaskBits::StartReceive) {
393+ static_cast <Service*>(self)->onRigTaskStartRx ();
394+ }
395+ else if (commandBits & RadioTaskBits::StartTransmit) {
396+ static_cast <Service*>(self)->onRigTaskStartTx ();
397+ }
391398 }
392399}
393400
401+ void Service::onRigTaskStartRx () {
402+ LOG_TRACE (" onRigTaskStartRx" );
403+ if (config_.PttEnable ) {
404+ digitalWrite (config_.PttPin , LOW);
405+ }
406+ if (isHalfDuplex ()) {
407+ setFreq (config_.LoraFreqRx );
408+ }
409+ int state = rig_->startReceive ();
410+ if (state != RADIOLIB_ERR_NONE) {
411+ LOG_ERROR (" Start receive error: " , state);
412+ }
413+ rigIsRxIsrEnabled_ = true ;
414+ }
415+
394416void Service::onRigTaskRxPacket () {
395417 int packetSize = rig_->getPacketLength ();
396418 LOG_TRACE (" onRigTaskRxPacket" , packetSize);
@@ -411,15 +433,21 @@ void Service::onRigTaskRxPacket() {
411433 rigIsRxActive_ = false ;
412434}
413435
414- void Service::onRigTaskTxPacket () {
415- rigIsRxIsrEnabled_ = false ;
416- if (isHalfDuplex ()) {
417- setFreq (config_.LoraFreqTx );
418- }
419- if (config_.PttEnable ) {
420- digitalWrite (config_.PttPin , HIGH);
436+ void Service::onRigTaskStartTx () {
437+ LOG_TRACE (" onRigTaskStartTx" );
438+ if (rigIsRxIsrEnabled_) {
439+ rigIsRxIsrEnabled_ = false ;
440+ if (isHalfDuplex ()) {
441+ setFreq (config_.LoraFreqTx );
442+ }
443+ if (config_.PttEnable ) {
444+ digitalWrite (config_.PttPin , HIGH);
445+ }
421446 delay (config_.PttTxDelayMs );
422447 }
448+ }
449+
450+ void Service::onRigTaskTxPacket () {
423451 while (rigTxQueueIndex_.size () > 0 ) {
424452 int txPacketSize = rigTxQueueIndex_.shift ();
425453 LOG_TRACE (" onRigTaskTxPacket" , txPacketSize);
@@ -435,18 +463,7 @@ void Service::onRigTaskTxPacket() {
435463 }
436464 vTaskDelay (1 );
437465 }
438- if (config_.PttEnable ) {
439- delay (config_.PttTxTailMs );
440- digitalWrite (config_.PttPin , LOW);
441- }
442- if (isHalfDuplex ()) {
443- setFreq (config_.LoraFreqRx );
444- }
445- int state = rig_->startReceive ();
446- if (state != RADIOLIB_ERR_NONE) {
447- LOG_ERROR (" Start receive error: " , state);
448- }
449- rigIsRxIsrEnabled_ = true ;
466+ startRxTimer_.in (config_.PttTxTailMs , &startRxTimer);
450467}
451468
452469void Service::sendPeriodicBeacon ()
@@ -528,6 +545,16 @@ bool Service::sendModemTelemetryTimer(void *param)
528545 return true ;
529546}
530547
548+ bool Service::startRxTimer (void *param)
549+ {
550+ static_cast <Service*>(param)->startRx ();
551+ return true ;
552+ }
553+
554+ void Service::startRx () {
555+ xTaskNotify (rigTaskHandle_, RadioTaskBits::StartReceive, eSetBits);
556+ }
557+
531558void Service::sendModemTelemetry ()
532559{
533560 float batVoltage = 2 * analogRead (config_.TlmBatMonPin ) * (3.3 / 4096.0 ) + config_.TlmBatMonCal ;
@@ -591,10 +618,6 @@ void Service::performFrequencyCorrection() {
591618
592619void Service::setFreq (long loraFreq) const {
593620 rig_->setFrequency ((float )loraFreq / 1e6 );
594- int state = rig_->startReceive ();
595- if (state != RADIOLIB_ERR_NONE) {
596- LOG_ERROR (" Start receive error:" , state);
597- }
598621}
599622
600623void Service::processIncomingRawPacketAsServer (const byte *packet, int packetLength) {
@@ -650,6 +673,8 @@ void Service::processIncomingRawPacketAsServer(const byte *packet, int packetLen
650673bool Service::onRigTxBegin ()
651674{
652675 LOG_TRACE (" onRigTxBegin" );
676+ startRxTimer_.cancel ();
677+ xTaskNotify (rigTaskHandle_, RadioTaskBits::StartTransmit, eSetBits);
653678 rigCurrentTxPacketSize_ = 0 ;
654679 return true ;
655680}
0 commit comments