14std::unique_ptr<GLL> GLL::create(std::unique_ptr<Message0183> baseMessage) {
15 std::string context =
"GLL::create";
16 if (baseMessage->getSentenceType() !=
"GLL") {
17 NMEALIB_RETURN_ERROR(NotGLLException(context,
"Expected sentence type 'GLL', got " + baseMessage->getSentenceType()));
21 std::string payload = baseMessage->getPayload();
22 std::istringstream ss(payload);
24 std::vector<std::string> fields;
26 while (std::getline(ss, token,
',')) {
27 fields.push_back(token);
30 if (!payload.empty() && payload.back() ==
',') {
35 if (!fields.empty()) {
36 fields.erase(fields.begin());
39 if (fields.size() != 6 && fields.size() != 7) {
40 NMEALIB_RETURN_ERROR(NotGLLException(context,
"Insufficient fields in GLL payload: expected 6 or 7, got " + std::to_string(fields.size()) +
". Payload: " + payload));
43 double latitude = 0.0;
44 double longitude = 0.0;
45 double timestamp = 0.0;
52 char latitudeDirection = fields[1].empty() ?
'\0' : fields[1][0];
53 char longitudeDirection = fields[3].empty() ?
'\0' : fields[3][0];
54 char status = fields[5].empty() ?
'\0' : fields[5][0];
55 char modeIndicator = (fields.size() > 6 && !fields[6].empty()) ? fields[6][0] :
'\0';
57 return std::unique_ptr<GLL>(
new GLL(std::move(*baseMessage),
67GLL::GLL(Message0183 baseMessage,
69 char latitudeDirection,
71 char longitudeDirection,
74 char modeIndicator) noexcept
75 : Message0183(std::move(baseMessage)),
77 latitudeDirection_(latitudeDirection),
78 longitude_(longitude),
79 longitudeDirection_(longitudeDirection),
82 modeIndicator_(modeIndicator) {}
84GLL::GLL(std::string talkerId,
86 char latitudeDirection,
88 char longitudeDirection,
101 latitudeDirection_(latitudeDirection),
102 longitude_(longitude),
103 longitudeDirection_(longitudeDirection),
106 modeIndicator_(modeIndicator) {}
109 return std::unique_ptr<GLL>(
new GLL(*
this));
113 std::ostringstream ss;
114 ss << this->toString(verbose);
115 std::ostringstream latStream;
116 latStream << std::setprecision(10) << latitude_;
117 const std::string latitudeStr = latStream.str();
119 std::ostringstream lonStream;
120 lonStream << std::setprecision(10) << longitude_;
121 const std::string longitudeStr = lonStream.str();
124 ss <<
"\tLatitude: " << latitudeStr <<
" " << latitudeDirection_ <<
"\n";
125 ss <<
"\tLongitude: " << longitudeStr <<
" " << longitudeDirection_ <<
"\n";
126 ss <<
"\tTimestamp: " << utcTime_ <<
"\n";
127 ss <<
"\tStatus: " << status_ <<
"\n";
128 ss <<
"\tMode Indicator: " << modeIndicator_;
131 ss <<
"Lat=" << latitudeStr << latitudeDirection_
132 <<
", Lon=" << longitudeStr << longitudeDirection_
133 <<
", Time=" << utcTime_
134 <<
", Status=" << status_
135 <<
", Mode=" << modeIndicator_;
140std::string GLL::composeRaw(
const std::string& talkerId,
142 char latitudeDirection,
144 char longitudeDirection,
147 char modeIndicator) {
148 std::ostringstream payloadStream;
149 payloadStream << talkerId <<
"GLL,";
151 double latitudeDegrees = std::floor(latitude);
152 double latitudeMinutes = (latitude - latitudeDegrees) * 60.0;
153 double latitudeNmea = latitudeDegrees * 100.0 + latitudeMinutes;
155 double longitudeDegrees = std::floor(longitude);
156 double longitudeMinutes = (longitude - longitudeDegrees) * 60.0;
157 double longitudeNmea = longitudeDegrees * 100.0 + longitudeMinutes;
159 payloadStream << std::fixed << std::setprecision(6) << std::setw(10) << std::setfill(
'0') << latitudeNmea <<
",";
160 payloadStream << latitudeDirection <<
",";
161 payloadStream << std::fixed << std::setprecision(6) << std::setw(11) << std::setfill(
'0') << longitudeNmea <<
",";
162 payloadStream << longitudeDirection <<
",";
163 payloadStream << std::fixed << std::setprecision(2) << std::setw(9) << std::setfill(
'0') << timestamp <<
",";
164 payloadStream << status <<
",";
165 payloadStream << modeIndicator;
167 std::string payload = payloadStream.str();
168 return "$" + payload +
"\r\n";
176 return latitudeDirection_;
184 return longitudeDirection_;
196 return modeIndicator_;
Represents a parsed NMEA 0183 GLL (Geographic Position - Latitude/Longitude) sentence.
double getUtcTime() const noexcept
Get UTC time in hhmmss.ss numeric form.
double getLatitude() const noexcept
Get latitude in decimal degrees.
std::unique_ptr< nmealib::Message > clone() const override
Create a polymorphic copy of this GLL message.
char getLongitudeDirection() const noexcept
Get longitude hemisphere indicator ('E' or 'W').
std::string getStringContent(bool verbose) const noexcept override
Return a human-readable string representation of this message.
char getLatitudeDirection() const noexcept
Get latitude hemisphere indicator ('N' or 'S').
GLL(std::string talkerId, double latitude, char latitudeDirection, double longitude, char longitudeDirection, double timestamp, char status, char modeIndicator)
Construct a GLL message from individual field values.
bool operator==(const GLL &other) const noexcept
Compare two GLL messages for equality.
double getLongitude() const noexcept
Get longitude in decimal degrees.
char getStatus() const noexcept
Get status indicator (typically 'A' or 'V').
char getModeIndicator() const noexcept
Get mode indicator character.
Represents an NMEA 0183 sentence.
bool operator==(const Message0183 &other) const noexcept
Compares two Message0183 objects for equality based on their content and timestamp.
#define NMEALIB_RETURN_ERROR(exceptionExpr)
bool parseNmeaCoordinate(const std::string &text, double &value) noexcept
bool parseOptionalDouble(const std::string &text, double &value) noexcept