mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 07:50:04 +00:00
Refactor ScitForecastDataPacket to ScitDataPacket
This commit is contained in:
parent
3b110516ed
commit
d92c1e50f2
6 changed files with 128 additions and 137 deletions
43
wxdata/include/scwx/wsr88d/rpg/scit_data_packet.hpp
Normal file
43
wxdata/include/scwx/wsr88d/rpg/scit_data_packet.hpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/wsr88d/rpg/special_graphic_symbol_packet.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace wsr88d
|
||||
{
|
||||
namespace rpg
|
||||
{
|
||||
|
||||
class ScitDataPacket : public SpecialGraphicSymbolPacket
|
||||
{
|
||||
public:
|
||||
explicit ScitDataPacket();
|
||||
~ScitDataPacket();
|
||||
|
||||
ScitDataPacket(const ScitDataPacket&) = delete;
|
||||
ScitDataPacket& operator=(const ScitDataPacket&) = delete;
|
||||
|
||||
ScitDataPacket(ScitDataPacket&&) noexcept;
|
||||
ScitDataPacket& operator=(ScitDataPacket&&) noexcept;
|
||||
|
||||
const std::vector<std::uint8_t>& data() const;
|
||||
|
||||
std::size_t RecordCount() const override;
|
||||
|
||||
static std::shared_ptr<ScitDataPacket> Create(std::istream& is);
|
||||
|
||||
protected:
|
||||
bool ParseData(std::istream& is) override;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> p;
|
||||
};
|
||||
|
||||
} // namespace rpg
|
||||
} // namespace wsr88d
|
||||
} // namespace scwx
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/wsr88d/rpg/special_graphic_symbol_packet.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace wsr88d
|
||||
{
|
||||
namespace rpg
|
||||
{
|
||||
|
||||
class ScitForecastDataPacketImpl;
|
||||
|
||||
class ScitForecastDataPacket : public SpecialGraphicSymbolPacket
|
||||
{
|
||||
public:
|
||||
explicit ScitForecastDataPacket();
|
||||
~ScitForecastDataPacket();
|
||||
|
||||
ScitForecastDataPacket(const ScitForecastDataPacket&) = delete;
|
||||
ScitForecastDataPacket& operator=(const ScitForecastDataPacket&) = delete;
|
||||
|
||||
ScitForecastDataPacket(ScitForecastDataPacket&&) noexcept;
|
||||
ScitForecastDataPacket& operator=(ScitForecastDataPacket&&) noexcept;
|
||||
|
||||
const std::vector<uint8_t>& data() const;
|
||||
|
||||
size_t RecordCount() const override;
|
||||
|
||||
static std::shared_ptr<ScitForecastDataPacket> Create(std::istream& is);
|
||||
|
||||
protected:
|
||||
bool ParseData(std::istream& is) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<ScitForecastDataPacketImpl> p;
|
||||
};
|
||||
|
||||
} // namespace rpg
|
||||
} // namespace wsr88d
|
||||
} // namespace scwx
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
#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/scit_forecast_data_packet.hpp>
|
||||
#include <scwx/wsr88d/rpg/scit_data_packet.hpp>
|
||||
#include <scwx/wsr88d/rpg/set_color_level_packet.hpp>
|
||||
#include <scwx/wsr88d/rpg/sti_circle_symbol_packet.hpp>
|
||||
#include <scwx/wsr88d/rpg/storm_id_symbol_packet.hpp>
|
||||
|
|
@ -63,8 +63,8 @@ static const std::unordered_map<unsigned int, CreateMessageFunction> create_ {
|
|||
{20, PointFeatureSymbolPacket::Create},
|
||||
{21, CellTrendDataPacket::Create},
|
||||
{22, CellTrendVolumeScanTimes::Create},
|
||||
{23, ScitForecastDataPacket::Create},
|
||||
{24, ScitForecastDataPacket::Create},
|
||||
{23, ScitDataPacket::Create},
|
||||
{24, ScitDataPacket::Create},
|
||||
{25, StiCircleSymbolPacket::Create},
|
||||
{26, PointGraphicSymbolPacket::Create},
|
||||
{28, GenericDataPacket::Create},
|
||||
|
|
|
|||
80
wxdata/source/scwx/wsr88d/rpg/scit_data_packet.cpp
Normal file
80
wxdata/source/scwx/wsr88d/rpg/scit_data_packet.cpp
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#include <scwx/wsr88d/rpg/scit_data_packet.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
||||
#include <istream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace wsr88d
|
||||
{
|
||||
namespace rpg
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ = "scwx::wsr88d::rpg::scit_data_packet";
|
||||
static const auto logger_ = util::Logger::Create(logPrefix_);
|
||||
|
||||
static const std::set<std::uint16_t> packetCodes_ = {23, 24};
|
||||
|
||||
class ScitDataPacket::Impl
|
||||
{
|
||||
public:
|
||||
explicit Impl() : data_ {}, recordCount_ {0} {}
|
||||
~Impl() = default;
|
||||
|
||||
std::vector<std::uint8_t> data_;
|
||||
size_t recordCount_;
|
||||
};
|
||||
|
||||
ScitDataPacket::ScitDataPacket() : p(std::make_unique<Impl>()) {}
|
||||
ScitDataPacket::~ScitDataPacket() = default;
|
||||
|
||||
ScitDataPacket::ScitDataPacket(ScitDataPacket&&) noexcept = default;
|
||||
ScitDataPacket& ScitDataPacket::operator=(ScitDataPacket&&) noexcept = default;
|
||||
|
||||
const std::vector<std::uint8_t>& ScitDataPacket::data() const
|
||||
{
|
||||
return p->data_;
|
||||
}
|
||||
|
||||
size_t ScitDataPacket::RecordCount() const
|
||||
{
|
||||
return p->recordCount_;
|
||||
}
|
||||
|
||||
bool ScitDataPacket::ParseData(std::istream& is)
|
||||
{
|
||||
bool blockValid = true;
|
||||
|
||||
if (!packetCodes_.contains(packet_code()))
|
||||
{
|
||||
logger_->warn("Invalid packet code: {}", packet_code());
|
||||
blockValid = false;
|
||||
}
|
||||
|
||||
if (blockValid)
|
||||
{
|
||||
p->recordCount_ = length_of_block();
|
||||
p->data_.resize(p->recordCount_);
|
||||
is.read(reinterpret_cast<char*>(p->data_.data()), p->recordCount_);
|
||||
}
|
||||
|
||||
return blockValid;
|
||||
}
|
||||
|
||||
std::shared_ptr<ScitDataPacket> ScitDataPacket::Create(std::istream& is)
|
||||
{
|
||||
std::shared_ptr<ScitDataPacket> packet = std::make_shared<ScitDataPacket>();
|
||||
|
||||
if (!packet->Parse(is))
|
||||
{
|
||||
packet.reset();
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
} // namespace rpg
|
||||
} // namespace wsr88d
|
||||
} // namespace scwx
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
#include <scwx/wsr88d/rpg/scit_forecast_data_packet.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
||||
#include <istream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace wsr88d
|
||||
{
|
||||
namespace rpg
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ =
|
||||
"scwx::wsr88d::rpg::scit_forecast_data_packet";
|
||||
static const auto logger_ = util::Logger::Create(logPrefix_);
|
||||
|
||||
static const std::set<uint16_t> packetCodes_ = {23, 24};
|
||||
|
||||
class ScitForecastDataPacketImpl
|
||||
{
|
||||
public:
|
||||
explicit ScitForecastDataPacketImpl() : data_ {}, recordCount_ {0} {}
|
||||
~ScitForecastDataPacketImpl() = default;
|
||||
|
||||
std::vector<uint8_t> data_;
|
||||
size_t recordCount_;
|
||||
};
|
||||
|
||||
ScitForecastDataPacket::ScitForecastDataPacket() :
|
||||
p(std::make_unique<ScitForecastDataPacketImpl>())
|
||||
{
|
||||
}
|
||||
ScitForecastDataPacket::~ScitForecastDataPacket() = default;
|
||||
|
||||
ScitForecastDataPacket::ScitForecastDataPacket(
|
||||
ScitForecastDataPacket&&) noexcept = default;
|
||||
ScitForecastDataPacket&
|
||||
ScitForecastDataPacket::operator=(ScitForecastDataPacket&&) noexcept = default;
|
||||
|
||||
const std::vector<uint8_t>& ScitForecastDataPacket::data() const
|
||||
{
|
||||
return p->data_;
|
||||
}
|
||||
|
||||
size_t ScitForecastDataPacket::RecordCount() const
|
||||
{
|
||||
return p->recordCount_;
|
||||
}
|
||||
|
||||
bool ScitForecastDataPacket::ParseData(std::istream& is)
|
||||
{
|
||||
bool blockValid = true;
|
||||
|
||||
if (!packetCodes_.contains(packet_code()))
|
||||
{
|
||||
logger_->warn("Invalid packet code: {}", packet_code());
|
||||
blockValid = false;
|
||||
}
|
||||
|
||||
if (blockValid)
|
||||
{
|
||||
p->recordCount_ = length_of_block();
|
||||
p->data_.resize(p->recordCount_);
|
||||
is.read(reinterpret_cast<char*>(p->data_.data()), p->recordCount_);
|
||||
}
|
||||
|
||||
return blockValid;
|
||||
}
|
||||
|
||||
std::shared_ptr<ScitForecastDataPacket>
|
||||
ScitForecastDataPacket::Create(std::istream& is)
|
||||
{
|
||||
std::shared_ptr<ScitForecastDataPacket> packet =
|
||||
std::make_shared<ScitForecastDataPacket>();
|
||||
|
||||
if (!packet->Parse(is))
|
||||
{
|
||||
packet.reset();
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
} // namespace rpg
|
||||
} // namespace wsr88d
|
||||
} // namespace scwx
|
||||
|
|
@ -152,7 +152,7 @@ set(HDR_WSR88D_RPG include/scwx/wsr88d/rpg/ccb_header.hpp
|
|||
include/scwx/wsr88d/rpg/radar_coded_message.hpp
|
||||
include/scwx/wsr88d/rpg/radial_data_packet.hpp
|
||||
include/scwx/wsr88d/rpg/raster_data_packet.hpp
|
||||
include/scwx/wsr88d/rpg/scit_forecast_data_packet.hpp
|
||||
include/scwx/wsr88d/rpg/scit_data_packet.hpp
|
||||
include/scwx/wsr88d/rpg/set_color_level_packet.hpp
|
||||
include/scwx/wsr88d/rpg/special_graphic_symbol_packet.hpp
|
||||
include/scwx/wsr88d/rpg/sti_circle_symbol_packet.hpp
|
||||
|
|
@ -191,7 +191,7 @@ set(SRC_WSR88D_RPG source/scwx/wsr88d/rpg/ccb_header.cpp
|
|||
source/scwx/wsr88d/rpg/radar_coded_message.cpp
|
||||
source/scwx/wsr88d/rpg/radial_data_packet.cpp
|
||||
source/scwx/wsr88d/rpg/raster_data_packet.cpp
|
||||
source/scwx/wsr88d/rpg/scit_forecast_data_packet.cpp
|
||||
source/scwx/wsr88d/rpg/scit_data_packet.cpp
|
||||
source/scwx/wsr88d/rpg/set_color_level_packet.cpp
|
||||
source/scwx/wsr88d/rpg/special_graphic_symbol_packet.cpp
|
||||
source/scwx/wsr88d/rpg/sti_circle_symbol_packet.cpp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue