213 lines
5.0 KiB
C++
213 lines
5.0 KiB
C++
/*
|
|
extended.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 "extended.h"
|
|
#include "../build/has_rtti.h"
|
|
|
|
namespace SACN {
|
|
namespace EXTENDED {
|
|
|
|
/**
|
|
* @brief frame_sync_header::streamSize
|
|
* @return
|
|
*/
|
|
size_t frame_sync_header::streamSize() const
|
|
{
|
|
return sizeof(sequence_number)
|
|
+ sizeof(sync_address)
|
|
+ sizeof(reserved);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief frame_sync_header::iStream
|
|
* @param stream
|
|
*/
|
|
void frame_sync_header::iStream(PDU::Stream stream)
|
|
{
|
|
*stream >> sequence_number;
|
|
*stream >> sync_address;
|
|
stream->read(reserved, sizeof(reserved));
|
|
if (stream->gcount() != sizeof(reserved))
|
|
stream->setstate(std::ios_base::failbit);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief frame_sync_header::oStream
|
|
* @return
|
|
*/
|
|
void frame_sync_header::oStream(__attribute__((unused)) PDU::Stream stream) const
|
|
{
|
|
/// TODO: write header to stream
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief frame_discovery_header::streamSize
|
|
* @return
|
|
*/
|
|
size_t frame_discovery_header::streamSize() const
|
|
{
|
|
return sizeof(source_name)
|
|
+ sizeof(reserved);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief frame_discovery_header::iStream
|
|
* @param stream
|
|
*/
|
|
void frame_discovery_header::iStream(PDU::Stream stream)
|
|
{
|
|
stream->read(source_name, sizeof(source_name));
|
|
if (stream->gcount() != sizeof(source_name))
|
|
stream->setstate(std::ios_base::failbit);
|
|
stream->read(reserved, sizeof(reserved));
|
|
if (stream->gcount() != sizeof(reserved))
|
|
stream->setstate(std::ios_base::failbit);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief frame_discovery_header::oStream
|
|
* @return
|
|
*/
|
|
void frame_discovery_header::oStream(__attribute__((unused)) PDU::Stream stream) const
|
|
{
|
|
/// TODO: write header to stream
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Pdu::Pdu
|
|
* @param stream
|
|
*/
|
|
Pdu::Pdu()
|
|
: PDU::Pdu(4) // vectors are 4 octets
|
|
{
|
|
}
|
|
|
|
void Pdu::iStream(PDU::Stream stream)
|
|
{
|
|
PDU::Pdu::iStream(stream);
|
|
if (stream->fail()) return;
|
|
if (!stream_->good()) return;
|
|
|
|
if (flags_.hasHeader)
|
|
switch(vector()) {
|
|
case VECTOR_E131_EXTENDED_SYNCHRONIZATION:
|
|
{
|
|
header_ = new frame_sync_header();
|
|
header_->iStream(stream_);
|
|
}
|
|
break;
|
|
case VECTOR_E131_EXTENDED_DISCOVERY:
|
|
{
|
|
header_ = new frame_discovery_header();
|
|
header_->iStream(stream_);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
namespace DISCOVERY {
|
|
|
|
/**
|
|
* @brief discovery_list_header::streamSize
|
|
* @return
|
|
*/
|
|
size_t discovery_list_header::streamSize() const
|
|
{
|
|
return sizeof(page)
|
|
+ sizeof(last_page);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief discovery_list_header::iStream
|
|
* @param stream
|
|
*/
|
|
void discovery_list_header::iStream(PDU::Stream stream)
|
|
{
|
|
*stream >> page;
|
|
*stream >> last_page;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief discovery_list_header::oStream
|
|
* @return
|
|
*/
|
|
void discovery_list_header::oStream(__attribute__((unused)) PDU::Stream stream) const
|
|
{
|
|
/// TODO: write header to stream
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Pdu::Pdu
|
|
* @param stream
|
|
*/
|
|
Pdu::Pdu()
|
|
: PDU::Pdu(4) // vectors are 4 octets
|
|
{
|
|
}
|
|
|
|
void Pdu::iStream(PDU::Stream stream)
|
|
{
|
|
PDU::Pdu::iStream(stream);
|
|
if (stream->fail()) return;
|
|
if (!stream_->good()) return;
|
|
|
|
if (flags_.hasHeader)
|
|
{
|
|
header_ = new discovery_list_header();
|
|
header_->iStream(stream_);
|
|
}
|
|
}
|
|
|
|
/**
|
|
Construct a Universe Source from an sACN discovery layer PDU
|
|
*/
|
|
DiscoveredUniverse::DiscoveredUniverse(const std::shared_ptr<EXTENDED::DISCOVERY::Pdu> pdu) {
|
|
#ifdef RTTI_ENABLED
|
|
auto root_header = dynamic_cast<RLP::rlp_header*>(pdu->parent()->parent()->header());
|
|
auto frame_header = dynamic_cast<EXTENDED::frame_discovery_header*>(pdu->parent()->header());
|
|
#else
|
|
auto root_header = static_cast<RLP::rlp_header*>(pdu->parent()->parent()->header());
|
|
auto frame_header = static_cast<EXTENDED::frame_discovery_header*>(pdu->parent()->header());
|
|
#endif
|
|
|
|
cid_ = root_header->cid;
|
|
description_ = std::string((char*)frame_header->source_name);
|
|
*pdu->stream() >> universe_;
|
|
}
|
|
|
|
} // DISCOVERY
|
|
} // EXTENDED
|
|
} // SACN
|