1
0
mirror of https://github.com/peterantypas/maiana.git synced 2025-05-31 23:00:16 -07:00

Better way to mange TX LED

This commit is contained in:
Peter Antypas 2021-10-04 14:38:04 -07:00
parent 91dfe55754
commit a4f3add396
4 changed files with 31 additions and 20 deletions

View File

@ -25,7 +25,7 @@ public:
void startTXTesting(); void startTXTesting();
void queueMessage18(VHFChannel channel); void queueMessage18(VHFChannel channel);
void queueMessage24(VHFChannel channel); void queueMessage24(VHFChannel channel);
bool isTXAllowed();
private: private:
TXScheduler (); TXScheduler ();
virtual ~TXScheduler (); virtual ~TXScheduler ();

View File

@ -20,6 +20,8 @@
#include "LEDManager.hpp" #include "LEDManager.hpp"
#include "bsp.hpp" #include "bsp.hpp"
#include "Configuration.hpp" #include "Configuration.hpp"
#include "TXScheduler.hpp"
LEDManager::LEDManager() LEDManager::LEDManager()
{ {
@ -37,17 +39,8 @@ void tickCB()
LEDManager::instance().onTick(); LEDManager::instance().onTick();
} }
static bool mForceTXLedOff = false;
void LEDManager::init() void LEDManager::init()
{ {
if ( !Configuration::instance().isStationDataProvisioned() )
{
mForceTXLedOff = true;
// This call actually has the opposite effect as it will cause the TX led to be pulled to GND
bsp_tx_led_on();
}
bsp_set_tick_callback(tickCB); bsp_set_tick_callback(tickCB);
} }
@ -61,11 +54,13 @@ void LEDManager::onTick()
bsp_rx_led_off(); bsp_rx_led_off();
} }
if ( count2++ == 250 )
if ( !mForceTXLedOff && count2++ == 250 )
{ {
count2 = 1; count2 = 1;
bsp_tx_led_off(); if ( !TXScheduler::instance().isTXAllowed() )
bsp_tx_led_off();
else
bsp_tx_led_on();
} }
} }

View File

@ -144,6 +144,16 @@ void TXScheduler::processEvent(const Event &e)
} }
/**
* This method may be called in EITHER thread OR interrupt context,
* so we keep it very lean ...
*/
bool TXScheduler::isTXAllowed()
{
return (mStationData.magic == STATION_DATA_MAGIC) && !bsp_is_tx_disabled();
}
void TXScheduler::queueMessage18(VHFChannel channel) void TXScheduler::queueMessage18(VHFChannel channel)
{ {
// If we don't have valid station data we don't do anything // If we don't have valid station data we don't do anything

View File

@ -26,6 +26,8 @@
#include "AISChannels.h" #include "AISChannels.h"
#include "bsp.hpp" #include "bsp.hpp"
#include <stdio.h> #include <stdio.h>
#include "TXScheduler.hpp"
Transceiver::Transceiver(GPIO_TypeDef *sdnPort, uint32_t sdnPin, GPIO_TypeDef *csPort, Transceiver::Transceiver(GPIO_TypeDef *sdnPort, uint32_t sdnPin, GPIO_TypeDef *csPort,
uint32_t csPin, GPIO_TypeDef *dataPort, uint32_t dataPin, uint32_t csPin, GPIO_TypeDef *dataPort, uint32_t dataPin,
@ -190,16 +192,11 @@ void Transceiver::onBitClock()
/* /*
We start transmitting a packet if: We start transmitting a packet if:
- We have a TX packet assigned - We have a TX packet assigned
- Transmission is enabled
- We are at bit CCA_SLOT_BIT+1 (after obtaining an RSSI level) - We are at bit CCA_SLOT_BIT+1 (after obtaining an RSSI level)
- The TX packet's transmission channel is our current listening channel - The TX packet's transmission channel is our current listening channel
- The RSSI is within 6dB of the noise floor for this channel - The RSSI is within 6dB of the noise floor for this channel
- It's been at least MIN_TX_INTERVAL seconds since our last transmission - It's been at least MIN_TX_INTERVAL seconds since our last transmission
With PCB revision 2.0 to 4.x:
- No TX packets are queued if the supercapacitor is not charged, so no need to check here.
With PCB revision >= 5.x:
- There is no supercapacitor anymore
*/ */
if ( !mTXPacket ) if ( !mTXPacket )
@ -211,6 +208,12 @@ void Transceiver::onBitClock()
// Test packets are sent immediately. Presumably, we're firing into a dummy load ;) // Test packets are sent immediately. Presumably, we're firing into a dummy load ;)
startTransmitting(); startTransmitting();
} }
else if ( !TXScheduler::instance().isTXAllowed() )
{
// Transmission has been disabled since scheduling, so don't transmit!
TXPacketPool::instance().deleteTXPacket(mTXPacket);
mTXPacket = NULL;
}
else if ( mUTC && mUTC - mTXPacket->timestamp() >= MIN_MSG_18_TX_INTERVAL ) else if ( mUTC && mUTC - mTXPacket->timestamp() >= MIN_MSG_18_TX_INTERVAL )
{ {
// The packet is way too old. Discard it. // The packet is way too old. Discard it.
@ -219,6 +222,7 @@ void Transceiver::onBitClock()
} }
else if ( mUTC - mLastTXTime < MIN_TX_INTERVAL ) else if ( mUTC - mLastTXTime < MIN_TX_INTERVAL )
{ {
// Got to wait a bit ...
return; return;
} }
else if ( mUTC && mSlotBitNumber == CCA_SLOT_BIT && mTXPacket->channel() == mChannel ) else if ( mUTC && mSlotBitNumber == CCA_SLOT_BIT && mTXPacket->channel() == mChannel )
@ -331,5 +335,7 @@ void Transceiver::reportTXEvent()
snprintf(e->nmeaBuffer.sentence, sizeof e->nmeaBuffer.sentence, "$PAITX,%c,%s*", AIS_CHANNELS[mTXPacket->channel()].designation, mTXPacket->messageType()); snprintf(e->nmeaBuffer.sentence, sizeof e->nmeaBuffer.sentence, "$PAITX,%c,%s*", AIS_CHANNELS[mTXPacket->channel()].designation, mTXPacket->messageType());
Utils::completeNMEA(e->nmeaBuffer.sentence); Utils::completeNMEA(e->nmeaBuffer.sentence);
EventQueue::instance().push(e); EventQueue::instance().push(e);
bsp_tx_led_on();
// We turn off the led and the LEDManager will turn it back on in 100ms or so
bsp_tx_led_off();
} }