344 lines
6.7 KiB
C++
344 lines
6.7 KiB
C++
/*
|
|
device.cpp
|
|
|
|
Copyright (c) 2022 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 "device.h"
|
|
|
|
namespace ARTNET {
|
|
|
|
/**
|
|
* @brief Device::Device
|
|
*
|
|
* \note A ArtPollReply packet is required to be broadcast to the Directed Broadcast address by
|
|
* all Art-Net devices on power up. Since information in that packet requres a fully configured
|
|
* device, it must be specifically sent later.
|
|
*/
|
|
Device::Device()
|
|
: diagnostic_reporting_threshold(DpCritial)
|
|
{
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::receive
|
|
* @param buffer
|
|
*/
|
|
void Device::receive(ACN::PDU::Stream buffer)
|
|
{
|
|
auto packet = std::make_shared<Packet>();
|
|
packet->iStream(buffer);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::receive
|
|
* @param packet
|
|
*/
|
|
void Device::receive(std::shared_ptr<Packet> packet)
|
|
{
|
|
switch (packet->opcode()) {
|
|
case OpPoll:
|
|
rxArtPoll(std::static_pointer_cast<ArtPoll>(packet));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::setSender
|
|
* @param sender
|
|
* @return
|
|
*/
|
|
std::shared_ptr<void> Device::setSender(const std::function<void(std::shared_ptr<bufferstream>,
|
|
ipAddress)> sender)
|
|
{
|
|
// wrap the callback with a shared pointer
|
|
auto sp = std::make_shared<std::function<void(std::shared_ptr<bufferstream>,
|
|
ipAddress)>>(std::move(sender));
|
|
// store sender function (as a weak pointer)
|
|
_sender = sp;
|
|
// return token that caller must keep throughout it's scope
|
|
return sp;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::send
|
|
* @param packet
|
|
* @param address
|
|
*/
|
|
void Device::send(const std::shared_ptr<Packet> packet, const ipAddress &address) const
|
|
{
|
|
auto buffer = std::vector<uint8_t>(packet->streamSize());
|
|
auto stream = std::make_shared<bufferstream>(buffer.data(), buffer.size());
|
|
packet->oStream(stream);
|
|
if (auto sp = _sender.lock()) // the owner is still holding the token
|
|
(*sp)(stream, address);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtPoll
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtPoll(std::shared_ptr<ArtPoll> packet)
|
|
{
|
|
auto data_opt = packet->data<poll_data>();
|
|
if (!data_opt.has_value())
|
|
return;
|
|
auto data = data_opt.value();
|
|
diagnostic_reporting_behavior = data->talk_to_me;
|
|
diagnostic_reporting_threshold = data->diagnostic_level;
|
|
|
|
/// All device types send an ArtPollReply in response to receiving an ArtPoll.
|
|
txArtPollReply();
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtPollReply
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtPollReply(std::shared_ptr<ArtPollReply> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtDiagData
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtDiagData(std::shared_ptr<ArtDiagData> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtCommand
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtCommand(std::shared_ptr<ArtCommand> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtDmx
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtDmx(std::shared_ptr<ArtDmx> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtNzs
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtNzs(std::shared_ptr<ArtNzs> packet)
|
|
{
|
|
if (packet->isVLC())
|
|
rxArtVlc(packet);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtVlc
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtVlc(std::shared_ptr<ArtNzs> packet)
|
|
{
|
|
auto data_opt = packet->data<nzs_data>();
|
|
if (!data_opt.has_value())
|
|
return;
|
|
auto data = std::make_shared<vlc_data>(data_opt.value().get());
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtSync
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtSync(std::shared_ptr<ArtSync> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtAddress
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtAddress(std::shared_ptr<ArtAddress> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtInput
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtInput(std::shared_ptr<ArtInput> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtTodRequest
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtTodRequest(std::shared_ptr<ArtTodRequest> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtTodData
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtTodData(std::shared_ptr<ArtTodData> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtTodControl
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtTodControl(std::shared_ptr<ArtTodControl> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtRdm
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtRdm(std::shared_ptr<ArtRdm> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtRdmSub
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtRdmSub(std::shared_ptr<ArtRdmSub> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtFirmwareMaster
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtFirmwareMaster(std::shared_ptr<ArtFirmwareMaster> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtFirmwareReply
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtFirmwareReply(std::shared_ptr<ArtFirmwareReply> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtIpProg
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtIpProg(std::shared_ptr<ArtIpProg> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtIpProgReply
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtIpProgReply(std::shared_ptr<ArtIpProgReply> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtTimeCode
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtTimeCode(std::shared_ptr<ArtTimeCode> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::rxArtTrigger
|
|
* @param packet
|
|
*/
|
|
void Device::rxArtTrigger(std::shared_ptr<ArtTrigger> packet)
|
|
{
|
|
(void)packet;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::txArtPollReply
|
|
*/
|
|
void Device::txArtPollReply()
|
|
{
|
|
auto packet = std::make_shared<ArtPollReply>();
|
|
/// \todo impliment txArtPollReply
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Device::txArtDiagData
|
|
*/
|
|
void Device::txArtDiagData()
|
|
{
|
|
auto packet = std::make_shared<ArtDiagData>();
|
|
/// \todo impliment txArtDiagData
|
|
}
|
|
|
|
} // namespace ARTNET
|