14std::unique_ptr<ZDA> ZDA::create(std::unique_ptr<Message0183> baseMessage) {
15 std::string context =
"ZDA::create";
16 if (baseMessage->getSentenceType() !=
"ZDA") {
17 NMEALIB_RETURN_ERROR(NotZDAException(context,
"Expected sentence type 'ZDA', got " + baseMessage->getSentenceType()));
20 std::string payload = baseMessage->getPayload();
21 std::istringstream ss(payload);
23 std::vector<std::string> fields;
25 while (std::getline(ss, token,
',')) {
26 fields.push_back(token);
29 if (!payload.empty() && payload.back() ==
',') {
33 if (!fields.empty()) {
34 fields.erase(fields.begin());
37 if (fields.size() != 6) {
38 NMEALIB_RETURN_ERROR(NotZDAException(context,
"Invalid fields in ZDA payload: expected 6, got " + std::to_string(fields.size()) +
". Payload: " + payload));
42 unsigned int day = 0U;
43 unsigned int month = 0U;
44 unsigned int year = 0U;
45 int localZoneHours = 0;
46 int localZoneMinutes = 0;
56 return std::unique_ptr<ZDA>(
new ZDA(std::move(*baseMessage),
65ZDA::ZDA(Message0183 baseMessage,
71 int localZoneMinutes) noexcept
72 : Message0183(std::move(baseMessage)),
77 localZoneHours_(localZoneHours),
78 localZoneMinutes_(localZoneMinutes) {}
80ZDA::ZDA(std::string talkerId,
98 localZoneHours_(localZoneHours),
99 localZoneMinutes_(localZoneMinutes) {}
102 return std::unique_ptr<ZDA>(
new ZDA(*
this));
106 std::ostringstream ss;
107 ss << this->toString(verbose);
110 ss <<
"\tUTC Time: " << utcTime_ <<
"\n";
111 ss <<
"\tDay: " << day_ <<
"\n";
112 ss <<
"\tMonth: " << month_ <<
"\n";
113 ss <<
"\tYear: " << year_ <<
"\n";
114 ss <<
"\tLocal Zone Hours: " << localZoneHours_ <<
"\n";
115 ss <<
"\tLocal Zone Minutes: " << localZoneMinutes_;
118 ss <<
"UTC=" << utcTime_
119 <<
", Date=" << day_ <<
"/" << month_ <<
"/" << year_
120 <<
", Zone=" << localZoneHours_ <<
":";
121 ss << std::setw(2) << std::setfill(
'0') << std::abs(localZoneMinutes_);
127std::string ZDA::composeRaw(
const std::string& talkerId,
133 int localZoneMinutes) {
134 std::ostringstream payloadStream;
135 payloadStream << talkerId <<
"ZDA,";
136 payloadStream << std::fixed << std::setprecision(2) << std::setw(9) << std::setfill(
'0') << utcTime <<
",";
137 payloadStream << std::setw(2) << std::setfill(
'0') << day <<
",";
138 payloadStream << std::setw(2) << std::setfill(
'0') << month <<
",";
139 payloadStream << std::setw(4) << std::setfill(
'0') << year <<
",";
140 payloadStream << localZoneHours <<
",";
141 payloadStream << std::setw(2) << std::setfill(
'0') << std::abs(localZoneMinutes);
143 std::string payload = payloadStream.str();
144 return "$" + payload +
"\r\n";
164 return localZoneHours_;
168 return localZoneMinutes_;
Represents an NMEA 0183 sentence.
bool operator==(const Message0183 &other) const noexcept
Compares two Message0183 objects for equality based on their content and timestamp.
Represents a parsed NMEA 0183 ZDA (Time and Date) sentence.
std::unique_ptr< nmealib::Message > clone() const override
Create a polymorphic copy of this ZDA message.
unsigned int getYear() const noexcept
Get four-digit year.
int getLocalZoneMinutes() const noexcept
Get local zone offset minutes.
double getUtcTime() const noexcept
Get UTC time in hhmmss.ss numeric form.
bool operator==(const ZDA &other) const noexcept
Compare two ZDA messages for equality.
ZDA(std::string talkerId, double utcTime, unsigned int day, unsigned int month, unsigned int year, int localZoneHours, int localZoneMinutes)
Construct a ZDA message from individual field values.
int getLocalZoneHours() const noexcept
Get local zone offset hours.
unsigned int getMonth() const noexcept
Get month number.
unsigned int getDay() const noexcept
Get day of month.
std::string getStringContent(bool verbose) const noexcept override
Return a human-readable string representation of this message.
#define NMEALIB_RETURN_ERROR(exceptionExpr)
bool parseOptionalInt(const std::string &text, int &value) noexcept
bool parseOptionalUnsigned(const std::string &text, unsigned int &value) noexcept
bool parseOptionalDouble(const std::string &text, double &value) noexcept