nmealib 0.0.4
NMEA 0183/NMEA 2000 parsing library
Loading...
Searching...
No Matches
vtg.h
Go to the documentation of this file.
1#pragma once
2
3#include <nmealib/nmea0183.h>
4
5#include <optional>
6
7namespace nmealib {
8namespace nmea0183 {
9
17public:
24 explicit NotVTGException(const std::string& context, const std::string& details = "") :
25 NmeaException(context, "The sentence is not a VTG sentence", details) {}
26};
27
44class VTG : public Message0183 {
45public:
57 VTG(std::string talkerId,
58 double courseOverGroundTrue,
59 double courseOverGroundMagnetic,
60 double speedOverGroundKnots,
61 double speedOverGroundKph,
62 std::optional<char> faaModeIndicator = std::nullopt,
63 bool legacyFormat = false
64 );
65
66 VTG(const VTG&) = default;
67 VTG& operator=(const VTG&) = default;
68 VTG(VTG&&) noexcept = default;
69 VTG& operator=(VTG&&) noexcept = default;
70
71 ~VTG() override = default;
72
78 std::unique_ptr<nmealib::Message> clone() const override;
79
81 double getCourseOverGroundTrue() const noexcept;
83 char getCourseOverGroundTrueType() const noexcept;
85 double getCourseOverGroundMagnetic() const noexcept;
87 char getCourseOverGroundMagneticType() const noexcept;
89 double getSpeedOverGroundKnots() const noexcept;
91 char getSpeedOverGroundKnotsType() const noexcept;
93 double getSpeedOverGroundKph() const noexcept;
95 char getSpeedOverGroundKphType() const noexcept;
97 bool hasFaaModeIndicator() const noexcept;
99 std::optional<char> getFaaModeIndicator() const noexcept;
101 bool isLegacyFormat() const noexcept;
102
109 std::string getStringContent(bool verbose) const noexcept override;
110
119 bool operator==(const VTG& other) const noexcept;
120
121private:
122 double courseOverGroundTrue_{};
123 char courseOverGroundTrueType_{};
124 double courseOverGroundMagnetic_{};
125 char courseOverGroundMagneticType_{};
126 double speedOverGroundKnots_{};
127 char speedOverGroundKnotsType_{};
128 double speedOverGroundKph_{};
129 char speedOverGroundKphType_{};
130 std::optional<char> faaModeIndicator_{};
131 bool legacyFormat_{};
132
133 VTG() = delete;
134
135 VTG(Message0183 baseMessage,
136 double courseOverGroundTrue,
137 char courseOverGroundTrueType,
138 double courseOverGroundMagnetic,
139 char courseOverGroundMagneticType,
140 double speedOverGroundKnots,
141 char speedOverGroundKnotsType,
142 double speedOverGroundKph,
143 char speedOverGroundKphType,
144 std::optional<char> faaModeIndicator,
145 bool legacyFormat
146 ) noexcept;
147
148 static std::unique_ptr<VTG> create(std::unique_ptr<Message0183> baseMessage);
149 static std::string composeRaw(const std::string& talkerId,
150 double courseOverGroundTrue,
151 double courseOverGroundMagnetic,
152 double speedOverGroundKnots,
153 double speedOverGroundKph,
154 std::optional<char> faaModeIndicator,
155 bool legacyFormat);
156
157 friend class Nmea0183Factory;
158 friend class MessageRegistry;
159};
160
161} // namespace nmea0183
162} // namespace nmealib
Defines a base class for NMEA messages, encapsulating common properties and behaviors.
Definition message.h:14
Base exception class for all NMEA library errors.
Represents an NMEA 0183 sentence.
Definition nmea0183.h:98
Registry for message type creators.
Factory for creating typed NMEA 0183 message objects from raw sentence strings.
Exception thrown when a sentence is not a valid VTG sentence.
Definition vtg.h:16
NotVTGException(const std::string &context, const std::string &details="")
Construct a NotVTGException with context and optional details.
Definition vtg.h:24
Represents a parsed NMEA 0183 VTG (Course Over Ground and Ground Speed) sentence.
Definition vtg.h:44
VTG(VTG &&) noexcept=default
char getSpeedOverGroundKphType() const noexcept
Get km/h unit indicator (typically 'K', or '\0' in legacy format).
Definition vtg.cpp:248
double getSpeedOverGroundKnots() const noexcept
Get speed over ground in knots.
Definition vtg.cpp:236
bool isLegacyFormat() const noexcept
Return whether this sentence uses legacy compact VTG format.
Definition vtg.cpp:260
VTG & operator=(const VTG &)=default
double getCourseOverGroundMagnetic() const noexcept
Get magnetic course over ground in degrees.
Definition vtg.cpp:228
VTG(std::string talkerId, double courseOverGroundTrue, double courseOverGroundMagnetic, double speedOverGroundKnots, double speedOverGroundKph, std::optional< char > faaModeIndicator=std::nullopt, bool legacyFormat=false)
Construct a VTG message from individual field values.
Definition vtg.cpp:131
char getCourseOverGroundTrueType() const noexcept
Get true course type indicator (typically 'T', or '\0' in legacy format).
Definition vtg.cpp:224
std::unique_ptr< nmealib::Message > clone() const override
Create a polymorphic copy of this VTG message.
Definition vtg.cpp:156
char getSpeedOverGroundKnotsType() const noexcept
Get knots unit indicator (typically 'N', or '\0' in legacy format).
Definition vtg.cpp:240
double getCourseOverGroundTrue() const noexcept
Get true course over ground in degrees.
Definition vtg.cpp:220
VTG(const VTG &)=default
std::string getStringContent(bool verbose) const noexcept override
Return a human-readable string representation of this message.
Definition vtg.cpp:160
char getCourseOverGroundMagneticType() const noexcept
Get magnetic course type indicator (typically 'M', or '\0' in legacy format).
Definition vtg.cpp:232
bool hasFaaModeIndicator() const noexcept
Return whether FAA mode indicator is present.
Definition vtg.cpp:252
double getSpeedOverGroundKph() const noexcept
Get speed over ground in kilometers per hour.
Definition vtg.cpp:244
std::optional< char > getFaaModeIndicator() const noexcept
Get optional FAA mode indicator.
Definition vtg.cpp:256