QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GPSASCIILog.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <optional>
5#include <string_view>
6
7#include "CRC32.h"
8#include "NMEASentence.h"
9
12{
14 std::string_view name;
16 std::string_view source;
17};
18
21[[nodiscard]] inline std::optional<GPSASCIILog> gpsASCIILog(std::string_view line)
22{
23 constexpr size_t CRC_DIGITS = 8;
24 const size_t star = line.rfind('*');
25 if (!line.starts_with('#') || star == std::string_view::npos || star + 1 + CRC_DIGITS != line.size()) {
26 return std::nullopt;
27 }
28 const auto expected = NMEA::hexNumber(line.substr(star + 1));
29 if (!expected || *expected != QGC::crc32Update({reinterpret_cast<const uint8_t*>(line.data() + 1), star - 1})) {
30 return std::nullopt;
31 }
32 const size_t semicolon = line.find(';');
33 const size_t first = line.find(',');
34 if (semicolon == std::string_view::npos || first == std::string_view::npos || first > semicolon) {
35 return std::nullopt;
36 }
37 const size_t second = line.find_first_of(",;", first + 1);
38 return GPSASCIILog{.name = line.substr(1, first - 1), .source = line.substr(first + 1, second - first - 1)};
39}
std::optional< GPSASCIILog > gpsASCIILog(std::string_view line)
Definition GPSASCIILog.h:21
std::optional< uint32_t > hexNumber(std::string_view digits)
The value of digits when every one is a hexadecimal digit, with no sign or prefix; nullopt otherwise.
constexpr uint32_t crc32Update(std::span< const uint8_t > bytes, uint32_t state=0)
Reflected CRC-32 update; the caller supplies the initial state and final complement policy.
Definition CRC32.h:39
The header fields receiver detection tells NovAtel-style ASCII logs apart by.
Definition GPSASCIILog.h:12
std::string_view name
The log name, such as "VERSIONA".
Definition GPSASCIILog.h:14
std::string_view source
The second header field: a port such as "COM1" from NovAtel-compatible receivers, CPU idle time from ...
Definition GPSASCIILog.h:16