OpenLCP/protocol/artistic/artnet/device.cpp

571 lines
12 KiB
C++
Raw Normal View History

/*
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)
{
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:40:10 -04:00
* @brief Device::receive
* @param buffer
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:40:10 -04:00
void Device::receive(ACN::PDU::Stream buffer)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:40:10 -04:00
auto packet = std::make_shared<Packet>();
packet->iStream(buffer);
2023-05-20 14:15:12 -04:00
receive(packet);
2023-05-20 13:40:10 -04:00
}
/**
* @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;
2023-05-20 14:15:12 -04:00
case OpPollReply:
rxArtPollReply(std::static_pointer_cast<ArtPollReply>(packet));
break;
case OpDiagData:
rxArtDiagData(std::static_pointer_cast<ArtDiagData>(packet));
break;
case OpCommand:
rxArtCommand(std::static_pointer_cast<ArtCommand>(packet));
break;
case OpDmx:
rxArtDmx(std::static_pointer_cast<ArtDmx>(packet));
break;
case OpNzs:
rxArtNzs(std::static_pointer_cast<ArtNzs>(packet));
break;
case OpSync:
rxArtSync(std::static_pointer_cast<ArtSync>(packet));
break;
case OpAddress:
rxArtAddress(std::static_pointer_cast<ArtAddress>(packet));
break;
case OpInput:
rxArtInput(std::static_pointer_cast<ArtInput>(packet));
break;
case OpTodRequest:
rxArtTodRequest(std::static_pointer_cast<ArtTodRequest>(packet));
break;
case OpTodData:
rxArtTodData(std::static_pointer_cast<ArtTodData>(packet));
break;
case OpTodControl:
rxArtTodControl(std::static_pointer_cast<ArtTodControl>(packet));
break;
case OpRdm:
rxArtRdm(std::static_pointer_cast<ArtRdm>(packet));
break;
case OpRdmSub:
rxArtRdmSub(std::static_pointer_cast<ArtRdmSub>(packet));
break;
case OpVideoSetup:
rxArtVideoSetup(std::static_pointer_cast<ArtVideoSetup>(packet));
break;
case OpVideoPalette:
rxArtVideoPalette(std::static_pointer_cast<ArtVideoPalette>(packet));
break;
case OpVideoData:
rxArtVideoData(std::static_pointer_cast<ArtVideoData>(packet));
break;
case OpFirmwareMaster:
rxArtFirmwareMaster(std::static_pointer_cast<ArtFirmwareMaster>(packet));
break;
case OpFirmwareReply:
rxArtFirmwareReply(std::static_pointer_cast<ArtFirmwareReply>(packet));
break;
case OpFileTnMaster:
rxArtFileTnMaster(std::static_pointer_cast<ArtFileTnMaster>(packet));
break;
case OpFileFnMaster:
rxArtFileFnMaster(std::static_pointer_cast<ArtFileFnMaster>(packet));
break;
case OpFileFnReply:
rxArtFileFnReply(std::static_pointer_cast<ArtFileFnReply>(packet));
break;
case OpIpProg:
rxArtIpProg(std::static_pointer_cast<ArtIpProg>(packet));
break;
case OpIpProgReply:
rxArtIpProgReply(std::static_pointer_cast<ArtIpProgReply>(packet));
break;
case OpMedia:
rxArtMedia(std::static_pointer_cast<ArtMedia>(packet));
break;
case OpMediaPatch:
rxArtMediaPatch(std::static_pointer_cast<ArtMediaPatch>(packet));
break;
case OpMediaControl:
rxArtMediaControl(std::static_pointer_cast<ArtMediaControl>(packet));
break;
case OpMediaContrlReply:
rxArtMediaControlReply(std::static_pointer_cast<ArtMediaControlReply>(packet));
break;
case OpTimeCode:
rxArtTimeCode(std::static_pointer_cast<ArtTimeCode>(packet));
break;
case OpTimeSync:
rxArtTimeSync(std::static_pointer_cast<ArtTimeSync>(packet));
break;
case OpTrigger:
rxArtTrigger(std::static_pointer_cast<ArtTrigger>(packet));
break;
case OpDirectory:
rxArtDirectory(std::static_pointer_cast<ArtDirectory>(packet));
break;
case OpDirectoryReply:
rxArtDirectoryReply(std::static_pointer_cast<ArtDirectoryReply>(packet));
break;
2023-05-20 13:40:10 -04:00
default:
break;
}
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:39:03 -04:00
* @brief Device::setSender
* @param sender
* @return
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:39:03 -04:00
std::shared_ptr<void> Device::setSender(const std::function<void(std::shared_ptr<bufferstream>,
ipAddress)> sender)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:39:03 -04:00
// 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;
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:39:03 -04:00
* @brief Device::send
* @param packet
* @param address
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:39:03 -04:00
void Device::send(const std::shared_ptr<Packet> packet, const ipAddress &address) const
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:39:03 -04:00
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);
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @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
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtPollReply(std::shared_ptr<ArtPollReply> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtDiagData
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtDiagData(std::shared_ptr<ArtDiagData> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
* @brief Device::rxArtCommand
2023-05-20 13:34:46 -04:00
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtCommand(std::shared_ptr<ArtCommand> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtDmx
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtDmx(std::shared_ptr<ArtDmx> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtNzs
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtNzs(std::shared_ptr<ArtNzs> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
if (packet->isVLC())
rxArtVlc(packet);
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtVlc
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtVlc(std::shared_ptr<ArtNzs> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
auto data_opt = packet->data<nzs_data>();
if (!data_opt.has_value())
return;
auto data = std::make_shared<vlc_data>(data_opt.value().get());
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtSync
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtSync(std::shared_ptr<ArtSync> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtAddress
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtAddress(std::shared_ptr<ArtAddress> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtInput
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtInput(std::shared_ptr<ArtInput> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtTodRequest
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtTodRequest(std::shared_ptr<ArtTodRequest> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtTodData
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtTodData(std::shared_ptr<ArtTodData> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtTodControl
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtTodControl(std::shared_ptr<ArtTodControl> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
* @brief Device::rxArtRdm
2023-05-20 13:34:46 -04:00
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtRdm(std::shared_ptr<ArtRdm> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtRdmSub
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtRdmSub(std::shared_ptr<ArtRdmSub> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
* @brief Device::rxArtVideoSetup
* @param packet
*/
void Device::rxArtVideoSetup(std::shared_ptr<ArtVideoSetup> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtVideoPalette
* @param packet
*/
void Device::rxArtVideoPalette(std::shared_ptr<ArtVideoPalette> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtVideoData
* @param packet
*/
void Device::rxArtVideoData(std::shared_ptr<ArtVideoData> packet)
{
(void)packet;
}
2022-11-15 11:42:27 -05:00
/**
2023-05-20 13:34:46 -04:00
* @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::rxArtFileTnMaster
* @param packet
*/
void Device::rxArtFileTnMaster(std::shared_ptr<ArtFileTnMaster> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtFileFnMaster
* @param packet
*/
void Device::rxArtFileFnMaster(std::shared_ptr<ArtFileFnMaster> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtFileFnReply
* @param packet
*/
void Device::rxArtFileFnReply(std::shared_ptr<ArtFileFnReply> packet)
{
(void)packet;
}
2023-05-20 13:34:46 -04:00
/**
* @brief Device::rxArtIpProg
* @param packet
*/
void Device::rxArtIpProg(std::shared_ptr<ArtIpProg> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtIpProgReply
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtIpProgReply(std::shared_ptr<ArtIpProgReply> packet)
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
(void)packet;
2022-11-15 11:42:27 -05:00
}
/**
* @brief Device::rxArtMedia
* @param packet
*/
void Device::rxArtMedia(std::shared_ptr<ArtMedia> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtMediaPatch
* @param packet
*/
void Device::rxArtMediaPatch(std::shared_ptr<ArtMediaPatch> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtMediaControl
* @param packet
*/
void Device::rxArtMediaControl(std::shared_ptr<ArtMediaControl> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtMediaControlReply
* @param packet
*/
void Device::rxArtMediaControlReply(std::shared_ptr<ArtMediaControlReply> packet)
{
(void)packet;
}
2022-11-15 11:42:27 -05:00
/**
2023-05-20 13:34:46 -04:00
* @brief Device::rxArtTimeCode
* @param packet
*/
void Device::rxArtTimeCode(std::shared_ptr<ArtTimeCode> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtTimeSync
* @param packet
*/
void Device::rxArtTimeSync(std::shared_ptr<ArtTimeSync> packet)
{
(void)packet;
}
2023-05-20 13:34:46 -04:00
/**
* @brief Device::rxArtTrigger
* @param packet
2022-11-15 11:42:27 -05:00
*/
2023-05-20 13:34:46 -04:00
void Device::rxArtTrigger(std::shared_ptr<ArtTrigger> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtDirectory
* @param packet
*/
void Device::rxArtDirectory(std::shared_ptr<ArtDirectory> packet)
{
(void)packet;
}
/**
* @brief Device::rxArtDirectoryReply
* @param packet
*/
void Device::rxArtDirectoryReply(std::shared_ptr<ArtDirectoryReply> packet)
{
(void)packet;
}
2023-05-20 13:34:46 -04:00
/**
* @brief Device::txArtPollReply
*/
void Device::txArtPollReply()
{
auto packet = std::make_shared<ArtPollReply>();
/// \todo impliment txArtPollReply
}
/**
* @brief Device::txArtDiagData
*/
void Device::txArtDiagData()
2022-11-15 11:42:27 -05:00
{
2023-05-20 13:34:46 -04:00
auto packet = std::make_shared<ArtDiagData>();
/// \todo impliment txArtDiagData
}
} // namespace ARTNET