diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 62563ab5a..ac6b726a9 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -4738,5 +4738,67 @@ attribute_t *create_opt_out_state(cluster_t *cluster, uint8_t value) } /* attribute */ } /* device_energy_management */ +namespace application_basic { +namespace attribute { +attribute_t *create_vendor_name(cluster_t *cluster, char *value, uint16_t length) +{ + if (length > k_max_vendor_name_length) { + ESP_LOGE(TAG, "Could not create attribute, string length out of bound"); + return NULL; + } + return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::VendorName::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_char_str(value, length), k_max_vendor_name_length); +} + +attribute_t *create_vendor_id(cluster_t *cluster, uint16_t value) +{ + return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::VendorID::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); +} + +attribute_t *create_application_name(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::ApplicationName::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_char_str(value, length)); +} + +attribute_t *create_product_id(cluster_t *cluster, uint16_t value) +{ + return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::ProductID::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); +} + +attribute_t *create_application(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::Application::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_array(value, length, count)); +} + +attribute_t *create_status(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::Status::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_enum8(value)); +} + +attribute_t *create_application_version(cluster_t *cluster, char *value, uint16_t length) +{ + if (length > k_max_application_version_length) { + ESP_LOGE(TAG, "Could not create attribute, string length out of bound"); + return NULL; + } + return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::ApplicationVersion::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_char_str(value, length), + k_max_application_version_length); +} + +attribute_t *create_allowed_vendor_list(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::AllowedVendorList::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_array(value, length, count)); +} + +} /* attribute */ +} /* application_basic */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index 74d090400..90b40033f 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -1090,5 +1090,21 @@ attribute_t *create_opt_out_state(cluster_t *cluster, uint8_t value); } /* attribute */ } /* device_energy_management */ +namespace application_basic { +constexpr uint8_t k_max_vendor_name_length = 32; +constexpr uint8_t k_max_application_version_length = 32; + +namespace attribute { +attribute_t *create_vendor_name(cluster_t *cluster, char *value, uint16_t length); +attribute_t *create_vendor_id(cluster_t *cluster, uint16_t value); +attribute_t *create_application_name(cluster_t *cluster, char *value, uint16_t length); +attribute_t *create_product_id(cluster_t *cluster, uint16_t value); +attribute_t *create_application(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count); +attribute_t *create_status(cluster_t *cluster, uint16_t value); +attribute_t *create_application_version(cluster_t *cluster, char *value, uint16_t length); +attribute_t *create_allowed_vendor_list(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count); +} /* attribute */ +} /* application_basic */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index bcfa021fa..e9e9c4232 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -871,6 +871,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } if (flags & CLUSTER_FLAG_SERVER) { + if (config -> delegate != nullptr) { + static const auto delegate_init_cb = TimeSynchronizationDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } static const auto plugin_server_init_cb = CALL_ONCE(MatterTimeSynchronizationPluginServerInitCallback); set_plugin_server_init_callback(cluster, plugin_server_init_cb); add_function_list(cluster, function_list, function_flags); @@ -2530,6 +2534,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } if (flags & CLUSTER_FLAG_SERVER) { + if (config && config -> delegate != nullptr) { + static const auto delegate_init_cb = DoorLockDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } static const auto plugin_server_init_cb = CALL_ONCE(MatterDoorLockPluginServerInitCallback); set_plugin_server_init_callback(cluster, plugin_server_init_cb); add_function_list(cluster, function_list, function_flags); @@ -2854,6 +2862,10 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_ } if (flags & CLUSTER_FLAG_SERVER) { + if (config && config -> delegate != nullptr) { + static const auto delegate_init_cb = BooleanStateConfigurationDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } static const auto plugin_server_init_cb = CALL_ONCE(MatterBooleanStateConfigurationPluginServerInitCallback); set_plugin_server_init_callback(cluster, plugin_server_init_cb); add_function_list(cluster, function_list, function_flags); @@ -4122,6 +4134,54 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } } /* device_energy_management_mode */ +namespace application_basic { +const function_generic_t *function_list = NULL; +const int function_flags = CLUSTER_FLAG_NONE; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features) +{ + cluster_t *cluster = cluster::create(endpoint, ApplicationBasic::Id, flags); + if (!cluster) { + ESP_LOGE(TAG, "Could not create cluster"); + return NULL; + } + if (flags & CLUSTER_FLAG_SERVER) { + if (config -> delegate != nullptr) { + static const auto delegate_init_cb = ApplicationBasicDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } + static const auto plugin_server_init_cb = CALL_ONCE(MatterApplicationBasicPluginServerInitCallback); + set_plugin_server_init_callback(cluster, plugin_server_init_cb); + add_function_list(cluster, function_list, function_flags); + } + if (flags & CLUSTER_FLAG_CLIENT) { + create_default_binding_cluster(endpoint); + } + + if (flags & CLUSTER_FLAG_SERVER) { + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); +#if CHIP_CONFIG_ENABLE_EVENTLIST_ATTRIBUTE + global::attribute::create_event_list(cluster, NULL, 0, 0); +#endif + + /* Attributes should managed by application */ + attribute::create_application_name(cluster, NULL, 0); + attribute::create_application(cluster, NULL, 0 , 0); + attribute::create_status(cluster, 0); + attribute::create_application_version(cluster, NULL, 0); + attribute::create_allowed_vendor_list(cluster, NULL, 0 , 0); + /** Attributes not managed internally **/ + if (config) { + global::attribute::create_cluster_revision(cluster, config->cluster_revision); + } else { + ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); + } + } + return cluster; +} +} /* application_basic */ + // namespace binary_input_basic { // // ToDo // } /* binary_input_basic */ diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index c48d09d34..8cdeb176d 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -217,7 +217,8 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); namespace time_synchronization { typedef struct config { uint16_t cluster_revision; - config() : cluster_revision(2) {} + void *delegate; + config() : cluster_revision(2), delegate(nullptr) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); @@ -613,7 +614,8 @@ typedef struct config { bool actuator_enabled; uint8_t operating_mode; uint16_t supported_operating_modes; - config() : cluster_revision(7), lock_state(0), lock_type(0), actuator_enabled(0), operating_mode(0), supported_operating_modes(0xFFF6) {} + void *delegate; + config() : cluster_revision(7), lock_state(0), lock_type(0), actuator_enabled(0), operating_mode(0), supported_operating_modes(0xFFF6), delegate(nullptr) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); @@ -699,7 +701,8 @@ typedef struct config { feature::audible::config_t audible; feature::alarm_suppress::config_t alarm_suppress; feature::sensitivity_level::config_t sensitivity_level; - config() : cluster_revision(1) {} + void *delegate; + config() : cluster_revision(1), delegate(nullptr) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features); @@ -980,5 +983,15 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* device_energy_management_mode */ +namespace application_basic { +typedef struct config { + uint16_t cluster_revision; + void *delegate; + config() : cluster_revision(1), delegate(nullptr) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* application_basic */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_delegate_callbacks.cpp b/components/esp_matter/esp_matter_delegate_callbacks.cpp index e24903ab8..bc20ffc47 100644 --- a/components/esp_matter/esp_matter_delegate_callbacks.cpp +++ b/components/esp_matter/esp_matter_delegate_callbacks.cpp @@ -25,6 +25,10 @@ #include #include #include +#include +#include +#include +#include using namespace chip::app::Clusters; namespace esp_matter { @@ -224,6 +228,46 @@ void DeviceEnergyManagementDelegateInitCB(void *delegate, uint16_t endpoint_id) deviceEnergyManagementInstance->Init(); } +void DoorLockDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + if(delegate == nullptr) + { + return; + } + DoorLock::Delegate *door_lock_delegate = static_cast(delegate); + DoorLock::SetDefaultDelegate(endpoint_id, door_lock_delegate); +} + +void BooleanStateConfigurationDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + if(delegate == nullptr) + { + return; + } + BooleanStateConfiguration::Delegate *boolean_state_configuration_delegate = static_cast(delegate); + BooleanStateConfiguration::SetDefaultDelegate(endpoint_id, boolean_state_configuration_delegate); +} + +void TimeSynchronizationDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + if(delegate == nullptr) + { + return; + } + TimeSynchronization::Delegate *time_synchronization_delegate = static_cast(delegate); + TimeSynchronization::SetDefaultDelegate(time_synchronization_delegate); +} + +void ApplicationBasicDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + if(delegate == nullptr) + { + return; + } + ApplicationBasic::Delegate *application_basic_delegate = static_cast(delegate); + ApplicationBasic::SetDefaultDelegate(endpoint_id, application_basic_delegate); +} + } // namespace delegate_cb } // namespace cluster diff --git a/components/esp_matter/esp_matter_delegate_callbacks.h b/components/esp_matter/esp_matter_delegate_callbacks.h index 0eb702cfd..0e8ac156a 100644 --- a/components/esp_matter/esp_matter_delegate_callbacks.h +++ b/components/esp_matter/esp_matter_delegate_callbacks.h @@ -34,6 +34,10 @@ void LaundryDryerControlsDelegateInitCB(void *delegate, uint16_t endpoint_id); void ValveConfigurationAndControlDelegateInitCB(void *delegate, uint16_t endpoint_id); void DeviceEnergyManagementDelegateInitCB(void *delegate, uint16_t endpoint_id); void DeviceEnergyManagementModeDelegateInitCB(void *delegate, uint16_t endpoint_id); +void DoorLockDelegateInitCB(void *delegate, uint16_t endpoint_id); +void BooleanStateConfigurationDelegateInitCB(void *delegate, uint16_t endpoint_id); +void TimeSynchronizationDelegateInitCB(void *delegate, uint16_t endpoint_id); +void ApplicationBasicDelegateInitCB(void *delegate, uint16_t endpoint_id); } // namespace delegate_cb } // namespace cluster diff --git a/docs/en/app_guide.rst b/docs/en/app_guide.rst index c61cdd189..cd64ba44c 100644 --- a/docs/en/app_guide.rst +++ b/docs/en/app_guide.rst @@ -84,7 +84,7 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven. .. csv-table:: Delegate and its impl :header: "Delegate Class", "Reference Implementation" - `Microwave Oven Control`_, None + `Microwave Oven Control`_, `Microwave Oven Control Delegate`_ 9.1.5 Fan Control Cluster ------------------------- @@ -117,7 +117,7 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven. .. csv-table:: Delegate and its impl :header: "Delegate Class", "Reference Implementation" - `Valve Configuration And Control`_, None + `Valve Configuration And Control`_, `Valve Configuration And Control Delegate`_ 9.1.9 Device Energy Management Cluster -------------------------------------- @@ -127,6 +127,38 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven. `Device Energy Management`_, `Device Energy Management Delegate`_ +9.1.10 Door Lock Cluster +------------------------ + +.. csv-table:: Delegate and its impl + :header: "Delegate Class", "Reference Implementation" + + `Door Lock`_, None + +9.1.11 Boolean State Configuration Cluster +------------------------------------------ + +.. csv-table:: Delegate and its impl + :header: "Delegate Class", "Reference Implementation" + + `Boolean State Configuration`_, None + +9.1.12 Time Synchronization Cluster +----------------------------------- + +.. csv-table:: Delegate and its impl + :header: "Delegate Class", "Reference Implementation" + + `Time Synchronization`_, `Time Synchronization Delegate`_ + +9.1.13 Application Basic Cluster +-------------------------------- + +.. csv-table:: Delegate and its impl + :header: "Delegate Class", "Reference Implementation" + + `Application Basic`_, None + .. note:: Make sure that after implementing delegate class, you set the delegate class pointer at the time of creating cluster. @@ -150,6 +182,7 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven. .. _`Operational State`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/operational-state-server/operational-state-server.h .. _`Operational State Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/include/operational-state-delegate-impl.h .. _`Microwave Oven Control`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h +.. _`Microwave Oven Control Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h .. _`Fan Control`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/fan-control-server/fan-control-delegate.h .. _`Fan Control Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp .. _`Resource Monitoring`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/resource-monitoring-server/resource-monitoring-server.h @@ -157,5 +190,11 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven. .. _`Laundry Dryer Controls`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/laundry-dryer-controls-server/laundry-dryer-controls-server.h .. _`Laundry Dryer Controls Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/all-clusters-app/all-clusters-common/include/laundry-dryer-controls-delegate-impl.h .. _`Valve Configuration And Control`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-delegate.h +.. _`Valve Configuration And Control Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/all-clusters-app/linux/ValveControlDelegate.h .. _`Device Energy Management`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/device-energy-management-server/device-energy-management-server.h .. _`Device Energy Management Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/examples/energy-management-app/energy-management-common/include/DeviceEnergyManagementDelegateImpl.h +.. _`Door Lock`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/door-lock-server/door-lock-delegate.h +.. _`Boolean State Configuration`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/boolean-state-configuration-server/boolean-state-configuration-delegate.h +.. _`Time Synchronization`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/time-synchronization-server/time-synchronization-delegate.h +.. _`Time Synchronization Delegate`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/time-synchronization-server/DefaultTimeSyncDelegate.h +.. _`Application Basic`: https://github.com/project-chip/connectedhomeip/blob/master/src/app/clusters/application-basic-server/application-basic-delegate.h