From 6d889c93721f3b1d90cf2b00982639e57906fd6a Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 28 Dec 2022 08:34:58 +0100 Subject: [PATCH] #29 ad logging of DPRS --- Common/APRSCollector.cpp | 12 ++++++++---- Common/APRSCollector.h | 5 +++-- Common/APRSHandler.cpp | 13 +++++++------ Common/NMEASentenceCollector.cpp | 4 ++-- Common/SlowDataCollector.cpp | 20 +++++++++++++++----- Common/SlowDataCollector.h | 15 ++++++++++----- Common/SlowDataCollectorThrottle.cpp | 19 +++++++++++++++---- Common/SlowDataCollectorThrottle.h | 6 ++++-- 8 files changed, 64 insertions(+), 30 deletions(-) diff --git a/Common/APRSCollector.cpp b/Common/APRSCollector.cpp index afba4d0..83bd8af 100644 --- a/Common/APRSCollector.cpp +++ b/Common/APRSCollector.cpp @@ -51,10 +51,14 @@ CAPRSCollector::~CAPRSCollector() m_collectors.clear(); } -void CAPRSCollector::writeHeader(const std::string& callsign) +void CAPRSCollector::writeHeader(const CHeaderData& header) { + std::string mycall1 = header.getMyCall1(); + std::string mycall2 = header.getMyCall2(); + for(auto collector : m_collectors) { - collector->setMyCall(callsign); + collector->setMyCall1(mycall1); + collector->setMyCall2(mycall2); } } @@ -95,12 +99,12 @@ unsigned int CAPRSCollector::getData(unsigned char dataType, unsigned char* data return 0U; } -void CAPRSCollector::getData(std::function dataHandler) +void CAPRSCollector::getData(std::function dataHandler) { for(auto collector : m_collectors) { std::string data; if(collector->getData(data)) { - dataHandler(data); + dataHandler(data, collector->getMyCall1().append("/").append(collector->getMyCall2())); collector->reset(); } } diff --git a/Common/APRSCollector.h b/Common/APRSCollector.h index 2f955bf..8e9ae3a 100644 --- a/Common/APRSCollector.h +++ b/Common/APRSCollector.h @@ -24,6 +24,7 @@ #include #include "SlowDataCollector.h" +#include "HeaderData.h" #include "Defs.h" enum APRS_STATE { @@ -39,7 +40,7 @@ public: CAPRSCollector(); ~CAPRSCollector(); - void writeHeader(const std::string& callsign); + void writeHeader(const CHeaderData& callsign); bool writeData(const unsigned char* data); @@ -49,7 +50,7 @@ public: unsigned int getData(unsigned char dataType, unsigned char* data, unsigned int length); - void getData(std::function dataHandler); + void getData(std::function dataHandler); void clock(unsigned int ms); diff --git a/Common/APRSHandler.cpp b/Common/APRSHandler.cpp index c81a745..919bb13 100644 --- a/Common/APRSHandler.cpp +++ b/Common/APRSHandler.cpp @@ -22,7 +22,6 @@ #include #include #include - #include "StringUtils.h" #include "Log.h" #include "APRSHandler.h" @@ -89,7 +88,7 @@ void CAPRSHandler::writeHeader(const std::string& callsign, const CHeaderData& h CAPRSCollector* collector = entry->getCollector(); - collector->writeHeader(header.getMyCall1()); + collector->writeHeader(header); } void CAPRSHandler::writeData(const std::string& callsign, const CAMBEData& data) @@ -122,17 +121,17 @@ void CAPRSHandler::writeData(const std::string& callsign, const CAMBEData& data) return; } - collector->getData([=](const std::string& text) + collector->getData([=](const std::string& rawFrame, const std::string& dstarCall) { CAPRSFrame frame; - if(!CAPRSParser::parseFrame(text, frame)) { - CLog::logWarning("Failed to parse DPRS Frame : %s", text.c_str()); + if(!CAPRSParser::parseFrame(rawFrame, frame)) { + CLog::logWarning("Failed to parse DPRS Frame : %s", rawFrame.c_str()); return; } // If we already have a q-construct, don't send it on if(std::any_of(frame.getPath().begin(), frame.getPath().end(), [] (std::string s) { return !s.empty() && s[0] == 'q'; })) { - CLog::logWarning("DPRS Frame already has q construct, not forwarding to APRS-IS: %s", text.c_str()); + CLog::logWarning("DPRS Frame already has q construct, not forwarding to APRS-IS: %s", rawFrame.c_str()); return; } @@ -142,6 +141,8 @@ void CAPRSHandler::writeData(const std::string& callsign, const CAMBEData& data) std::string output ; CAPRSFormater::frameToString(output, frame); + CLog::logInfo("DPRS\t%s\t%s\t%s", dstarCall.c_str(), frame.getSource().c_str(), rawFrame.c_str()); + m_thread->write(frame); }); } diff --git a/Common/NMEASentenceCollector.cpp b/Common/NMEASentenceCollector.cpp index 87c5817..5136a61 100644 --- a/Common/NMEASentenceCollector.cpp +++ b/Common/NMEASentenceCollector.cpp @@ -98,14 +98,14 @@ unsigned int CNMEASentenceCollector::getDataInt(unsigned char * data, unsigned i bool CNMEASentenceCollector::getDataInt(std::string& data) { - if(getMyCall().empty() || getSentence().empty()) + if(getMyCall1().empty() || getSentence().empty()) return false; data.clear(); auto nmea = getSentence(); fixUpNMEATimeStamp(nmea); - std::string fromCall = getMyCall(); + std::string fromCall = getMyCall1(); CAPRSUtils::dstarCallsignToAPRS(fromCall); std::string aprsFrame(fromCall); aprsFrame.append("-5>GPS30,DSTAR*:") diff --git a/Common/SlowDataCollector.cpp b/Common/SlowDataCollector.cpp index b9caad0..55f38e7 100644 --- a/Common/SlowDataCollector.cpp +++ b/Common/SlowDataCollector.cpp @@ -27,7 +27,7 @@ const unsigned int SLOW_DATA_BLOCK_LENGTH = 6U; CSlowDataCollector::CSlowDataCollector(unsigned char slowDataType) : m_slowDataType(slowDataType), -m_myCall(), +m_myCall1(), m_state(SS_FIRST) { m_buffer = new unsigned char[SLOW_DATA_BLOCK_LENGTH]; @@ -39,14 +39,24 @@ CSlowDataCollector::~CSlowDataCollector() delete[] m_buffer; } -std::string CSlowDataCollector::getMyCall() const +std::string CSlowDataCollector::getMyCall1() const { - return m_myCall; + return m_myCall1; } -void CSlowDataCollector::setMyCall(const std::string& myCall) +void CSlowDataCollector::setMyCall1(const std::string& myCall) { - m_myCall = myCall; + m_myCall1 = myCall; +} + +std::string CSlowDataCollector::getMyCall2() const +{ + return m_myCall2; +} + +void CSlowDataCollector::setMyCall2(const std::string& myCall) +{ + m_myCall2 = myCall; } bool CSlowDataCollector::writeData(const unsigned char* data) diff --git a/Common/SlowDataCollector.h b/Common/SlowDataCollector.h index f2389f9..1f6c803 100644 --- a/Common/SlowDataCollector.h +++ b/Common/SlowDataCollector.h @@ -29,8 +29,10 @@ class ISlowDataCollector public: virtual ~ISlowDataCollector() { } ; - virtual std::string getMyCall() const = 0; - virtual void setMyCall(const std::string& mycall) = 0; + virtual std::string getMyCall1() const = 0; + virtual void setMyCall1(const std::string& mycall) = 0; + virtual std::string getMyCall2() const = 0; + virtual void setMyCall2(const std::string& mycall) = 0; virtual bool writeData(const unsigned char* data) = 0; virtual void sync() = 0; virtual unsigned int getData(unsigned char* data, unsigned int length) = 0; @@ -46,8 +48,10 @@ public: CSlowDataCollector(unsigned char slowDataType); virtual ~CSlowDataCollector(); - std::string getMyCall() const; - void setMyCall(const std::string& mycall); + std::string getMyCall1() const; + void setMyCall1(const std::string& mycall); + std::string getMyCall2() const; + void setMyCall2(const std::string& mycall); bool writeData(const unsigned char* data); void sync(); unsigned int getData(unsigned char* data, unsigned int length); @@ -64,7 +68,8 @@ protected: private: unsigned char m_slowDataType; - std::string m_myCall; + std::string m_myCall1; + std::string m_myCall2; SLOWDATA_STATE m_state; unsigned char * m_buffer; }; \ No newline at end of file diff --git a/Common/SlowDataCollectorThrottle.cpp b/Common/SlowDataCollectorThrottle.cpp index 8d97fe1..37e0f23 100644 --- a/Common/SlowDataCollectorThrottle.cpp +++ b/Common/SlowDataCollectorThrottle.cpp @@ -33,16 +33,27 @@ CSlowDataCollectorThrottle::~CSlowDataCollectorThrottle() delete m_collector; } -std::string CSlowDataCollectorThrottle::getMyCall() const +std::string CSlowDataCollectorThrottle::getMyCall1() const { - return m_collector->getMyCall(); + return m_collector->getMyCall1(); } -void CSlowDataCollectorThrottle::setMyCall(const std::string& mycall) +void CSlowDataCollectorThrottle::setMyCall1(const std::string& mycall) { m_isFirst = true; - m_collector->setMyCall(mycall); + m_collector->setMyCall1(mycall); } +std::string CSlowDataCollectorThrottle::getMyCall2() const +{ + return m_collector->getMyCall2(); +} + +void CSlowDataCollectorThrottle::setMyCall2(const std::string& mycall) +{ + m_isFirst = true; + m_collector->setMyCall2(mycall); +} + bool CSlowDataCollectorThrottle::writeData(const unsigned char* data) { m_isComplete = false; diff --git a/Common/SlowDataCollectorThrottle.h b/Common/SlowDataCollectorThrottle.h index f7fbd23..55ca7b4 100644 --- a/Common/SlowDataCollectorThrottle.h +++ b/Common/SlowDataCollectorThrottle.h @@ -28,8 +28,10 @@ class CSlowDataCollectorThrottle : public ISlowDataCollector public: CSlowDataCollectorThrottle(ISlowDataCollector* collector, unsigned int timeout); ~CSlowDataCollectorThrottle(); - std::string getMyCall() const; - void setMyCall(const std::string& mycall); + std::string getMyCall1() const; + void setMyCall1(const std::string& mycall); + std::string getMyCall2() const; + void setMyCall2(const std::string& mycall); bool writeData(const unsigned char* data); void sync(); unsigned int getData(unsigned char* data, unsigned int length);