2022-12-08 19:09:39 -05:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
|
2022-12-09 09:26:42 -05:00
|
|
|
#include "data.h"
|
2022-12-08 21:22:20 -05:00
|
|
|
#include "dmp.h"
|
2022-12-09 09:26:42 -05:00
|
|
|
#include "../dmx/universe.h"
|
2022-12-08 19:09:39 -05:00
|
|
|
#include <condition_variable>
|
|
|
|
#include <memory>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
namespace sACN {
|
|
|
|
|
|
|
|
class Universe;
|
2022-12-08 21:22:20 -05:00
|
|
|
class Source;
|
2022-12-08 19:09:39 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The UniverseSender class
|
|
|
|
*/
|
|
|
|
class UniverseSender
|
|
|
|
{
|
|
|
|
public:
|
2022-12-08 21:22:20 -05:00
|
|
|
UniverseSender(Source*, Universe *);
|
2022-12-08 19:09:39 -05:00
|
|
|
~UniverseSender();
|
|
|
|
|
2022-12-09 21:27:27 -05:00
|
|
|
bool isSending() const;
|
2022-12-08 19:09:39 -05:00
|
|
|
|
|
|
|
void flush();
|
|
|
|
void kill();
|
|
|
|
|
|
|
|
private:
|
2022-12-08 21:22:20 -05:00
|
|
|
Source * mSource;
|
2022-12-08 19:09:39 -05:00
|
|
|
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
|
2022-12-09 11:46:18 -05:00
|
|
|
const std::chrono::microseconds minimum_update_time;
|
2022-12-08 19:09:39 -05:00
|
|
|
|
|
|
|
/// > \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.
|
2022-12-09 11:46:18 -05:00
|
|
|
const std::chrono::milliseconds keep_alive_interval;
|
2022-12-08 19:09:39 -05:00
|
|
|
|
2022-12-10 11:08:18 -05:00
|
|
|
volatile bool enabled_;
|
2022-12-09 11:18:27 -05:00
|
|
|
mutable std::shared_mutex mtx_control;
|
2022-12-09 10:29:01 -05:00
|
|
|
mutable std::mutex mtx_thread_;
|
2022-12-08 19:09:39 -05:00
|
|
|
std::condition_variable_any request_;
|
|
|
|
std::thread worker_;
|
|
|
|
void loop_();
|
2022-12-08 21:22:20 -05:00
|
|
|
|
2022-12-09 10:29:01 -05:00
|
|
|
DMX::DimmerData last_data_;
|
2022-12-08 21:22:20 -05:00
|
|
|
ACN::PDU::Message<ACN::DMP::Pdu> dmp_;
|
2022-12-09 10:29:01 -05:00
|
|
|
void update_dmp_();
|
2022-12-09 09:26:42 -05:00
|
|
|
|
|
|
|
ACN::PDU::Message<DATA::Pdu> frame_;
|
2022-12-08 21:22:20 -05:00
|
|
|
void dataFrameSender(ACN::PDU::Message<ACN::DMP::Pdu>) const;
|
2022-12-08 19:09:39 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sACN
|