146 lines
5.1 KiB
C++
146 lines
5.1 KiB
C++
/*
|
|
universe.h
|
|
|
|
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.
|
|
*/
|
|
#pragma once
|
|
|
|
#include "data.h"
|
|
#include "dmp/component.h"
|
|
#include "../dmx/universe.h"
|
|
#include "sacn.h"
|
|
#include "universesender.h"
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
namespace sACN {
|
|
|
|
/**
|
|
* @brief \cite sACN 3.2 Universe
|
|
*
|
|
* > A set of up to 512 data slots identified by universe number.
|
|
* > Note: In E1.31 there may be multiple sources for a universe. See also: Slot.
|
|
*/
|
|
class Universe
|
|
: public DMX::Universe
|
|
, public ACN::DMP::Component
|
|
, public std::enable_shared_from_this<Universe>
|
|
{
|
|
public:
|
|
explicit Universe(Source* = nullptr);
|
|
virtual ~Universe();
|
|
|
|
friend class UniverseSender;
|
|
|
|
virtual std::shared_ptr<DATA::data_header> metadata() const;
|
|
virtual void setMetadata(std::shared_ptr<DATA::data_header>);
|
|
|
|
virtual bool isSyncronized() const;
|
|
virtual void synchronize(uint8_t = 0);
|
|
virtual void resetSynchronization();
|
|
virtual void setSyncData(const std::vector<uint8_t> &);
|
|
|
|
virtual bool isEditable() const;
|
|
|
|
virtual uint16_t activeSlots() const;
|
|
|
|
// api for poly-source universes
|
|
virtual bool hasSources() const {return false;} //!< is not a poly-source universe @return
|
|
virtual const std::vector<DATA::data_header> sources() const;
|
|
virtual std::shared_ptr<Universe> sourceUniverse(const DATA::data_header&);
|
|
virtual std::shared_ptr<Universe> addNewSource(const DATA::data_header&);
|
|
virtual std::shared_ptr<void> onSourceListChange(std::function<void()>);
|
|
virtual void setHoldLastLook(const bool);
|
|
virtual bool getHoldLastLook() const;
|
|
/**
|
|
* @brief The MergeMode enum
|
|
*/
|
|
enum MergeMode {
|
|
MERGE_OTHER,
|
|
MERGE_HTP,
|
|
MERGE_LTP
|
|
};
|
|
virtual void setMergeMode(const MergeMode);
|
|
virtual MergeMode getMergeMode() const;
|
|
|
|
// DMX::Universe overrides
|
|
virtual void setValue (const uint16_t start, const uint16_t footprint,
|
|
const uint8_t* data) override;
|
|
virtual void setStatus(uint8_t) override;
|
|
|
|
/**
|
|
* @brief destination IP address
|
|
*
|
|
* Setting type to ACN::SDT::SDT_ADDR_NULL will send on the multicast group.
|
|
*/
|
|
ipAddress destination;
|
|
|
|
/**
|
|
* @brief Extend DMX::Universe::Status with the additional states of sACN.
|
|
*/
|
|
enum Status : uint8_t {
|
|
DMX_NULL = DMX::Universe::DMX_NULL, //!< uninitialized
|
|
DMX_ACTIVE = DMX::Universe::DMX_ACTIVE, //!< actively sending/receiving data
|
|
DMX_LOST = DMX::Universe::DMX_LOST, //!< no activity in E111_DATA_LOSS_TIMEOUT
|
|
sACN_TERMINATED = 11, //!< stream has been terminated or no activity in E131_NETWORK_DATA_LOSS_TIMEOUT
|
|
RX_TIMEOUT = DMX::Universe::RX_TIMEOUT //!< no activity in the constructed timeout period
|
|
};
|
|
|
|
protected:
|
|
// ACN::DMP::Component overrides
|
|
virtual void rxDmpGetProperty(ACN::PDU::Message<ACN::DMP::Pdu>) override;
|
|
virtual void rxDmpSetProperty(ACN::PDU::Message<ACN::DMP::Pdu>) override;
|
|
virtual void rxDmpSubscribe(ACN::PDU::Message<ACN::DMP::Pdu>) override;
|
|
|
|
private:
|
|
UniverseSender * sender_;
|
|
MergeMode mergeMode_;
|
|
std::shared_ptr<DATA::data_header> metadata_;
|
|
std::vector<uint8_t> * sync_data_;
|
|
|
|
/**
|
|
* @brief \cite sACN 3.7 Active Data Slots
|
|
*
|
|
* > When translating ANSI E1.11 DMX512-A \cite DMX to E1.31, the active data
|
|
* > slots are defined as ranging from data slot 1 to the maximum data slot in
|
|
* > the most recently received packet with the corresponding START Code.
|
|
* >
|
|
* > Devices originating E1.31 shall define their active data slots using
|
|
* > the DMP First Property Address and DMP Property Count fields shown in
|
|
* > Table 4-1.
|
|
*/
|
|
uint16_t active_data_slots_;
|
|
|
|
/**
|
|
* > \cite sACN 6.3.2 E1.31 Synchronization Packet: Sequence Number
|
|
* >
|
|
* > Sources shall maintain a sequence for each universe they transmit.
|
|
* > The sequence number for a universe shall be incremented by one for
|
|
* > every packet sent on that universe. There is no implied relationship
|
|
* > between the sequence number of an E1.31 Synchronization Packet and
|
|
* > the sequence number of an E1.31 Data Packet on that same universe.
|
|
*/
|
|
uint8_t sync_sequence_;
|
|
};
|
|
|
|
} // SACN namespace
|