From 060c2c5a612db373ab2ce49f8aa0b6fe551c9423 Mon Sep 17 00:00:00 2001 From: John Ronan Date: Sat, 3 Jun 2017 08:14:03 +0100 Subject: [PATCH] First go at using data from the config message --- APRSHelper.cpp | 13 ++++++++++++- APRSHelper.h | 6 ++++++ APRSWriter.cpp | 15 +++++++++------ DMRDefines.h | 2 ++ DMRGateway.cpp | 37 ++++++++++++++++++++++++++++++++++--- 5 files changed, 63 insertions(+), 10 deletions(-) diff --git a/APRSHelper.cpp b/APRSHelper.cpp index 94dd6ab..c689465 100644 --- a/APRSHelper.cpp +++ b/APRSHelper.cpp @@ -43,6 +43,12 @@ CAPRSHelper::~CAPRSHelper() delete[] m_buffer; } +void CAPRSHelper::setInfo(unsigned int txFrequency, unsigned int rxFrequency, float latitude, float longitude, int height) +{ + m_writer.setInfo(rxFrequency, rxFrequency, latitude, longitude, height); +} + + bool CAPRSHelper::open() { return m_writer.open(); @@ -70,7 +76,12 @@ void CAPRSHelper::send(std::string callsign, float latitude, float longitude, in //::sprintf(m_buffer[4U], 0x28U); m_writer.write(source, type, 0x28U, latitude, longitude, altitude); } - + +void CAPRSHelper::clock(unsigned int ms) +{ + m_writer.clock(ms); +} + void CAPRSHelper::close() { m_writer.close(); diff --git a/APRSHelper.h b/APRSHelper.h index c263eeb..252ade2 100644 --- a/APRSHelper.h +++ b/APRSHelper.h @@ -28,10 +28,16 @@ public: CAPRSHelper(const std::string& callsign, const std::string& suffix, const std::string& password, const std::string& address, unsigned int port); ~CAPRSHelper(); + void setInfo(unsigned int txFrequency, unsigned int rxFrequency, float latitude, float longitude, int height); + bool open(); + void clock(unsigned int ms); + void send(std::string callsign, float latitude, float longitude, int altitude); + void reset(); + void close(); private: diff --git a/APRSWriter.cpp b/APRSWriter.cpp index a387845..416707d 100644 --- a/APRSWriter.cpp +++ b/APRSWriter.cpp @@ -18,6 +18,8 @@ #include "APRSWriter.h" +#include "DMRDefines.h" + #include #include #include @@ -41,7 +43,7 @@ m_height(0) if (!suffix.empty()) { m_callsign.append("-"); - m_callsign.append(suffix.substr(0U, 2U)); + m_callsign.append(suffix.substr(0U, 1U)); } m_thread = new CAPRSWriterThread(m_callsign, password, address, port); @@ -62,6 +64,7 @@ void CAPRSWriter::setInfo(unsigned int txFrequency, unsigned int rxFrequency, fl bool CAPRSWriter::open() { + m_idTimer.start(); return m_thread->start(); } @@ -71,8 +74,8 @@ void CAPRSWriter::write(const unsigned char* source, const char* type, unsigned assert(type != NULL); char callsign[11U]; - ::memcpy(callsign, source, 10U); - callsign[10U] = 0x00U; + ::memcpy(callsign, source, DMR_CALLSIGN_LENGTH); + callsign[DMR_CALLSIGN_LENGTH] = 0x00U; size_t n = ::strspn(callsign, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); callsign[n] = 0x00U; @@ -177,10 +180,11 @@ void CAPRSWriter::sendIdFrames() longitude = (tempLong - longitude) * 60.0 + longitude * 100.0; char lat[20U]; - ::sprintf(lat, "%04.2lf", latitude); + ::sprintf(lat, "%07.2lf", latitude); char lon[20U]; - ::sprintf(lon, "%05.2lf", longitude); + + ::sprintf(lon, "%08.2lf", longitude); std::string server = m_callsign; size_t pos = server.find_first_of('-'); @@ -197,6 +201,5 @@ void CAPRSWriter::sendIdFrames() float(m_height) * 3.28F, band, desc); m_thread->write(output); - m_idTimer.start(); } diff --git a/DMRDefines.h b/DMRDefines.h index eb73a27..a7fced3 100644 --- a/DMRDefines.h +++ b/DMRDefines.h @@ -37,6 +37,8 @@ const unsigned int DMR_EMBEDDED_SIGNALLING_LENGTH_BYTES = 4U; const unsigned int DMR_AMBE_LENGTH_BITS = 108U * 2U; const unsigned int DMR_AMBE_LENGTH_BYTES = 27U; +const unsigned int DMR_CALLSIGN_LENGTH = 10U; + const unsigned char BS_SOURCED_AUDIO_SYNC[] = {0x07U, 0x55U, 0xFDU, 0x7DU, 0xF7U, 0x5FU, 0x70U}; const unsigned char BS_SOURCED_DATA_SYNC[] = {0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U}; diff --git a/DMRGateway.cpp b/DMRGateway.cpp index 502f05d..6efb38b 100644 --- a/DMRGateway.cpp +++ b/DMRGateway.cpp @@ -270,7 +270,6 @@ int CDMRGateway::run() LogMessage("DMRGateway-%s is starting", VERSION); LogMessage("Built %s %s (GitID #%.7s)", __TIME__, __DATE__, gitversion); - CDMRGateway::createAPRSHelper(); // For DMR we try to map IDs to callsigns std::string lookupFile = m_conf.getDMRIdLookupFile(); @@ -310,6 +309,8 @@ int CDMRGateway::run() LogMessage("MMDVM has connected"); + CDMRGateway::createAPRSHelper(); + if (m_conf.getDMRNetwork1Enabled()) { ret = createDMRNetwork1(); if (!ret) @@ -712,6 +713,9 @@ int CDMRGateway::run() if (voice2 != NULL) voice2->clock(ms); + if (m_aprsHelper != NULL) + m_aprsHelper->clock(ms); + for (unsigned int i = 1U; i < 3U; i++) { timer[i]->clock(ms); if (timer[i]->isRunning() && timer[i]->hasExpired()) { @@ -1037,7 +1041,6 @@ bool CDMRGateway::createXLXNetwork1() unsigned char config[400U]; unsigned int len = m_repeater->getConfig(config); - m_xlxNetwork1->setConfig(config, len); bool ret = m_xlxNetwork1->open(); @@ -1182,17 +1185,45 @@ void CDMRGateway::createAPRSHelper() if (!m_conf.getAPRSEnabled()) return; + unsigned char config[400U]; + unsigned int len = m_repeater->getConfig(config); + + if (len == 0U) + return; + std::string hostname = m_conf.getAPRSServer(); unsigned int port = m_conf.getAPRSPort(); std::string password = m_conf.getAPRSPassword(); m_aprsHelper = new CAPRSHelper(m_callsign, m_suffix, password, hostname, port); - + + char myRxFreq[10]; + snprintf(myRxFreq, 10, "%s", config + 8); + unsigned int rxFrequency = atoi(myRxFreq); + + char myTxFreq[10]; + snprintf(myTxFreq, 10, "%s", config + 17); + unsigned int txFrequency = atoi(myTxFreq); + + char myLat[9]; + snprintf(myLat, 9, "%s", config + 30); + float latitude = atof(myLat); + + char myLon[10]; + snprintf(myLon, 10, "%s", config + 38); + float longitude = atof(myLon); + + char myHeight[4]; + snprintf(myHeight, 4, "%s", config + 47 ); + int height = atoi(myHeight); + bool ret = m_aprsHelper->open(); if (!ret) { delete m_aprsHelper; m_aprsHelper = NULL; } + + m_aprsHelper->setInfo(txFrequency, rxFrequency, latitude, longitude, height); } void CDMRGateway::extractGPSData(const CDMRData& data)