diff --git a/wxdata/include/scwx/wsr88d/rpg/wmo_header.hpp b/wxdata/include/scwx/wsr88d/rpg/wmo_header.hpp index 33ba428b..97691a79 100644 --- a/wxdata/include/scwx/wsr88d/rpg/wmo_header.hpp +++ b/wxdata/include/scwx/wsr88d/rpg/wmo_header.hpp @@ -35,6 +35,7 @@ public: WmoHeader(WmoHeader&&) noexcept; WmoHeader& operator=(WmoHeader&&) noexcept; + const std::string& sequence_number() const; const std::string& data_type() const; const std::string& geographic_designator() const; const std::string& bulletin_id() const; diff --git a/wxdata/source/scwx/wsr88d/rpg/wmo_header.cpp b/wxdata/source/scwx/wsr88d/rpg/wmo_header.cpp index c4c86418..189f6668 100644 --- a/wxdata/source/scwx/wsr88d/rpg/wmo_header.cpp +++ b/wxdata/source/scwx/wsr88d/rpg/wmo_header.cpp @@ -26,6 +26,7 @@ class WmoHeaderImpl { public: explicit WmoHeaderImpl() : + sequenceNumber_ {}, dataType_ {}, geographicDesignator_ {}, bulletinId_ {}, @@ -36,6 +37,7 @@ public: productDesignator_ {} {}; ~WmoHeaderImpl() = default; + std::string sequenceNumber_; std::string dataType_; std::string geographicDesignator_; std::string bulletinId_; @@ -52,6 +54,11 @@ WmoHeader::~WmoHeader() = default; WmoHeader::WmoHeader(WmoHeader&&) noexcept = default; WmoHeader& WmoHeader::operator=(WmoHeader&&) noexcept = default; +const std::string& WmoHeader::sequence_number() const +{ + return p->sequenceNumber_; +} + const std::string& WmoHeader::data_type() const { return p->dataType_; @@ -96,9 +103,17 @@ bool WmoHeader::Parse(std::istream& is) { bool headerValid = true; + std::string sohLine; + std::string sequenceLine; std::string wmoLine; std::string awipsLine; + if (is.peek() == 0x01) + { + std::getline(is, sohLine); + std::getline(is, sequenceLine); + } + std::getline(is, wmoLine); std::getline(is, awipsLine); @@ -107,6 +122,17 @@ bool WmoHeader::Parse(std::istream& is) BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; headerValid = false; } + else if (!sohLine.empty() && !sohLine.ends_with("\r\r")) + { + BOOST_LOG_TRIVIAL(debug) + << logPrefix_ << "Start of Heading Line is malformed"; + headerValid = false; + } + else if (!sequenceLine.empty() && !sequenceLine.ends_with(" \r\r")) + { + BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Sequence Line is malformed"; + headerValid = false; + } else if (!wmoLine.ends_with("\r\r")) { BOOST_LOG_TRIVIAL(debug) @@ -122,10 +148,24 @@ bool WmoHeader::Parse(std::istream& is) else { // Remove delimiters from the end of the line + if (!sequenceLine.empty()) + { + sequenceLine.erase(sequenceLine.end() - 3); + } + wmoLine.erase(wmoLine.end() - 2); awipsLine.erase(awipsLine.end() - 2); } + // Transmission Header: + // [SOH] + // nnn + + if (headerValid && !sequenceLine.empty()) + { + p->sequenceNumber_ = sequenceLine; + } + // WMO Abbreviated Heading Line: // T1T2A1A2ii CCCC YYGGgg (BBB)