OpenLCP/sacn/universe.cpp
2021-05-27 10:59:22 -04:00

106 lines
3.5 KiB
C++

/*
universe.cpp
Copyright (c) 2020 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 "universe.h"
namespace SACN {
/**
Construct a Universe Source from an sACN frame PDU
*/
UniverseSource::UniverseSource(std::shared_ptr<DATA::Pdu> pdu) {
auto root_header = (RLP::rlp_header*)pdu->parent()->header();
cid_ = root_header->cid;
auto frame_header = (DATA::frame_header*)pdu->header();
description_ = std::string((char*)frame_header->source_name);
universe_ = frame_header->universe;
priority_ = frame_header->priority;
sync_address_ = frame_header->sync_address;
options_ = frame_header->options;
};
/**
Construct a new Universe.
*/
Universe::Universe()
: DMX::Universe()
{
synchronized_ = false;
}
/**
Set universe data from a DMP PDU from a UniverseSource.
*/
void Universe::set(std::shared_ptr<DMP::Pdu> dmp,
std::shared_ptr<UniverseSource> source) {
// 7.3 Address Type and Data Type
// Sources shall set the DMP Layer's Address Type and Data Type to 0xa1.
// Receivers shall discard the packet if the received value is not 0xa1.
if (!dmp->header())
return;
auto type = (ACN::DMP::address_type*)dmp->header();
if (!type->z_reserved) return; // needs to be true, but why?
if (type->relative) return;
if (type->type != ACN::DMP::ARRAY) return;
if (type->x_reserved != 0) return;
if (type->width != ACN::DMP::TWO) return;
// only act on the first property pair in the data
if (!dmp->data())
return;
auto data = (ACN::DMP::dmp_set_data*)dmp->data();
auto prop = data->properties.front();
auto pr = prop.first; // property range
auto pd = prop.second; // property data
// 7.4 First Property Address
// Sources shall set the DMP Layer's First Property Address to 0x0000.
// Receivers shall discard the packet if the received value is not 0x0000.
if (pr.address != 0)
return;
// 7.5 Address Increment
// Sources shall set the DMP Layer's Address Increment to 0x0001.
// Receivers shall discard the packet if the received value is not 0x0001.
if (pr.incriment != 1)
return;
// 7.6 Property Value Count
// The DMP Layer's Property Value Count is used to encode the number of
// DMX512-A [DMX] Slots (including the START Code slot).
if (pr.count < 1 || pr.count > 513)
return;
// 7.7 Property Values (DMX512-A Data)
/// The DMP Layer's Property values field is used to encode the
// DMX512-A [DMX] START Code and data.
DMX::Universe::set(pd);
source_ = source;
}
}; // SACN