1
0
Fork 0
OpenLCP/protocol/esta/sacn/universesender.h

101 lines
3.2 KiB
C++

/*
universesender.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.h"
#include "../dmx/universe.h"
#include <atomic>
#include <condition_variable>
#include <memory>
#include <thread>
namespace sACN {
class Universe;
class Source;
/**
* @brief The UniverseSender class
*/
class UniverseSender
{
public:
UniverseSender(Source*, Universe *);
~UniverseSender();
bool isSending() const;
void flush();
void kill();
private:
Source * mSource;
Universe * mUniverse;
/// \cite sACN 6.2.6 E1.31 Data Packet: Options - Stream_Terminated
/// Three packets containing this bit ... shall be sent by sources upon terminating
/// sourcing of a universe.
int terminated_resend;
/// > \cite sACN 6.6.1 Transmission Rate
/// >
/// > E1.31 sources shall not transmit packets for a given universe number
/// > at a rate which exceeds the maximum refresh rate specified in
/// > E1.11 \cite DMX
///
/// > \cite DMX Table 6 - Timing Diagram Values - output of transmitting UART
/// >
/// > Minimum Update Time for 513 slots : 22.7ms = 22700µs
const std::chrono::microseconds minimum_update_time;
/// > \cite sACN 6.6.2 Null START Code Transmission Requirements in E1.31
/// > Data Packets
/// >
/// > 1. Three packets containing the non-changing Property Values
/// > (corresponding to DMX512-A slot data) shall be sent before the
/// > initiation of transmission suppression.
unsigned int retransmission_count;
/// > 2. Thereafter, a single keep-alive packet shall be transmitted at
/// > intervals of between 800mS and 1000mS.
const std::chrono::milliseconds keep_alive_interval;
mutable std::shared_mutex mtx_control;
mutable std::mutex mtx_thread_;
std::atomic<bool> enabled_;
std::condition_variable_any request_;
std::thread worker_;
void loop_();
DMX::DimmerData last_data_;
ACN::PDU::Message<ACN::DMP::Pdu> dmp_;
void update_dmp_();
ACN::PDU::Message<DATA::Pdu> frame_;
void dataFrameSender(ACN::PDU::Message<ACN::DMP::Pdu>) const;
};
} // namespace sACN