From b6300cf80ba873ba4d94a527a422dab7bfdf01de Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Mon, 22 May 2023 10:16:20 -0400 Subject: [PATCH] handle ArtIpProg packets --- protocol/artistic/artnet/node.cpp | 87 +++++++++++++++++++++++++++++++ protocol/artistic/artnet/node.h | 14 +++-- 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/protocol/artistic/artnet/node.cpp b/protocol/artistic/artnet/node.cpp index aceda24..8d72a59 100644 --- a/protocol/artistic/artnet/node.cpp +++ b/protocol/artistic/artnet/node.cpp @@ -34,6 +34,34 @@ Node::Node() } +/** + * @brief Node::rxArtIpProg + * @param packet + */ +void Node::rxArtIpProg(std::shared_ptr packet) +{ + auto data_opt = packet->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 @@ -56,4 +84,63 @@ void Node::rxArtAddress(std::shared_ptr packet) txArtPollReply(); } + +/** + * @brief Node::txArtIpProgReply + * @param dest + * @param reply + */ +void Node::txArtIpProgReply(const uint32_t dest, std::shared_ptr reply) +{ + if (!reply) + reply = std::make_shared(); + + reply->ip_address = deviceIp().address.ipv4.value; + reply->subnet_mask = deviceSubnetMask(); + reply->status.dhcp_enabled = deviceHasDHCP(); + + auto packet = std::make_shared(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 diff --git a/protocol/artistic/artnet/node.h b/protocol/artistic/artnet/node.h index 8050e2a..76b27db 100644 --- a/protocol/artistic/artnet/node.h +++ b/protocol/artistic/artnet/node.h @@ -36,13 +36,21 @@ class Node : public Device { public: - explicit Node(); + explicit Node(); protected: - virtual void rxArtAddress(std::shared_ptr) override; + virtual void rxArtIpProg(std::shared_ptr) override; + virtual void rxArtAddress(std::shared_ptr) override; + + virtual void txArtIpProgReply(const uint32_t dest, std::shared_ptr = nullptr); + + // OSI layer 3 + virtual void setDhcpEnable(const bool); + virtual void setDeviceIP(const uint32_t); + virtual void setDeviceSubnetMask(const uint32_t); private: - std::vector _ports; + std::vector _ports; }; } // namespace ARTNET