#12 add some more frame types

pull/32/head
Geoffrey Merck 4 years ago
parent 5e1cfb4d2c
commit 6a7cf1a8df

@ -8,7 +8,8 @@
"type": "shell",
"command": "make",
"args": [
"-j3", "USE_GPSD=1"
"-j3",
"USE_GPSD=1"
],
"group": {
"kind": "build",
@ -22,7 +23,8 @@
"command": "make",
"args": [
"-j3",
"tests"
"tests",
"USE_GPSD=1"
],
"group": "build",
"problemMatcher": []

@ -28,7 +28,8 @@ enum APRS_FRAME_TYPE {
APFT_POSITION,
APFT_NMEA,
APFT_STATUS,
APFT_OBJECT
APFT_OBJECT,
APFT_WX
};
class CAPRSFrame {

@ -21,12 +21,8 @@
bool CAPRSParser::parseFrame(const std::string& frameStr, CAPRSFrame& frame)
{
return parseFrame(frameStr, frame, false);
}
bool CAPRSParser::parseFrame(const std::string& frameStr, CAPRSFrame& frame, bool doNotEnforceFrameType)
{
frame.clear();
bool ret = doNotEnforceFrameType;
bool ret = false;
if(!frameStr.empty()) {
auto pos = frameStr.find_first_of(':');
@ -48,14 +44,9 @@ bool CAPRSParser::parseFrame(const std::string& frameStr, CAPRSFrame& frame, boo
frame.getBody().assign(body);
if(!doNotEnforceFrameType) {
setFrameType(frame);
if(frame.getType() == APFT_UNKNOWN) {
CLog::logInfo("Invalid or unsupported APRS frame : %s", frameStr);
}
else {
ret = true;
}
ret = parseInt(frame);
if(!ret) {
frame.clear();
}
}
}
@ -64,37 +55,89 @@ bool CAPRSParser::parseFrame(const std::string& frameStr, CAPRSFrame& frame, boo
return ret;
}
void CAPRSParser::setFrameType(CAPRSFrame& frame)
bool CAPRSParser::parseInt(CAPRSFrame& frame)
{
APRS_FRAME_TYPE type = APFT_UNKNOWN;
std::string body(frame.getBody());
unsigned char typeChar = frame.getBody()[0];
std::string body(frame.getBody().substr(1));//strip the type char for processing purposes
if(body.empty())
return false;
if(!body.empty()) {
switch (body[0])
{
case ':':
if(body[10] == ':' && std::all_of(body.begin() + 1, body.begin() + 10,
[](char c){ return c == ' ' || c == '-' || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); }))
type = APFT_MESSAGE;
break;
// case '!':
// if(body.length() >= 2U && body[1] == '!') {
// // This is ultimeter 200 weather station
// type = APFT_UNKNOWN;
// break;
// } else {
// type = APFT_POSITION;
// }
// case '=':
// case '/':
// case '@':
// break;
default:
break;
}
}
switch (typeChar)
{
case '!':
if(body[0] == '!') {
// This is ultimeter 200 weather station
return false;
}
[[fallthrough]];
case '=':
case '/':
case '@':
{
if(body.length() < 10) return false;//enough chars to have a chance to parse it ?
/* Normal or compressed location packet, with or without
* timestamp, with or without messaging capability
*
* ! and / have messaging, / and @ have a prepended timestamp
*/
type = APFT_POSITION;
if(typeChar == '/' || typeChar== '@')//With a prepended timestamp, jump over it.
body = body.substr(7U);
auto posChar = body[0];
if(valid_sym_table_compressed(posChar)//Compressed format
&& body.length() >= 13){//we need at least 13 char
//icom unsupported, ignore for now
return false;//parse_aprs_compressed(pb, body, body_end);
}
else if(posChar >= '0' && posChar <= '9' //Normal uncompressed format
&& body.length() >=19){//we need at least 19 chars for it to be valid
// if(ensureIsIcomCompatible(packet))
// return Parse(packet.Raw(), packet);
}
}
break;
case '$' :
if(body.length() > 10) {
type = APFT_NMEA;
}
break;
case ':':
if(body[9] == ':' && std::all_of(body.begin(), body.begin() + 9,
[](char c){ return c == ' ' || c == '-' || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); }))
type = APFT_MESSAGE;
break;
case '>':
type = APFT_STATUS;
break;
case '#': /* Peet Bros U-II Weather Station */
case '*': /* Peet Bros U-I Weather Station */
case '_': /* Weather report without position */
type = APFT_WX;
break;
case '{':
type = APFT_UNKNOWN; //
break;
default:
type = APFT_UNKNOWN;
break;
}
frame.getType() = type;
if(type == APFT_UNKNOWN)
frame.clear();
return type != APFT_UNKNOWN;
}
bool CAPRSParser::valid_sym_table_compressed(unsigned char c)
{
return (c == '/' || c == '\\' || (c >= 0x41 && c <= 0x5A)
|| (c >= 0x61 && c <= 0x6A)); /* [\/\\A-Za-j] */
}
bool CAPRSParser::valid_sym_table_uncompressed(unsigned char c)
{
return (c == '/' || c == '\\' || (c >= 0x41 && c <= 0x5A)
|| (c >= 0x30 && c <= 0x39)); /* [\/\\A-Z0-9] */
}

@ -27,8 +27,9 @@ class CAPRSParser
{
public:
static bool parseFrame(const std::string& frameStr, CAPRSFrame& frame);
static bool parseFrame(const std::string& frameStr, CAPRSFrame& frame, bool doNotEnforceFrameType);
private:
static void setFrameType(CAPRSFrame& frame);
static bool parseInt(CAPRSFrame& frame);
static bool valid_sym_table_compressed(unsigned char c);
static bool valid_sym_table_uncompressed(unsigned char c);
};

@ -133,7 +133,7 @@ void CAPRSWriter::writeData(const std::string& callsign, const CAMBEData& data)
std::string text((char*)buffer, length);
CAPRSFrame frame;
if(!CAPRSParser::parseFrame(text, frame, true)) {
if(!CAPRSParser::parseFrame(text, frame)) {
collector->reset();
CLog::logWarning("Failed to parse DPRS Frame : %s", text.c_str());
return;

@ -104,33 +104,18 @@ TEST_F(APRSParser_parseAPRSFrame, InvalidMessageFrame) {
EXPECT_EQ(aprsFrame.getPath().size(), 0U);
}
TEST_F(APRSParser_parseAPRSFrame, ValidFrameDoNotEnforceType) {
CAPRSFrame aprsFrame;
bool retVal = CAPRSParser::parseFrame("N0CALL>APRS,WIDE1-1,WIDE2-2:Lorem Ipsum", aprsFrame, true);
EXPECT_TRUE(retVal);
EXPECT_STRCASEEQ(aprsFrame.getBody().c_str(), "Lorem Ipsum");
EXPECT_STRCASEEQ(aprsFrame.getDestination().c_str(), "APRS");
EXPECT_STRCASEEQ(aprsFrame.getSource().c_str(), "N0CALL");
EXPECT_EQ(aprsFrame.getType(), APFT_UNKNOWN);
EXPECT_EQ(aprsFrame.getPath().size(), 2);
EXPECT_STREQ(aprsFrame.getPath()[0].c_str(), "WIDE1-1");
EXPECT_STREQ(aprsFrame.getPath()[1].c_str(), "WIDE2-2");
}
//
TEST_F(APRSParser_parseAPRSFrame, ID51) {
CAPRSFrame aprsFrame;
bool retVal = CAPRSParser::parseFrame("F4FXL-8>API51,DSTAR:!1234.56N/12345.67E[/A=000886QRV DStar\r\r\n", aprsFrame, true);
bool retVal = CAPRSParser::parseFrame("F4FXL-8>API51,DSTAR:!1234.56N/12345.67E[/A=000886QRV DStar\r\r\n", aprsFrame);
EXPECT_TRUE(retVal);
EXPECT_STRCASEEQ(aprsFrame.getBody().c_str(), "!1234.56N/12345.67E[/A=000886QRV DStar\r\r\n");
EXPECT_STRCASEEQ(aprsFrame.getDestination().c_str(), "API51");
EXPECT_STRCASEEQ(aprsFrame.getSource().c_str(), "F4FXL-8");
EXPECT_EQ(aprsFrame.getType(), APFT_UNKNOWN);
EXPECT_EQ(aprsFrame.getType(), APFT_POSITION);
EXPECT_EQ(aprsFrame.getPath().size(), 1);
EXPECT_STREQ(aprsFrame.getPath()[0].c_str(), "DSTAR");
}
Loading…
Cancel
Save

Powered by TurnKey Linux.