better gps regex

pull/14/head
Tom Early 6 years ago
parent 283fac92cb
commit 0b57ee6af0

@ -26,8 +26,8 @@
CLocation::CLocation() CLocation::CLocation()
{ {
crc = std::regex("^.*([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); 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);
rmc = std::regex("^.*,([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
@ -38,9 +38,9 @@ bool CLocation::Parse(const char *instr)
trim(s); trim(s);
if (0 == s.find("$$CRC")) { if (0 == s.find("$$CRC")) {
std::regex_match(s.c_str(), cm, crc, std::regex_constants::match_default); std::regex_search(s.c_str(), cm, crc, std::regex_constants::match_default);
} else if ((0 == s.find("$GPGGA")) || (0 == s.find("$GPRMC"))) { } else if ((0 == s.find("$GPGGA")) || (0 == s.find("$GPRMC"))) {
std::regex_match(s.c_str(), cm, rmc, std::regex_constants::match_default); std::regex_search(s.c_str(), cm, rmc, std::regex_constants::match_default);
} else { } else {
if ('$' == s.at(0)) if ('$' == s.at(0))
std::cerr << "can't parse GPS string: " << s << std::endl; std::cerr << "can't parse GPS string: " << s << std::endl;

Loading…
Cancel
Save

Powered by TurnKey Linux.