147 lines
3.9 KiB
C++
147 lines
3.9 KiB
C++
/*
|
|
node.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 "node.h"
|
|
|
|
namespace ARTNET {
|
|
|
|
Node::Node()
|
|
: Device(StNode)
|
|
{
|
|
setShortName("OpenLCP Node");
|
|
setLongName("Generic OpenLCP Art-Net Node");
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Node::rxArtIpProg
|
|
* @param packet
|
|
*/
|
|
void Node::rxArtIpProg(std::shared_ptr<ArtIpProg> packet)
|
|
{
|
|
auto data_opt = packet->data<ipprog_data>();
|
|
if (!data_opt.has_value())
|
|
return;
|
|
auto data = data_opt.value();
|
|
|
|
if (data->command.enable_programming)
|
|
{
|
|
if (data->command.enable_dhcp)
|
|
setDhcpEnable(true);
|
|
else
|
|
{
|
|
setDhcpEnable(false);
|
|
if (data->command.program_ip)
|
|
setDeviceIP(data->ip_address);
|
|
if (data->command.program_netmask)
|
|
setDeviceSubnetMask(data->subnet_mask);
|
|
}
|
|
}
|
|
txArtIpProgReply(packet->originAddress);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Node::rxArtAddress
|
|
* @param packet
|
|
*/
|
|
void Node::rxArtAddress(std::shared_ptr<ArtAddress> packet)
|
|
{
|
|
auto data_opt = packet->data<address_data>();
|
|
if (!data_opt.has_value())
|
|
return;
|
|
auto data = data_opt.value();
|
|
|
|
if (data->short_name.length()) // The Node will ignore this value if the string is null.
|
|
setShortName(data->short_name);
|
|
if (data->long_name.length()) // The Node will ignore this value if the string is null.
|
|
setLongName(data->long_name);
|
|
|
|
/// \todo process additional fields in this packet
|
|
|
|
/// \cite ARTNET Reply by broadcasting ArtPollReply.
|
|
txArtPollReply();
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Node::txArtIpProgReply
|
|
* @param dest
|
|
* @param reply
|
|
*/
|
|
void Node::txArtIpProgReply(const uint32_t dest, std::shared_ptr<ipprogreply_data> reply)
|
|
{
|
|
if (!reply)
|
|
reply = std::make_shared<ipprogreply_data>();
|
|
|
|
reply->ip_address = deviceIp().address.ipv4.value;
|
|
reply->subnet_mask = deviceSubnetMask();
|
|
reply->status.dhcp_enabled = deviceHasDHCP();
|
|
|
|
auto packet = std::make_shared<ArtIpProgReply>(reply);
|
|
auto controller = ipAddress();
|
|
controller.address.ipv4.value = dest;
|
|
send(packet, controller);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Node::setDhcpEnable
|
|
* @param state
|
|
*
|
|
* The default implimentation is to ignore the request.
|
|
* \note Platform aware nodes may reimpliment to accept the DHCP state.
|
|
*/
|
|
void Node::setDhcpEnable(const bool state)
|
|
{
|
|
(void)state;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Node::setDeviceIP
|
|
* @param value
|
|
*
|
|
* The default implimentation is to ignore the request.
|
|
* \note Platform aware nodes may reimpliment to accept the IP address change.
|
|
*/
|
|
void Node::setDeviceIP(const uint32_t value)
|
|
{
|
|
(void)value;
|
|
}
|
|
|
|
/**
|
|
* @brief Node::setDeviceSubnetMask
|
|
* @param value
|
|
*
|
|
* The default implimentation is to ignore the request.
|
|
* \note Platform aware nodes may reimpliment to accept the Subnet Mask change.
|
|
*/
|
|
void Node::setDeviceSubnetMask(const uint32_t value)
|
|
{
|
|
(void)value;
|
|
}
|
|
|
|
} // namespace ARTNET
|