/* * Copyright (C) 2020 by Thomas Early N7TAE * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include "Utilities.h" #include "Location.h" 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); 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); } // returns true on success bool CLocation::Parse(const char *instr) { std::string s(instr); std::cmatch cm; trim(s); if (0 == s.find("$$CRC")) { std::regex_match(s.c_str(), cm, crc, std::regex_constants::match_default); } else if ((0 == s.find("$GPGGA")) || (0 == s.find("$GPRMC"))) { std::regex_match(s.c_str(), cm, rmc, std::regex_constants::match_default); } else { if ('$' == s.at(0)) std::cerr << "can't parse GPS string: " << s << std::endl; return false; } auto size = cm.size(); if (size != 7) { std::cerr << "Bad CRC Match for " << s << ":"; for (unsigned i=0; i