mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:20:06 +00:00 
			
		
		
		
	Precipitation rate data array packet
This commit is contained in:
		
							parent
							
								
									9f9837f237
								
							
						
					
					
						commit
						0487a40f67
					
				
					 5 changed files with 235 additions and 1 deletions
				
			
		|  | @ -0,0 +1,50 @@ | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <scwx/wsr88d/rpg/packet.hpp> | ||||||
|  | 
 | ||||||
|  | #include <cstdint> | ||||||
|  | #include <memory> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace wsr88d | ||||||
|  | { | ||||||
|  | namespace rpg | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | class PrecipitationRateDataArrayPacketImpl; | ||||||
|  | 
 | ||||||
|  | class PrecipitationRateDataArrayPacket : public Packet | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |    explicit PrecipitationRateDataArrayPacket(); | ||||||
|  |    ~PrecipitationRateDataArrayPacket(); | ||||||
|  | 
 | ||||||
|  |    PrecipitationRateDataArrayPacket( | ||||||
|  |       const PrecipitationRateDataArrayPacket&) = delete; | ||||||
|  |    PrecipitationRateDataArrayPacket& | ||||||
|  |    operator=(const PrecipitationRateDataArrayPacket&) = delete; | ||||||
|  | 
 | ||||||
|  |    PrecipitationRateDataArrayPacket( | ||||||
|  |       PrecipitationRateDataArrayPacket&&) noexcept; | ||||||
|  |    PrecipitationRateDataArrayPacket& | ||||||
|  |    operator=(PrecipitationRateDataArrayPacket&&) noexcept; | ||||||
|  | 
 | ||||||
|  |    uint16_t packet_code() const; | ||||||
|  |    uint16_t number_of_lfm_boxes_in_row() const; | ||||||
|  |    uint16_t number_of_rows() const; | ||||||
|  | 
 | ||||||
|  |    size_t data_size() const override; | ||||||
|  | 
 | ||||||
|  |    bool Parse(std::istream& is) override; | ||||||
|  | 
 | ||||||
|  |    static std::shared_ptr<PrecipitationRateDataArrayPacket> | ||||||
|  |    Create(std::istream& is); | ||||||
|  | 
 | ||||||
|  | private: | ||||||
|  |    std::unique_ptr<PrecipitationRateDataArrayPacketImpl> p; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | } // namespace rpg
 | ||||||
|  | } // namespace wsr88d
 | ||||||
|  | } // namespace scwx
 | ||||||
|  | @ -3,6 +3,7 @@ | ||||||
| #include <scwx/wsr88d/rpg/digital_precipitation_data_array_packet.hpp> | #include <scwx/wsr88d/rpg/digital_precipitation_data_array_packet.hpp> | ||||||
| #include <scwx/wsr88d/rpg/linked_contour_vector_packet.hpp> | #include <scwx/wsr88d/rpg/linked_contour_vector_packet.hpp> | ||||||
| #include <scwx/wsr88d/rpg/linked_vector_packet.hpp> | #include <scwx/wsr88d/rpg/linked_vector_packet.hpp> | ||||||
|  | #include <scwx/wsr88d/rpg/precipitation_rate_data_array_packet.hpp> | ||||||
| #include <scwx/wsr88d/rpg/radial_data_packet.hpp> | #include <scwx/wsr88d/rpg/radial_data_packet.hpp> | ||||||
| #include <scwx/wsr88d/rpg/raster_data_packet.hpp> | #include <scwx/wsr88d/rpg/raster_data_packet.hpp> | ||||||
| #include <scwx/wsr88d/rpg/set_color_level_packet.hpp> | #include <scwx/wsr88d/rpg/set_color_level_packet.hpp> | ||||||
|  | @ -35,6 +36,7 @@ static const std::unordered_map<uint16_t, CreateMessageFunction> create_ { | ||||||
|    {9, LinkedVectorPacket::Create}, |    {9, LinkedVectorPacket::Create}, | ||||||
|    {10, UnlinkedVectorPacket::Create}, |    {10, UnlinkedVectorPacket::Create}, | ||||||
|    {17, DigitalPrecipitationDataArrayPacket::Create}, |    {17, DigitalPrecipitationDataArrayPacket::Create}, | ||||||
|  |    {18, PrecipitationRateDataArrayPacket::Create}, | ||||||
|    {0x0802, SetColorLevelPacket::Create}, |    {0x0802, SetColorLevelPacket::Create}, | ||||||
|    {0x0E03, LinkedContourVectorPacket::Create}, |    {0x0E03, LinkedContourVectorPacket::Create}, | ||||||
|    {0x3501, UnlinkedContourVectorPacket::Create}, |    {0x3501, UnlinkedContourVectorPacket::Create}, | ||||||
|  |  | ||||||
|  | @ -0,0 +1,180 @@ | ||||||
|  | #include <scwx/wsr88d/rpg/precipitation_rate_data_array_packet.hpp> | ||||||
|  | 
 | ||||||
|  | #include <istream> | ||||||
|  | #include <string> | ||||||
|  | 
 | ||||||
|  | #include <boost/log/trivial.hpp> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace wsr88d | ||||||
|  | { | ||||||
|  | namespace rpg | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | static const std::string logPrefix_ = | ||||||
|  |    "[scwx::wsr88d::rpg::precipitation_rate_data_array_packet] "; | ||||||
|  | 
 | ||||||
|  | class PrecipitationRateDataArrayPacketImpl | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |    struct Row | ||||||
|  |    { | ||||||
|  |       uint16_t             numberOfBytes_; | ||||||
|  |       std::vector<uint8_t> data_; | ||||||
|  | 
 | ||||||
|  |       Row() : numberOfBytes_ {0}, data_ {} {} | ||||||
|  |    }; | ||||||
|  | 
 | ||||||
|  |    explicit PrecipitationRateDataArrayPacketImpl() : | ||||||
|  |        packetCode_ {0}, | ||||||
|  |        numberOfLfmBoxesInRow_ {0}, | ||||||
|  |        numberOfRows_ {0}, | ||||||
|  |        row_ {}, | ||||||
|  |        dataSize_ {0} {}; | ||||||
|  |    ~PrecipitationRateDataArrayPacketImpl() = default; | ||||||
|  | 
 | ||||||
|  |    uint16_t packetCode_; | ||||||
|  |    uint16_t numberOfLfmBoxesInRow_; | ||||||
|  |    uint16_t numberOfRows_; | ||||||
|  | 
 | ||||||
|  |    // Repeat for each row
 | ||||||
|  |    std::vector<Row> row_; | ||||||
|  | 
 | ||||||
|  |    size_t dataSize_; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | PrecipitationRateDataArrayPacket::PrecipitationRateDataArrayPacket() : | ||||||
|  |     p(std::make_unique<PrecipitationRateDataArrayPacketImpl>()) | ||||||
|  | { | ||||||
|  | } | ||||||
|  | PrecipitationRateDataArrayPacket::~PrecipitationRateDataArrayPacket() = default; | ||||||
|  | 
 | ||||||
|  | PrecipitationRateDataArrayPacket::PrecipitationRateDataArrayPacket( | ||||||
|  |    PrecipitationRateDataArrayPacket&&) noexcept = default; | ||||||
|  | PrecipitationRateDataArrayPacket& PrecipitationRateDataArrayPacket::operator=( | ||||||
|  |    PrecipitationRateDataArrayPacket&&) noexcept = default; | ||||||
|  | 
 | ||||||
|  | uint16_t PrecipitationRateDataArrayPacket::packet_code() const | ||||||
|  | { | ||||||
|  |    return p->packetCode_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint16_t PrecipitationRateDataArrayPacket::number_of_lfm_boxes_in_row() const | ||||||
|  | { | ||||||
|  |    return p->numberOfLfmBoxesInRow_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | uint16_t PrecipitationRateDataArrayPacket::number_of_rows() const | ||||||
|  | { | ||||||
|  |    return p->numberOfRows_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | size_t PrecipitationRateDataArrayPacket::data_size() const | ||||||
|  | { | ||||||
|  |    return p->dataSize_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | bool PrecipitationRateDataArrayPacket::Parse(std::istream& is) | ||||||
|  | { | ||||||
|  |    bool   blockValid = true; | ||||||
|  |    size_t bytesRead  = 0; | ||||||
|  | 
 | ||||||
|  |    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||||
|  |    is.seekg(4, std::ios_base::cur); | ||||||
|  |    is.read(reinterpret_cast<char*>(&p->numberOfLfmBoxesInRow_), 2); | ||||||
|  |    is.read(reinterpret_cast<char*>(&p->numberOfRows_), 2); | ||||||
|  |    bytesRead += 10; | ||||||
|  | 
 | ||||||
|  |    p->packetCode_            = ntohs(p->packetCode_); | ||||||
|  |    p->numberOfLfmBoxesInRow_ = ntohs(p->numberOfLfmBoxesInRow_); | ||||||
|  |    p->numberOfRows_          = ntohs(p->numberOfRows_); | ||||||
|  | 
 | ||||||
|  |    if (is.eof()) | ||||||
|  |    { | ||||||
|  |       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||||
|  |       blockValid = false; | ||||||
|  |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       if (p->packetCode_ != 18) | ||||||
|  |       { | ||||||
|  |          BOOST_LOG_TRIVIAL(warning) | ||||||
|  |             << logPrefix_ << "Invalid packet code: " << p->packetCode_; | ||||||
|  |          blockValid = false; | ||||||
|  |       } | ||||||
|  |       if (p->numberOfRows_ != 13) | ||||||
|  |       { | ||||||
|  |          BOOST_LOG_TRIVIAL(warning) | ||||||
|  |             << logPrefix_ << "Invalid number of rows: " << p->numberOfRows_; | ||||||
|  |          blockValid = false; | ||||||
|  |       } | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    if (blockValid) | ||||||
|  |    { | ||||||
|  |       p->row_.resize(p->numberOfRows_); | ||||||
|  | 
 | ||||||
|  |       for (uint16_t r = 0; r < p->numberOfRows_; r++) | ||||||
|  |       { | ||||||
|  |          size_t rowBytesRead = 0; | ||||||
|  | 
 | ||||||
|  |          auto& row = p->row_[r]; | ||||||
|  | 
 | ||||||
|  |          is.read(reinterpret_cast<char*>(&row.numberOfBytes_), 2); | ||||||
|  |          bytesRead += 2; | ||||||
|  | 
 | ||||||
|  |          row.numberOfBytes_ = ntohs(row.numberOfBytes_); | ||||||
|  | 
 | ||||||
|  |          if (row.numberOfBytes_ < 2 || row.numberOfBytes_ > 14 || | ||||||
|  |              row.numberOfBytes_ % 2 != 0) | ||||||
|  |          { | ||||||
|  |             BOOST_LOG_TRIVIAL(warning) | ||||||
|  |                << logPrefix_ | ||||||
|  |                << "Invalid number of bytes in row: " << row.numberOfBytes_ | ||||||
|  |                << " (Row " << r << ")"; | ||||||
|  |             blockValid = false; | ||||||
|  |             break; | ||||||
|  |          } | ||||||
|  | 
 | ||||||
|  |          // Read row data
 | ||||||
|  |          size_t dataSize = row.numberOfBytes_; | ||||||
|  |          row.data_.resize(dataSize); | ||||||
|  |          is.read(reinterpret_cast<char*>(row.data_.data()), dataSize); | ||||||
|  |          bytesRead += dataSize; | ||||||
|  | 
 | ||||||
|  |          // If the final byte is 0, truncate it
 | ||||||
|  |          if (row.data_.back() == 0) | ||||||
|  |          { | ||||||
|  |             row.data_.pop_back(); | ||||||
|  |          } | ||||||
|  |       } | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    p->dataSize_ = bytesRead; | ||||||
|  | 
 | ||||||
|  |    if (!ValidateMessage(is, bytesRead)) | ||||||
|  |    { | ||||||
|  |       blockValid = false; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    return blockValid; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | std::shared_ptr<PrecipitationRateDataArrayPacket> | ||||||
|  | PrecipitationRateDataArrayPacket::Create(std::istream& is) | ||||||
|  | { | ||||||
|  |    std::shared_ptr<PrecipitationRateDataArrayPacket> packet = | ||||||
|  |       std::make_shared<PrecipitationRateDataArrayPacket>(); | ||||||
|  | 
 | ||||||
|  |    if (!packet->Parse(is)) | ||||||
|  |    { | ||||||
|  |       packet.reset(); | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    return packet; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | } // namespace rpg
 | ||||||
|  | } // namespace wsr88d
 | ||||||
|  | } // namespace scwx
 | ||||||
|  | @ -105,13 +105,13 @@ bool ProductSymbologyBlock::Parse(std::istream& is) | ||||||
|    { |    { | ||||||
|       int16_t  layerDivider; |       int16_t  layerDivider; | ||||||
|       uint32_t lengthOfDataLayer; |       uint32_t lengthOfDataLayer; | ||||||
|       uint32_t bytesRead = 0; |  | ||||||
| 
 | 
 | ||||||
|       for (uint16_t i = 0; i < p->numberOfLayers_; i++) |       for (uint16_t i = 0; i < p->numberOfLayers_; i++) | ||||||
|       { |       { | ||||||
|          BOOST_LOG_TRIVIAL(trace) << logPrefix_ << "Layer " << i; |          BOOST_LOG_TRIVIAL(trace) << logPrefix_ << "Layer " << i; | ||||||
| 
 | 
 | ||||||
|          std::vector<std::shared_ptr<Packet>> packetList; |          std::vector<std::shared_ptr<Packet>> packetList; | ||||||
|  |          uint32_t                             bytesRead = 0; | ||||||
| 
 | 
 | ||||||
|          is.read(reinterpret_cast<char*>(&layerDivider), 2); |          is.read(reinterpret_cast<char*>(&layerDivider), 2); | ||||||
|          is.read(reinterpret_cast<char*>(&lengthOfDataLayer), 4); |          is.read(reinterpret_cast<char*>(&lengthOfDataLayer), 4); | ||||||
|  |  | ||||||
|  | @ -52,6 +52,7 @@ set(HDR_WSR88D_RPG include/scwx/wsr88d/rpg/digital_precipitation_data_array_pack | ||||||
|                    include/scwx/wsr88d/rpg/linked_vector_packet.hpp |                    include/scwx/wsr88d/rpg/linked_vector_packet.hpp | ||||||
|                    include/scwx/wsr88d/rpg/packet.hpp |                    include/scwx/wsr88d/rpg/packet.hpp | ||||||
|                    include/scwx/wsr88d/rpg/packet_factory.hpp |                    include/scwx/wsr88d/rpg/packet_factory.hpp | ||||||
|  |                    include/scwx/wsr88d/rpg/precipitation_rate_data_array_packet.hpp | ||||||
|                    include/scwx/wsr88d/rpg/product_description_block.hpp |                    include/scwx/wsr88d/rpg/product_description_block.hpp | ||||||
|                    include/scwx/wsr88d/rpg/product_symbology_block.hpp |                    include/scwx/wsr88d/rpg/product_symbology_block.hpp | ||||||
|                    include/scwx/wsr88d/rpg/radial_data_packet.hpp |                    include/scwx/wsr88d/rpg/radial_data_packet.hpp | ||||||
|  | @ -67,6 +68,7 @@ set(SRC_WSR88D_RPG source/scwx/wsr88d/rpg/digital_precipitation_data_array_packe | ||||||
|                    source/scwx/wsr88d/rpg/linked_vector_packet.cpp |                    source/scwx/wsr88d/rpg/linked_vector_packet.cpp | ||||||
|                    source/scwx/wsr88d/rpg/packet.cpp |                    source/scwx/wsr88d/rpg/packet.cpp | ||||||
|                    source/scwx/wsr88d/rpg/packet_factory.cpp |                    source/scwx/wsr88d/rpg/packet_factory.cpp | ||||||
|  |                    source/scwx/wsr88d/rpg/precipitation_rate_data_array_packet.cpp | ||||||
|                    source/scwx/wsr88d/rpg/product_description_block.cpp |                    source/scwx/wsr88d/rpg/product_description_block.cpp | ||||||
|                    source/scwx/wsr88d/rpg/product_symbology_block.cpp |                    source/scwx/wsr88d/rpg/product_symbology_block.cpp | ||||||
|                    source/scwx/wsr88d/rpg/radial_data_packet.cpp |                    source/scwx/wsr88d/rpg/radial_data_packet.cpp | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat