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

More cleanup

This commit is contained in:
Peter Antypas 2016-06-02 11:48:17 -07:00
parent ec3c02f093
commit b0115b9c4a
8 changed files with 60 additions and 61 deletions

View File

@ -20,7 +20,7 @@ typedef enum {
GPS_FIX_EVENT = 2, // The GPS obtained a fix. GPS_FIX_EVENT = 2, // The GPS obtained a fix.
CLOCK_EVENT = 4, // One pulse per second as triggered by GPS. This is a convenient 1 Hz "wall" clock, as it carries UTC. CLOCK_EVENT = 4, // One pulse per second as triggered by GPS. This is a convenient 1 Hz "wall" clock, as it carries UTC.
AIS_PACKET_EVENT = 8, // A packet was just decoded (not necessarily valid, must still be CRC checked, etc) AIS_PACKET_EVENT = 8, // A packet was just decoded (not necessarily valid, must still be CRC checked, etc)
PACKET_SENT_EVENT = 16, INTERROGATION_EVENT = 16,
DEBUG_EVENT = 32, DEBUG_EVENT = 32,
KEYPRESS_EVENT = 64 KEYPRESS_EVENT = 64
//GPS_ERROR_EVENT = 64, // A GPS failure //GPS_ERROR_EVENT = 64, // A GPS failure

View File

@ -17,11 +17,11 @@ EventPool &EventPool::instance()
void EventPool::init() void EventPool::init()
{ {
mAISPacketPool = new ObjectPool<AISPacketEvent>(20); mGenericPool = new ObjectPool<Event>(10);
mAISPacketPool = new ObjectPool<AISPacketEvent>(40);
mGPSNMEAPool = new ObjectPool<GPSNMEASentence>(20); mGPSNMEAPool = new ObjectPool<GPSNMEASentence>(20);
mGPSFixPool = new ObjectPool<GPSFIXEvent>(10); mGPSFixPool = new ObjectPool<GPSFIXEvent>(10);
mClockPool = new ObjectPool<ClockEvent>(10); mClockPool = new ObjectPool<ClockEvent>(10);
mAISPacketSentPool = new ObjectPool<AISPacketSentEvent>(5);
mDebugEventPool = new ObjectPool<DebugEvent>(2); mDebugEventPool = new ObjectPool<DebugEvent>(2);
mKeyPressPool = new ObjectPool<KeyPressEvent>(20); mKeyPressPool = new ObjectPool<KeyPressEvent>(20);
} }
@ -43,10 +43,6 @@ Event *EventPool::newEvent(EventType type)
result = mAISPacketPool->get(); result = mAISPacketPool->get();
break; break;
} }
case PACKET_SENT_EVENT: {
result = mAISPacketSentPool->get();
break;
}
case DEBUG_EVENT: { case DEBUG_EVENT: {
result = mDebugEventPool->get(); result = mDebugEventPool->get();
break; break;
@ -56,7 +52,9 @@ Event *EventPool::newEvent(EventType type)
break; break;
} }
default: default:
result = NULL; result = mGenericPool->get();
result->mType = type;
break;
} }
if ( result ) if ( result )
@ -89,11 +87,6 @@ void EventPool::deleteEvent(Event *event)
mAISPacketPool->put(p); mAISPacketPool->put(p);
break; break;
} }
case PACKET_SENT_EVENT: {
AISPacketSentEvent *p = static_cast<AISPacketSentEvent*>(event);
mAISPacketSentPool->put(p);
break;
}
case DEBUG_EVENT: { case DEBUG_EVENT: {
DebugEvent *e = static_cast<DebugEvent*>(event); DebugEvent *e = static_cast<DebugEvent*>(event);
mDebugEventPool->put(e); mDebugEventPool->put(e);
@ -105,6 +98,7 @@ void EventPool::deleteEvent(Event *event)
break; break;
} }
default: default:
mGenericPool->put(event);
break; break;
} }
} }

View File

@ -25,13 +25,29 @@ using namespace std;
*/ */
class Event class Event
{ {
friend class EventPool;
public: public:
Event () {}; Event()
virtual ~Event () {}; : mType(UNKNOWN_EVENT) {
virtual void prepare() {} }
virtual void clear() {}
virtual EventType type() = 0; Event (EventType type): mType(type) {
}
virtual ~Event () {
}
virtual void prepare() {
}
virtual void clear() {
}
virtual EventType type() {
return mType;
}
protected:
EventType mType;
}; };
/* /*
@ -48,19 +64,18 @@ public:
class GPSNMEASentence : public Event class GPSNMEASentence : public Event
{ {
public: public:
EventType type() { GPSNMEASentence()
return GPS_NMEA_SENTENCE; : Event(GPS_NMEA_SENTENCE){
} }
char mSentence[100]; char mSentence[100];
}; };
class GPSFIXEvent: public Event class GPSFIXEvent: public Event
{ {
public: public:
EventType type() { GPSFIXEvent()
return GPS_FIX_EVENT; : Event(GPS_FIX_EVENT) {
} }
time_t mUTC; time_t mUTC;
@ -73,20 +88,22 @@ public:
class ClockEvent : public Event class ClockEvent : public Event
{ {
public: public:
EventType type() { ClockEvent()
return CLOCK_EVENT; : Event(CLOCK_EVENT) {
} }
time_t mTime; time_t mTime;
}; };
class AISPacketEvent: public Event class AISPacketEvent: public Event
{ {
public: public:
EventType type() { AISPacketEvent()
return AIS_PACKET_EVENT; : Event(AIS_PACKET_EVENT) {
} }
void prepare() void prepare()
{ {
//mPacket = RXPacketPool::instance().newRXPacket(); //mPacket = RXPacketPool::instance().newRXPacket();
@ -102,23 +119,12 @@ public:
RXPacket *mPacket; RXPacket *mPacket;
}; };
class AISPacketSentEvent : public Event
{
public:
EventType type() {
return PACKET_SENT_EVENT;
}
uint8_t mChannel;
uint16_t mSize;
};
class DebugEvent: public Event class DebugEvent: public Event
{ {
public: public:
EventType type() { DebugEvent()
return DEBUG_EVENT; : Event(DEBUG_EVENT) {
} }
char mBuffer[256]; char mBuffer[256];
@ -127,10 +133,11 @@ public:
class KeyPressEvent : public Event class KeyPressEvent : public Event
{ {
public: public:
EventType type() { KeyPressEvent()
return KEYPRESS_EVENT; : Event(KEYPRESS_EVENT) {
} }
char key; char key;
}; };
@ -144,11 +151,11 @@ public:
void deleteEvent(Event *event); void deleteEvent(Event *event);
private: private:
ObjectPool<Event> *mGenericPool;
ObjectPool<AISPacketEvent> *mAISPacketPool; ObjectPool<AISPacketEvent> *mAISPacketPool;
ObjectPool<GPSNMEASentence> *mGPSNMEAPool; ObjectPool<GPSNMEASentence> *mGPSNMEAPool;
ObjectPool<GPSFIXEvent> *mGPSFixPool; ObjectPool<GPSFIXEvent> *mGPSFixPool;
ObjectPool<ClockEvent> *mClockPool; ObjectPool<ClockEvent> *mClockPool;
ObjectPool<AISPacketSentEvent> *mAISPacketSentPool;
ObjectPool<DebugEvent> *mDebugEventPool; ObjectPool<DebugEvent> *mDebugEventPool;
ObjectPool<KeyPressEvent> *mKeyPressPool; ObjectPool<KeyPressEvent> *mKeyPressPool;
}; };

View File

@ -25,7 +25,7 @@ NMEAEncoder::~NMEAEncoder()
{ {
} }
void NMEAEncoder::encode(RXPacket &packet, list<string> &sentences) void NMEAEncoder::encode(RXPacket &packet, vector<string> &sentences)
{ {
static uint16_t MAX_SENTENCE_BYTES = 56; static uint16_t MAX_SENTENCE_BYTES = 56;
static uint16_t MAX_SENTENCE_BITS = MAX_SENTENCE_BYTES * 6; static uint16_t MAX_SENTENCE_BITS = MAX_SENTENCE_BYTES * 6;

View File

@ -8,7 +8,7 @@
#ifndef NMEAENCODER_HPP_ #ifndef NMEAENCODER_HPP_
#define NMEAENCODER_HPP_ #define NMEAENCODER_HPP_
#include <list> #include <vector>
#include <string> #include <string>
#include "RXPacket.hpp" #include "RXPacket.hpp"
using namespace std; using namespace std;
@ -20,7 +20,7 @@ public:
NMEAEncoder(); NMEAEncoder();
virtual ~NMEAEncoder(); virtual ~NMEAEncoder();
void encode(RXPacket &packet, list<string> &sentences); void encode(RXPacket &packet, vector<string> &sentences);
private: private:
uint8_t nmeaCRC(const char* buff); uint8_t nmeaCRC(const char* buff);
private: private:

View File

@ -20,6 +20,8 @@
RXPacketProcessor::RXPacketProcessor () RXPacketProcessor::RXPacketProcessor ()
: mLastDumpTime(0), mGoodCount(0), mBadCRCCount(0), mInvalidCount(0), mLat(-200), mLng(-200) : mLastDumpTime(0), mGoodCount(0), mBadCRCCount(0), mInvalidCount(0), mLat(-200), mLng(-200)
{ {
mSentences.reserve(4); // We're not going to need more than 2 sentences for the longest AIS message we report ...
EEPROM::instance().readStationData(mStationData);
EventQueue::instance().addObserver(this, AIS_PACKET_EVENT | CLOCK_EVENT | GPS_FIX_EVENT); EventQueue::instance().addObserver(this, AIS_PACKET_EVENT | CLOCK_EVENT | GPS_FIX_EVENT);
} }
@ -67,7 +69,6 @@ void RXPacketProcessor::processEvent(Event *e)
if (pe->mPacket->checkCRC ()) { if (pe->mPacket->checkCRC ()) {
++mGoodCount; ++mGoodCount;
list<string> sentences;
mUniqueMMSIs.insert (pe->mPacket->mmsi ()); mUniqueMMSIs.insert (pe->mPacket->mmsi ());
switch (pe->mPacket->messageType ()) { switch (pe->mPacket->messageType ()) {
@ -121,17 +122,16 @@ void RXPacketProcessor::processEvent(Event *e)
} }
#ifdef ENABLE_TERMINAL #ifdef ENABLE_TERMINAL
mEncoder.encode (*pe->mPacket, sentences); mSentences.clear();
for (list<string>::iterator i = sentences.begin (); mEncoder.encode(*pe->mPacket, mSentences);
i != sentences.end (); ++i) { for (vector<string>::iterator i = mSentences.begin(); i != mSentences.end(); ++i) {
DataTerminal::instance ().write (i->c_str ()); DataTerminal::instance().write(i->c_str());
DataTerminal::instance ().write ("\r\n"); DataTerminal::instance().write("\r\n");
} }
#endif #endif
// TODO: Move this out of here switch (pe->mPacket->messageType()) {
switch (pe->mPacket->messageType ()) {
case 15: case 15:
// TODO: This is an interrogation. Check if we are any of the 3 possible recipients and respond with message 18 // TODO: This is an interrogation. If we are a target, push an appropriate event into the queue
break; break;
case 20: case 20:
// TODO: This is a time slot reservation from a base station. Possibly use this information to augment CCA? // TODO: This is a time slot reservation from a base station. Possibly use this information to augment CCA?

View File

@ -11,7 +11,8 @@
#include "Events.hpp" #include "Events.hpp"
#include "NMEAEncoder.hpp" #include "NMEAEncoder.hpp"
#include <set> #include <set>
#include "EEPROM.hpp"
#include <vector>
class RXPacketProcessor : public EventConsumer class RXPacketProcessor : public EventConsumer
{ {
@ -30,6 +31,8 @@ private:
double mLat; double mLat;
double mLng; double mLng;
std::set<uint32_t> mUniqueMMSIs; std::set<uint32_t> mUniqueMMSIs;
std::vector<std::string> mSentences;
StationData mStationData;
}; };
#endif /* RXPACKETPROCESSOR_HPP_ */ #endif /* RXPACKETPROCESSOR_HPP_ */

View File

@ -46,7 +46,6 @@ void TXScheduler::startTXTesting()
void TXScheduler::processEvent(Event *event) void TXScheduler::processEvent(Event *event)
{ {
//printf2("-> TXScheduler::processEvent()\r\n");
#ifndef ENABLE_TX #ifndef ENABLE_TX
return; return;
#endif #endif
@ -56,9 +55,6 @@ void TXScheduler::processEvent(Event *event)
if ( mTesting ) if ( mTesting )
return; return;
//if ( Radio::instance().isCalibratingRSSI() )
// return;
GPSFIXEvent *gfe = static_cast<GPSFIXEvent*> (event); GPSFIXEvent *gfe = static_cast<GPSFIXEvent*> (event);
//printf2("UTC: %d\r\n", mUTC); //printf2("UTC: %d\r\n", mUTC);
@ -132,7 +128,6 @@ void TXScheduler::processEvent(Event *event)
break; break;
} }
//printf2("<- TXScheduler::processEvent()\r\n");
} }
void TXScheduler::scheduleTestPacket() void TXScheduler::scheduleTestPacket()