#12 move calcCRC to APRSUtils

pull/32/head
Geoffrey Merck 4 years ago
parent e0ea97d8fc
commit 51748fda29

@ -31,4 +31,27 @@ void CAPRSUtils::dstarCallsignToAPRS(std::string& dstarCallsign)
}
boost::replace_all(dstarCallsign, " ", "-");//replace remaining blank with a -
}
}
unsigned int CAPRSUtils::calcIcomCRC(const std::string& gpsa)
{
unsigned int icomcrc = 0xFFFFU;
auto length = gpsa.length();
for (unsigned int j = 10U; j < length; 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;
}

@ -24,4 +24,5 @@ class CAPRSUtils
{
public:
static void dstarCallsignToAPRS(std::string& dstarCallsign);
static unsigned int calcIcomCRC(const std::string& gpsa);
};

@ -25,6 +25,7 @@
#include "GPSACollector.h"
#include "StringUtils.h"
#include "Log.h"
#include "APRSUtils.h"
const unsigned int APRS_CSUM_LENGTH = 4U;
@ -44,36 +45,13 @@ bool CGPSACollector::isValidGPSA(const std::string& gpsa)
if(gpsa.length() < 10U || !boost::starts_with(gpsa, "$$CRC"))
return false;
auto csum = calcCRC(gpsa);
auto csum = CAPRSUtils::calcIcomCRC(gpsa);
auto csumStr = CStringUtils::string_format("%04X", csum);
auto expectedCsum = gpsa.substr(5U, APRS_CSUM_LENGTH);
bool res = ::strcasecmp(csumStr.c_str(), expectedCsum.c_str()) == 0;
return res;
}
unsigned int CGPSACollector::calcCRC(const std::string& gpsa)
{
unsigned int icomcrc = 0xFFFFU;
auto length = gpsa.length();
for (unsigned int j = 10U; j < length; 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 CGPSACollector::getDataInt(unsigned char * data, unsigned int length)
{
if(data == nullptr || length == 0U || getSentence().empty())

Loading…
Cancel
Save

Powered by TurnKey Linux.