#13 use APRSFrame everywhere

pull/32/head
Geoffrey Merck 4 years ago
parent 0b6d9e560e
commit 59f7e51701

@ -29,7 +29,7 @@ CAPRSIdFrameProvider(20U) // Initial timeout of 20 seconds
}
bool CAPRSFixedIdFrameProvider::buildAPRSFramesInt(const std::string& gateway, const CAPRSEntry * entry, std::vector<std::string>& frames)
bool CAPRSFixedIdFrameProvider::buildAPRSFramesInt(const std::string& gateway, const CAPRSEntry * entry, std::vector<CAPRSFrame *>& frames)
{
if (entry == nullptr)
return false;
@ -107,24 +107,33 @@ bool CAPRSFixedIdFrameProvider::buildAPRSFramesInt(const std::string& gateway, c
boost::replace_all(lat, ",", ".");
boost::replace_all(lon, ",", ".");
std::string output = CStringUtils::string_format("%s-S>APD5T1,TCPIP*,qAC,%s-GS:;%-7s%-2s*%02d%02d%02dz%s%cD%s%caRNG%04.0lf/A=%06.0lf %s %s\r\n",
gateway.c_str(), gateway.c_str(), entry->getCallsign().c_str(), entry->getBand().c_str(),
std::string body = CStringUtils::string_format(";%-7s%-2s*%02d%02d%02dz%s%cD%s%caRNG%04.0lf/A=%06.0lf %s %s\r\n",
entry->getCallsign().c_str(), entry->getBand().c_str(),
tm->tm_mday, tm->tm_hour, tm->tm_min,
lat.c_str(), (entry->getLatitude() < 0.0F) ? 'S' : 'N',
lon.c_str(), (entry->getLongitude() < 0.0F) ? 'W' : 'E',
entry->getRange() * 0.6214, entry->getAGL() * 3.28, band.c_str(), desc.c_str());
CAPRSFrame * frame = new CAPRSFrame(gateway + "-S",
"APD5T1",
{ "TCPIP*", "qAC" , gateway + "-GS" },
body, APFT_OBJECT);
frames.push_back(output);
frames.push_back(frame);
if (entry->getBand().length() == 1U) {
output = CStringUtils::string_format("%s-%s>APD5T2,TCPIP*,qAC,%s-%sS:!%s%cD%s%c&RNG%04.0lf/A=%06.0lf %s %s\r\n",
entry->getCallsign().c_str(), entry->getBand().c_str(), entry->getCallsign().c_str(), entry->getBand().c_str(),
body = CStringUtils::string_format("!%s%cD%s%c&RNG%04.0lf/A=%06.0lf %s %s\r\n",
lat.c_str(), (entry->getLatitude() < 0.0F) ? 'S' : 'N',
lon.c_str(), (entry->getLongitude() < 0.0F) ? 'W' : 'E',
entry->getRange() * 0.6214, entry->getAGL() * 3.28, band.c_str(), desc.c_str());
frames.push_back(output);
frame = new CAPRSFrame(entry->getCallsign() + "-" + entry->getBand(),
"APD5T2",
{ "TCPIP*", "qAC", entry->getCallsign() + "-" + entry->getBand() + "S"},
body, APFT_POSITION);
frames.push_back(frame);
}
setTimeout(20U * 60U);//20 minutes, plenty enough for fixed

@ -26,5 +26,5 @@ public:
CAPRSFixedIdFrameProvider();
protected:
virtual bool buildAPRSFramesInt(const std::string& gateway, const CAPRSEntry * aprsEntry, std::vector<std::string>& frames);
virtual bool buildAPRSFramesInt(const std::string& gateway, const CAPRSEntry * aprsEntry, std::vector<CAPRSFrame *>& frames);
};

@ -27,6 +27,8 @@ enum APRS_FRAME_TYPE {
APFT_MESSAGE,
APFT_POSITION,
APFT_NMEA,
APFT_STATUS,
APFT_OBJECT
};
class CAPRSFrame {

@ -16,7 +16,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef USE_DGPS
#ifdef USE_GPSD
#include <cmath>
#include <boost/algorithm/string.hpp>
@ -56,7 +56,7 @@ void CAPRSGPSDIdFrameProvider::close()
}
}
bool CAPRSGPSDIdFrameProvider::buildAPRSFramesInt(const std::string& gateway, const CAPRSEntry * entry, std::vector<std::string>& frames)
bool CAPRSGPSDIdFrameProvider::buildAPRSFramesInt(const std::string& gateway, const CAPRSEntry * entry, std::vector<CAPRSFrame *>& frames)
{
if(!m_hasConnection) {
this->start();
@ -169,40 +169,44 @@ bool CAPRSGPSDIdFrameProvider::buildAPRSFramesInt(const std::string& gateway, co
boost::replace_all(lat, ",", ".");
boost::replace_all(lon, ",", ".");
std::string output1 = CStringUtils::string_format("%s-S>APD5T1,TCPIP*,qAC,%s-GS:;%-7s%-2s*%02d%02d%02dz%s%cD%s%ca/A=%06.0lf",
gateway.c_str(), gateway.c_str(), entry->getCallsign().c_str(), entry->getBand().c_str(),
std::string body = CStringUtils::string_format(";%-7s%-2s*%02d%02d%02dz%s%cD%s%ca/A=%06.0lf",
entry->getCallsign().c_str(), entry->getBand().c_str(),
tm->tm_mday, tm->tm_hour, tm->tm_min,
lat.c_str(), (rawLatitude < 0.0) ? 'S' : 'N',
lon.c_str(), (rawLongitude < 0.0) ? 'W' : 'E',
rawAltitude * 3.28);
std::string output2;
if (bearingSet && velocitySet)
output2 = CStringUtils::string_format("%03.0lf/%03.0lf", rawBearing, rawVelocity * 0.539957F);
body.append(CStringUtils::string_format("%03.0lf/%03.0lf", rawBearing, rawVelocity * 0.539957F));
std::string output3;
output3 = CStringUtils::string_format("RNG%04.0lf %s %s\r\n", entry->getRange() * 0.6214, band.c_str(), desc.c_str());
body.append(CStringUtils::string_format("RNG%04.0lf %s %s\r\n", entry->getRange() * 0.6214, band.c_str(), desc.c_str()));
CLog::logDebug("APRS ==> %s%s%s", output1.c_str(), output2.c_str(), output3.c_str());
frames.push_back(output1.append(output2).append(output3));
CAPRSFrame * frame = new CAPRSFrame(gateway + "-S",
"APD5T1",
{ "TCPIP*", "qAC" , gateway + "-GS" },
body, APFT_OBJECT);
frames.push_back(frame);
if (entry->getBand().length() == 1U) {
if (altitudeSet)
output1 = CStringUtils::string_format("%s-%s>APD5T2,TCPIP*,qAC,%s-%sS:!%s%cD%s%c&/A=%06.0lf",
entry->getCallsign().c_str(), entry->getBand().c_str(), entry->getCallsign().c_str(), entry->getBand().c_str(),
body = CStringUtils::string_format("%s%cD%s%c&/A=%06.0lf",
lat.c_str(), (rawLatitude < 0.0) ? 'S' : 'N',
lon.c_str(), (rawLongitude < 0.0) ? 'W' : 'E',
rawAltitude * 3.28);
else
output1 = CStringUtils::string_format("%s-%s>APD5T2,TCPIP*,qAC,%s-%sS:!%s%cD%s%c&",
entry->getCallsign().c_str(), entry->getBand().c_str(), entry->getCallsign().c_str(), entry->getBand().c_str(),
body = CStringUtils::string_format("!%s%cD%s%c&",
lat.c_str(), (rawLatitude < 0.0) ? 'S' : 'N',
lon.c_str(), (rawLongitude < 0.0) ? 'W' : 'E');
CLog::logDebug("APRS ==> %s%s%s", output1.c_str(), output2.c_str(), output3.c_str());
frame = new CAPRSFrame(gateway,
"APD5T2",
{ "TCPIP*", "qAC" , gateway + "-GS" },
body, APFT_POSITION);
frames.push_back(output1.append(output2).append(output3));
frames.push_back(frame);
}
setTimeout(60U * 5U);//5 Minutes is plenty enough we aint an APRS tracker !

@ -35,7 +35,7 @@ public:
virtual void close();
protected:
virtual bool buildAPRSFramesInt(const std::string& gateway, const CAPRSEntry * aprsEntry, std::vector<std::string>& frames);
virtual bool buildAPRSFramesInt(const std::string& gateway, const CAPRSEntry * aprsEntry, std::vector<CAPRSFrame *>& frames);
private:
std::string m_gpsdAddress;

@ -31,7 +31,7 @@ CAPRSIdFrameProvider::~CAPRSIdFrameProvider()
}
bool CAPRSIdFrameProvider::buildAPRSFrames(const std::string& gateway, const CAPRSEntry * entry, std::vector<std::string> & frames)
bool CAPRSIdFrameProvider::buildAPRSFrames(const std::string& gateway, const CAPRSEntry * entry, std::vector<CAPRSFrame *> & frames)
{
assert(entry != nullptr);

@ -22,6 +22,7 @@
#include "Timer.h"
#include "APRSEntry.h"
#include "APRSFrame.h"
class CAPRSIdFrameProvider
{
@ -29,14 +30,14 @@ public:
CAPRSIdFrameProvider(unsigned int timeOut);
virtual ~CAPRSIdFrameProvider();
bool buildAPRSFrames(const std::string& gateway, const CAPRSEntry * aprsEntry, std::vector<std::string>& frames);
bool buildAPRSFrames(const std::string& gateway, const CAPRSEntry * aprsEntry, std::vector<CAPRSFrame *>& frames);
void clock(unsigned int ms) { m_timer.clock(ms); }
bool wantsToSend();
virtual void start() { };
virtual void close() { };
protected:
virtual bool buildAPRSFramesInt(const std::string& gateway, const CAPRSEntry * aprsEntry, std::vector<std::string>& frames) = 0;
virtual bool buildAPRSFramesInt(const std::string& gateway, const CAPRSEntry * aprsEntry, std::vector<CAPRSFrame *>& frames) = 0;
void setTimeout(unsigned int timeout)
{

@ -32,6 +32,7 @@
#include "APRSFrame.h"
#include "APRSParser.h"
#include "APRSFormater.h"
#include "APRSUtils.h"
CAPRSWriter::CAPRSWriter(const std::string& hostname, unsigned int port, const std::string& gateway, const std::string& password, const std::string& address) :
m_thread(NULL),
@ -150,12 +151,7 @@ void CAPRSWriter::writeData(const std::string& callsign, const CAMBEData& data)
std::string output ;
CAPRSFormater::frameToString(output, frame);
char ascii[500U];
::memset(ascii, 0x00, 500U);
for (unsigned int i = 0U; i < output.length(); i++)
ascii[i] = output[i];
m_thread->write(ascii);
m_thread->write(frame);
collector->reset();
}
@ -198,17 +194,22 @@ void CAPRSWriter::sendStatusFrame(CAPRSEntry * entry)
if(!m_thread->isConnected())
return;
auto linkStatus = entry->getStatus();
std::string body = boost::trim_copy(linkStatus.getStatus());
if(body[0] != '>')
body = '>' + body;
body.insert(0, ">");
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());
std::string sourCall = entry->getCallsign() + '-' + entry->getBand();
CAPRSFrame frame(sourCall,
"APD5T3",
{ "TCPIP*", "qAC", sourCall + "S" },
linkStatus.getStatus(),
APFT_STATUS);
m_thread->write(output.c_str());
m_thread->write(frame);
}
@ -217,10 +218,11 @@ void CAPRSWriter::sendIdFrames()
if(m_thread->isConnected())
{
for(auto entry : m_array) {
std::vector<std::string> frames;
std::vector<CAPRSFrame *> frames;
if(m_idFrameProvider->buildAPRSFrames(m_gateway, entry.second, frames)) {
for(auto frame : frames) {
m_thread->write(frame.c_str());
m_thread->write(*frame);
delete frame;
}
}
}

@ -27,6 +27,8 @@
#include "Defs.h"
#include "Log.h"
#include "Version.h"
#include "APRSFormater.h"
#include "APRSParser.h"
// #define DUMP_TX
@ -139,22 +141,17 @@ void* CAPRSWriterThread::Entry()
m_tries = 0U;
if(!m_queue.empty()){
char* p = m_queue.getData();
auto frameStr = m_queue.getData();
std::string text(p);
CLog::logInfo("APRS ==> %s", text.c_str());
CLog::logInfo("APRS ==> %s", frameStr.c_str());
::strcat(p, "\r\n");
bool ret = m_socket.write((unsigned char*)p, ::strlen(p));
bool ret = m_socket.writeLine(frameStr);
if (!ret) {
m_connected = false;
m_socket.close();
CLog::logInfo("Connection to the APRS thread has failed");
startReconnectionTimer();
}
delete[] p;
}
{
std::string line;
@ -176,8 +173,12 @@ void* CAPRSWriterThread::Entry()
if(length > 0 && line[0] != '#'//check if we have something and if that something is an APRS frame
&& m_APRSReadCallback.size() > 0U)//do we have someone wanting an APRS Frame?
{
for(auto cb : m_APRSReadCallback) {
cb->readAprsFrame(line);
CAPRSFrame readFrame;
if(CAPRSParser::parseFrame(line, readFrame)) {
for(auto cb : m_APRSReadCallback) {
CAPRSFrame f(readFrame);
cb->readAprsFrame(f);
}
}
}
}
@ -189,8 +190,8 @@ void* CAPRSWriterThread::Entry()
m_socket.close();
while (!m_queue.empty()) {
char* p = m_queue.getData();
delete[] p;
auto s = m_queue.getData();
s.clear();
}
}
catch (std::exception& e) {
@ -212,19 +213,19 @@ void CAPRSWriterThread::addReadAPRSCallback(CReadAPRSFrameCallback * cb)
m_APRSReadCallback.push_back(cb);
}
void CAPRSWriterThread::write(const char* data)
void CAPRSWriterThread::write(CAPRSFrame& frame)
{
assert(data != NULL);
if (!m_connected)
return;
unsigned int len = ::strlen(data);
std::string frameString;
if(CAPRSFormater::frameToString(frameString, frame)) {
char* p = new char[len + 5U];
::strcpy(p, data);
boost::trim_if(frameString, [] (char c) { return c == '\r' || c == '\n'; }); // trim all CRLF, we will add our own, just to make sure we get rid of any garbage that might come from slow data
frameString.append("\r\n");
m_queue.addData(p);
m_queue.addData(frameString);
}
}
bool CAPRSWriterThread::isConnected() const

@ -26,6 +26,7 @@
#include "Timer.h"
#include "Thread.h"
#include "ReadAPRSFrameCallback.h"
#include "APRSFrame.h"
class CAPRSWriterThread : public CThread {
@ -38,7 +39,7 @@ public:
bool isConnected() const;
void write(const char* data);
void write(CAPRSFrame& data);
void* Entry();
@ -53,7 +54,7 @@ private:
std::string m_password;
std::string m_ssid;
CTCPReaderWriterClient m_socket;
CRingBuffer<char*> m_queue;
CRingBuffer<std::string> m_queue;
bool m_exit;
bool m_connected;
CTimer m_reconnectTimer;

@ -20,9 +20,11 @@
#include <string>
#include "APRSFrame.h"
class CReadAPRSFrameCallback
{
public:
virtual ~CReadAPRSFrameCallback(){ }
virtual bool readAprsFrame(const std::string& aprsFrame) = 0;
virtual bool readAprsFrame(CAPRSFrame& aprsFrame) = 0;
};

@ -36,8 +36,6 @@ public:
assert(length > 0U);
m_buffer = new T[length];
::memset(m_buffer, 0x00, length * sizeof(T));
}
~CRingBuffer()

Loading…
Cancel
Save

Powered by TurnKey Linux.