diff --git a/wxdata/include/scwx/wsr88d/rpg/radar_coded_message.hpp b/wxdata/include/scwx/wsr88d/rpg/radar_coded_message.hpp new file mode 100644 index 00000000..f1a22b5e --- /dev/null +++ b/wxdata/include/scwx/wsr88d/rpg/radar_coded_message.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include +#include + +#include +#include + +namespace scwx +{ +namespace wsr88d +{ +namespace rpg +{ + +class RadarCodedMessageImpl; + +class RadarCodedMessage : public Level3Message +{ +public: + explicit RadarCodedMessage(); + ~RadarCodedMessage(); + + RadarCodedMessage(const RadarCodedMessage&) = delete; + RadarCodedMessage& operator=(const RadarCodedMessage&) = delete; + + RadarCodedMessage(RadarCodedMessage&&) noexcept; + RadarCodedMessage& operator=(RadarCodedMessage&&) noexcept; + + std::shared_ptr description_block() const; + + bool Parse(std::istream& is) override; + + static std::shared_ptr + Create(Level3MessageHeader&& header, std::istream& is); + +private: + std::unique_ptr p; +}; + +} // namespace rpg +} // namespace wsr88d +} // namespace scwx diff --git a/wxdata/source/scwx/wsr88d/rpg/level3_message_factory.cpp b/wxdata/source/scwx/wsr88d/rpg/level3_message_factory.cpp index 2a159f36..04a0f9d9 100644 --- a/wxdata/source/scwx/wsr88d/rpg/level3_message_factory.cpp +++ b/wxdata/source/scwx/wsr88d/rpg/level3_message_factory.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,7 @@ static const std::unordered_map // {65, GraphicProductMessage::Create}, {66, GraphicProductMessage::Create}, {67, GraphicProductMessage::Create}, + {74, RadarCodedMessage::Create}, {75, TabularProductMessage::Create}, {77, TabularProductMessage::Create}, {78, GraphicProductMessage::Create}, diff --git a/wxdata/source/scwx/wsr88d/rpg/radar_coded_message.cpp b/wxdata/source/scwx/wsr88d/rpg/radar_coded_message.cpp new file mode 100644 index 00000000..7bb11c0c --- /dev/null +++ b/wxdata/source/scwx/wsr88d/rpg/radar_coded_message.cpp @@ -0,0 +1,112 @@ +#include + +#include +#include + +#include + +namespace scwx +{ +namespace wsr88d +{ +namespace rpg +{ + +static const std::string logPrefix_ = + "[scwx::wsr88d::rpg::radar_coded_message] "; + +class RadarCodedMessageImpl +{ +public: + explicit RadarCodedMessageImpl() : + descriptionBlock_ {0}, + pupSiteIdentifier_ {}, + productCategory_ {}, + rdaSiteIdentifier_ {} + { + } + ~RadarCodedMessageImpl() = default; + + bool LoadBlocks(std::istream& is); + + std::shared_ptr descriptionBlock_; + + std::string pupSiteIdentifier_; + std::string productCategory_; + std::string rdaSiteIdentifier_; +}; + +RadarCodedMessage::RadarCodedMessage() : + p(std::make_unique()) +{ +} +RadarCodedMessage::~RadarCodedMessage() = default; + +RadarCodedMessage::RadarCodedMessage(RadarCodedMessage&&) noexcept = default; +RadarCodedMessage& +RadarCodedMessage::operator=(RadarCodedMessage&&) noexcept = default; + +std::shared_ptr +RadarCodedMessage::description_block() const +{ + return p->descriptionBlock_; +} + +bool RadarCodedMessage::Parse(std::istream& is) +{ + bool dataValid = true; + + const std::streampos dataStart = is.tellg(); + + p->descriptionBlock_ = std::make_shared(); + dataValid = p->descriptionBlock_->Parse(is); + + if (dataValid) + { + dataValid = p->LoadBlocks(is); + } + + const std::streampos dataEnd = is.tellg(); + if (!ValidateMessage(is, dataEnd - dataStart)) + { + dataValid = false; + } + + return dataValid; +} + +bool RadarCodedMessageImpl::LoadBlocks(std::istream& is) +{ + BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Loading Blocks"; + + pupSiteIdentifier_.resize(4); + productCategory_.resize(5); + rdaSiteIdentifier_.resize(4); + + is.read(pupSiteIdentifier_.data(), 4); + is.seekg(1, std::ios_base::cur); + is.read(productCategory_.data(), 5); + is.seekg(1, std::ios_base::cur); + is.read(rdaSiteIdentifier_.data(), 4); + + return !is.eof(); +} + +std::shared_ptr +RadarCodedMessage::Create(Level3MessageHeader&& header, std::istream& is) +{ + std::shared_ptr message = + std::make_shared(); + message->set_header(std::move(header)); + + if (!message->Parse(is)) + { + message.reset(); + } + + return message; +} + +} // namespace rpg +} // namespace wsr88d +} // namespace scwx diff --git a/wxdata/wxdata.cmake b/wxdata/wxdata.cmake index 6291f5d3..a4cc8748 100644 --- a/wxdata/wxdata.cmake +++ b/wxdata/wxdata.cmake @@ -69,6 +69,7 @@ set(HDR_WSR88D_RPG include/scwx/wsr88d/rpg/ccb_header.hpp include/scwx/wsr88d/rpg/precipitation_rate_data_array_packet.hpp include/scwx/wsr88d/rpg/product_description_block.hpp include/scwx/wsr88d/rpg/product_symbology_block.hpp + include/scwx/wsr88d/rpg/radar_coded_message.hpp include/scwx/wsr88d/rpg/radial_data_packet.hpp include/scwx/wsr88d/rpg/raster_data_packet.hpp include/scwx/wsr88d/rpg/scit_forecast_data_packet.hpp @@ -107,6 +108,7 @@ set(SRC_WSR88D_RPG source/scwx/wsr88d/rpg/ccb_header.cpp source/scwx/wsr88d/rpg/precipitation_rate_data_array_packet.cpp source/scwx/wsr88d/rpg/product_description_block.cpp source/scwx/wsr88d/rpg/product_symbology_block.cpp + source/scwx/wsr88d/rpg/radar_coded_message.cpp source/scwx/wsr88d/rpg/radial_data_packet.cpp source/scwx/wsr88d/rpg/raster_data_packet.cpp source/scwx/wsr88d/rpg/scit_forecast_data_packet.cpp