the OTP Advertisement PDU
This commit is contained in:
parent
d77cf14dae
commit
00cb16a5e5
|
@ -57,6 +57,8 @@ set(SOURCE_FILES
|
|||
dmx/personality.cpp
|
||||
dmx/universe.cpp
|
||||
dmx/universe.h
|
||||
otp/advertisement.h
|
||||
otp/advertisement.cpp
|
||||
otp/base.h
|
||||
otp/base.cpp
|
||||
otp/otp.h
|
||||
|
|
|
@ -0,0 +1,254 @@
|
|||
/*
|
||||
otp/advertisement.cpp
|
||||
|
||||
Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "advertisement.h"
|
||||
|
||||
#include "otp.h"
|
||||
|
||||
|
||||
namespace OTP::Advertisement {
|
||||
|
||||
namespace Module {
|
||||
|
||||
/**
|
||||
* @brief Advertisement::Module::pdu::iStream
|
||||
* @param stream
|
||||
*/
|
||||
void pdu::iStream(PDU::Stream stream)
|
||||
{
|
||||
PDU::pdu::iStream(stream); // vector and length;
|
||||
createData<module_data>(); // data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief module_identifier::iStream
|
||||
* @param stream
|
||||
*/
|
||||
void module_identifier::iStream(PDU::Stream stream)
|
||||
{
|
||||
*stream >> manufacturer;
|
||||
*stream >> number;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief module_identifier::oStream
|
||||
* @param stream
|
||||
*/
|
||||
void module_identifier::oStream(PDU::Stream stream) const
|
||||
{
|
||||
*stream << manufacturer;
|
||||
*stream << number;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief module_data::iStream
|
||||
* @param stream
|
||||
*/
|
||||
void module_data::iStream(PDU::Stream stream)
|
||||
{
|
||||
*stream >> reserved;
|
||||
while (stream->good())
|
||||
{
|
||||
modules.push_back(module_identifier());
|
||||
modules.back().iStream(stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief module_data::oStream
|
||||
* @param stream
|
||||
*/
|
||||
void module_data::oStream(PDU::Stream stream) const
|
||||
{
|
||||
*stream << reserved;
|
||||
for (const auto & m : modules)
|
||||
m.oStream(stream);
|
||||
}
|
||||
|
||||
} // namespace Module
|
||||
|
||||
|
||||
namespace Name {
|
||||
|
||||
/**
|
||||
* @brief Advertisement::Name::pdu::iStream
|
||||
* @param stream
|
||||
*/
|
||||
void pdu::iStream(PDU::Stream stream)
|
||||
{
|
||||
PDU::pdu::iStream(stream); // vector and length;
|
||||
createData<name_data>(); // data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief point_description::iStream
|
||||
* @param stream
|
||||
*/
|
||||
void point_description::iStream(PDU::Stream stream)
|
||||
{
|
||||
*stream >> system;
|
||||
*stream >> group;
|
||||
*stream >> point;
|
||||
stream->readString(name, 32);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief point_description::oStream
|
||||
* @param stream
|
||||
*/
|
||||
void point_description::oStream(PDU::Stream stream) const
|
||||
{
|
||||
*stream << system;
|
||||
*stream << group;
|
||||
*stream << point;
|
||||
stream->writeString(name, 32);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief name_data::iStream
|
||||
* @param stream
|
||||
*/
|
||||
void name_data::iStream(PDU::Stream stream)
|
||||
{
|
||||
*stream >> flags;
|
||||
*stream >> reserved;
|
||||
while (stream->good())
|
||||
{
|
||||
points.push_back(point_description());
|
||||
points.back().iStream(stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief name_data::oStream
|
||||
* @param stream
|
||||
*/
|
||||
void name_data::oStream(PDU::Stream stream) const
|
||||
{
|
||||
*stream << flags;
|
||||
*stream << reserved;
|
||||
for (const auto & p : points)
|
||||
p.oStream(stream);
|
||||
}
|
||||
|
||||
} // namespace Name
|
||||
|
||||
|
||||
namespace System {
|
||||
|
||||
/**
|
||||
* @brief Advertisement::System::pdu::iStream
|
||||
* @param stream
|
||||
*/
|
||||
void pdu::iStream(PDU::Stream stream)
|
||||
{
|
||||
PDU::pdu::iStream(stream); // vector and length;
|
||||
createData<system_data>(); // data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief system_data::iStream
|
||||
* @param stream
|
||||
*/
|
||||
void system_data::iStream(PDU::Stream stream)
|
||||
{
|
||||
*stream >> flags;
|
||||
*stream >> reserved;
|
||||
while (stream->good())
|
||||
systems.push_back(stream->get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief system_data::oStream
|
||||
* @param stream
|
||||
*/
|
||||
void system_data::oStream(PDU::Stream stream) const
|
||||
{
|
||||
*stream << flags;
|
||||
*stream << reserved;
|
||||
for (const auto & s : systems)
|
||||
*stream << s;
|
||||
}
|
||||
|
||||
} // namespace System
|
||||
|
||||
|
||||
/**
|
||||
* @brief Advertisement::pdu::iStream
|
||||
* @param stream
|
||||
*/
|
||||
void pdu::iStream(PDU::Stream stream)
|
||||
{
|
||||
PDU::pdu::iStream(stream); // vector and length;
|
||||
createData<advertisement_data>(); // data
|
||||
|
||||
auto d = static_cast<advertisement_data*>(data);
|
||||
switch (vector)
|
||||
{
|
||||
case VECTOR_OTP_ADVERTISEMENT_MODULE:
|
||||
d->payload = std::shared_ptr<Module::pdu>(new Module::pdu());
|
||||
break;
|
||||
case VECTOR_OTP_ADVERTISEMENT_NAME:
|
||||
d->payload = std::shared_ptr<Name::pdu>(new Name::pdu());
|
||||
break;
|
||||
case VECTOR_OTP_ADVERTISEMENT_SYSTEM:
|
||||
d->payload = std::shared_ptr<System::pdu>(new System::pdu());
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
d->payload->iStream(stream_);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief advertisement_data::iStream
|
||||
* @param stream
|
||||
*/
|
||||
void advertisement_data::iStream(PDU::Stream stream)
|
||||
{
|
||||
*stream >> reserved;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief advertisement_data::oStream
|
||||
* @param stream
|
||||
*/
|
||||
void advertisement_data::oStream(PDU::Stream stream) const
|
||||
{
|
||||
*stream << reserved;
|
||||
payload->oStream(stream);
|
||||
}
|
||||
|
||||
} // namespace OTP::Advertisement
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
otp/advertisement.h
|
||||
|
||||
Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "pdu.h"
|
||||
|
||||
namespace OTP::Advertisement {
|
||||
|
||||
namespace Module {
|
||||
|
||||
/**
|
||||
* @brief The Advertisement::Module::pdu class
|
||||
*/
|
||||
class pdu
|
||||
: public OTP::PDU::pdu
|
||||
{
|
||||
public:
|
||||
virtual void iStream(PDU::Stream) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The module_identifier struct
|
||||
*/
|
||||
struct module_identifier
|
||||
: PDU::pdu_stream_object
|
||||
{
|
||||
uint16_t manufacturer;
|
||||
uint16_t number;
|
||||
|
||||
virtual size_t streamSize() const override { return 4; }
|
||||
virtual void iStream(PDU::Stream) override;
|
||||
virtual void oStream(PDU::Stream) const override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The module_data struct
|
||||
*/
|
||||
struct module_data
|
||||
: PDU::pdu_data
|
||||
{
|
||||
uint32_t reserved;
|
||||
std::vector<module_identifier> modules;
|
||||
|
||||
virtual size_t streamSize() const override { return 4 + (4 * modules.size()); }
|
||||
virtual void iStream(PDU::Stream) override;
|
||||
virtual void oStream(PDU::Stream) const override;
|
||||
};
|
||||
|
||||
} // namespace Module
|
||||
|
||||
|
||||
namespace Name {
|
||||
|
||||
/**
|
||||
* @brief The Advertisement::Name::pdu class
|
||||
*/
|
||||
class pdu
|
||||
: public OTP::PDU::pdu
|
||||
{
|
||||
public:
|
||||
virtual void iStream(PDU::Stream) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The point_description struct
|
||||
*/
|
||||
struct point_description
|
||||
: PDU::pdu_stream_object
|
||||
{
|
||||
uint8_t system;
|
||||
uint16_t group;
|
||||
uint32_t point;
|
||||
std::string name;
|
||||
|
||||
virtual size_t streamSize() const override { return 39; }
|
||||
virtual void iStream(PDU::Stream) override;
|
||||
virtual void oStream(PDU::Stream) const override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The name_data struct
|
||||
*/
|
||||
struct name_data
|
||||
: PDU::pdu_data
|
||||
{
|
||||
union {
|
||||
u_int8_t flags;
|
||||
struct {
|
||||
uint8_t x_reserved : 7;
|
||||
bool response : 1;
|
||||
};
|
||||
};
|
||||
uint32_t reserved;
|
||||
std::vector<point_description> points;
|
||||
|
||||
virtual size_t streamSize() const override { return 5 + (39 * points.size()); }
|
||||
virtual void iStream(PDU::Stream) override;
|
||||
virtual void oStream(PDU::Stream) const override;
|
||||
};
|
||||
|
||||
} // namespace Name
|
||||
|
||||
|
||||
namespace System {
|
||||
|
||||
/**
|
||||
* @brief The Advertisement::System::pdu class
|
||||
*/
|
||||
class pdu
|
||||
: public OTP::PDU::pdu
|
||||
{
|
||||
public:
|
||||
virtual void iStream(PDU::Stream) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The system_data struct
|
||||
*/
|
||||
struct system_data
|
||||
: PDU::pdu_data
|
||||
{
|
||||
union {
|
||||
u_int8_t flags;
|
||||
struct {
|
||||
uint8_t x_reserved : 7;
|
||||
bool response : 1;
|
||||
};
|
||||
};
|
||||
uint32_t reserved;
|
||||
std::vector<uint8_t> systems;
|
||||
|
||||
virtual size_t streamSize() const override { return 5 + systems.size(); }
|
||||
virtual void iStream(PDU::Stream) override;
|
||||
virtual void oStream(PDU::Stream) const override;
|
||||
};
|
||||
|
||||
} // namespace System
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Advertisement::pdu class
|
||||
*/
|
||||
class pdu
|
||||
: public OTP::PDU::pdu
|
||||
{
|
||||
public:
|
||||
virtual void iStream(PDU::Stream) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The advertisement_data struct
|
||||
*/
|
||||
struct advertisement_data
|
||||
: PDU::pdu_data
|
||||
{
|
||||
uint32_t reserved;
|
||||
PDU::Pdu payload;
|
||||
|
||||
virtual size_t streamSize() const override { return 4 + payload->streamSize(); }
|
||||
virtual void iStream(PDU::Stream) override;
|
||||
virtual void oStream(PDU::Stream) const override;
|
||||
};
|
||||
|
||||
|
||||
} // OTP::Advertisement
|
Loading…
Reference in New Issue