mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:20:05 +00:00 
			
		
		
		
	Generic data packet
This commit is contained in:
		
							parent
							
								
									cbb3ec0368
								
							
						
					
					
						commit
						54ac07a254
					
				
					 4 changed files with 163 additions and 0 deletions
				
			
		
							
								
								
									
										114
									
								
								wxdata/source/scwx/wsr88d/rpg/generic_data_packet.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								wxdata/source/scwx/wsr88d/rpg/generic_data_packet.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,114 @@ | |||
| #include <scwx/wsr88d/rpg/generic_data_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::generic_data_packet] "; | ||||
| 
 | ||||
| class GenericDataPacketImpl | ||||
| { | ||||
| public: | ||||
|    explicit GenericDataPacketImpl() : | ||||
|        packetCode_ {0}, lengthOfBlock_ {0}, data_ {} | ||||
|    { | ||||
|    } | ||||
|    ~GenericDataPacketImpl() = default; | ||||
| 
 | ||||
|    uint16_t packetCode_; | ||||
|    uint32_t lengthOfBlock_; | ||||
| 
 | ||||
|    std::vector<uint8_t> data_; | ||||
| }; | ||||
| 
 | ||||
| GenericDataPacket::GenericDataPacket() : | ||||
|     p(std::make_unique<GenericDataPacketImpl>()) | ||||
| { | ||||
| } | ||||
| GenericDataPacket::~GenericDataPacket() = default; | ||||
| 
 | ||||
| GenericDataPacket::GenericDataPacket(GenericDataPacket&&) noexcept = default; | ||||
| GenericDataPacket& | ||||
| GenericDataPacket::operator=(GenericDataPacket&&) noexcept = default; | ||||
| 
 | ||||
| uint16_t GenericDataPacket::packet_code() const | ||||
| { | ||||
|    return p->packetCode_; | ||||
| } | ||||
| 
 | ||||
| uint32_t GenericDataPacket::length_of_block() const | ||||
| { | ||||
|    return p->lengthOfBlock_; | ||||
| } | ||||
| 
 | ||||
| size_t GenericDataPacket::data_size() const | ||||
| { | ||||
|    return p->lengthOfBlock_ + 8u; | ||||
| } | ||||
| 
 | ||||
| bool GenericDataPacket::Parse(std::istream& is) | ||||
| { | ||||
|    bool blockValid = true; | ||||
| 
 | ||||
|    std::streampos isBegin = is.tellg(); | ||||
| 
 | ||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||
|    is.seekg(2, std::ios_base::cur); | ||||
|    is.read(reinterpret_cast<char*>(&p->lengthOfBlock_), 4); | ||||
| 
 | ||||
|    p->packetCode_    = ntohs(p->packetCode_); | ||||
|    p->lengthOfBlock_ = ntohl(p->lengthOfBlock_); | ||||
| 
 | ||||
|    if (is.eof()) | ||||
|    { | ||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||
|       blockValid = false; | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       if (p->packetCode_ != 28 && p->packetCode_ != 29) | ||||
|       { | ||||
|          BOOST_LOG_TRIVIAL(warning) | ||||
|             << logPrefix_ << "Invalid packet code: " << p->packetCode_; | ||||
|          blockValid = false; | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    p->data_.resize(p->lengthOfBlock_); | ||||
|    is.read(reinterpret_cast<char*>(p->data_.data()), p->lengthOfBlock_); | ||||
| 
 | ||||
|    std::streampos isEnd = is.tellg(); | ||||
| 
 | ||||
|    if (!ValidateMessage(is, isEnd - isBegin)) | ||||
|    { | ||||
|       blockValid = false; | ||||
|    } | ||||
| 
 | ||||
|    return blockValid; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<GenericDataPacket> GenericDataPacket::Create(std::istream& is) | ||||
| { | ||||
|    std::shared_ptr<GenericDataPacket> packet = | ||||
|       std::make_shared<GenericDataPacket>(); | ||||
| 
 | ||||
|    if (!packet->Parse(is)) | ||||
|    { | ||||
|       packet.reset(); | ||||
|    } | ||||
| 
 | ||||
|    return packet; | ||||
| } | ||||
| 
 | ||||
| } // namespace rpg
 | ||||
| } // namespace wsr88d
 | ||||
| } // namespace scwx
 | ||||
|  | @ -2,6 +2,7 @@ | |||
| 
 | ||||
| #include <scwx/wsr88d/rpg/digital_precipitation_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/hda_hail_symbol_packet.hpp> | ||||
| #include <scwx/wsr88d/rpg/linked_contour_vector_packet.hpp> | ||||
| #include <scwx/wsr88d/rpg/linked_vector_packet.hpp> | ||||
|  | @ -62,6 +63,8 @@ static const std::unordered_map<uint16_t, CreateMessageFunction> create_ { | |||
|    {24, ScitForecastDataPacket::Create}, | ||||
|    {25, StiCircleSymbolPacket::Create}, | ||||
|    {26, PointGraphicSymbolPacket::Create}, | ||||
|    {28, GenericDataPacket::Create}, | ||||
|    {29, GenericDataPacket::Create}, | ||||
|    {0x0802, SetColorLevelPacket::Create}, | ||||
|    {0x0E03, LinkedContourVectorPacket::Create}, | ||||
|    {0x3501, UnlinkedContourVectorPacket::Create}, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat