Skip to content

Commit

Permalink
#8 Simplify and add language suport to APRS status
Browse files Browse the repository at this point in the history
  • Loading branch information
F4FXL committed Dec 31, 2021
1 parent 79fda5f commit 654c4ae
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 74 deletions.
2 changes: 1 addition & 1 deletion APRSEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ CAPRSCollector* CAPRSEntry::getCollector() const
return m_collector;
}

CAPRSEntryLinkStatus& CAPRSEntry::getLinkStatus()
CAPRSEntryStatus& CAPRSEntry::getStatus()
{
return m_linkStatus;
}
Expand Down
6 changes: 3 additions & 3 deletions APRSEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <string>

#include "APRSCollector.h"
#include "APRSEntryLinkStatus.h"
#include "APRSEntryStatus.h"
#include "Timer.h"
#include "Defs.h"

Expand All @@ -40,7 +40,7 @@ class CAPRSEntry {
double getLongitude() const;
double getAGL() const;
CAPRSCollector* getCollector() const;
CAPRSEntryLinkStatus& getLinkStatus();
CAPRSEntryStatus& getStatus();

// Transmission timer
void reset();
Expand All @@ -59,5 +59,5 @@ class CAPRSEntry {
CTimer m_timer;
bool m_first;
CAPRSCollector* m_collector;
CAPRSEntryLinkStatus m_linkStatus;
CAPRSEntryStatus m_linkStatus;
};
40 changes: 15 additions & 25 deletions APRSEntryLinkStatus.cpp → APRSEntryStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
18 changes: 8 additions & 10 deletions APRSEntryLinkStatus.h → APRSEntryStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,22 @@

#pragma once

#include <string>

#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;
};
37 changes: 7 additions & 30 deletions APRSWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ 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) {
CLog::logError("Cannot find the callsign \"%s\" in the APRS array", callsign.c_str());
return;
}

entry->getLinkStatus().setLink(status, destination);
entry->getStatus().setStatus(status);
}

void CAPRSWriter::clock(unsigned int ms)
Expand All @@ -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);
}
}
Expand All @@ -193,44 +193,21 @@ 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(),
body.c_str());

m_thread->write(output.c_str());

linkStatus.reset();
}

void CAPRSWriter::sendIdFrames()
Expand Down
2 changes: 1 addition & 1 deletion APRSWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions RepeaterHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 654c4ae

Please sign in to comment.