diff --git a/wxdata/include/scwx/wsr88d/rpg/linked_contour_vector_packet.hpp b/wxdata/include/scwx/wsr88d/rpg/linked_contour_vector_packet.hpp new file mode 100644 index 00000000..4ef4e063 --- /dev/null +++ b/wxdata/include/scwx/wsr88d/rpg/linked_contour_vector_packet.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include + +#include +#include + +namespace scwx +{ +namespace wsr88d +{ +namespace rpg +{ + +class LinkedContourVectorPacketImpl; + +class LinkedContourVectorPacket : public Packet +{ +public: + explicit LinkedContourVectorPacket(); + ~LinkedContourVectorPacket(); + + LinkedContourVectorPacket(const LinkedContourVectorPacket&) = delete; + LinkedContourVectorPacket& + operator=(const LinkedContourVectorPacket&) = delete; + + LinkedContourVectorPacket(LinkedContourVectorPacket&&) noexcept; + LinkedContourVectorPacket& operator=(LinkedContourVectorPacket&&) noexcept; + + uint16_t packet_code() const; + uint16_t initial_point_indicator() const; + uint16_t length_of_vectors() const; + + size_t data_size() const override; + + bool Parse(std::istream& is) override; + +private: + std::unique_ptr p; +}; + +} // namespace rpg +} // namespace wsr88d +} // namespace scwx diff --git a/wxdata/include/scwx/wsr88d/rpg/set_color_level_packet.hpp b/wxdata/include/scwx/wsr88d/rpg/set_color_level_packet.hpp new file mode 100644 index 00000000..d2395704 --- /dev/null +++ b/wxdata/include/scwx/wsr88d/rpg/set_color_level_packet.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include + +#include +#include + +namespace scwx +{ +namespace wsr88d +{ +namespace rpg +{ + +class SetColorLevelPacketImpl; + +class SetColorLevelPacket : public Packet +{ +public: + explicit SetColorLevelPacket(); + ~SetColorLevelPacket(); + + SetColorLevelPacket(const SetColorLevelPacket&) = delete; + SetColorLevelPacket& operator=(const SetColorLevelPacket&) = delete; + + SetColorLevelPacket(SetColorLevelPacket&&) noexcept; + SetColorLevelPacket& operator=(SetColorLevelPacket&&) noexcept; + + uint16_t packet_code() const; + uint16_t color_value_indicator() const; + uint16_t value_of_contour() const; + + size_t data_size() const override; + + bool Parse(std::istream& is) override; + + static constexpr size_t SIZE = 6u; + +private: + std::unique_ptr p; +}; + +} // namespace rpg +} // namespace wsr88d +} // namespace scwx diff --git a/wxdata/include/scwx/wsr88d/rpg/unlinked_contour_vector_packet.hpp b/wxdata/include/scwx/wsr88d/rpg/unlinked_contour_vector_packet.hpp new file mode 100644 index 00000000..3caf58d3 --- /dev/null +++ b/wxdata/include/scwx/wsr88d/rpg/unlinked_contour_vector_packet.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include + +#include +#include + +namespace scwx +{ +namespace wsr88d +{ +namespace rpg +{ + +class UnlinkedContourVectorPacketImpl; + +class UnlinkedContourVectorPacket : public Packet +{ +public: + explicit UnlinkedContourVectorPacket(); + ~UnlinkedContourVectorPacket(); + + UnlinkedContourVectorPacket(const UnlinkedContourVectorPacket&) = delete; + UnlinkedContourVectorPacket& + operator=(const UnlinkedContourVectorPacket&) = delete; + + UnlinkedContourVectorPacket(UnlinkedContourVectorPacket&&) noexcept; + UnlinkedContourVectorPacket& + operator=(UnlinkedContourVectorPacket&&) noexcept; + + uint16_t packet_code() const; + uint16_t length_of_vectors() const; + + size_t data_size() const override; + + bool Parse(std::istream& is) override; + +private: + std::unique_ptr p; +}; + +} // namespace rpg +} // namespace wsr88d +} // namespace scwx diff --git a/wxdata/source/scwx/wsr88d/rpg/linked_contour_vector_packet.cpp b/wxdata/source/scwx/wsr88d/rpg/linked_contour_vector_packet.cpp new file mode 100644 index 00000000..e50b5da3 --- /dev/null +++ b/wxdata/source/scwx/wsr88d/rpg/linked_contour_vector_packet.cpp @@ -0,0 +1,141 @@ +#include + +#include +#include + +#include + +namespace scwx +{ +namespace wsr88d +{ +namespace rpg +{ + +static const std::string logPrefix_ = + "[scwx::wsr88d::rpg::linked_contour_vector_packet] "; + +class LinkedContourVectorPacketImpl +{ +public: + explicit LinkedContourVectorPacketImpl() : + packetCode_ {}, + initialPointIndicator_ {}, + lengthOfVectors_ {}, + startI_ {}, + startJ_ {}, + endI_ {}, + endJ_ {} {}; + ~LinkedContourVectorPacketImpl() = default; + + uint16_t packetCode_; + uint16_t initialPointIndicator_; + uint16_t lengthOfVectors_; + + int16_t startI_; + int16_t startJ_; + std::vector endI_; + std::vector endJ_; +}; + +LinkedContourVectorPacket::LinkedContourVectorPacket() : + p(std::make_unique()) +{ +} +LinkedContourVectorPacket::~LinkedContourVectorPacket() = default; + +LinkedContourVectorPacket::LinkedContourVectorPacket( + LinkedContourVectorPacket&&) noexcept = default; +LinkedContourVectorPacket& LinkedContourVectorPacket::operator=( + LinkedContourVectorPacket&&) noexcept = default; + +uint16_t LinkedContourVectorPacket::packet_code() const +{ + return p->packetCode_; +} + +uint16_t LinkedContourVectorPacket::initial_point_indicator() const +{ + return p->initialPointIndicator_; +} + +uint16_t LinkedContourVectorPacket::length_of_vectors() const +{ + return p->lengthOfVectors_; +} + +size_t LinkedContourVectorPacket::data_size() const +{ + return p->lengthOfVectors_ + 10u; +} + +bool LinkedContourVectorPacket::Parse(std::istream& is) +{ + bool blockValid = true; + + is.read(reinterpret_cast(&p->packetCode_), 2); + is.read(reinterpret_cast(&p->initialPointIndicator_), 2); + is.read(reinterpret_cast(&p->startI_), 2); + is.read(reinterpret_cast(&p->startJ_), 2); + is.read(reinterpret_cast(&p->lengthOfVectors_), 2); + + p->packetCode_ = ntohs(p->packetCode_); + p->initialPointIndicator_ = ntohs(p->initialPointIndicator_); + p->startI_ = ntohs(p->startI_); + p->startJ_ = ntohs(p->startJ_); + p->lengthOfVectors_ = ntohs(p->lengthOfVectors_); + + int vectorSize = static_cast(p->lengthOfVectors_); + + if (is.eof()) + { + BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; + blockValid = false; + } + + // The number of vectors is equal to the size divided by the number of bytes + // in a vector coordinate + int vectorCount = vectorSize / 4; + int16_t endI; + int16_t endJ; + + for (int v = 0; v < vectorCount && !is.eof(); v++) + { + is.read(reinterpret_cast(&endI), 2); + is.read(reinterpret_cast(&endJ), 2); + + endI = ntohs(endI); + endJ = ntohs(endJ); + + p->endI_.push_back(endI); + p->endJ_.push_back(endJ); + } + + if (is.eof()) + { + BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; + blockValid = false; + } + else + { + if (p->packetCode_ != 0x0E03) + { + BOOST_LOG_TRIVIAL(warning) + << logPrefix_ << "Invalid packet code: " << p->packetCode_; + blockValid = false; + } + if (p->initialPointIndicator_ != 0x8000) + { + BOOST_LOG_TRIVIAL(warning) + << logPrefix_ + << "Invalid initial point indicator: " << p->initialPointIndicator_; + blockValid = false; + } + } + + return blockValid; +} + +} // namespace rpg +} // namespace wsr88d +} // namespace scwx diff --git a/wxdata/source/scwx/wsr88d/rpg/linked_vector_packet.cpp b/wxdata/source/scwx/wsr88d/rpg/linked_vector_packet.cpp index 3f74ff51..f935d938 100644 --- a/wxdata/source/scwx/wsr88d/rpg/linked_vector_packet.cpp +++ b/wxdata/source/scwx/wsr88d/rpg/linked_vector_packet.cpp @@ -32,10 +32,10 @@ public: uint16_t lengthOfBlock_; uint16_t valueOfVector_; - uint16_t startI_; - uint16_t startJ_; - std::vector endI_; - std::vector endJ_; + int16_t startI_; + int16_t startJ_; + std::vector endI_; + std::vector endJ_; }; LinkedVectorPacket::LinkedVectorPacket() : @@ -108,9 +108,9 @@ bool LinkedVectorPacket::Parse(std::istream& is) // The number of vectors is equal to the size divided by the number of bytes // in a vector coordinate - int vectorCount = vectorSize / 4; - uint16_t endI; - uint16_t endJ; + int vectorCount = vectorSize / 4; + int16_t endI; + int16_t endJ; for (int v = 0; v < vectorCount && !is.eof(); v++) { diff --git a/wxdata/source/scwx/wsr88d/rpg/set_color_level_packet.cpp b/wxdata/source/scwx/wsr88d/rpg/set_color_level_packet.cpp new file mode 100644 index 00000000..d38294e6 --- /dev/null +++ b/wxdata/source/scwx/wsr88d/rpg/set_color_level_packet.cpp @@ -0,0 +1,100 @@ +#include + +#include +#include + +#include + +namespace scwx +{ +namespace wsr88d +{ +namespace rpg +{ + +static const std::string logPrefix_ = + "[scwx::wsr88d::rpg::set_color_level_packet] "; + +class SetColorLevelPacketImpl +{ +public: + explicit SetColorLevelPacketImpl() : + packetCode_ {}, colorValueIndicator_ {}, valueOfContour_ {} {}; + ~SetColorLevelPacketImpl() = default; + + uint16_t packetCode_; + uint16_t colorValueIndicator_; + uint16_t valueOfContour_; +}; + +SetColorLevelPacket::SetColorLevelPacket() : + p(std::make_unique()) +{ +} +SetColorLevelPacket::~SetColorLevelPacket() = default; + +SetColorLevelPacket::SetColorLevelPacket(SetColorLevelPacket&&) noexcept = + default; +SetColorLevelPacket& +SetColorLevelPacket::operator=(SetColorLevelPacket&&) noexcept = default; + +uint16_t SetColorLevelPacket::packet_code() const +{ + return p->packetCode_; +} + +uint16_t SetColorLevelPacket::color_value_indicator() const +{ + return p->colorValueIndicator_; +} + +uint16_t SetColorLevelPacket::value_of_contour() const +{ + return p->valueOfContour_; +} + +size_t SetColorLevelPacket::data_size() const +{ + return SIZE; +} + +bool SetColorLevelPacket::Parse(std::istream& is) +{ + bool blockValid = true; + + is.read(reinterpret_cast(&p->packetCode_), 2); + is.read(reinterpret_cast(&p->colorValueIndicator_), 2); + is.read(reinterpret_cast(&p->valueOfContour_), 2); + + p->packetCode_ = ntohs(p->packetCode_); + p->colorValueIndicator_ = ntohs(p->colorValueIndicator_); + p->valueOfContour_ = ntohs(p->valueOfContour_); + + if (is.eof()) + { + BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; + blockValid = false; + } + else + { + if (p->packetCode_ != 0x0802) + { + BOOST_LOG_TRIVIAL(warning) + << logPrefix_ << "Invalid packet code: " << p->packetCode_; + blockValid = false; + } + if (p->colorValueIndicator_ != 0x0002) + { + BOOST_LOG_TRIVIAL(warning) + << logPrefix_ + << "Invalid color value indicator: " << p->colorValueIndicator_; + blockValid = false; + } + } + + return blockValid; +} + +} // namespace rpg +} // namespace wsr88d +} // namespace scwx diff --git a/wxdata/source/scwx/wsr88d/rpg/unlinked_contour_vector_packet.cpp b/wxdata/source/scwx/wsr88d/rpg/unlinked_contour_vector_packet.cpp new file mode 100644 index 00000000..740b8e08 --- /dev/null +++ b/wxdata/source/scwx/wsr88d/rpg/unlinked_contour_vector_packet.cpp @@ -0,0 +1,125 @@ +#include + +#include +#include + +#include + +namespace scwx +{ +namespace wsr88d +{ +namespace rpg +{ + +static const std::string logPrefix_ = + "[scwx::wsr88d::rpg::unlinked_contour_vector_packet] "; + +class UnlinkedContourVectorPacketImpl +{ +public: + explicit UnlinkedContourVectorPacketImpl() : + packetCode_ {}, + lengthOfVectors_ {}, + beginI_ {}, + beginJ_ {}, + endI_ {}, + endJ_ {} {}; + ~UnlinkedContourVectorPacketImpl() = default; + + uint16_t packetCode_; + uint16_t lengthOfVectors_; + uint16_t valueOfVector_; + + std::vector beginI_; + std::vector beginJ_; + std::vector endI_; + std::vector endJ_; +}; + +UnlinkedContourVectorPacket::UnlinkedContourVectorPacket() : + p(std::make_unique()) +{ +} +UnlinkedContourVectorPacket::~UnlinkedContourVectorPacket() = default; + +UnlinkedContourVectorPacket::UnlinkedContourVectorPacket( + UnlinkedContourVectorPacket&&) noexcept = default; +UnlinkedContourVectorPacket& UnlinkedContourVectorPacket::operator=( + UnlinkedContourVectorPacket&&) noexcept = default; + +uint16_t UnlinkedContourVectorPacket::packet_code() const +{ + return p->packetCode_; +} + +uint16_t UnlinkedContourVectorPacket::length_of_vectors() const +{ + return p->lengthOfVectors_ + 4u; + ; +} + +size_t UnlinkedContourVectorPacket::data_size() const +{ + return p->lengthOfVectors_ + 4u; +} + +bool UnlinkedContourVectorPacket::Parse(std::istream& is) +{ + bool blockValid = true; + + is.read(reinterpret_cast(&p->packetCode_), 2); + is.read(reinterpret_cast(&p->lengthOfVectors_), 2); + + p->packetCode_ = ntohs(p->packetCode_); + p->lengthOfVectors_ = ntohs(p->lengthOfVectors_); + + int vectorSize = static_cast(p->lengthOfVectors_); + + // The number of vectors is equal to the size divided by the number of bytes + // in a vector + int vectorCount = vectorSize / 8; + int16_t beginI; + int16_t beginJ; + int16_t endI; + int16_t endJ; + + for (int v = 0; v < vectorCount && !is.eof(); v++) + { + is.read(reinterpret_cast(&beginI), 2); + is.read(reinterpret_cast(&beginJ), 2); + is.read(reinterpret_cast(&endI), 2); + is.read(reinterpret_cast(&endJ), 2); + + beginI = ntohs(beginI); + beginJ = ntohs(beginJ); + endI = ntohs(endI); + endJ = ntohs(endJ); + + p->beginI_.push_back(beginI); + p->beginJ_.push_back(beginJ); + p->endI_.push_back(endI); + p->endJ_.push_back(endJ); + } + + if (is.eof()) + { + BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; + blockValid = false; + } + else + { + if (p->packetCode_ != 0x3501) + { + BOOST_LOG_TRIVIAL(warning) + << logPrefix_ << "Invalid packet code: " << p->packetCode_; + blockValid = false; + } + } + + return blockValid; +} + +} // namespace rpg +} // namespace wsr88d +} // namespace scwx diff --git a/wxdata/source/scwx/wsr88d/rpg/unlinked_vector_packet.cpp b/wxdata/source/scwx/wsr88d/rpg/unlinked_vector_packet.cpp index 1a04a937..5aa57530 100644 --- a/wxdata/source/scwx/wsr88d/rpg/unlinked_vector_packet.cpp +++ b/wxdata/source/scwx/wsr88d/rpg/unlinked_vector_packet.cpp @@ -32,10 +32,10 @@ public: uint16_t lengthOfBlock_; uint16_t valueOfVector_; - std::vector beginI_; - std::vector beginJ_; - std::vector endI_; - std::vector endJ_; + std::vector beginI_; + std::vector beginJ_; + std::vector endI_; + std::vector endJ_; }; UnlinkedVectorPacket::UnlinkedVectorPacket() : @@ -103,11 +103,11 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) // The number of vectors is equal to the size divided by the number of bytes // in a vector - int vectorCount = vectorSize / 8; - uint16_t beginI; - uint16_t beginJ; - uint16_t endI; - uint16_t endJ; + int vectorCount = vectorSize / 8; + int16_t beginI; + int16_t beginJ; + int16_t endI; + int16_t endJ; for (int v = 0; v < vectorCount && !is.eof(); v++) {