Tabular alphanumeric block

This commit is contained in:
Dan Paulat 2022-01-12 18:05:33 -06:00
parent add6c41016
commit 0b063f6e8c
5 changed files with 267 additions and 5 deletions

View file

@ -0,0 +1,44 @@
#pragma once
#include <scwx/wsr88d/message.hpp>
#include <cstdint>
#include <memory>
namespace scwx
{
namespace wsr88d
{
namespace rpg
{
class TabularAlphanumericBlockImpl;
class TabularAlphanumericBlock : public Message
{
public:
explicit TabularAlphanumericBlock();
~TabularAlphanumericBlock();
TabularAlphanumericBlock(const TabularAlphanumericBlock&) = delete;
TabularAlphanumericBlock&
operator=(const TabularAlphanumericBlock&) = delete;
TabularAlphanumericBlock(TabularAlphanumericBlock&&) noexcept;
TabularAlphanumericBlock& operator=(TabularAlphanumericBlock&&) noexcept;
int16_t block_divider() const;
size_t data_size() const override;
bool Parse(std::istream& is);
static constexpr size_t SIZE = 102u;
private:
std::unique_ptr<TabularAlphanumericBlockImpl> p;
};
} // namespace rpg
} // namespace wsr88d
} // namespace scwx

View file

@ -4,6 +4,7 @@
#include <scwx/wsr88d/rpg/level3_message_header.hpp> #include <scwx/wsr88d/rpg/level3_message_header.hpp>
#include <scwx/wsr88d/rpg/product_description_block.hpp> #include <scwx/wsr88d/rpg/product_description_block.hpp>
#include <scwx/wsr88d/rpg/product_symbology_block.hpp> #include <scwx/wsr88d/rpg/product_symbology_block.hpp>
#include <scwx/wsr88d/rpg/tabular_alphanumeric_block.hpp>
#include <scwx/wsr88d/rpg/wmo_header.hpp> #include <scwx/wsr88d/rpg/wmo_header.hpp>
#include <scwx/util/rangebuf.hpp> #include <scwx/util/rangebuf.hpp>
#include <scwx/util/time.hpp> #include <scwx/util/time.hpp>
@ -47,7 +48,7 @@ public:
std::shared_ptr<rpg::ProductDescriptionBlock> descriptionBlock_; std::shared_ptr<rpg::ProductDescriptionBlock> descriptionBlock_;
std::shared_ptr<rpg::ProductSymbologyBlock> symbologyBlock_; std::shared_ptr<rpg::ProductSymbologyBlock> symbologyBlock_;
std::shared_ptr<rpg::GraphicAlphanumericBlock> graphicBlock_; std::shared_ptr<rpg::GraphicAlphanumericBlock> graphicBlock_;
std::shared_ptr<void> tabularBlock_; std::shared_ptr<rpg::TabularAlphanumericBlock> tabularBlock_;
}; };
Level3File::Level3File() : p(std::make_unique<Level3FileImpl>()) {} Level3File::Level3File() : p(std::make_unique<Level3FileImpl>()) {}
@ -304,13 +305,19 @@ bool Level3FileImpl::LoadBlocks(std::istream& is)
if (offsetToTabular >= offsetBase) if (offsetToTabular >= offsetBase)
{ {
// TODO tabularBlock_ = std::make_shared<rpg::TabularAlphanumericBlock>();
is.seekg(offsetToTabular - offsetBase, std::ios_base::cur); is.seekg(offsetToTabular - offsetBase, std::ios_base::cur);
tabularValid = tabularBlock_->Parse(is);
is.seekg(offsetBasePos, std::ios_base::beg); is.seekg(offsetBasePos, std::ios_base::beg);
BOOST_LOG_TRIVIAL(debug) BOOST_LOG_TRIVIAL(debug)
<< logPrefix_ << logPrefix_ << "Tabular alphanumeric block valid: " << tabularValid;
<< "Tabular alphanumeric block found: " << offsetToTabular;
if (!tabularValid)
{
tabularBlock_ = nullptr;
}
} }
return (symbologyValid && graphicValid && tabularValid); return (symbologyValid && graphicValid && tabularValid);

View file

@ -126,7 +126,7 @@ bool Level3MessageHeader::Parse(std::istream& is)
<< logPrefix_ << "Invalid message code: " << p->messageCode_; << logPrefix_ << "Invalid message code: " << p->messageCode_;
headerValid = false; headerValid = false;
} }
if (p->dateOfMessage_ < 1u || p->dateOfMessage_ > 32'767u) if (p->dateOfMessage_ > 32'767u)
{ {
BOOST_LOG_TRIVIAL(warning) BOOST_LOG_TRIVIAL(warning)
<< logPrefix_ << "Invalid date: " << p->dateOfMessage_; << logPrefix_ << "Invalid date: " << p->dateOfMessage_;

View file

@ -0,0 +1,209 @@
#include <scwx/wsr88d/rpg/tabular_alphanumeric_block.hpp>
#include <scwx/wsr88d/rpg/level3_message_header.hpp>
#include <scwx/wsr88d/rpg/packet_factory.hpp>
#include <scwx/wsr88d/rpg/product_description_block.hpp>
#include <istream>
#include <string>
#include <boost/log/trivial.hpp>
namespace scwx
{
namespace wsr88d
{
namespace rpg
{
static const std::string logPrefix_ =
"[scwx::wsr88d::rpg::tabular_alphanumeric_block] ";
class TabularAlphanumericBlockImpl
{
public:
explicit TabularAlphanumericBlockImpl() :
blockDivider1_ {0},
blockId_ {0},
lengthOfBlock_ {0},
messageHeader_ {},
descriptionBlock_ {},
blockDivider2_ {0},
numberOfPages_ {0},
pageList_ {}
{
}
~TabularAlphanumericBlockImpl() = default;
int16_t blockDivider1_;
int16_t blockId_;
uint32_t lengthOfBlock_;
std::shared_ptr<Level3MessageHeader> messageHeader_;
std::shared_ptr<ProductDescriptionBlock> descriptionBlock_;
int16_t blockDivider2_;
uint16_t numberOfPages_;
std::vector<std::vector<std::string>> pageList_;
};
TabularAlphanumericBlock::TabularAlphanumericBlock() :
Message(), p(std::make_unique<TabularAlphanumericBlockImpl>())
{
}
TabularAlphanumericBlock::~TabularAlphanumericBlock() = default;
TabularAlphanumericBlock::TabularAlphanumericBlock(
TabularAlphanumericBlock&&) noexcept = default;
TabularAlphanumericBlock& TabularAlphanumericBlock::operator=(
TabularAlphanumericBlock&&) noexcept = default;
int16_t TabularAlphanumericBlock::block_divider() const
{
return p->blockDivider1_;
}
size_t TabularAlphanumericBlock::data_size() const
{
return p->lengthOfBlock_;
}
bool TabularAlphanumericBlock::Parse(std::istream& is)
{
bool blockValid = true;
const std::streampos blockStart = is.tellg();
is.read(reinterpret_cast<char*>(&p->blockDivider1_), 2);
is.read(reinterpret_cast<char*>(&p->blockId_), 2);
is.read(reinterpret_cast<char*>(&p->lengthOfBlock_), 4);
p->blockDivider1_ = ntohs(p->blockDivider1_);
p->blockId_ = ntohs(p->blockId_);
p->lengthOfBlock_ = ntohl(p->lengthOfBlock_);
if (is.eof())
{
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file";
blockValid = false;
}
else
{
if (p->blockDivider1_ != -1)
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_
<< "Invalid first block divider: " << p->blockDivider1_;
blockValid = false;
}
if (p->blockId_ != 3)
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_ << "Invalid block ID: " << p->blockId_;
blockValid = false;
}
if (p->lengthOfBlock_ < 10)
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_ << "Invalid block length: " << p->lengthOfBlock_;
blockValid = false;
}
}
if (blockValid)
{
p->messageHeader_ = std::make_shared<Level3MessageHeader>();
blockValid = p->messageHeader_->Parse(is);
if (!blockValid)
{
p->messageHeader_ = nullptr;
}
}
if (blockValid)
{
p->descriptionBlock_ = std::make_shared<ProductDescriptionBlock>();
blockValid = p->descriptionBlock_->Parse(is);
if (!blockValid)
{
p->descriptionBlock_ = nullptr;
}
}
if (blockValid)
{
is.read(reinterpret_cast<char*>(&p->blockDivider2_), 2);
is.read(reinterpret_cast<char*>(&p->numberOfPages_), 2);
p->blockDivider2_ = ntohs(p->blockDivider2_);
p->numberOfPages_ = ntohs(p->numberOfPages_);
if (p->blockDivider2_ != -1)
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_
<< "Invalid second block divider: " << p->blockDivider2_;
blockValid = false;
}
if (p->numberOfPages_ < 1 || p->numberOfPages_ > 48)
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_ << "Invalid number of pages: " << p->numberOfPages_;
blockValid = false;
}
}
if (blockValid)
{
uint16_t numberOfCharacters;
for (uint16_t i = 0; i < p->numberOfPages_; i++)
{
std::vector<std::string> lineList;
while (!is.eof())
{
is.read(reinterpret_cast<char*>(&numberOfCharacters), 2);
numberOfCharacters = ntohs(numberOfCharacters);
if (static_cast<int16_t>(numberOfCharacters) == -1)
{
// End of page
break;
}
else if (numberOfCharacters > 80)
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_
<< "Invalid number of characters: " << numberOfCharacters
<< " (Page " << (i + 1) << ")";
blockValid = false;
break;
}
std::string line;
line.resize(numberOfCharacters);
is.read(line.data(), numberOfCharacters);
lineList.push_back(std::move(line));
}
p->pageList_.push_back(std::move(lineList));
}
}
const std::streampos blockEnd = is.tellg();
if (!ValidateMessage(is, blockEnd - blockStart))
{
blockValid = false;
}
return blockValid;
}
} // namespace rpg
} // namespace wsr88d
} // namespace scwx

View file

@ -72,6 +72,7 @@ set(HDR_WSR88D_RPG include/scwx/wsr88d/rpg/ccb_header.hpp
include/scwx/wsr88d/rpg/special_graphic_symbol_packet.hpp include/scwx/wsr88d/rpg/special_graphic_symbol_packet.hpp
include/scwx/wsr88d/rpg/sti_circle_symbol_packet.hpp include/scwx/wsr88d/rpg/sti_circle_symbol_packet.hpp
include/scwx/wsr88d/rpg/storm_id_symbol_packet.hpp include/scwx/wsr88d/rpg/storm_id_symbol_packet.hpp
include/scwx/wsr88d/rpg/tabular_alphanumeric_block.hpp
include/scwx/wsr88d/rpg/text_and_special_symbol_packet.hpp include/scwx/wsr88d/rpg/text_and_special_symbol_packet.hpp
include/scwx/wsr88d/rpg/unlinked_contour_vector_packet.hpp include/scwx/wsr88d/rpg/unlinked_contour_vector_packet.hpp
include/scwx/wsr88d/rpg/unlinked_vector_packet.hpp include/scwx/wsr88d/rpg/unlinked_vector_packet.hpp
@ -104,6 +105,7 @@ set(SRC_WSR88D_RPG source/scwx/wsr88d/rpg/ccb_header.cpp
source/scwx/wsr88d/rpg/special_graphic_symbol_packet.cpp source/scwx/wsr88d/rpg/special_graphic_symbol_packet.cpp
source/scwx/wsr88d/rpg/sti_circle_symbol_packet.cpp source/scwx/wsr88d/rpg/sti_circle_symbol_packet.cpp
source/scwx/wsr88d/rpg/storm_id_symbol_packet.cpp source/scwx/wsr88d/rpg/storm_id_symbol_packet.cpp
source/scwx/wsr88d/rpg/tabular_alphanumeric_block.cpp
source/scwx/wsr88d/rpg/text_and_special_symbol_packet.cpp source/scwx/wsr88d/rpg/text_and_special_symbol_packet.cpp
source/scwx/wsr88d/rpg/unlinked_contour_vector_packet.cpp source/scwx/wsr88d/rpg/unlinked_contour_vector_packet.cpp
source/scwx/wsr88d/rpg/unlinked_vector_packet.cpp source/scwx/wsr88d/rpg/unlinked_vector_packet.cpp