mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:50:05 +00:00
Generic data packet
This commit is contained in:
parent
cbb3ec0368
commit
54ac07a254
4 changed files with 163 additions and 0 deletions
44
wxdata/include/scwx/wsr88d/rpg/generic_data_packet.hpp
Normal file
44
wxdata/include/scwx/wsr88d/rpg/generic_data_packet.hpp
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <scwx/wsr88d/rpg/packet.hpp>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace scwx
|
||||||
|
{
|
||||||
|
namespace wsr88d
|
||||||
|
{
|
||||||
|
namespace rpg
|
||||||
|
{
|
||||||
|
|
||||||
|
class GenericDataPacketImpl;
|
||||||
|
|
||||||
|
class GenericDataPacket : public Packet
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit GenericDataPacket();
|
||||||
|
~GenericDataPacket();
|
||||||
|
|
||||||
|
GenericDataPacket(const GenericDataPacket&) = delete;
|
||||||
|
GenericDataPacket& operator=(const GenericDataPacket&) = delete;
|
||||||
|
|
||||||
|
GenericDataPacket(GenericDataPacket&&) noexcept;
|
||||||
|
GenericDataPacket& operator=(GenericDataPacket&&) noexcept;
|
||||||
|
|
||||||
|
uint16_t packet_code() const;
|
||||||
|
uint32_t length_of_block() const;
|
||||||
|
|
||||||
|
size_t data_size() const override;
|
||||||
|
|
||||||
|
bool Parse(std::istream& is) override;
|
||||||
|
|
||||||
|
static std::shared_ptr<GenericDataPacket> Create(std::istream& is);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<GenericDataPacketImpl> p;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace rpg
|
||||||
|
} // namespace wsr88d
|
||||||
|
} // namespace scwx
|
||||||
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_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/hda_hail_symbol_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_contour_vector_packet.hpp>
|
||||||
#include <scwx/wsr88d/rpg/linked_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},
|
{24, ScitForecastDataPacket::Create},
|
||||||
{25, StiCircleSymbolPacket::Create},
|
{25, StiCircleSymbolPacket::Create},
|
||||||
{26, PointGraphicSymbolPacket::Create},
|
{26, PointGraphicSymbolPacket::Create},
|
||||||
|
{28, GenericDataPacket::Create},
|
||||||
|
{29, GenericDataPacket::Create},
|
||||||
{0x0802, SetColorLevelPacket::Create},
|
{0x0802, SetColorLevelPacket::Create},
|
||||||
{0x0E03, LinkedContourVectorPacket::Create},
|
{0x0E03, LinkedContourVectorPacket::Create},
|
||||||
{0x3501, UnlinkedContourVectorPacket::Create},
|
{0x3501, UnlinkedContourVectorPacket::Create},
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ set(SRC_WSR88D_RDA source/scwx/wsr88d/rda/clutter_filter_map.cpp
|
||||||
source/scwx/wsr88d/rda/volume_coverage_pattern_data.cpp)
|
source/scwx/wsr88d/rda/volume_coverage_pattern_data.cpp)
|
||||||
set(HDR_WSR88D_RPG include/scwx/wsr88d/rpg/digital_precipitation_data_array_packet.hpp
|
set(HDR_WSR88D_RPG 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/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
|
||||||
|
|
@ -75,6 +76,7 @@ set(HDR_WSR88D_RPG include/scwx/wsr88d/rpg/digital_precipitation_data_array_pack
|
||||||
include/scwx/wsr88d/rpg/wmo_header.hpp)
|
include/scwx/wsr88d/rpg/wmo_header.hpp)
|
||||||
set(SRC_WSR88D_RPG source/scwx/wsr88d/rpg/digital_precipitation_data_array_packet.cpp
|
set(SRC_WSR88D_RPG 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/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