mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:10:04 +00:00 
			
		
		
		
	Graphic alphanumeric block
This commit is contained in:
		
							parent
							
								
									09649c0fe7
								
							
						
					
					
						commit
						add6c41016
					
				
					 4 changed files with 251 additions and 11 deletions
				
			
		|  | @ -0,0 +1,44 @@ | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <scwx/wsr88d/message.hpp> | ||||||
|  | 
 | ||||||
|  | #include <cstdint> | ||||||
|  | #include <memory> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace wsr88d | ||||||
|  | { | ||||||
|  | namespace rpg | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | class GraphicAlphanumericBlockImpl; | ||||||
|  | 
 | ||||||
|  | class GraphicAlphanumericBlock : public Message | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |    explicit GraphicAlphanumericBlock(); | ||||||
|  |    ~GraphicAlphanumericBlock(); | ||||||
|  | 
 | ||||||
|  |    GraphicAlphanumericBlock(const GraphicAlphanumericBlock&) = delete; | ||||||
|  |    GraphicAlphanumericBlock& | ||||||
|  |    operator=(const GraphicAlphanumericBlock&) = delete; | ||||||
|  | 
 | ||||||
|  |    GraphicAlphanumericBlock(GraphicAlphanumericBlock&&) noexcept; | ||||||
|  |    GraphicAlphanumericBlock& operator=(GraphicAlphanumericBlock&&) noexcept; | ||||||
|  | 
 | ||||||
|  |    int16_t block_divider() const; | ||||||
|  | 
 | ||||||
|  |    size_t data_size() const override; | ||||||
|  | 
 | ||||||
|  |    bool Parse(std::istream& is); | ||||||
|  | 
 | ||||||
|  |    static constexpr size_t SIZE = 102u; | ||||||
|  | 
 | ||||||
|  | private: | ||||||
|  |    std::unique_ptr<GraphicAlphanumericBlockImpl> p; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | } // namespace rpg
 | ||||||
|  | } // namespace wsr88d
 | ||||||
|  | } // namespace scwx
 | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| #include <scwx/wsr88d/level3_file.hpp> | #include <scwx/wsr88d/level3_file.hpp> | ||||||
| #include <scwx/wsr88d/rpg/ccb_header.hpp> | #include <scwx/wsr88d/rpg/ccb_header.hpp> | ||||||
|  | #include <scwx/wsr88d/rpg/graphic_alphanumeric_block.hpp> | ||||||
| #include <scwx/wsr88d/rpg/level3_message_header.hpp> | #include <scwx/wsr88d/rpg/level3_message_header.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> | ||||||
|  | @ -39,14 +40,14 @@ public: | ||||||
|    bool LoadFileData(std::istream& is); |    bool LoadFileData(std::istream& is); | ||||||
|    bool LoadBlocks(std::istream& is); |    bool LoadBlocks(std::istream& is); | ||||||
| 
 | 
 | ||||||
|    std::shared_ptr<rpg::WmoHeader>               wmoHeader_; |    std::shared_ptr<rpg::WmoHeader>                wmoHeader_; | ||||||
|    std::shared_ptr<rpg::CcbHeader>               ccbHeader_; |    std::shared_ptr<rpg::CcbHeader>                ccbHeader_; | ||||||
|    std::shared_ptr<rpg::WmoHeader>               innerHeader_; |    std::shared_ptr<rpg::WmoHeader>                innerHeader_; | ||||||
|    std::shared_ptr<rpg::Level3MessageHeader>     messageHeader_; |    std::shared_ptr<rpg::Level3MessageHeader>      messageHeader_; | ||||||
|    std::shared_ptr<rpg::ProductDescriptionBlock> descriptionBlock_; |    std::shared_ptr<rpg::ProductDescriptionBlock>  descriptionBlock_; | ||||||
|    std::shared_ptr<rpg::ProductSymbologyBlock>   symbologyBlock_; |    std::shared_ptr<rpg::ProductSymbologyBlock>    symbologyBlock_; | ||||||
|    std::shared_ptr<void>                         graphicBlock_; |    std::shared_ptr<rpg::GraphicAlphanumericBlock> graphicBlock_; | ||||||
|    std::shared_ptr<void>                         tabularBlock_; |    std::shared_ptr<void>                          tabularBlock_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| Level3File::Level3File() : p(std::make_unique<Level3FileImpl>()) {} | Level3File::Level3File() : p(std::make_unique<Level3FileImpl>()) {} | ||||||
|  | @ -286,13 +287,19 @@ bool Level3FileImpl::LoadBlocks(std::istream& is) | ||||||
| 
 | 
 | ||||||
|    if (offsetToGraphic >= offsetBase) |    if (offsetToGraphic >= offsetBase) | ||||||
|    { |    { | ||||||
|       // TODO
 |       graphicBlock_ = std::make_shared<rpg::GraphicAlphanumericBlock>(); | ||||||
|  | 
 | ||||||
|       is.seekg(offsetToGraphic - offsetBase, std::ios_base::cur); |       is.seekg(offsetToGraphic - offsetBase, std::ios_base::cur); | ||||||
|  |       graphicValid = graphicBlock_->Parse(is); | ||||||
|       is.seekg(offsetBasePos, std::ios_base::beg); |       is.seekg(offsetBasePos, std::ios_base::beg); | ||||||
| 
 | 
 | ||||||
|       BOOST_LOG_TRIVIAL(debug) |       BOOST_LOG_TRIVIAL(debug) | ||||||
|          << logPrefix_ |          << logPrefix_ << "Graphic alphanumeric block valid: " << graphicValid; | ||||||
|          << "Graphic alphanumeric block found: " << offsetToGraphic; | 
 | ||||||
|  |       if (!graphicValid) | ||||||
|  |       { | ||||||
|  |          graphicBlock_ = nullptr; | ||||||
|  |       } | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    if (offsetToTabular >= offsetBase) |    if (offsetToTabular >= offsetBase) | ||||||
|  |  | ||||||
							
								
								
									
										187
									
								
								wxdata/source/scwx/wsr88d/rpg/graphic_alphanumeric_block.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								wxdata/source/scwx/wsr88d/rpg/graphic_alphanumeric_block.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,187 @@ | ||||||
|  | #include <scwx/wsr88d/rpg/graphic_alphanumeric_block.hpp> | ||||||
|  | #include <scwx/wsr88d/rpg/packet_factory.hpp> | ||||||
|  | 
 | ||||||
|  | #include <istream> | ||||||
|  | #include <string> | ||||||
|  | 
 | ||||||
|  | #include <boost/log/trivial.hpp> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace wsr88d | ||||||
|  | { | ||||||
|  | namespace rpg | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | static const std::string logPrefix_ = | ||||||
|  |    "[scwx::wsr88d::rpg::graphic_alphanumeric_block] "; | ||||||
|  | 
 | ||||||
|  | class GraphicAlphanumericBlockImpl | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |    explicit GraphicAlphanumericBlockImpl() : | ||||||
|  |        blockDivider_ {0}, | ||||||
|  |        blockId_ {0}, | ||||||
|  |        lengthOfBlock_ {0}, | ||||||
|  |        numberOfPages_ {0}, | ||||||
|  |        pageList_ {} | ||||||
|  |    { | ||||||
|  |    } | ||||||
|  |    ~GraphicAlphanumericBlockImpl() = default; | ||||||
|  | 
 | ||||||
|  |    int16_t  blockDivider_; | ||||||
|  |    int16_t  blockId_; | ||||||
|  |    uint32_t lengthOfBlock_; | ||||||
|  |    uint16_t numberOfPages_; | ||||||
|  | 
 | ||||||
|  |    std::vector<std::vector<std::shared_ptr<Packet>>> pageList_; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | GraphicAlphanumericBlock::GraphicAlphanumericBlock() : | ||||||
|  |     Message(), p(std::make_unique<GraphicAlphanumericBlockImpl>()) | ||||||
|  | { | ||||||
|  | } | ||||||
|  | GraphicAlphanumericBlock::~GraphicAlphanumericBlock() = default; | ||||||
|  | 
 | ||||||
|  | GraphicAlphanumericBlock::GraphicAlphanumericBlock( | ||||||
|  |    GraphicAlphanumericBlock&&) noexcept                     = default; | ||||||
|  | GraphicAlphanumericBlock& GraphicAlphanumericBlock::operator=( | ||||||
|  |    GraphicAlphanumericBlock&&) noexcept = default; | ||||||
|  | 
 | ||||||
|  | int16_t GraphicAlphanumericBlock::block_divider() const | ||||||
|  | { | ||||||
|  |    return p->blockDivider_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | size_t GraphicAlphanumericBlock::data_size() const | ||||||
|  | { | ||||||
|  |    return p->lengthOfBlock_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | bool GraphicAlphanumericBlock::Parse(std::istream& is) | ||||||
|  | { | ||||||
|  |    bool blockValid = true; | ||||||
|  | 
 | ||||||
|  |    const std::streampos blockStart = is.tellg(); | ||||||
|  | 
 | ||||||
|  |    is.read(reinterpret_cast<char*>(&p->blockDivider_), 2); | ||||||
|  |    is.read(reinterpret_cast<char*>(&p->blockId_), 2); | ||||||
|  |    is.read(reinterpret_cast<char*>(&p->lengthOfBlock_), 4); | ||||||
|  |    is.read(reinterpret_cast<char*>(&p->numberOfPages_), 2); | ||||||
|  | 
 | ||||||
|  |    p->blockDivider_  = ntohs(p->blockDivider_); | ||||||
|  |    p->blockId_       = ntohs(p->blockId_); | ||||||
|  |    p->lengthOfBlock_ = ntohl(p->lengthOfBlock_); | ||||||
|  |    p->numberOfPages_ = ntohs(p->numberOfPages_); | ||||||
|  | 
 | ||||||
|  |    if (is.eof()) | ||||||
|  |    { | ||||||
|  |       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||||
|  |       blockValid = false; | ||||||
|  |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       if (p->blockDivider_ != -1) | ||||||
|  |       { | ||||||
|  |          BOOST_LOG_TRIVIAL(warning) | ||||||
|  |             << logPrefix_ << "Invalid block divider: " << p->blockDivider_; | ||||||
|  |          blockValid = false; | ||||||
|  |       } | ||||||
|  |       if (p->blockId_ != 2) | ||||||
|  |       { | ||||||
|  |          BOOST_LOG_TRIVIAL(warning) | ||||||
|  |             << logPrefix_ << "Invalid block ID: " << p->blockId_; | ||||||
|  |          blockValid = false; | ||||||
|  |       } | ||||||
|  |       if (p->lengthOfBlock_ < 10) | ||||||
|  |       { | ||||||
|  |          BOOST_LOG_TRIVIAL(warning) | ||||||
|  |             << logPrefix_ << "Invalid block length: " << p->lengthOfBlock_; | ||||||
|  |          blockValid = false; | ||||||
|  |       } | ||||||
|  |       if (p->numberOfPages_ < 1 || p->numberOfPages_ > 48) | ||||||
|  |       { | ||||||
|  |          BOOST_LOG_TRIVIAL(warning) | ||||||
|  |             << logPrefix_ << "Invalid number of pages: " << p->numberOfPages_; | ||||||
|  |          blockValid = false; | ||||||
|  |       } | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    if (blockValid) | ||||||
|  |    { | ||||||
|  |       uint16_t pageNumber; | ||||||
|  |       uint16_t lengthOfPage; | ||||||
|  | 
 | ||||||
|  |       for (uint16_t i = 0; i < p->numberOfPages_; i++) | ||||||
|  |       { | ||||||
|  |          BOOST_LOG_TRIVIAL(trace) << logPrefix_ << "Page " << (i + 1); | ||||||
|  | 
 | ||||||
|  |          std::vector<std::shared_ptr<Packet>> packetList; | ||||||
|  |          uint32_t                             bytesRead = 0; | ||||||
|  | 
 | ||||||
|  |          is.read(reinterpret_cast<char*>(&pageNumber), 2); | ||||||
|  |          is.read(reinterpret_cast<char*>(&lengthOfPage), 2); | ||||||
|  | 
 | ||||||
|  |          pageNumber   = ntohs(pageNumber); | ||||||
|  |          lengthOfPage = ntohs(lengthOfPage); | ||||||
|  | 
 | ||||||
|  |          std::streampos pageStart = is.tellg(); | ||||||
|  |          std::streampos pageEnd = | ||||||
|  |             pageStart + static_cast<std::streamoff>(lengthOfPage); | ||||||
|  | 
 | ||||||
|  |          if (pageNumber != i + 1) | ||||||
|  |          { | ||||||
|  |             BOOST_LOG_TRIVIAL(warning) | ||||||
|  |                << logPrefix_ << "Page out of order: Expected " << (i + 1) | ||||||
|  |                << ", found " << pageNumber; | ||||||
|  |          } | ||||||
|  | 
 | ||||||
|  |          while (bytesRead < lengthOfPage) | ||||||
|  |          { | ||||||
|  |             std::shared_ptr<Packet> packet = PacketFactory::Create(is); | ||||||
|  |             if (packet != nullptr) | ||||||
|  |             { | ||||||
|  |                packetList.push_back(packet); | ||||||
|  |                bytesRead += static_cast<uint32_t>(packet->data_size()); | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                break; | ||||||
|  |             } | ||||||
|  |          } | ||||||
|  | 
 | ||||||
|  |          if (bytesRead < lengthOfPage) | ||||||
|  |          { | ||||||
|  |             BOOST_LOG_TRIVIAL(trace) | ||||||
|  |                << logPrefix_ | ||||||
|  |                << "Page bytes read smaller than size: " << bytesRead << " < " | ||||||
|  |                << lengthOfPage << " bytes"; | ||||||
|  |             blockValid = false; | ||||||
|  |             is.seekg(pageEnd, std::ios_base::beg); | ||||||
|  |          } | ||||||
|  |          if (bytesRead > lengthOfPage) | ||||||
|  |          { | ||||||
|  |             BOOST_LOG_TRIVIAL(warning) | ||||||
|  |                << logPrefix_ | ||||||
|  |                << "Page bytes read larger than size: " << bytesRead << " > " | ||||||
|  |                << lengthOfPage << " bytes"; | ||||||
|  |             blockValid = false; | ||||||
|  |             is.seekg(pageEnd, std::ios_base::beg); | ||||||
|  |          } | ||||||
|  | 
 | ||||||
|  |          p->pageList_.push_back(std::move(packetList)); | ||||||
|  |       } | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    const std::streampos blockEnd = is.tellg(); | ||||||
|  |    if (!ValidateMessage(is, blockEnd - blockStart)) | ||||||
|  |    { | ||||||
|  |       blockValid = false; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    return blockValid; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | } // namespace rpg
 | ||||||
|  | } // namespace wsr88d
 | ||||||
|  | } // namespace scwx
 | ||||||
|  | @ -52,6 +52,7 @@ set(HDR_WSR88D_RPG include/scwx/wsr88d/rpg/ccb_header.hpp | ||||||
|                    include/scwx/wsr88d/rpg/digital_precipitation_data_array_packet.hpp |                    include/scwx/wsr88d/rpg/digital_precipitation_data_array_packet.hpp | ||||||
|                    include/scwx/wsr88d/rpg/digital_radial_data_array_packet.hpp |                    include/scwx/wsr88d/rpg/digital_radial_data_array_packet.hpp | ||||||
|                    include/scwx/wsr88d/rpg/generic_data_packet.hpp |                    include/scwx/wsr88d/rpg/generic_data_packet.hpp | ||||||
|  |                    include/scwx/wsr88d/rpg/graphic_alphanumeric_block.hpp | ||||||
|                    include/scwx/wsr88d/rpg/hda_hail_symbol_packet.hpp |                    include/scwx/wsr88d/rpg/hda_hail_symbol_packet.hpp | ||||||
|                    include/scwx/wsr88d/rpg/level3_message_header.hpp |                    include/scwx/wsr88d/rpg/level3_message_header.hpp | ||||||
|                    include/scwx/wsr88d/rpg/linked_contour_vector_packet.hpp |                    include/scwx/wsr88d/rpg/linked_contour_vector_packet.hpp | ||||||
|  | @ -83,6 +84,7 @@ set(SRC_WSR88D_RPG source/scwx/wsr88d/rpg/ccb_header.cpp | ||||||
|                    source/scwx/wsr88d/rpg/digital_precipitation_data_array_packet.cpp |                    source/scwx/wsr88d/rpg/digital_precipitation_data_array_packet.cpp | ||||||
|                    source/scwx/wsr88d/rpg/digital_radial_data_array_packet.cpp |                    source/scwx/wsr88d/rpg/digital_radial_data_array_packet.cpp | ||||||
|                    source/scwx/wsr88d/rpg/generic_data_packet.cpp |                    source/scwx/wsr88d/rpg/generic_data_packet.cpp | ||||||
|  |                    source/scwx/wsr88d/rpg/graphic_alphanumeric_block.cpp | ||||||
|                    source/scwx/wsr88d/rpg/hda_hail_symbol_packet.cpp |                    source/scwx/wsr88d/rpg/hda_hail_symbol_packet.cpp | ||||||
|                    source/scwx/wsr88d/rpg/level3_message_header.cpp |                    source/scwx/wsr88d/rpg/level3_message_header.cpp | ||||||
|                    source/scwx/wsr88d/rpg/linked_contour_vector_packet.cpp |                    source/scwx/wsr88d/rpg/linked_contour_vector_packet.cpp | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat