#12 add some more frame types

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

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

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

@ -21,12 +21,8 @@
bool CAPRSParser::parseFrame(const std::string& frameStr, CAPRSFrame& frame) 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(); frame.clear();
bool ret = doNotEnforceFrameType; bool ret = false;
if(!frameStr.empty()) { if(!frameStr.empty()) {
auto pos = frameStr.find_first_of(':'); auto pos = frameStr.find_first_of(':');
@ -48,14 +44,9 @@ bool CAPRSParser::parseFrame(const std::string& frameStr, CAPRSFrame& frame, boo
frame.getBody().assign(body); frame.getBody().assign(body);
if(!doNotEnforceFrameType) { ret = parseInt(frame);
setFrameType(frame); if(!ret) {
if(frame.getType() == APFT_UNKNOWN) { frame.clear();
CLog::logInfo("Invalid or unsupported APRS frame : %s", frameStr);
}
else {
ret = true;
}
} }
} }
} }
@ -64,37 +55,89 @@ bool CAPRSParser::parseFrame(const std::string& frameStr, CAPRSFrame& frame, boo
return ret; return ret;
} }
void CAPRSParser::setFrameType(CAPRSFrame& frame) bool CAPRSParser::parseInt(CAPRSFrame& frame)
{ {
APRS_FRAME_TYPE type = APFT_UNKNOWN; 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 (typeChar)
switch (body[0]) {
{ case '!':
case ':': if(body[0] == '!') {
if(body[10] == ':' && std::all_of(body.begin() + 1, body.begin() + 10, // This is ultimeter 200 weather station
[](char c){ return c == ' ' || c == '-' || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); })) return false;
type = APFT_MESSAGE; }
break; [[fallthrough]];
// case '!': case '=':
// if(body.length() >= 2U && body[1] == '!') { case '/':
// // This is ultimeter 200 weather station case '@':
// type = APFT_UNKNOWN; {
// break; if(body.length() < 10) return false;//enough chars to have a chance to parse it ?
// } else { /* Normal or compressed location packet, with or without
// type = APFT_POSITION; * timestamp, with or without messaging capability
// } *
// case '=': * ! and / have messaging, / and @ have a prepended timestamp
// case '/': */
// case '@': type = APFT_POSITION;
// break; if(typeChar == '/' || typeChar== '@')//With a prepended timestamp, jump over it.
default: body = body.substr(7U);
break;
}
}
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; frame.getType() = type;
if(type == APFT_UNKNOWN) return type != APFT_UNKNOWN;
frame.clear(); }
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: public:
static bool parseFrame(const std::string& frameStr, CAPRSFrame& frame); static bool parseFrame(const std::string& frameStr, CAPRSFrame& frame);
static bool parseFrame(const std::string& frameStr, CAPRSFrame& frame, bool doNotEnforceFrameType);
private: 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); std::string text((char*)buffer, length);
CAPRSFrame frame; CAPRSFrame frame;
if(!CAPRSParser::parseFrame(text, frame, true)) { if(!CAPRSParser::parseFrame(text, frame)) {
collector->reset(); collector->reset();
CLog::logWarning("Failed to parse DPRS Frame : %s", text.c_str()); CLog::logWarning("Failed to parse DPRS Frame : %s", text.c_str());
return; return;

@ -104,33 +104,18 @@ TEST_F(APRSParser_parseAPRSFrame, InvalidMessageFrame) {
EXPECT_EQ(aprsFrame.getPath().size(), 0U); 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) { TEST_F(APRSParser_parseAPRSFrame, ID51) {
CAPRSFrame aprsFrame; 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_TRUE(retVal);
EXPECT_STRCASEEQ(aprsFrame.getBody().c_str(), "!1234.56N/12345.67E[/A=000886QRV DStar\r\r\n"); 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.getDestination().c_str(), "API51");
EXPECT_STRCASEEQ(aprsFrame.getSource().c_str(), "F4FXL-8"); 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_EQ(aprsFrame.getPath().size(), 1);
EXPECT_STREQ(aprsFrame.getPath()[0].c_str(), "DSTAR"); EXPECT_STREQ(aprsFrame.getPath()[0].c_str(), "DSTAR");
} }
Loading…
Cancel
Save

Powered by TurnKey Linux.