diff --git a/Common/APRSCollector.cpp b/Common/APRSCollector.cpp index e59f8a4..b44fc06 100644 --- a/Common/APRSCollector.cpp +++ b/Common/APRSCollector.cpp @@ -24,6 +24,9 @@ const unsigned int APRS_CSUM_LENGTH = 4U; const unsigned int APRS_DATA_LENGTH = 300U; const unsigned int SLOW_DATA_BLOCK_LENGTH = 6U; +const char APRS_OVERLAY = '\\'; +const char APRS_SYMBOL = 'K'; + CAPRSCollector::CAPRSCollector() : m_state(AS_NONE), m_ggaData(NULL), @@ -32,24 +35,17 @@ m_ggaValid(false), m_rmcData(NULL), m_rmcLength(0U), m_rmcValid(false), -m_csData(NULL), -m_csLength(0U), -m_csValid(false), m_crcData(NULL), m_crcLength(0U), m_crcValid(false), -m_txtData(NULL), -m_txtLength(0U), -m_txtValid(false), m_buffer(NULL), m_slowData(SS_FIRST), -m_collector() +m_collector(), +m_callsign() { m_ggaData = new unsigned char[APRS_DATA_LENGTH]; m_rmcData = new unsigned char[APRS_DATA_LENGTH]; - m_csData = new unsigned char[APRS_DATA_LENGTH]; m_crcData = new unsigned char[APRS_DATA_LENGTH]; - m_txtData = new unsigned char[APRS_DATA_LENGTH]; m_buffer = new unsigned char[SLOW_DATA_BLOCK_LENGTH]; } @@ -57,16 +53,16 @@ CAPRSCollector::~CAPRSCollector() { delete[] m_ggaData; delete[] m_rmcData; - delete[] m_csData; delete[] m_crcData; - delete[] m_txtData; delete[] m_buffer; } -bool CAPRSCollector::writeData(const unsigned char* data) +bool CAPRSCollector::writeData(const wxString& callsign, const unsigned char* data) { wxASSERT(data != NULL); + m_callsign = callsign; + switch (m_slowData) { case SS_FIRST: m_buffer[0U] = data[0U] ^ SCRAMBLER_BYTE1; @@ -83,12 +79,6 @@ bool CAPRSCollector::writeData(const unsigned char* data) break; } - CUtils::dump(wxT("Slow data received"), m_buffer, 6U); - - // Is it slow text data? - if ((m_buffer[0U] & SLOW_DATA_TYPE_MASK) == SLOW_DATA_TYPE_TEXT) - addTextData(m_buffer); - // Is it GPS data? if ((m_buffer[0U] & SLOW_DATA_TYPE_MASK) == SLOW_DATA_TYPE_GPS) return addGPSData(m_buffer + 1U); @@ -103,14 +93,11 @@ void CAPRSCollector::reset() m_ggaValid = false; m_rmcLength = 0U; m_rmcValid = false; - m_csLength = 0U; - m_csValid = false; m_crcLength = 0U; m_crcValid = false; - m_txtLength = 0U; - m_txtValid = false; m_slowData = SS_FIRST; m_collector.Clear(); + m_callsign.Clear(); } void CAPRSCollector::sync() @@ -128,10 +115,7 @@ bool CAPRSCollector::addGPSData(const unsigned char* data) addGGAData(); return false; } else if (m_state == AS_RMC) { - addRMCData(); - return false; - } else if (m_state == AS_CS) { - return addCSData(); + return addRMCData(); } else if (m_state == AS_CRC) { return addCRCData(); } @@ -142,15 +126,11 @@ bool CAPRSCollector::addGPSData(const unsigned char* data) m_ggaValid = false; m_rmcLength = 0U; m_rmcValid = false; - m_txtLength = 0U; - m_txtValid = false; return false; } else if (m_state != AS_RMC && m_collector.Find(wxT("$GPRMC")) != wxNOT_FOUND) { m_state = AS_RMC; m_rmcLength = 0U; m_rmcValid = false; - m_txtLength = 0U; - m_txtValid = false; return false; } else if (m_state != AS_CRC && m_collector.Find(wxT("$$CRC")) != wxNOT_FOUND) { m_state = AS_CRC; @@ -192,11 +172,11 @@ void CAPRSCollector::addGGAData() bool ret = checkXOR(m_ggaData + 1U, m_ggaLength - 1U); if (ret) { - CUtils::dump(wxT("$GPGGA Valid"), m_ggaData, m_ggaLength); + // CUtils::dump(wxT("$GPGGA Valid"), m_ggaData, m_ggaLength); m_ggaValid = true; m_state = AS_RMC; } else { - CUtils::dump(wxT("$GPGGA Bad checksum"), m_ggaData, m_ggaLength); + // CUtils::dump(wxT("$GPGGA Bad checksum"), m_ggaData, m_ggaLength); m_ggaLength = 0U; m_ggaValid = false; m_state = AS_RMC; @@ -205,18 +185,18 @@ void CAPRSCollector::addGGAData() m_collector = m_collector.Mid(n2); } -void CAPRSCollector::addRMCData() +bool CAPRSCollector::addRMCData() { int n2 = m_collector.Find(wxT('\x0A'), true); if (n2 == wxNOT_FOUND) - return; + return false; int n1 = m_collector.Find(wxT("$GPRMC")); if (n1 == wxNOT_FOUND) - return; + return false; if (n2 < n1) - return; + return false; unsigned int len = n2 - n1; @@ -224,7 +204,7 @@ void CAPRSCollector::addRMCData() m_rmcLength = 0U; m_rmcValid = false; m_state = AS_NONE; - return; + return false; } m_rmcLength = 0U; @@ -236,44 +216,17 @@ void CAPRSCollector::addRMCData() bool ret = checkXOR(m_rmcData + 1U, m_rmcLength - 1U); if (ret) { - CUtils::dump(wxT("$GPRMC Valid"), m_rmcData, m_rmcLength); + // CUtils::dump(wxT("$GPRMC Valid"), m_rmcData, m_rmcLength); m_rmcValid = true; - m_state = AS_CS; } else { - CUtils::dump(wxT("$GPRMC Bad checksum"), m_rmcData, m_rmcLength); + // CUtils::dump(wxT("$GPRMC Bad checksum"), m_rmcData, m_rmcLength); m_rmcLength = 0U; m_rmcValid = false; - m_state = AS_CS; } m_collector = m_collector.Mid(n2); -} -bool CAPRSCollector::addCSData() -{ - int n = m_collector.Find(wxT(' ')); - if (n == wxNOT_FOUND) - return false; - - if (n >= APRS_DATA_LENGTH) { - m_csLength = 0U; - m_csValid = false; - m_state = AS_NONE; - return false; - } - - m_csLength = 0U; - for (int i = 1; i < n; i++) { - m_csData[m_csLength] = m_collector.GetChar(i); - m_csData[m_csLength] &= 0x7FU; - m_csLength++; - } - - CUtils::dump(wxT("Callsign Valid"), m_csData, m_csLength); - m_csValid = true; - m_state = AS_NONE; - - m_collector = m_collector.Mid(n); + m_state = AS_NONE; return true; } @@ -308,13 +261,13 @@ bool CAPRSCollector::addCRCData() bool ret = checkCRC(m_crcData, m_crcLength); if (ret) { - CUtils::dump(wxT("$$CRC Valid"), m_crcData, m_crcLength); + // CUtils::dump(wxT("$$CRC Valid"), m_crcData, m_crcLength); m_crcValid = true; m_state = AS_NONE; m_collector = m_collector.Mid(n2); return true; } else { - CUtils::dump(wxT("$$CRC Bad checksum"), m_crcData, m_crcLength); + // CUtils::dump(wxT("$$CRC Bad checksum"), m_crcData, m_crcLength); m_crcLength = 0U; m_crcValid = false; m_state = AS_NONE; @@ -323,31 +276,6 @@ bool CAPRSCollector::addCRCData() } } -void CAPRSCollector::addTextData(const unsigned char* data) -{ - unsigned char pos = data[0U] & 0x0FU; - if (pos > 3U) - return; - - pos *= 5U; - - for (unsigned int i = 1U; i < 6U; i++) { - unsigned char c = data[i]; - - m_txtData[pos] = c & 0x7FU; - pos++; - - bool ret = checkXOR(m_txtData, 20U); - if (ret) { - CUtils::dump(wxT("Text Valid"), m_txtData, 20U); - m_state = AS_NONE; - m_txtValid = true; - m_txtLength = 20U; - return; - } - } -} - unsigned int CAPRSCollector::getData(unsigned char* data, unsigned int length) { wxASSERT(data != NULL); @@ -366,34 +294,26 @@ unsigned int CAPRSCollector::getData(unsigned char* data, unsigned int length) return len; } - // Have we got GGA and text data? - if (m_ggaValid && m_txtValid) { + // Have we got GGA data? + if (m_ggaValid) { unsigned int len = convertNMEA1(data, length); m_ggaLength = 0U; m_rmcLength = 0U; - m_csLength = 0U; - m_txtLength = 0U; m_ggaValid = false; m_rmcValid = false; - m_csValid = false; - m_txtValid = false; return len; } - // Have we got RMC and text data? - if (m_rmcValid && m_txtValid) { + // Have we got RMC data? + if (m_rmcValid) { unsigned int len = convertNMEA2(data, length); m_ggaLength = 0U; m_rmcLength = 0U; - m_csLength = 0U; - m_txtLength = 0U; m_ggaValid = false; m_rmcValid = false; - m_csValid = false; - m_txtValid = false; return len; } @@ -496,24 +416,14 @@ unsigned int CAPRSCollector::convertNMEA1(unsigned char* data, unsigned int) char callsign[10U]; ::memset(callsign, ' ', 10U); - ::strncpy(callsign, (char*)m_txtData, 7U); + for (unsigned int i = 0U; i < m_callsign.Len(); i++) + callsign[i] = m_callsign.GetChar(i); // This can't fail! char* p = ::strchr(callsign, ' '); - - if (m_txtData[6U] == ' ' && m_txtData[7U] != ' ') { - *p++ = '-'; - *p++ = m_txtData[7U]; - } else if (m_txtData[6U] != ' ' && m_txtData[7U] != ' ') { - *p++ = m_txtData[7U]; - } - *p = '\0'; - char symbol, overlay; - getSymbol(m_txtData + 9U, symbol, overlay); - - ::sprintf((char*)data, "%s>APDPRS,DSTAR*:!%.7s%s%c%.8s%s%c", callsign, pGGA[2U], pGGA[3U], overlay, pGGA[4U], pGGA[5U], symbol); + ::sprintf((char*)data, "%s>APDPRS,DSTAR*:!%.7s%s%c%.8s%s%c", callsign, pGGA[2U], pGGA[3U], APRS_OVERLAY, pGGA[4U], pGGA[5U], APRS_SYMBOL); // Get the bearing and speed from the RMC data if (m_rmcValid) { @@ -540,21 +450,6 @@ unsigned int CAPRSCollector::convertNMEA1(unsigned char* data, unsigned int) } } - ::strcat((char*)data, " "); - - // Insert the message text - unsigned int j = ::strlen((char*)data); - for (unsigned int i = 13U; i < 29U; i++) { - unsigned char c = m_txtData[i]; - - if (c == '*') { - data[j] = '\0'; - break; - } - - data[j++] = c; - } - if (pGGA[9U] != NULL && ::strlen(pGGA[9U]) > 0U) { // Convert altitude from metres to feet int altitude = ::atoi(pGGA[9U]); @@ -590,24 +485,14 @@ unsigned int CAPRSCollector::convertNMEA2(unsigned char* data, unsigned int) char callsign[10U]; ::memset(callsign, ' ', 10U); - ::strncpy(callsign, (char*)m_txtData, 7U); + for (unsigned int i = 0U; i < m_callsign.Len(); i++) + callsign[i] = m_callsign.GetChar(i); // This can't fail! char* p = ::strchr(callsign, ' '); - - if (m_txtData[6U] == ' ' && m_txtData[7U] != ' ') { - *p++ = '-'; - *p++ = m_txtData[7U]; - } else if (m_txtData[6U] != ' ' && m_txtData[7U] != ' ') { - *p++ = m_txtData[7U]; - } - *p = '\0'; - char symbol, overlay; - getSymbol(m_txtData + 9U, symbol, overlay); - - ::sprintf((char*)data, "%s>APDPRS,DSTAR*:!%.7s%s%c%.8s%s%c", callsign, pRMC[3U], pRMC[4U], overlay, pRMC[5U], pRMC[6U], symbol); + ::sprintf((char*)data, "%s>APDPRS,DSTAR*:!%.7s%s%c%.8s%s%c", callsign, pRMC[3U], pRMC[4U], APRS_OVERLAY, pRMC[5U], pRMC[6U], APRS_SYMBOL); if (pRMC[7U] != NULL && pRMC[8U] != NULL && ::strlen(pRMC[7U]) > 0U && ::strlen(pRMC[8U]) > 0U) { int bearing = ::atoi(pRMC[8U]); @@ -616,110 +501,9 @@ unsigned int CAPRSCollector::convertNMEA2(unsigned char* data, unsigned int) ::sprintf((char*)data + ::strlen((char*)data), "%03d/%03d", bearing, speed); } - if (m_txtLength == 20U) { - ::strcat((char*)data, " "); - - // Insert the message text - unsigned int j = ::strlen((char*)data); - for (unsigned int i = 2U; i < 20U; i++) { - unsigned char c = m_txtData[i]; - - if (c == '*') { - data[j] = '\0'; - break; - } - - data[j++] = c; - } - } else { - if (m_txtData[13U] != '*') - ::strcat((char*)data, " "); - - // Insert the message text - unsigned int j = ::strlen((char*)data); - for (unsigned int i = 13U; i < 29U; i++) { - unsigned char c = m_txtData[i]; - - if (c == '*') { - data[j] = '\0'; - break; - } - - data[j++] = c; - } - } - return ::strlen((char*)data); } -// Function taken from DPRSIntf.java from Pete Loveall AE5PL -void CAPRSCollector::getSymbol(const unsigned char* data, char& symbol, char& overlay) -{ - symbol = '.'; - - if (data[3U] == ' ') { - int offset = -1; - - switch (data[0U]) { - case 'B': - case 'O': - offset = -33; - break; - case 'P': - case 'A': - offset = 0; - break; - case 'M': - case 'N': - offset = -24; - break; - case 'H': - case 'D': - offset = 8; - break; - case 'L': - case 'S': - offset = 32; - break; - case 'J': - case 'Q': - offset = 74; - break; - default: - break; - } - - if (offset != -1 && ::isalnum(data[1U])) { - bool altIcons = false; - - // x is valid, lets get y - switch (data[0U]) { - case 'O': - case 'A': - case 'N': - case 'D': - case 'S': - case 'Q': - altIcons = true; - break; - } - - symbol = char(data[1U] + offset); - - overlay = '/'; - - if (altIcons) { - if (data[2] == ' ') - overlay = '\\'; - else if (::isalnum(data[2])) - overlay = data[2U]; - else - overlay = 0; - } - } - } -} - // Source found at char* CAPRSCollector::mystrsep(char** sp, const char* sep) const { diff --git a/Common/APRSCollector.h b/Common/APRSCollector.h index 7c8261f..85bd3da 100644 --- a/Common/APRSCollector.h +++ b/Common/APRSCollector.h @@ -27,7 +27,6 @@ enum APRS_STATE { AS_NONE, AS_GGA, AS_RMC, - AS_CS, AS_CRC }; @@ -36,7 +35,7 @@ public: CAPRSCollector(); ~CAPRSCollector(); - bool writeData(const unsigned char* data); + bool writeData(const wxString& callsign, const unsigned char* data); void sync(); @@ -52,25 +51,18 @@ private: unsigned char* m_rmcData; unsigned int m_rmcLength; bool m_rmcValid; - unsigned char* m_csData; - unsigned int m_csLength; - bool m_csValid; unsigned char* m_crcData; unsigned int m_crcLength; bool m_crcValid; - unsigned char* m_txtData; - unsigned int m_txtLength; - bool m_txtValid; unsigned char* m_buffer; SLOWDATA_STATE m_slowData; wxString m_collector; + wxString m_callsign; bool addGPSData(const unsigned char* data); - void addTextData(const unsigned char* data); void addGGAData(); - void addRMCData(); - bool addCSData(); + bool addRMCData(); bool addCRCData(); bool checkXOR(const unsigned char* data, unsigned int length) const; @@ -82,8 +74,6 @@ private: unsigned int convertNMEA1(unsigned char* data, unsigned int length); unsigned int convertNMEA2(unsigned char* data, unsigned int length); - void getSymbol(const unsigned char* data, char& symbol, char& overlay); - char* mystrsep(char** sp, const char* sep) const; }; diff --git a/Common/APRSWriter.cpp b/Common/APRSWriter.cpp index ae5d6a0..d34ab3c 100644 --- a/Common/APRSWriter.cpp +++ b/Common/APRSWriter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 by Jonathan Naylor G4KLX + * Copyright (C) 2010-2014,2018 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -118,9 +118,8 @@ bool CAPRSEntry::isOK() } } -CAPRSWriter::CAPRSWriter(const wxString& hostname, unsigned int port, const wxString& gateway, const wxString& address) : +CAPRSWriter::CAPRSWriter(const wxString& hostname, unsigned int port, const wxString& gateway, const wxString& password, const wxString& address) : m_thread(NULL), -m_enabled(false), m_idTimer(1000U, 20U * 60U), // 20 minutes m_gateway(), m_array() @@ -128,8 +127,9 @@ m_array() wxASSERT(!hostname.IsEmpty()); wxASSERT(port > 0U); wxASSERT(!gateway.IsEmpty()); + wxASSERT(!password.IsEmpty()); - m_thread = new CAPRSWriterThread(gateway, address, hostname, port); + m_thread = new CAPRSWriterThread(gateway, password, address, hostname, port); m_gateway = gateway; m_gateway.Truncate(LONG_CALLSIGN_LENGTH - 1U); @@ -179,15 +179,10 @@ void CAPRSWriter::writeData(const wxString& callsign, const CAMBEData& data) unsigned char buffer[400U]; data.getData(buffer, DV_FRAME_MAX_LENGTH_BYTES); - bool complete = collector->writeData(buffer + VOICE_FRAME_LENGTH_BYTES); + bool complete = collector->writeData(callsign, buffer + VOICE_FRAME_LENGTH_BYTES); if (!complete) return; - if (!m_enabled) { - collector->reset(); - return; - } - if (!m_thread->isConnected()) { collector->reset(); return; @@ -246,16 +241,6 @@ void CAPRSWriter::reset(const wxString& callsign) entry->reset(); } -void CAPRSWriter::setEnabled(bool enabled) -{ - m_enabled = enabled; - - if (m_enabled) { - sendIdFrames(); - m_idTimer.start(); - } -} - void CAPRSWriter::clock(unsigned int ms) { m_idTimer.clock(ms); diff --git a/Common/APRSWriter.h b/Common/APRSWriter.h index 8eb1bf6..bf7f607 100644 --- a/Common/APRSWriter.h +++ b/Common/APRSWriter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010,2011,2012 by Jonathan Naylor G4KLX + * Copyright (C) 2010,2011,2012,2018 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -66,7 +66,7 @@ WX_DECLARE_STRING_HASH_MAP(CAPRSEntry*, CEntry_t); class CAPRSWriter { public: - CAPRSWriter(const wxString& hostname, unsigned int port, const wxString& gateway, const wxString& address); + CAPRSWriter(const wxString& hostname, unsigned int port, const wxString& gateway, const wxString& password, const wxString& address); ~CAPRSWriter(); bool open(); @@ -77,8 +77,6 @@ public: void reset(const wxString& callsign); - void setEnabled(bool enable); - bool isConnected() const; void clock(unsigned int ms); @@ -87,7 +85,6 @@ public: private: CAPRSWriterThread* m_thread; - bool m_enabled; CTimer m_idTimer; wxString m_gateway; CEntry_t m_array; diff --git a/Common/APRSWriterThread.cpp b/Common/APRSWriterThread.cpp index dfaf250..6c97d62 100644 --- a/Common/APRSWriterThread.cpp +++ b/Common/APRSWriterThread.cpp @@ -25,9 +25,10 @@ const unsigned int APRS_TIMEOUT = 10U; -CAPRSWriterThread::CAPRSWriterThread(const wxString& callsign, const wxString& address, const wxString& hostname, unsigned int port) : +CAPRSWriterThread::CAPRSWriterThread(const wxString& callsign, const wxString& password, const wxString& address, const wxString& hostname, unsigned int port) : wxThread(wxTHREAD_JOINABLE), m_username(callsign), +m_password(password), m_ssid(callsign), m_socket(hostname, port, address), m_queue(20U), @@ -38,6 +39,7 @@ m_filter(wxT("")), m_clientName(wxT("ircDDBGateway")) { wxASSERT(!callsign.IsEmpty()); + wxASSERT(!password.IsEmpty()); wxASSERT(!hostname.IsEmpty()); wxASSERT(port > 0U); @@ -48,9 +50,10 @@ m_clientName(wxT("ircDDBGateway")) m_ssid = m_ssid.SubString(LONG_CALLSIGN_LENGTH - 1U, 1); } -CAPRSWriterThread::CAPRSWriterThread(const wxString& callsign, const wxString& address, const wxString& hostname, unsigned int port, const wxString& filter, const wxString& clientName) : +CAPRSWriterThread::CAPRSWriterThread(const wxString& callsign, const wxString& password, const wxString& address, const wxString& hostname, unsigned int port, const wxString& filter, const wxString& clientName) : wxThread(wxTHREAD_JOINABLE), m_username(callsign), +m_password(password), m_ssid(callsign), m_socket(hostname, port, address), m_queue(20U), @@ -61,6 +64,7 @@ m_filter(filter), m_clientName(clientName) { wxASSERT(!callsign.IsEmpty()); + wxASSERT(!password.IsEmpty()); wxASSERT(!hostname.IsEmpty()); wxASSERT(port > 0U); @@ -74,6 +78,7 @@ m_clientName(clientName) CAPRSWriterThread::~CAPRSWriterThread() { m_username.Clear(); + m_password.Clear(); } bool CAPRSWriterThread::start() @@ -198,8 +203,6 @@ void CAPRSWriterThread::stop() bool CAPRSWriterThread::connect() { - unsigned int password = getAPRSPassword(m_username); - bool ret = m_socket.open(); if (!ret) return false; @@ -217,7 +220,7 @@ bool CAPRSWriterThread::connect() wxString filter(m_filter); if (filter.Length() > 0) filter.Prepend(wxT(" filter ")); - wxString connectString = wxString::Format(wxT("user %s-%s pass %u vers %s%s\n"), m_username.c_str(), m_ssid.c_str(), password, + wxString connectString = wxString::Format(wxT("user %s-%s pass %s vers %s%s\n"), m_username.c_str(), m_ssid.c_str(), m_password.c_str(), (m_clientName.Length() ? m_clientName : wxT("ircDDBGateway")).c_str(), filter.c_str()); //wxLogMessage(wxT("Connect String : ") + connectString); @@ -227,7 +230,6 @@ bool CAPRSWriterThread::connect() return false; } - length = m_socket.readLine(serverResponse, APRS_TIMEOUT); if (length == 0) { wxLogError(wxT("No reply from the APRS server after %u seconds"), APRS_TIMEOUT); @@ -246,18 +248,3 @@ bool CAPRSWriterThread::connect() return true; } - -unsigned int CAPRSWriterThread::getAPRSPassword(wxString callsign) const -{ - unsigned int len = callsign.Length(); - - wxUint16 hash = 0x73E2U; - - for (unsigned int i = 0U; i < len; i += 2U) { - hash ^= (char)callsign.GetChar(i) << 8; - if(i + 1 < len) - hash ^= (char)callsign.GetChar(i + 1); - } - - return hash & 0x7FFFU; -} diff --git a/Common/APRSWriterThread.h b/Common/APRSWriterThread.h index 1e31254..cdac160 100644 --- a/Common/APRSWriterThread.h +++ b/Common/APRSWriterThread.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010,2011,2012 by Jonathan Naylor G4KLX + * Copyright (C) 2010,2011,2012,2018 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,8 +27,8 @@ typedef void (*ReadAPRSFrameCallback)(const wxString&); class CAPRSWriterThread : public wxThread { public: - CAPRSWriterThread(const wxString& callsign, const wxString& address, const wxString& hostname, unsigned int port); - CAPRSWriterThread(const wxString& callsign, const wxString& address, const wxString& hostname, unsigned int port, const wxString& filter, const wxString& clientName); + CAPRSWriterThread(const wxString& callsign, const wxString& password, const wxString& address, const wxString& hostname, unsigned int port); + CAPRSWriterThread(const wxString& callsign, const wxString& password, const wxString& address, const wxString& hostname, unsigned int port, const wxString& filter, const wxString& clientName); virtual ~CAPRSWriterThread(); virtual bool start(); @@ -45,6 +45,7 @@ public: private: wxString m_username; + wxString m_password; wxString m_ssid; CTCPReaderWriterClient m_socket; CRingBuffer m_queue; @@ -55,7 +56,6 @@ private: wxString m_clientName; bool connect(); - unsigned int getAPRSPassword(wxString username) const; }; #endif diff --git a/Common/IRCDDBGatewayConfig.cpp b/Common/IRCDDBGatewayConfig.cpp index 9e97d14..cbcd5e6 100644 --- a/Common/IRCDDBGatewayConfig.cpp +++ b/Common/IRCDDBGatewayConfig.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 by Jonathan Naylor G4KLX + * Copyright (C) 2010-2015,2018 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -129,6 +129,7 @@ const wxString KEY_IRCDDB_HOSTNAME4 = wxT("ircddbHostname4"); const wxString KEY_IRCDDB_USERNAME4 = wxT("ircddbUsername4"); const wxString KEY_IRCDDB_PASSWORD4 = wxT("ircddbPassword4"); const wxString KEY_APRS_ENABLED = wxT("aprsEnabled"); +const wxString KEY_APRS_PASSWORD = wxT("aprsPassword"); const wxString KEY_APRS_HOSTNAME = wxT("aprsHostname"); const wxString KEY_APRS_PORT = wxT("aprsPort"); const wxString KEY_DEXTRA_ENABLED = wxT("dextraEnabled"); @@ -139,7 +140,7 @@ const wxString KEY_DPLUS_LOGIN = wxT("dplusLogin"); const wxString KEY_DCS_ENABLED = wxT("dcsEnabled"); const wxString KEY_CCS_ENABLED = wxT("ccsEnabled"); const wxString KEY_CCS_HOST = wxT("ccsHost"); -const wxString KEY_XLX_ENABLED = wxT("xlxEnabled"); +const wxString KEY_XLX_ENABLED = wxT("xlxEnabled"); const wxString KEY_XLX_OVERRIDE_LOCAL = wxT("xlxOverrideLocal"); const wxString KEY_XLX_HOSTS_FILE_URL = wxT("xlxHostsFileUrl"); const wxString KEY_STARNET_BAND1 = wxT("starNetBand1"); @@ -250,7 +251,8 @@ const bool DEFAULT_IRCDDB_ENABLED4 = false; const wxString DEFAULT_IRCDDB_HOSTNAME4 = wxEmptyString; const wxString DEFAULT_IRCDDB_USERNAME4 = wxEmptyString; const wxString DEFAULT_IRCDDB_PASSWORD4 = wxEmptyString; -const bool DEFAULT_APRS_ENABLED = true; +const bool DEFAULT_APRS_ENABLED = false; +const wxString DEFAULT_APRS_PASSWORD = wxT("00000"); const wxString DEFAULT_APRS_HOSTNAME = wxT("rotate.aprs2.net"); const unsigned int DEFAULT_APRS_PORT = 14580U; const bool DEFAULT_DEXTRA_ENABLED = true; @@ -261,8 +263,8 @@ const wxString DEFAULT_DPLUS_LOGIN = wxEmptyString; const bool DEFAULT_DCS_ENABLED = true; const bool DEFAULT_CCS_ENABLED = true; const wxString DEFAULT_CCS_HOST = wxT("CCS704 "); -const bool DEFAULT_XLX_ENABLED = true; -const bool DEFAULT_XLX_OVERRIDE_LOCAL = true; +const bool DEFAULT_XLX_ENABLED = true; +const bool DEFAULT_XLX_OVERRIDE_LOCAL = true; const wxString DEFAULT_XLX_HOSTS_FILE_URL = _T("http://xlxapi.rlx.lu/api.php?do=GetReflectorHostname"); const wxString DEFAULT_STARNET_BAND = wxEmptyString; const wxString DEFAULT_STARNET_CALLSIGN = wxEmptyString; @@ -402,6 +404,7 @@ m_ircddbHostname4(DEFAULT_IRCDDB_HOSTNAME4), m_ircddbUsername4(DEFAULT_IRCDDB_USERNAME4), m_ircddbPassword4(DEFAULT_IRCDDB_PASSWORD4), m_aprsEnabled(DEFAULT_APRS_ENABLED), +m_aprsPassword(DEFAULT_APRS_PASSWORD), m_aprsHostname(DEFAULT_APRS_HOSTNAME), m_aprsPort(DEFAULT_APRS_PORT), m_dextraEnabled(DEFAULT_DEXTRA_ENABLED), @@ -723,6 +726,8 @@ m_y(DEFAULT_WINDOW_Y) m_config->Read(m_name + KEY_APRS_ENABLED, &m_aprsEnabled, DEFAULT_APRS_ENABLED); + m_config->Read(m_name + KEY_APRS_PASSWORD, &m_aprsPassword, DEFAULT_APRS_PASSWORD); + m_config->Read(m_name + KEY_APRS_HOSTNAME, &m_aprsHostname, DEFAULT_APRS_HOSTNAME); m_config->Read(m_name + KEY_APRS_PORT, &temp, long(DEFAULT_APRS_PORT)); @@ -1012,6 +1017,7 @@ m_ircddbHostname4(DEFAULT_IRCDDB_HOSTNAME4), m_ircddbUsername4(DEFAULT_IRCDDB_USERNAME4), m_ircddbPassword4(DEFAULT_IRCDDB_PASSWORD4), m_aprsEnabled(DEFAULT_APRS_ENABLED), +m_aprsPassword(DEFAULT_APRS_PASSWORD), m_aprsHostname(DEFAULT_APRS_HOSTNAME), m_aprsPort(DEFAULT_APRS_PORT), m_dextraEnabled(DEFAULT_DEXTRA_ENABLED), @@ -1381,6 +1387,8 @@ m_y(DEFAULT_WINDOW_Y) } else if (key.IsSameAs(KEY_APRS_ENABLED)) { val.ToLong(&temp1); m_aprsEnabled = temp1 == 1L; + } else if (key.IsSameAs(KEY_APRS_PASSWORD)) { + m_aprsPassword = val; } else if (key.IsSameAs(KEY_APRS_HOSTNAME)) { m_aprsHostname = val; } else if (key.IsSameAs(KEY_APRS_PORT)) { @@ -1877,16 +1885,18 @@ void CIRCDDBGatewayConfig::setIrcDDB4(bool enabled, const wxString& hostname, co m_ircddbPassword4 = password; } -void CIRCDDBGatewayConfig::getDPRS(bool& enabled, wxString& hostname, unsigned int& port) const +void CIRCDDBGatewayConfig::getDPRS(bool& enabled, wxString& password, wxString& hostname, unsigned int& port) const { enabled = m_aprsEnabled; + password = m_aprsPassword; hostname = m_aprsHostname; port = m_aprsPort; } -void CIRCDDBGatewayConfig::setDPRS(bool enabled, const wxString& hostname, unsigned int port) +void CIRCDDBGatewayConfig::setDPRS(bool enabled, const wxString& password, const wxString& hostname, unsigned int port) { m_aprsEnabled = enabled; + m_aprsPassword = password; m_aprsHostname = hostname; m_aprsPort = port; } @@ -2356,6 +2366,7 @@ bool CIRCDDBGatewayConfig::write() m_config->Write(m_name + KEY_IRCDDB_USERNAME4, m_ircddbUsername4); m_config->Write(m_name + KEY_IRCDDB_PASSWORD4, m_ircddbPassword4); m_config->Write(m_name + KEY_APRS_ENABLED, m_aprsEnabled); + m_config->Write(m_name + KEY_APRS_PASSWORD, m_aprsPassword); m_config->Write(m_name + KEY_APRS_HOSTNAME, m_aprsHostname); m_config->Write(m_name + KEY_APRS_PORT, long(m_aprsPort)); m_config->Write(m_name + KEY_DEXTRA_ENABLED, m_dextraEnabled); @@ -2563,6 +2574,7 @@ bool CIRCDDBGatewayConfig::write() buffer.Printf("%s=%s", KEY_IRCDDB_USERNAME4.c_str(), m_ircddbUsername4.c_str()); file.AddLine(buffer); buffer.Printf("%s=%s", KEY_IRCDDB_PASSWORD4.c_str(), m_ircddbPassword4.c_str()); file.AddLine(buffer); buffer.Printf(wxT("%s=%d"), KEY_APRS_ENABLED.c_str(), m_aprsEnabled ? 1 : 0); file.AddLine(buffer); + buffer.Printf(wxT("%s=%s"), KEY_APRS_PASSWORD.c_str(), m_aprsPassword.c_str()); file.AddLine(buffer); buffer.Printf(wxT("%s=%s"), KEY_APRS_HOSTNAME.c_str(), m_aprsHostname.c_str()); file.AddLine(buffer); buffer.Printf(wxT("%s=%u"), KEY_APRS_PORT.c_str(), m_aprsPort); file.AddLine(buffer); buffer.Printf(wxT("%s=%d"), KEY_DEXTRA_ENABLED.c_str(), m_dextraEnabled ? 1 : 0); file.AddLine(buffer); diff --git a/Common/IRCDDBGatewayConfig.h b/Common/IRCDDBGatewayConfig.h index f1c8ca2..09e8921 100644 --- a/Common/IRCDDBGatewayConfig.h +++ b/Common/IRCDDBGatewayConfig.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 by Jonathan Naylor G4KLX + * Copyright (C) 2010-2014,2018 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,8 +59,8 @@ public: void setIrcDDB3(bool enabled, const wxString& hostname, const wxString& username, const wxString& password); void setIrcDDB4(bool enabled, const wxString& hostname, const wxString& username, const wxString& password); - void getDPRS(bool& enabled, wxString& hostname, unsigned int& port) const; - void setDPRS(bool enabled, const wxString& hostname, unsigned int port); + void getDPRS(bool& enabled, wxString& password, wxString& hostname, unsigned int& port) const; + void setDPRS(bool enabled, const wxString& password, const wxString& hostname, unsigned int port); void getDExtra(bool& enabled, unsigned int& maxDongles) const; void setDExtra(bool enabled, unsigned int maxDongles); @@ -232,6 +232,7 @@ private: wxString m_ircddbUsername4; wxString m_ircddbPassword4; bool m_aprsEnabled; + wxString m_aprsPassword; wxString m_aprsHostname; unsigned int m_aprsPort; bool m_dextraEnabled; diff --git a/GUICommon/DPRSSet.cpp b/GUICommon/DPRSSet.cpp index 5a99dde..d300a2e 100644 --- a/GUICommon/DPRSSet.cpp +++ b/GUICommon/DPRSSet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 by Jonathan Naylor G4KLX + * Copyright (C) 2010,2018 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,10 +25,11 @@ const unsigned int CONTROL_WIDTH2 = 80U; const unsigned int PORT_LENGTH = 5U; const unsigned int PASSWORD_LENGTH = 5U; -CDPRSSet::CDPRSSet(wxWindow* parent, int id, const wxString& title, bool enabled, const wxString& hostname, unsigned int port) : +CDPRSSet::CDPRSSet(wxWindow* parent, int id, const wxString& title, bool enabled, const wxString& password, const wxString& hostname, unsigned int port) : wxPanel(parent, id), m_title(title), m_enabled(NULL), +m_password(NULL), m_hostname(NULL), m_port(NULL) { @@ -43,6 +44,12 @@ m_port(NULL) sizer->Add(m_enabled, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); m_enabled->SetSelection(enabled ? 1 : 0); + wxStaticText* passwordLabel = new wxStaticText(this, -1, _("Password")); + sizer->Add(passwordLabel, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + + m_password = new wxTextCtrl(this, -1, password, wxDefaultPosition, wxSize(CONTROL_WIDTH1, -1)); + sizer->Add(m_password, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + wxStaticText* hostnameLabel = new wxStaticText(this, -1, _("Hostname")); sizer->Add(hostnameLabel, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); @@ -75,6 +82,10 @@ bool CDPRSSet::Validate() if (n == wxNOT_FOUND) return false; + wxString password = m_password->GetValue(); + if (password.IsEmpty()) + return true; + wxString hostname = m_hostname->GetValue(); if (hostname.IsEmpty()) return true; @@ -99,6 +110,11 @@ bool CDPRSSet::getEnabled() const return c == 1; } +wxString CDPRSSet::getPassword() const +{ + return m_password->GetValue(); +} + wxString CDPRSSet::getHostname() const { return m_hostname->GetValue(); diff --git a/GUICommon/DPRSSet.h b/GUICommon/DPRSSet.h index 2d18220..56764f5 100644 --- a/GUICommon/DPRSSet.h +++ b/GUICommon/DPRSSet.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 by Jonathan Naylor G4KLX + * Copyright (C) 2010,2018 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,18 +25,20 @@ class CDPRSSet : public wxPanel { public: - CDPRSSet(wxWindow* parent, int id, const wxString& title, bool enabled, const wxString& hostname, unsigned int port); + CDPRSSet(wxWindow* parent, int id, const wxString& title, bool enabled, const wxString& password, const wxString& hostname, unsigned int port); virtual ~CDPRSSet(); virtual bool Validate(); virtual bool getEnabled() const; + virtual wxString getPassword() const; virtual wxString getHostname() const; virtual unsigned int getPort() const; private: wxString m_title; wxChoice* m_enabled; + wxTextCtrl* m_password; wxTextCtrl* m_hostname; CPortTextCtrl* m_port; }; diff --git a/ircDDBGateway/IRCDDBGatewayApp.cpp b/ircDDBGateway/IRCDDBGatewayApp.cpp index 9efde78..93fa3ba 100644 --- a/ircDDBGateway/IRCDDBGatewayApp.cpp +++ b/ircDDBGateway/IRCDDBGatewayApp.cpp @@ -254,15 +254,15 @@ void CIRCDDBGatewayApp::createThread() thread->setGateway(gatewayType, gatewayCallsign, gatewayAddress); - wxString aprsHostname; + wxString aprsHostname, aprsPassword; unsigned int aprsPort; bool aprsEnabled; - m_config->getDPRS(aprsEnabled, aprsHostname, aprsPort); + m_config->getDPRS(aprsEnabled, aprsPassword, aprsHostname, aprsPort); wxLogInfo(wxT("APRS enabled: %d, host: %s:%u"), int(aprsEnabled), aprsHostname.c_str(), aprsPort); CAPRSWriter* aprs = NULL; if (aprsEnabled && !gatewayCallsign.IsEmpty() && !aprsHostname.IsEmpty() && aprsPort != 0U) { - aprs = new CAPRSWriter(aprsHostname, aprsPort, gatewayCallsign, gatewayAddress); + aprs = new CAPRSWriter(aprsHostname, aprsPort, gatewayCallsign, aprsPassword, gatewayAddress); bool res = aprs->open(); if (!res) diff --git a/ircDDBGateway/IRCDDBGatewayFrame.cpp b/ircDDBGateway/IRCDDBGatewayFrame.cpp index 6569d8c..bb01e68 100644 --- a/ircDDBGateway/IRCDDBGatewayFrame.cpp +++ b/ircDDBGateway/IRCDDBGatewayFrame.cpp @@ -271,14 +271,10 @@ void CIRCDDBGatewayFrame::onTimer(wxTimerEvent&) } bool dprsStatus = status->getDPRSStatus(); - if (dprsStatus) { - if (ircDDBStatus == IS_CONNECTED || ircDDBStatus == IS_DISABLED) - m_dprsStatus->SetLabel(_("Active")); - else - m_dprsStatus->SetLabel(_("Waiting")); - } else { + if (dprsStatus) + m_dprsStatus->SetLabel(_("Active")); + else m_dprsStatus->SetLabel(_("Inactive")); - } for (unsigned int i = 0U; i < 4U; i++) { wxString callsign = status->getCallsign(i); diff --git a/ircDDBGateway/IRCDDBGatewayThread.cpp b/ircDDBGateway/IRCDDBGatewayThread.cpp index 9b9f830..917fb98 100644 --- a/ircDDBGateway/IRCDDBGatewayThread.cpp +++ b/ircDDBGateway/IRCDDBGatewayThread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 by Jonathan Naylor G4KLX + * Copyright (C) 2010-2015,2018 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -318,10 +318,6 @@ void CIRCDDBGatewayThread::run() CCCSHandler::setHeaderLogger(headerLogger); CCCSHandler::setHost(m_ccsHost); - // If no ircDDB then APRS is started immediately - if (m_aprsWriter != NULL && m_irc == NULL) - m_aprsWriter->setEnabled(true); - if (m_remoteEnabled && !m_remotePassword.IsEmpty() && m_remotePort > 0U) { m_remote = new CRemoteHandler(m_remotePassword, m_remotePort, m_gatewayAddress); bool res = m_remote->open(); @@ -689,24 +685,18 @@ void CIRCDDBGatewayThread::processIrcDDB() if (m_lastStatus != IS_DISCONNECTED) { wxLogInfo(wxT("Disconnected from ircDDB")); m_lastStatus = IS_DISCONNECTED; - if (m_aprsWriter != NULL) - m_aprsWriter->setEnabled(false); } break; case 7: if (m_lastStatus != IS_CONNECTED) { wxLogInfo(wxT("Connected to ircDDB")); m_lastStatus = IS_CONNECTED; - if (m_aprsWriter != NULL) - m_aprsWriter->setEnabled(true); } break; default: if (m_lastStatus != IS_CONNECTING) { wxLogInfo(wxT("Connecting to ircDDB")); m_lastStatus = IS_CONNECTING; - if (m_aprsWriter != NULL) - m_aprsWriter->setEnabled(false); } break; } diff --git a/ircDDBGatewayConfig/IRCDDBGatewayConfigFrame.cpp b/ircDDBGatewayConfig/IRCDDBGatewayConfigFrame.cpp index 1710617..2b10e6d 100644 --- a/ircDDBGatewayConfig/IRCDDBGatewayConfigFrame.cpp +++ b/ircDDBGatewayConfig/IRCDDBGatewayConfigFrame.cpp @@ -194,12 +194,12 @@ m_miscellaneous(NULL) m_ircDDB4 = new CIRCDDBGatewayConfigIrcDDBSet(noteBook, -1, APPLICATION_NAME, ircDDBEnabled, ircDDBHostname, ircDDBUsername, ircDDBPassword); noteBook->AddPage(m_ircDDB4, wxT("ircDDB 4th Network"), false); - wxString aprsHostname; + wxString aprsHostname, aprsPassword; unsigned int aprsPort; bool aprsEnabled; - m_config->getDPRS(aprsEnabled, aprsHostname, aprsPort); + m_config->getDPRS(aprsEnabled, aprsPassword, aprsHostname, aprsPort); - m_dprs = new CDPRSSet(noteBook, -1, APPLICATION_NAME, aprsEnabled, aprsHostname, aprsPort); + m_dprs = new CDPRSSet(noteBook, -1, APPLICATION_NAME, aprsEnabled, aprsPassword, aprsHostname, aprsPort); noteBook->AddPage(m_dprs, wxT("D-PRS"), false); m_dextra = new CDExtraSet(noteBook, -1, APPLICATION_NAME, dextraEnabled, maxDExtraDongles, MAX_DEXTRA_LINKS); @@ -497,9 +497,10 @@ void CIRCDDBGatewayConfigFrame::onSave(wxCommandEvent&) m_config->setIrcDDB4(ircDDBEnabled, ircDDBHostname, ircDDBUsername, ircDDBPassword); bool aprsEnabled = m_dprs->getEnabled(); + wxString aprsPassword = m_dprs->getPassword(); wxString aprsHostname = m_dprs->getHostname(); unsigned int aprsPort = m_dprs->getPort(); - m_config->setDPRS(aprsEnabled, aprsHostname, aprsPort); + m_config->setDPRS(aprsEnabled, aprsPassword, aprsHostname, aprsPort); bool dextraEnabled = m_dextra->getEnabled(); unsigned int maxDExtraDongles = m_dextra->getMaxDongles();