-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#9 First working proof of concept, msg dstar->
- Loading branch information
Showing
7 changed files
with
267 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA | ||
* | ||
* 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 | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
*/ | ||
|
||
#include <boost/algorithm/string.hpp> | ||
|
||
#include "APRSUtils.h" | ||
|
||
void CAPRSUtils::dstarCallsignToAPRS(std::string& dstarCallsign) | ||
{ | ||
if(dstarCallsign[dstarCallsign.length() - 1] == ' ') { | ||
boost::trim(dstarCallsign); | ||
} else { | ||
//loop until got rid of all double blanks | ||
while(dstarCallsign.find(" ") != std::string::npos) { | ||
boost::replace_all(dstarCallsign, " ", " "); | ||
} | ||
boost::replace_all(dstarCallsign, " ", "-");//replace remaining blank with a - | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (C) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA | ||
* | ||
* 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 | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
class CAPRSUtils | ||
{ | ||
public: | ||
static void dstarCallsignToAPRS(std::string& dstarCallsign); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright (C) 2010,2012,2018 by Jonathan Naylor G4KLX | ||
* Copyright (C) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA | ||
* | ||
* 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 | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
*/ | ||
|
||
|
||
#include <cstring> | ||
#include <cassert> | ||
#include <boost/algorithm/string.hpp> | ||
#include <vector> | ||
|
||
#include "RSMS1AMessageCollector.h" | ||
#include "StringUtils.h" | ||
#include "Log.h" | ||
#include "Utils.h" | ||
#include "APRSUtils.h" | ||
|
||
const unsigned int APRS_CSUM_LENGTH = 4U; | ||
|
||
CRSMS1AMessageCollector::CRSMS1AMessageCollector() : | ||
CSentenceCollector(SLOW_DATA_TYPE_GPS, "$$Msg", '\x0D') | ||
{ | ||
|
||
} | ||
|
||
bool CRSMS1AMessageCollector::isValidSentence(const std::string& sentence) | ||
{ | ||
return isValidGPSA(sentence); | ||
} | ||
|
||
bool CRSMS1AMessageCollector::isValidGPSA(const std::string& msg) | ||
{ | ||
if(msg.empty() || !boost::starts_with(msg, "$$Msg")) | ||
return false; | ||
|
||
std::vector<std::string> splits; | ||
boost::split(splits, msg, boost::is_any_of(",")); | ||
|
||
bool ret = splits.size() == 4 | ||
&& !splits[1].empty() | ||
&& !splits[2].empty() | ||
&& splits[3].length() > 6U; | ||
return ret; | ||
|
||
// CUtils::dump("RS-MS1A:", (unsigned char *)gpsa.c_str(), gpsa.length() + 1U); | ||
// CLog::logDebug("RS-MS1A: %s", gpsa.c_str()); | ||
|
||
// auto thirdCommaPos = CStringUtils::find_nth(gpsa, 0U, ',', 3); | ||
// auto csum = calcCRC(gpsa, thirdCommaPos + 6 + 1, gpsa.length() - thirdCommaPos - 2U - 6U); | ||
// auto csumStr = CStringUtils::string_format("%06X", csum); | ||
// CLog::logDebug("RS-MS1A CRC: %s", csumStr.c_str()); | ||
|
||
// auto expectedCsum = gpsa.substr(5U, APRS_CSUM_LENGTH); | ||
// bool res = ::strcasecmp(csumStr.c_str(), expectedCsum.c_str()) == 0; | ||
// return res; | ||
} | ||
|
||
unsigned int CRSMS1AMessageCollector::calcCRC(const std::string& gpsa, unsigned int start, unsigned int length) | ||
{ | ||
unsigned int icomcrc = 0xFFFFU; | ||
auto end = start + length; | ||
if(end > gpsa.length()) { | ||
end = gpsa.length(); | ||
} | ||
|
||
for (unsigned int j = start; j < end; j++) { | ||
unsigned char ch = (unsigned char)gpsa[j]; | ||
|
||
for (unsigned int i = 0U; i < 8U; i++) { | ||
bool xorflag = (((icomcrc ^ ch) & 0x01U) == 0x01U); | ||
|
||
icomcrc >>= 1; | ||
|
||
if (xorflag) | ||
icomcrc ^= 0x8408U; | ||
|
||
ch >>= 1; | ||
} | ||
} | ||
|
||
return ~icomcrc & 0xFFFFU; | ||
} | ||
|
||
unsigned int CRSMS1AMessageCollector::getDataInt(unsigned char * data, unsigned int length) | ||
{ | ||
if(data == nullptr || length == 0U || getSentence().empty()) | ||
return 0U; | ||
|
||
auto sentence = getSentence(); | ||
|
||
std::vector<std::string> splits; | ||
boost::split(splits, sentence, boost::is_any_of(",")); | ||
|
||
bool ret = splits.size() == 4 | ||
&& !splits[1].empty() | ||
&& !splits[2].empty() | ||
&& splits[3].length() > 6U; | ||
if(!ret) { | ||
return 0U; | ||
} | ||
|
||
auto sender = splits[1]; | ||
auto recipient = CUtils::ToUpper(splits[2]); | ||
auto message = splits[3].substr(6, splits[3].length() - 2); | ||
|
||
CAPRSUtils::dstarCallsignToAPRS(sender); | ||
CAPRSUtils::dstarCallsignToAPRS(recipient); | ||
recipient.resize(9, ' '); | ||
|
||
//unescape commas in message body | ||
boost::replace_all(message, "o,", ","); | ||
|
||
auto aprsFrame = CStringUtils::string_format("%s-5>APDPRS,DSTAR*::%s:%s\r\n", sender.c_str(), recipient.c_str(), message.c_str()); | ||
|
||
auto aprsFrameLen = aprsFrame.length(); | ||
|
||
if(length < aprsFrameLen) { | ||
CLog::logDebug("Not enough space to copy GPS-A APRS frame"); | ||
return 0U; | ||
} | ||
|
||
for(unsigned int i = 0U; i < aprsFrameLen; i++){ | ||
data[i] = aprsFrame[i]; | ||
} | ||
|
||
return aprsFrameLen; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2010,2012,2018 by Jonathan Naylor G4KLX | ||
* Copyright (C) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA | ||
* | ||
* 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 | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "SentenceCollector.h" | ||
|
||
class CRSMS1AMessageCollector : public CSentenceCollector | ||
{ | ||
public: | ||
CRSMS1AMessageCollector(); | ||
|
||
protected: | ||
unsigned int getDataInt(unsigned char * data, unsigned int length); | ||
bool isValidSentence(const std::string& sentence); | ||
|
||
private: | ||
static unsigned int calcCRC(const std::string& gpsa, unsigned int start, unsigned int length); | ||
static bool isValidGPSA(const std::string& gpsa); | ||
|
||
std::string m_sentence; | ||
std::string m_collector; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters