mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 19:20:05 +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
|
|
@ -3,6 +3,7 @@
|
|||
#include <scwx/wsr88d/rpg/digital_precipitation_data_array_packet.hpp>
|
||||
#include <scwx/wsr88d/rpg/linked_contour_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/raster_data_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},
|
||||
{10, UnlinkedVectorPacket::Create},
|
||||
{17, DigitalPrecipitationDataArrayPacket::Create},
|
||||
{18, PrecipitationRateDataArrayPacket::Create},
|
||||
{0x0802, SetColorLevelPacket::Create},
|
||||
{0x0E03, LinkedContourVectorPacket::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;
|
||||
uint32_t lengthOfDataLayer;
|
||||
uint32_t bytesRead = 0;
|
||||
|
||||
for (uint16_t i = 0; i < p->numberOfLayers_; i++)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(trace) << logPrefix_ << "Layer " << i;
|
||||
|
||||
std::vector<std::shared_ptr<Packet>> packetList;
|
||||
uint32_t bytesRead = 0;
|
||||
|
||||
is.read(reinterpret_cast<char*>(&layerDivider), 2);
|
||||
is.read(reinterpret_cast<char*>(&lengthOfDataLayer), 4);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue