Parse Performance/Maintenance Data (Message Type 3)

This commit is contained in:
Dan Paulat 2021-06-19 15:58:36 -05:00
parent e440d8c657
commit 2fc12d44db
10 changed files with 2854 additions and 86 deletions

View file

@ -10,12 +10,6 @@
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/log/trivial.hpp>
#ifdef WIN32
# include <WinSock2.h>
#else
# include <arpa/inet.h>
#endif
namespace scwx
{
namespace wsr88d

View file

@ -1,16 +1,9 @@
#include <scwx/wsr88d/rda/clutter_filter_map.hpp>
#include <istream>
#include <vector>
#include <boost/log/trivial.hpp>
#ifdef WIN32
# include <WinSock2.h>
#else
# include <arpa/inet.h>
#endif
namespace scwx
{
namespace wsr88d
@ -205,7 +198,7 @@ bool ClutterFilterMap::Parse(std::istream& is)
}
}
if (!ValidateSize(is, bytesRead))
if (!ValidateMessage(is, bytesRead))
{
messageValid = false;
}

View file

@ -1,7 +1,5 @@
#include <scwx/wsr88d/rda/message.hpp>
#include <istream>
#include <boost/log/trivial.hpp>
namespace scwx
@ -28,12 +26,23 @@ Message::~Message() = default;
Message::Message(Message&&) noexcept = default;
Message& Message::operator=(Message&&) noexcept = default;
bool Message::ValidateSize(std::istream& is, size_t bytesRead) const
bool Message::ValidateMessage(std::istream& is, size_t bytesRead) const
{
bool messageValid = true;
size_t dataSize = header().message_size() * 2 - header().SIZE;
if (bytesRead != dataSize)
if (is.eof())
{
BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "Reached end of file";
messageValid = false;
}
else if (is.fail())
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_ << "Could not read from input stream";
messageValid = false;
}
else if (bytesRead != dataSize)
{
is.seekg(static_cast<std::streamoff>(dataSize) -
static_cast<std::streamoff>(bytesRead),

View file

@ -2,9 +2,9 @@
#include <scwx/util/vectorbuf.hpp>
#include <scwx/wsr88d/rda/clutter_filter_map.hpp>
#include <scwx/wsr88d/rda/performance_maintenance_data.hpp>
#include <scwx/wsr88d/rda/rda_adaptation_data.hpp>
#include <istream>
#include <unordered_map>
#include <vector>
@ -23,7 +23,9 @@ typedef std::function<std::unique_ptr<Message>(MessageHeader&&, std::istream&)>
CreateMessageFunction;
static const std::unordered_map<uint8_t, CreateMessageFunction> create_ {
{15, ClutterFilterMap::Create}, {18, RdaAdaptationData::Create}};
{3, PerformanceMaintenanceData::Create},
{15, ClutterFilterMap::Create},
{18, RdaAdaptationData::Create}};
static std::vector<char> messageData_;
static size_t bufferedSize_;

File diff suppressed because it is too large Load diff

View file

@ -1,18 +1,7 @@
#include <scwx/wsr88d/rda/rda_adaptation_data.hpp>
#include <array>
#include <execution>
#include <istream>
#include <map>
#include <boost/log/trivial.hpp>
#ifdef WIN32
# include <WinSock2.h>
#else
# include <arpa/inet.h>
#endif
namespace scwx
{
namespace wsr88d
@ -23,14 +12,6 @@ namespace rda
static const std::string logPrefix_ =
"[scwx::wsr88d::rda::rda_adaptation_data] ";
static void ReadBoolean(std::istream& is, bool& value);
static void ReadChar(std::istream& is, char& value);
static float SwapFloat(float f);
template<size_t _Size>
static void SwapFloatArray(std::array<float, _Size>& arr);
template<typename T>
static void SwapFloatMap(std::map<T, float>& m);
struct AntManualSetup
{
int32_t ielmin_;
@ -1757,13 +1738,7 @@ bool RdaAdaptationData::Parse(std::istream& is)
p->txbBaseline_ = SwapFloat(p->txbBaseline_);
p->txbAlarmThresh_ = SwapFloat(p->txbAlarmThresh_);
if (is.eof())
{
BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "Reached end of file (1)";
messageValid = false;
}
if (!ValidateSize(is, bytesRead))
if (!ValidateMessage(is, bytesRead))
{
messageValid = false;
}
@ -1781,43 +1756,6 @@ RdaAdaptationData::Create(MessageHeader&& header, std::istream& is)
return message;
}
static void ReadBoolean(std::istream& is, bool& value)
{
std::string data(4, ' ');
is.read(reinterpret_cast<char*>(&data[0]), 4);
value = (data.at(0) == 'T');
}
static void ReadChar(std::istream& is, char& value)
{
std::string data(4, ' ');
is.read(reinterpret_cast<char*>(&data[0]), 4);
value = data.at(0);
}
static float SwapFloat(float f)
{
return ntohf(*reinterpret_cast<uint32_t*>(&f));
}
template<size_t _Size>
static void SwapFloatArray(std::array<float, _Size>& arr)
{
std::transform(std::execution::par_unseq,
arr.begin(),
arr.end(),
arr.begin(),
[](float f) { return SwapFloat(f); });
}
template<typename T>
static void SwapFloatMap(std::map<T, float>& m)
{
std::for_each(std::execution::par_unseq, m.begin(), m.end(), [](auto& p) {
p.second = SwapFloat(p.second);
});
}
} // namespace rda
} // namespace wsr88d
} // namespace scwx