From 176022d4902d8db183b136d21d92b1ceb4b6f2fb Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Wed, 5 Aug 2026 23:10:56 +0300 Subject: [PATCH] ... --- include/adclib/adclib_netmsg.h | 101 +++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 include/adclib/adclib_netmsg.h diff --git a/include/adclib/adclib_netmsg.h b/include/adclib/adclib_netmsg.h new file mode 100644 index 0000000..1583ef0 --- /dev/null +++ b/include/adclib/adclib_netmsg.h @@ -0,0 +1,101 @@ +#pragma once + +#include + +namespace adc +{ + +/* */ + +static constexpr std::string_view ADCLIB_NETMSG_KEYWORD_PARAM_DELIM{" "}; +static constexpr std::string_view ADCLIB_NETMSG_PARAM_PARAM_DELIM{" "}; + +/* network message valid keywords */ +// +static constexpr std::string_view ADCLIB_NETMSG_KEYWORD_ACK{"ACK"}; + +// error message +static constexpr std::string_view ADCLIB_NETMSG_KEYWORD_ERR{"ERR"}; + +// set device attribute value +static constexpr std::string_view ADCLIB_NETMSG_KEYWORD_SET{"SET"}; + +// get device attribute value +static constexpr std::string_view ADCLIB_NETMSG_KEYWORD_GET{"GET"}; + +// execute device command +static constexpr std::string_view ADCLIB_NETMSG_KEYWORD_CMD{"CMD"}; + + +static constexpr std::array ADCLIB_NETMSG_VALID_KEYWORDS{ADCLIB_NETMSG_KEYWORD_ACK, ADCLIB_NETMSG_KEYWORD_ERR, + ADCLIB_NETMSG_KEYWORD_SET, ADCLIB_NETMSG_KEYWORD_GET, + ADCLIB_NETMSG_KEYWORD_CMD}; + + +template > +class AdcNetworkMessage final : protected snplib::snplib_keyvalue_expr_t +{ + typedef snplib::snplib_keyvalue_expr_t base_t; + +public: + using typename base_t::error_t; + + using base_t::isValid; + using base_t::key; + + AdcNetworkMessage() = default; + + bool isACK() const + { + return std::ranges::equal(this->_key, ADCLIB_NETMSG_KEYWORD_ACK); + } + + bool isCMD() const + { + return std::ranges::equal(this->_key, ADCLIB_NETMSG_KEYWORD_CMD); + } + + bool isSET() const + { + return std::ranges::equal(this->_key, ADCLIB_NETMSG_KEYWORD_SET); + } + + bool isGET() const + { + return std::ranges::equal(this->_key, ADCLIB_NETMSG_KEYWORD_GET); + } + + + error_t createACK() + { + return this->setKey(ADCLIB_NETMSG_KEYWORD_ACK); + } + + + error_t createERR(error_t err) + { + return this->setKey(ADCLIB_NETMSG_KEYWORD_ERR, err.value()); + } + + template + error_t createSET(ATTR_NAME_T&& attr_name, ValueT&& value) + { + return this->setKeyValue(ADCLIB_NETMSG_KEYWORD_SET, std::forward(attr_name), + std::forward(value)); + } + + template + error_t createGET(ATTR_NAME_T&& attr_name) + { + return this->setKeyValue(ADCLIB_NETMSG_KEYWORD_GET, std::forward(attr_name)); + } + + template + error_t createCMD(CMD_NAME_T&& cmd_name) + { + return this->setKeyValue(ADCLIB_NETMSG_KEYWORD_CMD, std::forward(cmd_name)); + } +}; + + +} // namespace adc \ No newline at end of file