OpenLCP/sacn/extended.cpp

213 lines
4.9 KiB
C++
Raw Normal View History

/*
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"
2021-08-09 15:01:41 -04:00
#include "config.h"
namespace SACN {
namespace EXTENDED {
2021-07-26 13:34:11 -04:00
/**
2021-07-29 11:20:03 -04:00
* @brief frame_sync_header::streamSize
2021-07-26 13:34:11 -04:00
* @return
*/
2021-08-14 09:26:42 -04:00
size_t sync_header::streamSize() const
2021-07-29 11:20:03 -04:00
{
return sizeof(sequence_number)
+ sizeof(sync_address)
+ sizeof(reserved);
}
/**
* @brief frame_sync_header::iStream
* @param stream
*/
2021-08-14 09:26:42 -04:00
void sync_header::iStream(PDU::Stream stream)
2021-07-26 13:34:11 -04:00
{
2021-07-29 11:20:03 -04:00
*stream >> sequence_number;
*stream >> sync_address;
stream->read(reserved, sizeof(reserved));
if (stream->gcount() != sizeof(reserved))
2021-06-19 10:18:09 -04:00
stream->setstate(std::ios_base::failbit);
2021-07-29 11:20:03 -04:00
}
/**
2021-08-14 09:26:42 -04:00
* @brief sync_header::oStream
2021-07-29 11:20:03 -04:00
* @return
*/
2021-08-14 09:26:42 -04:00
void sync_header::oStream(__attribute__((unused)) PDU::Stream stream) const
2021-07-29 11:20:03 -04:00
{
/// TODO: write header to stream
}
2021-07-26 13:34:11 -04:00
/**
2021-08-14 09:26:42 -04:00
* @brief discovery_header::streamSize
2021-07-26 13:34:11 -04:00
* @return
*/
2021-08-14 09:26:42 -04:00
size_t discovery_header::streamSize() const
2021-07-29 11:20:03 -04:00
{
return sizeof(source_name)
+ sizeof(reserved);
}
/**
2021-08-14 09:26:42 -04:00
* @brief discovery_header::iStream
2021-07-29 11:20:03 -04:00
* @param stream
*/
2021-08-14 09:26:42 -04:00
void discovery_header::iStream(PDU::Stream stream)
2021-07-26 13:34:11 -04:00
{
2021-07-29 11:20:03 -04:00
stream->read(source_name, sizeof(source_name));
if (stream->gcount() != sizeof(source_name))
2021-06-19 10:18:09 -04:00
stream->setstate(std::ios_base::failbit);
2021-07-29 11:20:03 -04:00
stream->read(reserved, sizeof(reserved));
if (stream->gcount() != sizeof(reserved))
2021-06-19 10:18:09 -04:00
stream->setstate(std::ios_base::failbit);
}
2021-07-29 11:20:03 -04:00
/**
2021-08-14 09:26:42 -04:00
* @brief discovery_header::oStream
2021-07-29 11:20:03 -04:00
* @return
*/
2021-08-14 09:26:42 -04:00
void discovery_header::oStream(__attribute__((unused)) PDU::Stream stream) const
2021-07-29 11:20:03 -04:00
{
/// TODO: write header to stream
}
/**
* @brief Pdu::Pdu
* @param stream
*/
2021-07-29 19:26:49 -04:00
Pdu::Pdu()
: PDU::Pdu(4) // vectors are 4 octets
{
}
2021-07-29 19:26:49 -04:00
void Pdu::iStream(PDU::Stream stream)
{
PDU::Pdu::iStream(stream);
if (stream->fail()) return;
if (!stream_->good()) return;
if (flags_.hasHeader)
2021-08-14 09:26:42 -04:00
switch(vector_) {
2021-07-29 19:26:49 -04:00
case VECTOR_E131_EXTENDED_SYNCHRONIZATION:
{
2021-08-14 09:26:42 -04:00
header_ = new sync_header();
2021-07-29 19:26:49 -04:00
header_->iStream(stream_);
}
break;
case VECTOR_E131_EXTENDED_DISCOVERY:
{
2021-08-14 09:26:42 -04:00
header_ = new discovery_header();
2021-07-29 19:26:49 -04:00
header_->iStream(stream_);
}
break;
default:
break;
}
2021-07-26 13:34:11 -04:00
}
2021-07-29 19:26:49 -04:00
namespace DISCOVERY {
2021-07-26 13:34:11 -04:00
/**
2021-07-29 11:20:03 -04:00
* @brief discovery_list_header::streamSize
* @return
*/
2021-07-29 23:40:46 -04:00
size_t discovery_list_header::streamSize() const
2021-07-29 11:20:03 -04:00
{
return sizeof(page)
+ sizeof(last_page);
}
/**
* @brief discovery_list_header::iStream
2021-07-26 13:34:11 -04:00
* @param stream
2021-07-29 11:20:03 -04:00
*/
void discovery_list_header::iStream(PDU::Stream stream)
{
*stream >> page;
*stream >> last_page;
}
/**
* @brief discovery_list_header::oStream
2021-07-26 13:34:11 -04:00
* @return
*/
2021-08-02 10:10:55 -04:00
void discovery_list_header::oStream(__attribute__((unused)) PDU::Stream stream) const
2021-07-26 13:34:11 -04:00
{
2021-07-29 11:20:03 -04:00
/// TODO: write header to stream
}
2021-07-26 13:34:11 -04:00
/**
* @brief Pdu::Pdu
* @param stream
*/
2021-07-29 19:26:49 -04:00
Pdu::Pdu()
: PDU::Pdu(4) // vectors are 4 octets
{
}
2021-07-29 19:26:49 -04:00
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) {
2021-07-29 19:26:49 -04:00
#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
2021-07-29 19:26:49 -04:00
cid_ = root_header->cid;
description_ = std::string((char*)frame_header->source_name);
2021-07-29 19:26:49 -04:00
*pdu->stream() >> universe_;
}
} // DISCOVERY
} // EXTENDED
} // SACN