From 7817994344e90e3f8c816da00e0614a344309416 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Tue, 16 Jun 2020 07:59:01 -0700 Subject: [PATCH] more efficient gps parsing --- Location.cpp | 15 ++------------- Location.h | 2 +- QnetGateway.cpp | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/Location.cpp b/Location.cpp index fa309bf..61fd6d4 100644 --- a/Location.cpp +++ b/Location.cpp @@ -26,8 +26,7 @@ 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); - 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); + 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); } // returns true on success @@ -39,17 +38,7 @@ bool CLocation::Parse(const char *instr) if (s.size() < 20) return false; - bool success; - 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) { + if (! std::regex_search(s.c_str(), cm, gps, std::regex_constants::match_default)) { std::cerr << "Unsuccessful gps parse of '" << s << "'" << std::endl; return false; } diff --git a/Location.h b/Location.h index 483bbed..bad628a 100644 --- a/Location.h +++ b/Location.h @@ -29,5 +29,5 @@ public: private: char maidenhead[7]; double latitude, longitude; - std::regex crc, rmc; + std::regex gps; }; diff --git a/QnetGateway.cpp b/QnetGateway.cpp index de873e6..79e56ac 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -54,7 +54,7 @@ #define CFG_DIR "/usr/local/etc" #endif -const std::string GW_VERSION("QnetGateway-615"); +const std::string GW_VERSION("QnetGateway-616"); int CQnetGateway::FindIndex(const int i) const {