From eaa2c741541e1fbcea75307aa1a06115c83ceda8 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Fri, 31 Dec 2021 09:52:12 +0100 Subject: [PATCH] #8 Simplify and add language suport to APRS status --- APRSEntry.cpp | 2 +- APRSEntry.h | 6 +-- ...EntryLinkStatus.cpp => APRSEntryStatus.cpp | 40 +++++++------------ APRSEntryLinkStatus.h => APRSEntryStatus.h | 18 ++++----- APRSWriter.cpp | 37 ++++------------- APRSWriter.h | 2 +- RepeaterHandler.cpp | 8 ++-- 7 files changed, 39 insertions(+), 74 deletions(-) rename APRSEntryLinkStatus.cpp => APRSEntryStatus.cpp (53%) rename APRSEntryLinkStatus.h => APRSEntryStatus.h (73%) diff --git a/APRSEntry.cpp b/APRSEntry.cpp index 879b536..2d1c3d3 100644 --- a/APRSEntry.cpp +++ b/APRSEntry.cpp @@ -90,7 +90,7 @@ CAPRSCollector* CAPRSEntry::getCollector() const return m_collector; } -CAPRSEntryLinkStatus& CAPRSEntry::getLinkStatus() +CAPRSEntryStatus& CAPRSEntry::getStatus() { return m_linkStatus; } diff --git a/APRSEntry.h b/APRSEntry.h index 53335e2..e9bc5af 100644 --- a/APRSEntry.h +++ b/APRSEntry.h @@ -22,7 +22,7 @@ #include #include "APRSCollector.h" -#include "APRSEntryLinkStatus.h" +#include "APRSEntryStatus.h" #include "Timer.h" #include "Defs.h" @@ -40,7 +40,7 @@ class CAPRSEntry { double getLongitude() const; double getAGL() const; CAPRSCollector* getCollector() const; - CAPRSEntryLinkStatus& getLinkStatus(); + CAPRSEntryStatus& getStatus(); // Transmission timer void reset(); @@ -59,5 +59,5 @@ class CAPRSEntry { CTimer m_timer; bool m_first; CAPRSCollector* m_collector; - CAPRSEntryLinkStatus m_linkStatus; + CAPRSEntryStatus m_linkStatus; }; diff --git a/APRSEntryLinkStatus.cpp b/APRSEntryStatus.cpp similarity index 53% rename from APRSEntryLinkStatus.cpp rename to APRSEntryStatus.cpp index 8a8b19d..e16200d 100644 --- a/APRSEntryLinkStatus.cpp +++ b/APRSEntryStatus.cpp @@ -16,49 +16,39 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "APRSEntryLinkStatus.h" +#include "APRSEntryStatus.h" -CAPRSEntryLinkStatus::CAPRSEntryLinkStatus() : -m_linkStatus(LS_NONE), -m_linkDestination(), -m_linkStatusChanged(false), +CAPRSEntryStatus::CAPRSEntryStatus() : +m_status(), +m_statusChanged(false), m_timer(1000U) { m_timer.setTimeout(20U * 60U); //statuses go out every 20 minutes or every change } -bool CAPRSEntryLinkStatus::isOutOfDate() +bool CAPRSEntryStatus::isOutOfDate() { - return m_linkStatusChanged || m_timer.hasExpired(); + bool ouOfDate = m_statusChanged || m_timer.hasExpired(); + m_statusChanged = false; + return ouOfDate; } -std::string CAPRSEntryLinkStatus::getLinkDestination() const -{ - return m_linkDestination; -} -LINK_STATUS CAPRSEntryLinkStatus::getLinkStatus() const +std::string CAPRSEntryStatus::getStatus() const { - return m_linkStatus; + return m_status; } -void CAPRSEntryLinkStatus::setLink(LINK_STATUS linkstatus, const std::string& destination) +void CAPRSEntryStatus::setStatus(const std::string& linkstatus) { - bool changed = m_linkStatus != linkstatus || m_linkDestination != destination; + bool changed = m_status != linkstatus; if(changed) { - m_linkStatus = linkstatus; - m_linkDestination = destination; + m_status = linkstatus; } - m_linkStatusChanged = changed; -} - -void CAPRSEntryLinkStatus::reset() -{ - m_linkStatusChanged = false; - m_timer.start(); + m_statusChanged = changed; } -void CAPRSEntryLinkStatus::clock(unsigned int ms) +void CAPRSEntryStatus::clock(unsigned int ms) { m_timer.clock(ms); } \ No newline at end of file diff --git a/APRSEntryLinkStatus.h b/APRSEntryStatus.h similarity index 73% rename from APRSEntryLinkStatus.h rename to APRSEntryStatus.h index c1834a3..da795a2 100644 --- a/APRSEntryLinkStatus.h +++ b/APRSEntryStatus.h @@ -18,24 +18,22 @@ #pragma once +#include + #include "Timer.h" -#include "Defs.h" -class CAPRSEntryLinkStatus +class CAPRSEntryStatus { public: - CAPRSEntryLinkStatus() ; + CAPRSEntryStatus() ; - LINK_STATUS getLinkStatus() const; - std::string getLinkDestination() const; + std::string getStatus() const; bool isOutOfDate(); - void setLink(LINK_STATUS linkstatus, const std::string& destination); - void reset(); + void setStatus(const std::string& destination); void clock(unsigned int ms); private: - LINK_STATUS m_linkStatus; - std::string m_linkDestination; - bool m_linkStatusChanged; + std::string m_status; + bool m_statusChanged; CTimer m_timer; }; \ No newline at end of file diff --git a/APRSWriter.cpp b/APRSWriter.cpp index 2fdd71c..57ea6e8 100644 --- a/APRSWriter.cpp +++ b/APRSWriter.cpp @@ -158,7 +158,7 @@ void CAPRSWriter::writeData(const std::string& callsign, const CAMBEData& data) collector->reset(); } -void CAPRSWriter::writeLinkStatus(const std::string& callsign, LINK_STATUS status, const std::string& destination) +void CAPRSWriter::writeStatus(const std::string& callsign, const std::string status) { CAPRSEntry* entry = m_array[callsign]; if (entry == NULL) { @@ -166,7 +166,7 @@ void CAPRSWriter::writeLinkStatus(const std::string& callsign, LINK_STATUS statu return; } - entry->getLinkStatus().setLink(status, destination); + entry->getStatus().setStatus(status); } void CAPRSWriter::clock(unsigned int ms) @@ -183,7 +183,7 @@ void CAPRSWriter::clock(unsigned int ms) for (auto it : m_array) { if(it.second != NULL) { it.second->clock(ms); - if(it.second->getLinkStatus().isOutOfDate()) + if(it.second->getStatus().isOutOfDate()) sendStatusFrame(it.second); } } @@ -193,36 +193,14 @@ void CAPRSWriter::sendStatusFrame(CAPRSEntry * entry) { assert(entry != nullptr); - // 20211231 TODO F4FXL support different languages - if(!m_thread->isConnected()) return; - auto linkStatus = entry->getLinkStatus(); - std::string body; + auto linkStatus = entry->getStatus(); + std::string body = boost::trim_copy(linkStatus.getStatus()); - switch (linkStatus.getLinkStatus()) - { - case LS_LINKED_DCS: - case LS_LINKED_CCS: - case LS_LINKED_DEXTRA: - case LS_LINKED_DPLUS: - case LS_LINKED_LOOPBACK: - body = ">Linked to " + linkStatus.getLinkDestination(); - break; - - case LS_LINKING_DCS: - case LS_LINKING_CCS: - case LS_LINKING_DEXTRA: - case LS_LINKING_DPLUS: - case LS_LINKING_LOOPBACK: - body = ">Linking to " + linkStatus.getLinkDestination();; - break; - - default: - body = ">Not linked"; - break; - } + if(body[0] != '>') + body = '>' + body; std::string output = CStringUtils::string_format("%s-%s>APD5T3,TCPIP*,qAC,%s-%sS:%s\r\n", entry->getCallsign().c_str(), entry->getBand().c_str(), entry->getCallsign().c_str(), entry->getBand().c_str(), @@ -230,7 +208,6 @@ void CAPRSWriter::sendStatusFrame(CAPRSEntry * entry) m_thread->write(output.c_str()); - linkStatus.reset(); } void CAPRSWriter::sendIdFrames() diff --git a/APRSWriter.h b/APRSWriter.h index 90f4156..3543930 100644 --- a/APRSWriter.h +++ b/APRSWriter.h @@ -51,7 +51,7 @@ class CAPRSWriter { void writeData(const std::string& callsign, const CAMBEData& data); - void writeLinkStatus(const std::string& callsign, LINK_STATUS status, const std::string& destination); + void writeStatus(const std::string& callsign, const std::string status); bool isConnected() const; diff --git a/RepeaterHandler.cpp b/RepeaterHandler.cpp index a5ea17c..13635b3 100644 --- a/RepeaterHandler.cpp +++ b/RepeaterHandler.cpp @@ -2564,7 +2564,7 @@ void CRepeaterHandler::writeLinkingTo(const std::string &callsign) triggerInfo(); if(m_aprsWriter != nullptr) - m_aprsWriter->writeLinkStatus(m_rptCallsign, m_linkStatus, callsign); + m_aprsWriter->writeStatus(m_rptCallsign, text); #ifdef USE_CCS m_ccsHandler->setReflector(); @@ -2619,7 +2619,7 @@ void CRepeaterHandler::writeLinkedTo(const std::string &callsign) triggerInfo(); if(m_aprsWriter != nullptr) - m_aprsWriter->writeLinkStatus(m_rptCallsign, m_linkStatus, callsign); + m_aprsWriter->writeStatus(m_rptCallsign, text); #ifdef USE_CCS m_ccsHandler->setReflector(callsign); @@ -2674,7 +2674,7 @@ void CRepeaterHandler::writeNotLinked() triggerInfo(); if(m_aprsWriter != nullptr) - m_aprsWriter->writeLinkStatus(m_rptCallsign, m_linkStatus, ""); + m_aprsWriter->writeStatus(m_rptCallsign, text); #ifdef USE_CCS m_ccsHandler->setReflector(); @@ -2745,7 +2745,7 @@ void CRepeaterHandler::writeIsBusy(const std::string& callsign) triggerInfo(); if(m_aprsWriter != nullptr) - m_aprsWriter->writeLinkStatus(m_rptCallsign, m_linkStatus, callsign); + m_aprsWriter->writeStatus(m_rptCallsign, text); #ifdef USE_CCS m_ccsHandler->setReflector();