mirror of
https://github.com/peterantypas/maiana.git
synced 2025-05-28 05:10:40 -07:00
Better way to mange TX LED
This commit is contained in:
parent
91dfe55754
commit
a4f3add396
@ -25,7 +25,7 @@ public:
|
||||
void startTXTesting();
|
||||
void queueMessage18(VHFChannel channel);
|
||||
void queueMessage24(VHFChannel channel);
|
||||
|
||||
bool isTXAllowed();
|
||||
private:
|
||||
TXScheduler ();
|
||||
virtual ~TXScheduler ();
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "LEDManager.hpp"
|
||||
#include "bsp.hpp"
|
||||
#include "Configuration.hpp"
|
||||
#include "TXScheduler.hpp"
|
||||
|
||||
|
||||
LEDManager::LEDManager()
|
||||
{
|
||||
@ -37,17 +39,8 @@ void tickCB()
|
||||
LEDManager::instance().onTick();
|
||||
}
|
||||
|
||||
static bool mForceTXLedOff = false;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -61,11 +54,13 @@ void LEDManager::onTick()
|
||||
bsp_rx_led_off();
|
||||
}
|
||||
|
||||
|
||||
if ( !mForceTXLedOff && count2++ == 250 )
|
||||
if ( count2++ == 250 )
|
||||
{
|
||||
count2 = 1;
|
||||
bsp_tx_led_off();
|
||||
if ( !TXScheduler::instance().isTXAllowed() )
|
||||
bsp_tx_led_off();
|
||||
else
|
||||
bsp_tx_led_on();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
// If we don't have valid station data we don't do anything
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "AISChannels.h"
|
||||
#include "bsp.hpp"
|
||||
#include <stdio.h>
|
||||
#include "TXScheduler.hpp"
|
||||
|
||||
|
||||
Transceiver::Transceiver(GPIO_TypeDef *sdnPort, uint32_t sdnPin, GPIO_TypeDef *csPort,
|
||||
uint32_t csPin, GPIO_TypeDef *dataPort, uint32_t dataPin,
|
||||
@ -190,16 +192,11 @@ void Transceiver::onBitClock()
|
||||
/*
|
||||
We start transmitting a packet if:
|
||||
- We have a TX packet assigned
|
||||
- Transmission is enabled
|
||||
- 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 RSSI is within 6dB of the noise floor for this channel
|
||||
- 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 )
|
||||
@ -211,6 +208,12 @@ void Transceiver::onBitClock()
|
||||
// Test packets are sent immediately. Presumably, we're firing into a dummy load ;)
|
||||
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 )
|
||||
{
|
||||
// The packet is way too old. Discard it.
|
||||
@ -219,6 +222,7 @@ void Transceiver::onBitClock()
|
||||
}
|
||||
else if ( mUTC - mLastTXTime < MIN_TX_INTERVAL )
|
||||
{
|
||||
// Got to wait a bit ...
|
||||
return;
|
||||
}
|
||||
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());
|
||||
Utils::completeNMEA(e->nmeaBuffer.sentence);
|
||||
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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user