diff --git a/include/device/device.hpp b/include/device/device.hpp index 5711db7..ebc1d83 100644 --- a/include/device/device.hpp +++ b/include/device/device.hpp @@ -3,17 +3,15 @@ #include #include +#include #include #include -#include - #include +#include "nwk/pan.hpp" #include "zcl/common/cluster.hpp" #include "zcl/common/commands.hpp" -#include "nwk/pan.hpp" - namespace device { @@ -66,7 +64,8 @@ class MacAddress if (size > address.size()) { - throw std::runtime_error("MacAddress constructor received too many bytes"); + throw std::runtime_error( + "MacAddress constructor received too many bytes"); } for (auto arg : {args...}) @@ -75,7 +74,6 @@ class MacAddress } std::cout << "MacAddress created with " << size << " bytes" << std::endl; - } [[nodiscard]] std::string get_string() const @@ -98,34 +96,29 @@ class MacAddress return address == rhs.address; } - bool operator!=(const MacAddress& rhs) const - { - return !(rhs == *this); - } + bool operator!=(const MacAddress& rhs) const { return !(rhs == *this); } }; class Device { - MacAddress mac_address; + MacAddress mac_address; endpoint_list_t endpoints; // Attributes depending on the network std::weak_ptr pan{}; - short_address_t short_address{}; - bool reacheable{true}; + short_address_t short_address{}; + bool reacheable{true}; public: Device() = delete; Device(const MacAddress& mac_address, endpoint_list_t endpoints) - : mac_address(mac_address), - endpoints(std::move(endpoints)) + : mac_address(mac_address), endpoints(std::move(endpoints)) { - std::cout << "Device created with MAC: " << mac_address.get_string() - << " and " << endpoints.size() << " endpoints" - << std::endl; + std::cout << "Device created with MAC: " << mac_address.get_string() + << " and " << endpoints.size() << " endpoints" << std::endl; } - [[nodiscard]] MacAddress get_mac_address() const { return mac_address; } + [[nodiscard]] MacAddress get_mac_address() const { return mac_address; } [[nodiscard]] short_address_t get_short_address() const { @@ -144,7 +137,8 @@ class Device Endpoint& get_endpoint(const endpoint_id_t ep_id) { auto ept = std::find_if(endpoints.begin(), endpoints.end(), - [ep_id](const Endpoint& ept) { return ept.get_endpoint_id() == ep_id; }); + [ep_id](const Endpoint& ept) + { return ept.get_endpoint_id() == ep_id; }); if (ept == endpoints.end()) { @@ -154,19 +148,6 @@ class Device return *ept; } - template - zcl::ZclStatus execute_cluster_command(const endpoint_id_t ep_id, - const zcl::cluster_id_t cluster_id, - const zcl::command_id_t command_id, - bool is_common, Args... args) - { - Endpoint ept = get_endpoint(ep_id); - zcl::Cluster cluster = ept.get_cluster(cluster_id); - - return cluster.execute_cluster_command(command_id, is_common, - args...); - } - bool join_pan(const std::shared_ptr& pan) { if (!pan->is_permit_joining()) @@ -179,10 +160,7 @@ class Device return true; } - void leave_pan() - { - pan.reset(); - } + void leave_pan() { pan.reset(); } }; class OnOffDevice : public Device diff --git a/include/device_pool/pool.hpp b/include/device_pool/pool.hpp index b3dc3d2..c971825 100644 --- a/include/device_pool/pool.hpp +++ b/include/device_pool/pool.hpp @@ -2,9 +2,8 @@ #define DEVICE_POOL_POOL_HPP #include -#include - #include +#include namespace device { @@ -14,7 +13,7 @@ class Pool device_list devices = {}; // Each pool has its own PAN - std::shared_ptr pan; + std::shared_ptr pan; public: Pool() = delete; @@ -22,7 +21,7 @@ class Pool explicit Pool(nwk::pan_id_t pan_id) : pan(std::make_shared(pan_id)) { } - + Pool(device_list devices, nwk::pan_id_t pan_id) : devices(std::move(devices)), pan(std::make_shared(pan_id)) { diff --git a/include/events.hpp b/include/events.hpp index 2f57741..63865de 100644 --- a/include/events.hpp +++ b/include/events.hpp @@ -3,54 +3,64 @@ #include -namespace event { +namespace event +{ // Base event class -class Event { -public: - virtual ~Event() = default; +class Event +{ + public: + virtual ~Event() = default; }; // Device announcement event -class DeviceAnnouncementEvent : public Event { +class DeviceAnnouncementEvent : public Event +{ Device& device; -public: + public: explicit DeviceAnnouncementEvent(Device& device) : device(device) {} [[nodiscard]] Device& get_device() const { return device; } }; // Reporting event -class ReportingEvent : public Event { +class ReportingEvent : public Event +{ }; // Event handler interface -class IEventHandler { -public: - virtual void handleEvent(const Event& event) = 0; - virtual ~IEventHandler() = default; +class IEventHandler +{ + public: + virtual void handleEvent(const Event& event) = 0; + virtual ~IEventHandler() = default; }; // Zigbee device mocker -class ZigbeeDeviceMocker { -private: - std::vector eventHandlers; // Event handler interface pointers - -public: - // Register an event handler - void registerEventHandler(IEventHandler* handler) { - eventHandlers.push_back(handler); - } +class ZigbeeDeviceMocker +{ + private: + std::vector + eventHandlers; // Event handler interface pointers + + public: + // Register an event handler + void registerEventHandler(IEventHandler* handler) + { + eventHandlers.push_back(handler); + } - // Emit an event and notify all registered event handlers - void emitEvent(const Event& event) { - for (auto handler : eventHandlers) { - handler->handleEvent(event); - } + // Emit an event and notify all registered event handlers + void emitEvent(const Event& event) + { + for (auto handler : eventHandlers) + { + handler->handleEvent(event); } + } }; } // namespace event -#endif // EVENTS_HPP +#endif // EVENTS_HPP diff --git a/include/nwk/nwk_mgt_commands.hpp b/include/nwk/nwk_mgt_commands.hpp index 7dece32..f8865d5 100644 --- a/include/nwk/nwk_mgt_commands.hpp +++ b/include/nwk/nwk_mgt_commands.hpp @@ -13,40 +13,31 @@ namespace nwk { // Request NWK address command -const zcl::CommandDescriptor requestNwkAddressCmdDescriptor{ +const zcl::CommandDescriptor requestNwkAddressCommandDescriptor{ /*cmd_id=*/0, /*is_common=*/true, /*is_mandatory=*/true, /*description=*/"Request NWK address"}; - -zcl::ZclStatus requestNwkAddressExecuter( +zcl::ZclStatus requestNwkAddressCommand( device::Pool& pool, const device::MacAddress& input_mac_address, device::short_address_t& output_nwk_address); -const zcl::Command requestNwkAddressCommand{/*exec=*/requestNwkAddressExecuter}; - // Request mac address command -const zcl::CommandDescriptor requestMacAddressCmdDescriptor{ +const zcl::CommandDescriptor requestMacAddressCommandDescriptor{ /*cmd_id=*/1, /*is_common=*/true, /*is_mandatory=*/true, /*description=*/"Request MAC address"}; - -zcl::ZclStatus requestMacAddressExecuter( +zcl::ZclStatus requestMacAddressCommand( device::Pool& pool, const device::short_address_t& input_nwk_address, device::MacAddress& output_mac_address); -const zcl::Command requestMacAddressCommand{/*exec=*/requestMacAddressExecuter}; - // Leave command -const zcl::CommandDescriptor leaveCmdDescriptor{/*cmd_id=*/0x34, - /*is_common=*/true, - /*is_mandatory=*/true, - /*description=*/"leave"}; - -zcl::ZclStatus leaveExecuter(device::Device& device); - -const zcl::Command leaveCommand{/*exec=*/leaveExecuter}; +const zcl::CommandDescriptor leaveCommandDescriptor{/*cmd_id=*/0x34, + /*is_common=*/true, + /*is_mandatory=*/true, + /*description=*/"leave"}; +zcl::ZclStatus leaveCommand(device::Device& device); } // namespace nwk diff --git a/include/nwk/pan.hpp b/include/nwk/pan.hpp index a94d53d..2904e09 100644 --- a/include/nwk/pan.hpp +++ b/include/nwk/pan.hpp @@ -11,17 +11,20 @@ using pan_id_t = uint16_t; class Pan { pan_id_t pan_id{}; - bool permit_joining{false}; + bool permit_joining{false}; public: explicit Pan(pan_id_t pan_id) : pan_id(pan_id) {} [[nodiscard]] pan_id_t get_pan_id() const { return pan_id; } - [[nodiscard]] bool is_permit_joining() const { return permit_joining; } + [[nodiscard]] bool is_permit_joining() const { return permit_joining; } - void set_permit_joining(bool permit_joining) { this->permit_joining = permit_joining; } + void set_permit_joining(bool permit_joining) + { + this->permit_joining = permit_joining; + } }; } // namespace nwk -#endif // NWK_PAN_HPP +#endif // NWK_PAN_HPP diff --git a/include/zcl/clusters/global_commands.hpp b/include/zcl/clusters/global_commands.hpp index 69508fb..7b21086 100644 --- a/include/zcl/clusters/global_commands.hpp +++ b/include/zcl/clusters/global_commands.hpp @@ -21,10 +21,6 @@ const CommandDescriptor read_attribute_command_descriptor{ /*is_common*/ true, /*is_mandatory*/ true, /*description*/ "Read attribute"}; -ZclStatus readAttributeCommandExecuter(Cluster& cluster, - const attr_id_t& attribute_id, - attr_value_t& value); -const Command readAttributeCommand{/*exec=*/readAttributeCommandExecuter}; // Write attribute command const CommandDescriptor write_attribute_command_descriptor{ @@ -32,10 +28,6 @@ const CommandDescriptor write_attribute_command_descriptor{ /*is_common*/ true, /*is_mandatory*/ true, /*description*/ "Write attribute"}; -ZclStatus writeAttributeCommandExecuter(Cluster& cluster, - const attr_id_t& attribute_id, - const attr_value_t& value); -const Command writeAttributeCommand{/*exec=*/writeAttributeCommandExecuter}; // Configure reporting command const CommandDescriptor configure_reporting_command_descriptor{ @@ -43,11 +35,6 @@ const CommandDescriptor configure_reporting_command_descriptor{ /*is_common*/ true, /*is_mandatory*/ true, /*description*/ "Configure reporting"}; -ZclStatus configureReportingCommandExecuter( - Cluster& cluster, const attr_id_t& attribute_id, - const ReportingConfiguration& reporting_configuration); -const Command configureReportingCommand{ - /*exec=*/configureReportingCommandExecuter}; // Discover attributes command const CommandDescriptor discover_attributes_command_descriptor{ @@ -55,11 +42,6 @@ const CommandDescriptor discover_attributes_command_descriptor{ /*is_common*/ true, /*is_mandatory*/ true, /*description*/ "Discover attributes"}; -ZclStatus discoverAttributesCommandExecuter( - Cluster& cluster, - std::vector& attribute_descriptors); -const Command discoverAttributesCommand{ - /*exec=*/discoverAttributesCommandExecuter}; // FIXME This command requires a special handling // since it is send by the device @@ -68,9 +50,6 @@ const CommandDescriptor report_attributes_command_descriptor{ /*is_common*/ true, /*is_mandatory*/ true, /*description*/ "Report attributes"}; -ZclStatus reportAttributesCommandExecuter(Cluster& cluster, - const Attribute& attribute); -const Command reportAttributesCommand{/*exec=*/reportAttributesCommandExecuter}; } // namespace zcl diff --git a/include/zcl/clusters/on_off_cluster.hpp b/include/zcl/clusters/on_off_cluster.hpp index 12b8bec..2cfaac7 100644 --- a/include/zcl/clusters/on_off_cluster.hpp +++ b/include/zcl/clusters/on_off_cluster.hpp @@ -39,28 +39,17 @@ const attribute_descriptor_t offWaitTimeAttributeDescriptor = { ////////////////////////////// // setOff command -const CommandDescriptor setOffCmdDescriptor{/*cmd_id=*/0, - /*is_common=*/false, - /*is_mandatory=*/true, - /*description=*/"setOff"}; -ZclStatus setOffExecuter(Cluster& cluster); -const Command setOffCommand{/*exec=*/setOffExecuter}; - // setOn command const CommandDescriptor setOnCmdDescriptor{/*cmd_id=*/1, /*is_common=*/false, /*is_mandatory=*/true, /*description=*/"setOn"}; -ZclStatus setOnExecuter(Cluster& cluster); -const Command setOnCommand{/*exec=*/setOnExecuter}; // toggle command const CommandDescriptor toggleCmdDescriptor{/*cmd_id=*/2, /*is_common=*/false, /*is_mandatory=*/true, /*description=*/"toggle"}; -ZclStatus toggleExecuter(Cluster& cluster); -const Command toggleCommand{/*exec=*/toggleExecuter}; // offWithEffect command const CommandDescriptor offWithEffectCmdDescriptor{ @@ -68,9 +57,6 @@ const CommandDescriptor offWithEffectCmdDescriptor{ /*is_common=*/false, /*is_mandatory=*/false, /*description=*/"offWithEffect"}; -ZclStatus offWithEffectExecuter(Cluster& cluster, uint8_t effectIdentifier, - uint16_t effectVariant); -const Command offWithEffectCommand{/*exec=*/offWithEffectExecuter}; // onWithRecallGlobalScene command const CommandDescriptor onWithRecallGlobalSceneCmdDescriptor{ @@ -78,9 +64,6 @@ const CommandDescriptor onWithRecallGlobalSceneCmdDescriptor{ /*is_common=*/false, /*is_mandatory=*/false, /*description=*/"onWithRecallGlobalScene"}; -ZclStatus onWithRecallGlobalSceneExecuter(Cluster& cluster); -const Command onWithRecallGlobalSceneCommand{ - /*exec=*/onWithRecallGlobalSceneExecuter}; // onWithTimedOff command const CommandDescriptor onWithTimedOffCmdDescriptor{ @@ -88,9 +71,6 @@ const CommandDescriptor onWithTimedOffCmdDescriptor{ /*is_common=*/false, /*is_mandatory=*/false, /*description=*/"onWithTimedOff"}; -ZclStatus onWithTimedOffExecuter(Cluster& cluster, uint8_t onOffControl, - uint16_t onTime, uint16_t offWaitTime); -const Command onWithTimedOffCommand{/*exec=*/onWithTimedOffExecuter}; ////////////////////////////// @@ -102,30 +82,66 @@ const cluster_descriptor_t cluster_descriptor{/*id=*/6, // OnOffCluster class class OnOffCluster : public Cluster { - - - commands_map_t on_off_commands_map{}; - // FIXME add commands as methods - // fill command map using std::bind - // Mapping of command IDs to command functions - /* - std::unordered_map> commandMap{ - {1, std::bind(&LightingCluster::setOff, this)}, - {2, std::bind(&LightingCluster::setOn, this)} - }; - */ - public: OnOffCluster() : Cluster( /*descriptor=*/cluster_descriptor, /*attribute_descriptors=*/ {onOffAttributeDescriptor, onTimeAttributeDescriptor, - offWaitTimeAttributeDescriptor}, - /*commands_map=*/ on_off_commands_map) + offWaitTimeAttributeDescriptor}) { - register_command(on_off_commands_map, setOffCmdDescriptor, &setOffExecuter); } + + /** + * @brief Trigger OFF command + * + * @return ZclStatus + */ + ZclStatus setOffCommand(); + + /** + * @brief Trigger ON command + * + * @return ZclStatus + */ + ZclStatus setOnCommand(); + + /** + * @brief Trigger TOGGLE command + * + * @return ZclStatus + */ + ZclStatus toggleCommand(); + + /** + * @brief Trigger OFF_WITH_EFFECT command + * + * @param effectIdentifier + * @param effectVariant + * @return ZclStatus + */ + + ZclStatus offWithEffectCommand(uint8_t effectIdentifier, + uint16_t effectVariant); + + /** + * @brief Trigger ON_WITH_RECALL_GLOBAL_SCENE command + * + * @return ZclStatus + */ + + ZclStatus onWithRecallGlobalSceneCommand(); + + /** + * @brief Trigger ON_WITH_TIMED_OFF command + * + * @param onOffControl + * @param onTime + * @param offWaitTime + * @return ZclStatus + */ + ZclStatus onWithTimedOffCommand(uint8_t onOffControl, uint16_t onTime, + uint16_t offWaitTime); }; } // namespace zcl::on_off_cluster diff --git a/include/zcl/common/cluster.hpp b/include/zcl/common/cluster.hpp index 5768440..8e71641 100644 --- a/include/zcl/common/cluster.hpp +++ b/include/zcl/common/cluster.hpp @@ -27,19 +27,15 @@ struct cluster_descriptor_t class Cluster { - cluster_descriptor_t descriptor; - attributes_list_t attributes; - const commands_map_t* commands_map; - static const commands_map_t common_commands_map; + cluster_descriptor_t descriptor; + attributes_list_t attributes; public: // Constructor Cluster(cluster_descriptor_t descriptor, - const std::vector& attribute_descriptors, - const commands_map_t& commands_map) + const std::vector& attribute_descriptors) : descriptor(std::move(descriptor)), - attributes(create_attributes_list(attribute_descriptors)), - commands_map(&commands_map) + attributes(create_attributes_list(attribute_descriptors)) { } @@ -49,12 +45,6 @@ class Cluster return attributes; } - // Method to get the list of commands - [[nodiscard]] const commands_map_t* get_commands() const - { - return commands_map; - } - // Method to get the cluster descriptor [[nodiscard]] const cluster_descriptor_t& get_descriptor() const { @@ -101,50 +91,28 @@ class Cluster attr.set_value(value); } - // Generic command executer - template - ZclStatus execute_cluster_command(command_id_t cmd_id, const bool is_common, - Args... args) - { - const commands_map_t* target_commands_map = nullptr; + // ZCL commands methods - if (is_common) - { - target_commands_map = &common_commands_map; - } - else - { - target_commands_map = commands_map; - } + // readAttributeCommand + ZclStatus readAttributeCommand(const attr_id_t& attribute_id, + attr_value_t& value) const; - for (const auto& [descriptor, gen_cmd_ptr] : *target_commands_map) - { - if (descriptor.check_match(cmd_id, is_common)) - { - if (gen_cmd_ptr == nullptr) - { - throw std::runtime_error("Command null pointer"); - } - // Downcast from CommandBase to a cluster command - using target_type = const Command* const; - - std::cout << "Calling command " << descriptor.get_description() - << " of cluster " << this->descriptor.description << " " - << __PRETTY_FUNCTION__ << '\n'; - - auto cmd_ptr = dynamic_cast(gen_cmd_ptr); - if (cmd_ptr == nullptr) - { - throw std::runtime_error( - "Command downcast failed," - "make sure the template arguments are correct"); - } - - return (*cmd_ptr)(*this, args...); - } - } - throw std::runtime_error("Command not found"); - } + // writeAttributeCommand + ZclStatus writeAttributeCommand(const attr_id_t& attribute_id, + const attr_value_t& value); + + // configureReportingCommand + ZclStatus configureReportingCommand( + const attr_id_t& attribute_id, + const ReportingConfiguration& reporting_configuration); + + // discoverAttributesCommand + ZclStatus discoverAttributesCommand( + std::vector& attribute_descriptors) const; + + // sendReportingCommand + [[nodiscard]] ZclStatus sendReportingCommand(const attr_id_t& attribute_id, + const attr_value_t& value) const; }; } // namespace zcl diff --git a/include/zcl/common/commands.hpp b/include/zcl/common/commands.hpp index 22d51e6..f293ff9 100644 --- a/include/zcl/common/commands.hpp +++ b/include/zcl/common/commands.hpp @@ -48,66 +48,6 @@ class CommandDescriptor return description; } }; - -class CommandBase -{ - public: - CommandBase() = default; - virtual ~CommandBase() = default; - - // cppcoreguidelines-special-member-functions implies these definitions: - CommandBase(const CommandBase&) = delete; - CommandBase& operator=(const CommandBase&) = delete; - CommandBase(CommandBase&&) = delete; - CommandBase& operator=(CommandBase&&) = delete; -}; - -template -class Command : public CommandBase -{ - using exec_t = ZclStatus (*)(Args...); - exec_t exec_; - - public: - explicit Command(exec_t exec) : exec_(exec) {} - - ZclStatus operator()(Args... args) const - { - if (exec_ == nullptr) - { - std::cout << "Command operator() exec_ == nullptr" << '\n'; - return ZclStatus::null_pointer; - } - - std::cout << "Command operator()" << exec_ << '\n'; - return exec_(args...); - } -}; - -using command_generic_ptr_t = const CommandBase* const; - -using commands_map_t = std::map; - -/** - * @brief Emplace command into commands map - * - * @tparam Args - * @param commands_map - * @param cmd_descriptor - * @param cmd - */ -template -constexpr void register_command(commands_map_t& commands_map, - const CommandDescriptor& cmd_descriptor, - ZclStatus (*cmd)(Args...)) -{ - commands_map.emplace(cmd_descriptor,new Command(cmd)); - - std::cout << "register_command called for " << cmd_descriptor.get_description() << '\n'; - // log commands_map size - std::cout << "commands_map size: " << commands_map.size() << '\n'; -} - } // namespace zcl #endif // ZCL_COMMON_COMMANDS_HPP diff --git a/src/clusters/global_commands.cpp b/src/clusters/global_commands.cpp index b8e742f..b1a0973 100644 --- a/src/clusters/global_commands.cpp +++ b/src/clusters/global_commands.cpp @@ -3,23 +3,10 @@ namespace zcl { -const commands_map_t Cluster::common_commands_map = { - {read_attribute_command_descriptor, - static_cast(&readAttributeCommand)}, - {write_attribute_command_descriptor, - static_cast(&writeAttributeCommand)}, - {configure_reporting_command_descriptor, - static_cast(&configureReportingCommand)}, - {discover_attributes_command_descriptor, - static_cast(&discoverAttributesCommand)}, - {report_attributes_command_descriptor, - static_cast(&reportAttributesCommand)}}; - -ZclStatus readAttributeCommandExecuter(Cluster& cluster, - const attr_id_t& attribute_id, - attr_value_t& value) +ZclStatus Cluster::readAttributeCommand(const attr_id_t& attribute_id, + attr_value_t& value) const { - const Attribute& attribute = cluster.get_attribute_const(attribute_id); + const Attribute& attribute = this->get_attribute_const(attribute_id); std::cout << "Read attribute command" << '\n'; @@ -28,24 +15,23 @@ ZclStatus readAttributeCommandExecuter(Cluster& cluster, return ZclStatus::success; } -ZclStatus writeAttributeCommandExecuter(Cluster& cluster, - const attr_id_t& attribute_id, - const attr_value_t& value) +ZclStatus Cluster::writeAttributeCommand(const attr_id_t& attribute_id, + const attr_value_t& value) { std::cout << "Write attribute command" << '\n'; // Update the attribute value - Attribute& attribute = cluster.get_attribute_not_const(attribute_id); + Attribute& attribute = this->get_attribute_not_const(attribute_id); attribute.write(value); return ZclStatus::success; } -ZclStatus configureReportingCommandExecuter( - Cluster& cluster, const attr_id_t& attribute_id, +ZclStatus Cluster::configureReportingCommand( + const attr_id_t& attribute_id, const ReportingConfiguration& reporting_configuration) { - Attribute attribute = cluster.get_attribute_not_const(attribute_id); + Attribute attribute = this->get_attribute_not_const(attribute_id); std::cout << "Configure reporting command" << '\n'; @@ -55,15 +41,14 @@ ZclStatus configureReportingCommandExecuter( return ZclStatus::success; } -ZclStatus reportAttributesCommandExecuter(Cluster& cluster, - const Attribute& attribute) +ZclStatus reportAttributesCommand(Cluster& cluster, const Attribute& attribute) { std::cout << "Report attributes command" << '\n'; return ZclStatus::success; } -ZclStatus discoverAttributesCommandExecuter( +ZclStatus discoverAttributesCommand( Cluster& cluster, std::vector& attribute_descriptors) { diff --git a/src/clusters/on_off.cpp b/src/clusters/on_off.cpp index d07b9b9..f9a0285 100644 --- a/src/clusters/on_off.cpp +++ b/src/clusters/on_off.cpp @@ -3,48 +3,50 @@ namespace zcl::on_off_cluster { -ZclStatus setOffExecuter(Cluster& cluster) +ZclStatus OnOffCluster::setOffCommand() { - std::cout << "setOffExecuter" << '\n'; - cluster.set_attribute_value(onOffAttributeDescriptor.id, true); + std::cout << "setOffCommand" << '\n'; + this->set_attribute_value(onOffAttributeDescriptor.id, true); return ZclStatus::success; } -ZclStatus setOnExecuter(Cluster& cluster) +ZclStatus OnOffCluster::setOnCommand() { - cluster.set_attribute_value(onOffAttributeDescriptor.id, true); + this->set_attribute_value(onOffAttributeDescriptor.id, true); return ZclStatus::success; } -ZclStatus toggleExecuter(Cluster& cluster) +ZclStatus OnOffCluster::toggleCommand() { - std::cout << "toggleExecuter" << '\n'; + std::cout << "toggleCommand" << '\n'; return ZclStatus::not_implemented; } -ZclStatus onWithRecallGlobalSceneExecuter(Cluster& cluster) +ZclStatus OnOffCluster::offWithEffectCommand(uint8_t effectIdentifier, + uint16_t effectVariant) { - std::cout << "onWithRecallGlobalSceneExecuter" << '\n'; + std::cout << "offWithEffectCommand" << '\n'; return ZclStatus::not_implemented; } -ZclStatus offWithEffectExecuter(Cluster& cluster, uint8_t effectIdentifier, - uint16_t effectVariant) +ZclStatus OnOffCluster::onWithRecallGlobalSceneCommand() { - std::cout << "offWithEffectExecuter" << '\n'; + std::cout << "onWithRecallGlobalSceneCommand" << '\n'; return ZclStatus::not_implemented; } -ZclStatus onWithTimedOffExecuter(Cluster& cluster, uint8_t onOffControl, - uint16_t onTime, uint16_t offWaitTime) +ZclStatus OnOffCluster::onWithTimedOffCommand(uint8_t onOffControl, + uint16_t onTime, + uint16_t offWaitTime) { - std::cout << "onWithTimedOffExecuter" << '\n'; + std::cout << "onWithTimedOffCommand" << '\n'; return ZclStatus::not_implemented; } + } // namespace zcl::on_off_cluster diff --git a/src/main.cpp b/src/main.cpp index 7bdaeaa..ce4d39d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,10 +5,9 @@ #include #include - const device::MacAddress mac_address{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; -const nwk::pan_id_t pan_id = 0x1234; +const nwk::pan_id_t pan_id = 0x1234; // Do not optimize int main(int argc, char* argv[]) @@ -17,18 +16,16 @@ int main(int argc, char* argv[]) std::cout << "Running..." << '\n'; - device.execute_cluster_command( - 1, zcl::on_off_cluster::cluster_descriptor.id, - zcl::on_off_cluster::setOffCmdDescriptor.get_id(), false); - const zcl::attr_id_t attr_id = zcl::on_off_cluster::onOffAttributeDescriptor.id; + const zcl::cluster_id_t cluster_id = + zcl::on_off_cluster::cluster_descriptor.id; + zcl::attr_value_t read_attr; - device.execute_cluster_command( - 1, zcl::on_off_cluster::cluster_descriptor.id, - zcl::read_attribute_command_descriptor.get_id(), true, attr_id, - read_attr); + device.get_endpoint(1) + .get_cluster(cluster_id) + .readAttributeCommand(attr_id, read_attr); // Pool @@ -40,7 +37,7 @@ int main(int argc, char* argv[]) device.join_pan(pool.get_pan()); - nwk::requestNwkAddressExecuter(pool, mac_address, nwk_address); + nwk::requestNwkAddressCommand(pool, mac_address, nwk_address); std::cout << " --- Exiting --- " << '\n'; diff --git a/src/nwk_mgt_commands.cpp b/src/nwk_mgt_commands.cpp index 45b6fab..ed1d5bf 100644 --- a/src/nwk_mgt_commands.cpp +++ b/src/nwk_mgt_commands.cpp @@ -3,7 +3,7 @@ namespace nwk { -zcl::ZclStatus requestNwkAddressExecuter( +zcl::ZclStatus requestNwkAddressCommand( device::Pool& pool, const device::MacAddress& input_mac_address, device::short_address_t& output_nwk_address) { @@ -14,7 +14,7 @@ zcl::ZclStatus requestNwkAddressExecuter( return zcl::ZclStatus::success; } -zcl::ZclStatus requestMacAddressExecuter( +zcl::ZclStatus requestMacAddressCommand( device::Pool& pool, const device::short_address_t& input_nwk_address, device::MacAddress& output_mac_address) { @@ -25,7 +25,7 @@ zcl::ZclStatus requestMacAddressExecuter( return zcl::ZclStatus::success; } -zcl::ZclStatus leaveExecuter(device::Device& device) +zcl::ZclStatus leaveCommand(device::Device& device) { device.leave_pan();