more efficient gps parsing

pull/14/head
Tom Early 6 years ago
parent af0d399cd4
commit 7817994344

@ -26,8 +26,7 @@
CLocation::CLocation() CLocation::CLocation()
{ {
crc = std::regex("[^0-9]([0-9]{1,2})([0-9]{2}\\.[0-9]{1,})([NS])/([0-9]{1,3})([0-9]{2}\\.[0-9]{1,})([WE])", std::regex::extended); gps = std::regex("[^0-9]([0-9]{1,2})([0-9]{2}\\.[0-9]{1,}),?([NS])[/,]([0-9]{1,3})([0-9]{2}\\.[0-9]{1,}),?([WE])", std::regex::extended);
rmc = std::regex("[^0-9]([0-9]{1,2})([0-9]{2}\\.[0-9]{1,}),([NS]),([0-9]{1,3})([0-9]{2}\\.[0-9]{1,}),([WE]),", std::regex::extended);
} }
// returns true on success // returns true on success
@ -39,17 +38,7 @@ bool CLocation::Parse(const char *instr)
if (s.size() < 20) if (s.size() < 20)
return false; return false;
bool success; if (! std::regex_search(s.c_str(), cm, gps, std::regex_constants::match_default)) {
if (3 > s.find("$$CRC")) {
success = std::regex_search(s.c_str(), cm, crc, std::regex_constants::match_default);
} else if ((3 > s.find("$GPGGA")) || (3 > s.find("$GPRMC"))) {
success = std::regex_search(s.c_str(), cm, rmc, std::regex_constants::match_default);
} else {
std::cerr << "Unrecognized GPS string: " << s << std::endl;
return false;
}
if (! success) {
std::cerr << "Unsuccessful gps parse of '" << s << "'" << std::endl; std::cerr << "Unsuccessful gps parse of '" << s << "'" << std::endl;
return false; return false;
} }

@ -29,5 +29,5 @@ public:
private: private:
char maidenhead[7]; char maidenhead[7];
double latitude, longitude; double latitude, longitude;
std::regex crc, rmc; std::regex gps;
}; };

@ -54,7 +54,7 @@
#define CFG_DIR "/usr/local/etc" #define CFG_DIR "/usr/local/etc"
#endif #endif
const std::string GW_VERSION("QnetGateway-615"); const std::string GW_VERSION("QnetGateway-616");
int CQnetGateway::FindIndex(const int i) const int CQnetGateway::FindIndex(const int i) const
{ {

Loading…
Cancel
Save

Powered by TurnKey Linux.