1
0
mirror of https://github.com/peterantypas/maiana.git synced 2025-05-28 05:10:40 -07:00

Working, push is 4x faster

This commit is contained in:
Peter Antypas 2020-11-02 13:38:52 -08:00
parent 8480817518
commit 23edf89502
14 changed files with 81 additions and 50 deletions

View File

@ -49,7 +49,7 @@ public:
/*
* We push events here to be processed by the dispatching task
*/
void push(const Event &event);
void push(Event *event);
/*
* This method must be called repeatedly by an RTOS task or main() (never an ISR)

View File

@ -108,7 +108,7 @@ public:
virtual void processEvent(const Event &event)=0;
};
#if 0
#if 1
class EventPool
{
public:

View File

@ -64,7 +64,7 @@
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 7 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)16384)
#define configTOTAL_HEAP_SIZE ((size_t)20480)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 0

View File

@ -66,8 +66,11 @@ void Configuration::reportStationData()
if ( !readStationData(d) )
memset(&d, 0, sizeof d);
Event e(PROPR_NMEA_SENTENCE);
sprintf(e.nmeaBuffer.sentence,
Event *e = EventPool::instance().newEvent(PROPR_NMEA_SENTENCE);
if ( !e )
return;
sprintf(e->nmeaBuffer.sentence,
"$PAISTN,%lu,%s,%s,%d,%d,%d,%d,%d*",
d.mmsi,
d.name,
@ -77,7 +80,7 @@ void Configuration::reportStationData()
d.beam,
d.portOffset,
d.bowOffset);
Utils::completeNMEA(e.nmeaBuffer.sentence);
Utils::completeNMEA(e->nmeaBuffer.sentence);
EventQueue::instance().push(e);
}

View File

@ -111,8 +111,8 @@ void termInputCB(char c)
else if ( c == '\n' )
{
__rxbuff[__rxpos++] = 0;
Event e(COMMAND_EVENT);
strncpy(e.command.buffer, __rxbuff, sizeof e.command.buffer);
Event *e = EventPool::instance().newEvent(COMMAND_EVENT);
strncpy(e->command.buffer, __rxbuff, sizeof e->command.buffer);
EventQueue::instance().push(e);
}
}

View File

@ -29,9 +29,9 @@
#include "task.h"
#include "bsp.hpp"
#define EVENT_QUEUE_SIZE 50
#define EVENT_QUEUE_SIZE 80
static Event __queue[EVENT_QUEUE_SIZE];
static Event* __queue[EVENT_QUEUE_SIZE];
EventQueue &EventQueue::instance()
{
@ -45,11 +45,11 @@ EventQueue::EventQueue()
void EventQueue::init()
{
mQueueHandle = xQueueCreateStatic(EVENT_QUEUE_SIZE, sizeof(Event), (uint8_t*)&__queue[0], &mQueue);
mQueueHandle = xQueueCreateStatic(EVENT_QUEUE_SIZE, sizeof(Event*), (uint8_t*)&__queue[0], &mQueue);
configASSERT(mQueueHandle);
}
void EventQueue::push(const Event &e)
void EventQueue::push(Event *e)
{
if ( xTaskGetSchedulerState() != taskSCHEDULER_RUNNING )
return;
@ -87,18 +87,19 @@ void EventQueue::removeObserver(EventConsumer *c)
void EventQueue::dispatch()
{
Event e;
Event *e = nullptr;
while ( xQueueReceive(mQueueHandle, &e, 10) == pdTRUE )
{
for ( map<EventConsumer*, uint32_t>::iterator c = mConsumers.begin(); c != mConsumers.end(); ++c )
{
if ( c->second & e.type )
if ( c->second & e->type )
{
c->first->processEvent(e);
c->first->processEvent(*e);
}
}
EventPool::instance().deleteEvent(e);
}
}

View File

@ -21,7 +21,7 @@
#include "Events.hpp"
#include "printf_serial.h"
#if 0
#if 1
EventPool &EventPool::instance()
{
static EventPool __instance;
@ -30,7 +30,7 @@ EventPool &EventPool::instance()
void EventPool::init()
{
mISRPool = new ObjectPool<Event>(40);
mISRPool = new ObjectPool<Event>(25);
mThreadPool = new ObjectPool<Event>(10);
}

View File

@ -112,9 +112,12 @@ void GPS::onRX(char c)
else if (c == '\n')
{
mBuff[mBuffPos] = 0;
Event event(GPS_NMEA_SENTENCE);
strncpy(event.nmeaBuffer.sentence, mBuff, sizeof event.nmeaBuffer.sentence);
EventQueue::instance ().push(event);
Event *e = EventPool::instance().newEvent(GPS_NMEA_SENTENCE);
if ( e )
{
strncpy(e->nmeaBuffer.sentence, mBuff, sizeof e->nmeaBuffer.sentence);
EventQueue::instance ().push(e);
}
mBuffPos = 0;
mBuff[mBuffPos] = 0;
}
@ -168,9 +171,12 @@ void GPS::onPPS()
}
}
Event event(CLOCK_EVENT);
event.clock.utc = mUTC;
EventQueue::instance ().push(event);
Event *e = EventPool::instance().newEvent(CLOCK_EVENT);
if ( e )
{
e->clock.utc = mUTC;
EventQueue::instance ().push(e);
}
}
@ -253,13 +259,17 @@ void GPS::parseSentence(const char *buff)
mLng = Utils::longitudeFromNMEA (sentence.fields()[5], sentence.fields()[6]);
mSpeed = atof(sentence.fields()[7].c_str());
mCOG = atof(sentence.fields()[8].c_str());
Event event(GPS_FIX_EVENT);
event.gpsFix.utc = mUTC;
event.gpsFix.lat = mLat;
event.gpsFix.lng = mLng;
event.gpsFix.speed = mSpeed;
event.gpsFix.cog = mCOG;
EventQueue::instance().push (event);
Event *e = EventPool::instance().newEvent(GPS_FIX_EVENT);
if ( e )
{
Event &event = *e;
event.gpsFix.utc = mUTC;
event.gpsFix.lat = mLat;
event.gpsFix.lng = mLng;
event.gpsFix.speed = mSpeed;
event.gpsFix.cog = mCOG;
EventQueue::instance().push (e);
}
}
}
}

View File

@ -147,14 +147,20 @@ uint8_t NoiseFloorDetector::medianValue(ChannelReadings &window)
void NoiseFloorDetector::dump()
{
Event e(PROPR_NMEA_SENTENCE);
Event *e = EventPool::instance().newEvent(PROPR_NMEA_SENTENCE);
if ( !e )
return;
sprintf(e.nmeaBuffer.sentence, "$PAINF,A,0x%.2x*", mChannelACurrent);
Utils::completeNMEA(e.nmeaBuffer.sentence);
sprintf(e->nmeaBuffer.sentence, "$PAINF,A,0x%.2x*", mChannelACurrent);
Utils::completeNMEA(e->nmeaBuffer.sentence);
EventQueue::instance().push(e);
sprintf(e.nmeaBuffer.sentence, "$PAINF,B,0x%.2x*", mChannelBCurrent);
Utils::completeNMEA(e.nmeaBuffer.sentence);
e = EventPool::instance().newEvent(PROPR_NMEA_SENTENCE);
if ( !e )
return;
sprintf(e->nmeaBuffer.sentence, "$PAINF,B,0x%.2x*", mChannelBCurrent);
Utils::completeNMEA(e->nmeaBuffer.sentence);
EventQueue::instance().push(e);
}

View File

@ -76,12 +76,14 @@ void RXPacketProcessor::processEvent(const Event &e)
case 18:
case 24:
{
#if 0
Event ie(INTERROGATION_EVENT);
ie.interrogation.channel = e.rxPacket.channel();
ie.interrogation.messageType = target.messageType;
//printf2("Scheduling message %d in response to interrogation\r\n", ie->interrogation.messageType);
EventQueue::instance().push(ie);
#endif
break;
}
default:

View File

@ -245,14 +245,19 @@ bool Receiver::addBit(uint8_t bit)
void Receiver::pushPacket()
{
bsp_signal_high();
#ifndef TX_TEST_MODE
Event p(AIS_PACKET_EVENT);
p.rxPacket = mRXPacket;
Event *p = EventPool::instance().newEvent(AIS_PACKET_EVENT);
if ( p )
{
p->rxPacket = mRXPacket;
EventQueue::instance().push(p);
}
mRXPacket.reset();
EventQueue::instance().push(p);
#else
mRXPacket.reset();
#endif
bsp_signal_low();
}
uint8_t Receiver::reportRSSI()

View File

@ -351,10 +351,11 @@ void Transceiver::configureGPIOsForRX()
void Transceiver::reportTXEvent()
{
Event e(PROPR_NMEA_SENTENCE);
Event *e = EventPool::instance().newEvent(PROPR_NMEA_SENTENCE);
if ( !e )
return;
snprintf(e.nmeaBuffer.sentence, sizeof e.nmeaBuffer.sentence, "$PAITX,%c,%s*", AIS_CHANNELS[mTXPacket->channel()].designation, mTXPacket->messageType());
Utils::completeNMEA(e.nmeaBuffer.sentence);
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);
}

View File

@ -52,6 +52,7 @@ void jump_to_bootloader()
void mainTask(void *params)
{
EventPool::instance().init();
EventQueue::instance().init();
Configuration::instance().init();
CommandProcessor::instance().init();

View File

@ -15,7 +15,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
*/
*/
#include <stdio.h>
@ -50,14 +50,16 @@ void printf_serial(const char *format, ...)
{
if ( Utils::inISR() )
{
Event e(DEBUG_EVENT);
Event *e = EventPool::instance().newEvent(DEBUG_EVENT);
if ( e )
{
va_list list;
va_start(list, format);
vsnprintf(e->debugMessage.buffer, sizeof e->debugMessage, format, list);
va_end(list);
va_list list;
va_start(list, format);
vsnprintf(e.debugMessage.buffer, sizeof e.debugMessage, format, list);
va_end(list);
EventQueue::instance().push(e);
EventQueue::instance().push(e);
}
}
else
{