1
0
Fork 0
OpenLCP/protocol/artistic/artnet/device.h

109 lines
4.0 KiB
C++

/*
device.h
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.
*/
#pragma once
#include "packet.h"
#include <functional>
#include <udp.h>
namespace ARTNET {
using ACN::SDT::UDP::ipAddress;
/**
* @brief The Device class is the base class for ARTNET::Controller
* and ARTNET::Node
*/
class Device
{
public:
explicit Device(Style);
const Style styleCode; //!< \cite ARTNET The Style code defines the equipment style of the device.
void receive(ACN::PDU::Stream, ipAddress&);
void receive(std::shared_ptr<Packet>);
std::shared_ptr<void> setSender(const std::function<void(std::shared_ptr<bufferstream>,
ipAddress)>);
std::string shortName() const;
void setShortName(const std::string &newShortName);
std::string longName() const;
void setLongName(const std::string &newLongName);
protected:
TalkToMe diagnostic_reporting_behavior; //!< behavior flags
Priority diagnostic_reporting_threshold; //!< lowest priority dignostic message to send
GeneralStatus device_status; //!< general status register
void send(const std::shared_ptr<Packet> packet, const ipAddress &) const;
void setReport(const NodeReport, const std::string &);
void rxArtPoll(std::shared_ptr<ArtPoll>);
virtual void rxArtPollReply(std::shared_ptr<ArtPollReply>);
virtual void rxArtDiagData(std::shared_ptr<ArtDiagData>);
virtual void rxArtCommand(std::shared_ptr<ArtCommand>);
virtual void rxArtDmx(std::shared_ptr<ArtDmx>);
virtual void rxArtNzs(std::shared_ptr<ArtNzs>);
virtual void rxArtVlc(std::shared_ptr<ArtNzs>);
virtual void rxArtSync(std::shared_ptr<ArtSync>);
virtual void rxArtAddress(std::shared_ptr<ArtAddress>);
virtual void rxArtInput(std::shared_ptr<ArtInput>);
virtual void rxArtTodRequest(std::shared_ptr<ArtTodRequest>);
virtual void rxArtTodData(std::shared_ptr<ArtTodData>);
virtual void rxArtTodControl(std::shared_ptr<ArtTodControl>);
virtual void rxArtRdm(std::shared_ptr<ArtRdm>);
virtual void rxArtRdmSub(std::shared_ptr<ArtRdmSub>);
virtual void rxArtFirmwareMaster(std::shared_ptr<ArtFirmwareMaster>);
virtual void rxArtFirmwareReply(std::shared_ptr<ArtFirmwareReply>);
virtual void rxArtIpProg(std::shared_ptr<ArtIpProg>);
virtual void rxArtIpProgReply(std::shared_ptr<ArtIpProgReply>);
virtual void rxArtTimeCode(std::shared_ptr<ArtTimeCode>);
virtual void rxArtTrigger(std::shared_ptr<ArtTrigger>);
virtual void txArtPollReply(std::shared_ptr<pollreply_data> = nullptr);
virtual void txArtDiagData();
// OSI layer 2
virtual std::array<uint8_t, 6> deviceMac() const;
// OSI layer 3
virtual ipAddress deviceIp() const;
virtual ipAddress broadcastIp() const;
virtual uint32_t deviceSubnetMask() const;
virtual bool deviceHasDHCP() const;
private:
std::weak_ptr<const std::function<void(std::shared_ptr<bufferstream>, ipAddress)>> _sender;
std::string _shortName;
std::string _longName;
NodeReport _report_code;
uint _poll_reply_count;
std::string _report_text;
};
} // namespace ARTNET