Contour vectors

This commit is contained in:
Dan Paulat 2021-12-27 12:29:03 -06:00
parent 96cd27adcb
commit e505edf156
8 changed files with 515 additions and 16 deletions

View file

@ -0,0 +1,141 @@
#include <scwx/wsr88d/rpg/linked_contour_vector_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::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<int16_t> endI_;
std::vector<int16_t> endJ_;
};
LinkedContourVectorPacket::LinkedContourVectorPacket() :
p(std::make_unique<LinkedContourVectorPacketImpl>())
{
}
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<char*>(&p->packetCode_), 2);
is.read(reinterpret_cast<char*>(&p->initialPointIndicator_), 2);
is.read(reinterpret_cast<char*>(&p->startI_), 2);
is.read(reinterpret_cast<char*>(&p->startJ_), 2);
is.read(reinterpret_cast<char*>(&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<int>(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<char*>(&endI), 2);
is.read(reinterpret_cast<char*>(&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

View file

@ -32,10 +32,10 @@ public:
uint16_t lengthOfBlock_;
uint16_t valueOfVector_;
uint16_t startI_;
uint16_t startJ_;
std::vector<uint16_t> endI_;
std::vector<uint16_t> endJ_;
int16_t startI_;
int16_t startJ_;
std::vector<int16_t> endI_;
std::vector<int16_t> 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++)
{

View file

@ -0,0 +1,100 @@
#include <scwx/wsr88d/rpg/set_color_level_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::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<SetColorLevelPacketImpl>())
{
}
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<char*>(&p->packetCode_), 2);
is.read(reinterpret_cast<char*>(&p->colorValueIndicator_), 2);
is.read(reinterpret_cast<char*>(&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

View file

@ -0,0 +1,125 @@
#include <scwx/wsr88d/rpg/unlinked_contour_vector_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::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<int16_t> beginI_;
std::vector<int16_t> beginJ_;
std::vector<int16_t> endI_;
std::vector<int16_t> endJ_;
};
UnlinkedContourVectorPacket::UnlinkedContourVectorPacket() :
p(std::make_unique<UnlinkedContourVectorPacketImpl>())
{
}
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<char*>(&p->packetCode_), 2);
is.read(reinterpret_cast<char*>(&p->lengthOfVectors_), 2);
p->packetCode_ = ntohs(p->packetCode_);
p->lengthOfVectors_ = ntohs(p->lengthOfVectors_);
int vectorSize = static_cast<int>(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<char*>(&beginI), 2);
is.read(reinterpret_cast<char*>(&beginJ), 2);
is.read(reinterpret_cast<char*>(&endI), 2);
is.read(reinterpret_cast<char*>(&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

View file

@ -32,10 +32,10 @@ public:
uint16_t lengthOfBlock_;
uint16_t valueOfVector_;
std::vector<uint16_t> beginI_;
std::vector<uint16_t> beginJ_;
std::vector<uint16_t> endI_;
std::vector<uint16_t> endJ_;
std::vector<int16_t> beginI_;
std::vector<int16_t> beginJ_;
std::vector<int16_t> endI_;
std::vector<int16_t> 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++)
{