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

@ -2,6 +2,18 @@
#include <scwx/wsr88d/rda/message_header.hpp>
#include <array>
#include <execution>
#include <istream>
#include <map>
#include <string>
#ifdef WIN32
# include <WinSock2.h>
#else
# include <arpa/inet.h>
#endif
namespace scwx
{
namespace wsr88d
@ -22,7 +34,54 @@ protected:
Message(Message&&) noexcept;
Message& operator=(Message&&) noexcept;
bool ValidateSize(std::istream& is, size_t bytesRead) const;
bool ValidateMessage(std::istream& is, size_t bytesRead) const;
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<size_t _Size>
static void SwapUInt16Array(std::array<uint16_t, _Size>& arr)
{
std::transform(std::execution::par_unseq,
arr.begin(),
arr.end(),
arr.begin(),
[](uint16_t u) { return ntohs(u); });
}
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);
});
}
public:
virtual ~Message();