From 593861d62f4b28fcac06d01550ad437e8500b1a8 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Fri, 17 Jan 2025 17:59:46 -0800 Subject: [PATCH] Decouple ember functions from general diagnostics cluster (#37001) * Decouple ember functions from general diagnostics cluster * Optimize flash cost * Add compile flag for each command * Address review comments --- .../app-templates/IMClusterCommandHandler.cpp | 62 --- .../app-templates/gen_config.h | 261 ++++++++++++ .../app-templates/IMClusterCommandHandler.cpp | 53 --- .../lighting-app/app-templates/gen_config.h | 118 ++++++ .../general-diagnostics-server.cpp | 390 ++++++++++-------- src/app/common/templates/config-data.yaml | 1 + .../templates/app/gen_config.zapt | 11 + .../app-common/zap-generated/callback.h | 18 - 8 files changed, 600 insertions(+), 314 deletions(-) diff --git a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/IMClusterCommandHandler.cpp b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/IMClusterCommandHandler.cpp index d4f8d623590185..09f8a2cbe1e4e6 100644 --- a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/IMClusterCommandHandler.cpp +++ b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/IMClusterCommandHandler.cpp @@ -577,65 +577,6 @@ Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCom } // namespace FaultInjection -namespace GeneralDiagnostics { - -Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, - TLV::TLVReader & aDataTlv) -{ - CHIP_ERROR TLVError = CHIP_NO_ERROR; - bool wasHandled = false; - { - switch (aCommandPath.mCommandId) - { - case Commands::TestEventTrigger::Id: { - Commands::TestEventTrigger::DecodableType commandData; - TLVError = DataModel::Decode(aDataTlv, commandData); - if (TLVError == CHIP_NO_ERROR) - { - wasHandled = emberAfGeneralDiagnosticsClusterTestEventTriggerCallback(apCommandObj, aCommandPath, commandData); - } - break; - } - case Commands::TimeSnapshot::Id: { - Commands::TimeSnapshot::DecodableType commandData; - TLVError = DataModel::Decode(aDataTlv, commandData); - if (TLVError == CHIP_NO_ERROR) - { - wasHandled = emberAfGeneralDiagnosticsClusterTimeSnapshotCallback(apCommandObj, aCommandPath, commandData); - } - break; - } - case Commands::PayloadTestRequest::Id: { - Commands::PayloadTestRequest::DecodableType commandData; - TLVError = DataModel::Decode(aDataTlv, commandData); - if (TLVError == CHIP_NO_ERROR) - { - wasHandled = emberAfGeneralDiagnosticsClusterPayloadTestRequestCallback(apCommandObj, aCommandPath, commandData); - } - break; - } - default: { - // Unrecognized command ID, error status will apply. - ChipLogError(Zcl, "Unknown command " ChipLogFormatMEI " for cluster " ChipLogFormatMEI, - ChipLogValueMEI(aCommandPath.mCommandId), ChipLogValueMEI(aCommandPath.mClusterId)); - return Protocols::InteractionModel::Status::UnsupportedCommand; - } - } - } - - if (CHIP_NO_ERROR != TLVError || !wasHandled) - { - ChipLogProgress(Zcl, "Failed to dispatch command, TLVError=%" CHIP_ERROR_FORMAT, TLVError.Format()); - return Protocols::InteractionModel::Status::InvalidCommand; - } - - // We use success as a marker that no special handling is required - // This is to avoid having a std::optional which uses slightly more code. - return Protocols::InteractionModel::Status::Success; -} - -} // namespace GeneralDiagnostics - namespace GroupKeyManagement { Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, @@ -1975,9 +1916,6 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, TLV: case Clusters::FaultInjection::Id: errorStatus = Clusters::FaultInjection::DispatchServerCommand(apCommandObj, aCommandPath, aReader); break; - case Clusters::GeneralDiagnostics::Id: - errorStatus = Clusters::GeneralDiagnostics::DispatchServerCommand(apCommandObj, aCommandPath, aReader); - break; case Clusters::GroupKeyManagement::Id: errorStatus = Clusters::GroupKeyManagement::DispatchServerCommand(apCommandObj, aCommandPath, aReader); break; diff --git a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/gen_config.h b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/gen_config.h index 9c1886588e4529..effa1945e9cf27 100644 --- a/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/gen_config.h +++ b/scripts/tools/zap/tests/outputs/all-clusters-app/app-templates/gen_config.h @@ -586,3 +586,264 @@ #define ZCL_USING_FAULT_INJECTION_CLUSTER_SERVER #define MATTER_DM_PLUGIN_FAULT_INJECTION_SERVER #define MATTER_DM_PLUGIN_FAULT_INJECTION + +/**** Cluster Commands Flag ****/ +// ActivatedCarbonFilterMonitoring Cluster Commands +#define ACTIVATED_CARBON_FILTER_MONITORING_ENABLE_RESET_CONDITION_CMD 1 + +// AdministratorCommissioning Cluster Commands +#define ADMINISTRATOR_COMMISSIONING_ENABLE_OPEN_COMMISSIONING_WINDOW_CMD 1 +#define ADMINISTRATOR_COMMISSIONING_ENABLE_OPEN_BASIC_COMMISSIONING_WINDOW_CMD 1 +#define ADMINISTRATOR_COMMISSIONING_ENABLE_REVOKE_COMMISSIONING_CMD 1 + +// BooleanStateConfiguration Cluster Commands +#define BOOLEAN_STATE_CONFIGURATION_ENABLE_SUPPRESS_ALARM_CMD 1 +#define BOOLEAN_STATE_CONFIGURATION_ENABLE_ENABLE_DISABLE_ALARM_CMD 1 + +// ColorControl Cluster Commands +#define COLOR_CONTROL_ENABLE_MOVE_TO_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_STEP_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_TO_SATURATION_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_SATURATION_CMD 1 +#define COLOR_CONTROL_ENABLE_STEP_SATURATION_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_TO_HUE_AND_SATURATION_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_TO_COLOR_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_COLOR_CMD 1 +#define COLOR_CONTROL_ENABLE_STEP_COLOR_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_TO_COLOR_TEMPERATURE_CMD 1 +#define COLOR_CONTROL_ENABLE_ENHANCED_MOVE_TO_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_ENHANCED_MOVE_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_ENHANCED_STEP_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_ENHANCED_MOVE_TO_HUE_AND_SATURATION_CMD 1 +#define COLOR_CONTROL_ENABLE_COLOR_LOOP_SET_CMD 1 +#define COLOR_CONTROL_ENABLE_STOP_MOVE_STEP_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_COLOR_TEMPERATURE_CMD 1 +#define COLOR_CONTROL_ENABLE_STEP_COLOR_TEMPERATURE_CMD 1 + +// DeviceEnergyManagement Cluster Commands +#define DEVICE_ENERGY_MANAGEMENT_ENABLE_POWER_ADJUST_REQUEST_CMD 1 +#define DEVICE_ENERGY_MANAGEMENT_ENABLE_CANCEL_POWER_ADJUST_REQUEST_CMD 1 +#define DEVICE_ENERGY_MANAGEMENT_ENABLE_START_TIME_ADJUST_REQUEST_CMD 1 +#define DEVICE_ENERGY_MANAGEMENT_ENABLE_PAUSE_REQUEST_CMD 1 +#define DEVICE_ENERGY_MANAGEMENT_ENABLE_RESUME_REQUEST_CMD 1 +#define DEVICE_ENERGY_MANAGEMENT_ENABLE_MODIFY_FORECAST_REQUEST_CMD 1 +#define DEVICE_ENERGY_MANAGEMENT_ENABLE_REQUEST_CONSTRAINT_BASED_FORECAST_CMD 1 +#define DEVICE_ENERGY_MANAGEMENT_ENABLE_CANCEL_REQUEST_CMD 1 + +// DeviceEnergyManagementMode Cluster Commands +#define DEVICE_ENERGY_MANAGEMENT_MODE_ENABLE_CHANGE_TO_MODE_CMD 1 + +// DiagnosticLogs Cluster Commands +#define DIAGNOSTIC_LOGS_ENABLE_RETRIEVE_LOGS_REQUEST_CMD 1 + +// DishwasherAlarm Cluster Commands +#define DISHWASHER_ALARM_ENABLE_RESET_CMD 1 +#define DISHWASHER_ALARM_ENABLE_MODIFY_ENABLED_ALARMS_CMD 1 + +// DishwasherMode Cluster Commands +#define DISHWASHER_MODE_ENABLE_CHANGE_TO_MODE_CMD 1 + +// EnergyEvse Cluster Commands +#define ENERGY_EVSE_ENABLE_DISABLE_CMD 1 +#define ENERGY_EVSE_ENABLE_ENABLE_CHARGING_CMD 1 +#define ENERGY_EVSE_ENABLE_ENABLE_DISCHARGING_CMD 1 +#define ENERGY_EVSE_ENABLE_START_DIAGNOSTICS_CMD 1 +#define ENERGY_EVSE_ENABLE_SET_TARGETS_CMD 1 +#define ENERGY_EVSE_ENABLE_GET_TARGETS_CMD 1 +#define ENERGY_EVSE_ENABLE_CLEAR_TARGETS_CMD 1 + +// EnergyEvseMode Cluster Commands +#define ENERGY_EVSE_MODE_ENABLE_CHANGE_TO_MODE_CMD 1 + +// EthernetNetworkDiagnostics Cluster Commands +#define ETHERNET_NETWORK_DIAGNOSTICS_ENABLE_RESET_COUNTS_CMD 1 + +// FanControl Cluster Commands +#define FAN_CONTROL_ENABLE_STEP_CMD 1 + +// FaultInjection Cluster Commands +#define FAULT_INJECTION_ENABLE_FAIL_AT_FAULT_CMD 1 +#define FAULT_INJECTION_ENABLE_FAIL_RANDOMLY_AT_FAULT_CMD 1 + +// GeneralCommissioning Cluster Commands +#define GENERAL_COMMISSIONING_ENABLE_ARM_FAIL_SAFE_CMD 1 +#define GENERAL_COMMISSIONING_ENABLE_SET_REGULATORY_CONFIG_CMD 1 +#define GENERAL_COMMISSIONING_ENABLE_COMMISSIONING_COMPLETE_CMD 1 + +// GeneralDiagnostics Cluster Commands +#define GENERAL_DIAGNOSTICS_ENABLE_TEST_EVENT_TRIGGER_CMD 1 +#define GENERAL_DIAGNOSTICS_ENABLE_TIME_SNAPSHOT_CMD 1 +#define GENERAL_DIAGNOSTICS_ENABLE_PAYLOAD_TEST_REQUEST_CMD 1 + +// GroupKeyManagement Cluster Commands +#define GROUP_KEY_MANAGEMENT_ENABLE_KEY_SET_WRITE_CMD 1 +#define GROUP_KEY_MANAGEMENT_ENABLE_KEY_SET_READ_CMD 1 +#define GROUP_KEY_MANAGEMENT_ENABLE_KEY_SET_REMOVE_CMD 1 +#define GROUP_KEY_MANAGEMENT_ENABLE_KEY_SET_READ_ALL_INDICES_CMD 1 + +// Groups Cluster Commands +#define GROUPS_ENABLE_ADD_GROUP_CMD 1 +#define GROUPS_ENABLE_VIEW_GROUP_CMD 1 +#define GROUPS_ENABLE_GET_GROUP_MEMBERSHIP_CMD 1 +#define GROUPS_ENABLE_REMOVE_GROUP_CMD 1 +#define GROUPS_ENABLE_REMOVE_ALL_GROUPS_CMD 1 +#define GROUPS_ENABLE_ADD_GROUP_IF_IDENTIFYING_CMD 1 + +// HepaFilterMonitoring Cluster Commands +#define HEPA_FILTER_MONITORING_ENABLE_RESET_CONDITION_CMD 1 + +// Identify Cluster Commands +#define IDENTIFY_ENABLE_IDENTIFY_CMD 1 +#define IDENTIFY_ENABLE_TRIGGER_EFFECT_CMD 1 + +// LaundryWasherMode Cluster Commands +#define LAUNDRY_WASHER_MODE_ENABLE_CHANGE_TO_MODE_CMD 1 + +// LevelControl Cluster Commands +#define LEVEL_CONTROL_ENABLE_MOVE_TO_LEVEL_CMD 1 +#define LEVEL_CONTROL_ENABLE_MOVE_CMD 1 +#define LEVEL_CONTROL_ENABLE_STEP_CMD 1 +#define LEVEL_CONTROL_ENABLE_STOP_CMD 1 +#define LEVEL_CONTROL_ENABLE_MOVE_TO_LEVEL_WITH_ON_OFF_CMD 1 +#define LEVEL_CONTROL_ENABLE_MOVE_WITH_ON_OFF_CMD 1 +#define LEVEL_CONTROL_ENABLE_STEP_WITH_ON_OFF_CMD 1 +#define LEVEL_CONTROL_ENABLE_STOP_WITH_ON_OFF_CMD 1 + +// LowPower Cluster Commands +#define LOW_POWER_ENABLE_SLEEP_CMD 1 + +// ModeSelect Cluster Commands +#define MODE_SELECT_ENABLE_CHANGE_TO_MODE_CMD 1 + +// NetworkCommissioning Cluster Commands +#define NETWORK_COMMISSIONING_ENABLE_SCAN_NETWORKS_CMD 1 +#define NETWORK_COMMISSIONING_ENABLE_ADD_OR_UPDATE_WI_FI_NETWORK_CMD 1 +#define NETWORK_COMMISSIONING_ENABLE_ADD_OR_UPDATE_THREAD_NETWORK_CMD 1 +#define NETWORK_COMMISSIONING_ENABLE_REMOVE_NETWORK_CMD 1 +#define NETWORK_COMMISSIONING_ENABLE_CONNECT_NETWORK_CMD 1 +#define NETWORK_COMMISSIONING_ENABLE_REORDER_NETWORK_CMD 1 + +// OtaSoftwareUpdateRequestor Cluster Commands +#define OTA_SOFTWARE_UPDATE_REQUESTOR_ENABLE_ANNOUNCE_OTA_PROVIDER_CMD 1 + +// OnOff Cluster Commands +#define ON_OFF_ENABLE_OFF_CMD 1 +#define ON_OFF_ENABLE_ON_CMD 1 +#define ON_OFF_ENABLE_TOGGLE_CMD 1 +#define ON_OFF_ENABLE_OFF_WITH_EFFECT_CMD 1 +#define ON_OFF_ENABLE_ON_WITH_RECALL_GLOBAL_SCENE_CMD 1 +#define ON_OFF_ENABLE_ON_WITH_TIMED_OFF_CMD 1 + +// OperationalCredentials Cluster Commands +#define OPERATIONAL_CREDENTIALS_ENABLE_ATTESTATION_REQUEST_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_CERTIFICATE_CHAIN_REQUEST_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_CSR_REQUEST_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_ADD_NOC_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_UPDATE_NOC_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_UPDATE_FABRIC_LABEL_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_REMOVE_FABRIC_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_ADD_TRUSTED_ROOT_CERTIFICATE_CMD 1 + +// OperationalState Cluster Commands +#define OPERATIONAL_STATE_ENABLE_PAUSE_CMD 1 +#define OPERATIONAL_STATE_ENABLE_STOP_CMD 1 +#define OPERATIONAL_STATE_ENABLE_START_CMD 1 +#define OPERATIONAL_STATE_ENABLE_RESUME_CMD 1 + +// OvenCavityOperationalState Cluster Commands +#define OVEN_CAVITY_OPERATIONAL_STATE_ENABLE_PAUSE_CMD 1 +#define OVEN_CAVITY_OPERATIONAL_STATE_ENABLE_STOP_CMD 1 +#define OVEN_CAVITY_OPERATIONAL_STATE_ENABLE_START_CMD 1 +#define OVEN_CAVITY_OPERATIONAL_STATE_ENABLE_RESUME_CMD 1 + +// OvenMode Cluster Commands +#define OVEN_MODE_ENABLE_CHANGE_TO_MODE_CMD 1 + +// RvcCleanMode Cluster Commands +#define RVC_CLEAN_MODE_ENABLE_CHANGE_TO_MODE_CMD 1 + +// RvcOperationalState Cluster Commands +#define RVC_OPERATIONAL_STATE_ENABLE_PAUSE_CMD 1 +#define RVC_OPERATIONAL_STATE_ENABLE_RESUME_CMD 1 +#define RVC_OPERATIONAL_STATE_ENABLE_GO_HOME_CMD 1 + +// RvcRunMode Cluster Commands +#define RVC_RUN_MODE_ENABLE_CHANGE_TO_MODE_CMD 1 + +// RefrigeratorAndTemperatureControlledCabinetMode Cluster Commands +#define REFRIGERATOR_AND_TEMPERATURE_CONTROLLED_CABINET_MODE_ENABLE_CHANGE_TO_MODE_CMD 1 + +// ScenesManagement Cluster Commands +#define SCENES_MANAGEMENT_ENABLE_ADD_SCENE_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_VIEW_SCENE_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_REMOVE_SCENE_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_REMOVE_ALL_SCENES_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_STORE_SCENE_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_RECALL_SCENE_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_GET_SCENE_MEMBERSHIP_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_COPY_SCENE_CMD 1 + +// SmokeCoAlarm Cluster Commands +#define SMOKE_CO_ALARM_ENABLE_SELF_TEST_REQUEST_CMD 1 + +// SoftwareDiagnostics Cluster Commands +#define SOFTWARE_DIAGNOSTICS_ENABLE_RESET_WATERMARKS_CMD 1 + +// TemperatureControl Cluster Commands +#define TEMPERATURE_CONTROL_ENABLE_SET_TEMPERATURE_CMD 1 + +// Thermostat Cluster Commands +#define THERMOSTAT_ENABLE_SETPOINT_RAISE_LOWER_CMD 1 +#define THERMOSTAT_ENABLE_SET_ACTIVE_SCHEDULE_REQUEST_CMD 1 +#define THERMOSTAT_ENABLE_SET_ACTIVE_PRESET_REQUEST_CMD 1 +#define THERMOSTAT_ENABLE_ATOMIC_REQUEST_CMD 1 + +// ThreadNetworkDiagnostics Cluster Commands +#define THREAD_NETWORK_DIAGNOSTICS_ENABLE_RESET_COUNTS_CMD 1 + +// TimeSynchronization Cluster Commands +#define TIME_SYNCHRONIZATION_ENABLE_SET_UTC_TIME_CMD 1 +#define TIME_SYNCHRONIZATION_ENABLE_SET_TRUSTED_TIME_SOURCE_CMD 1 +#define TIME_SYNCHRONIZATION_ENABLE_SET_TIME_ZONE_CMD 1 +#define TIME_SYNCHRONIZATION_ENABLE_SET_DST_OFFSET_CMD 1 +#define TIME_SYNCHRONIZATION_ENABLE_SET_DEFAULT_NTP_CMD 1 + +// UnitTesting Cluster Commands +#define UNIT_TESTING_ENABLE_TEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_NOT_HANDLED_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_SPECIFIC_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_ADD_ARGUMENTS_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_STRUCT_ARGUMENT_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_NESTED_STRUCT_ARGUMENT_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_LIST_STRUCT_ARGUMENT_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_LIST_INT8_U_ARGUMENT_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_NESTED_STRUCT_LIST_ARGUMENT_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_LIST_NESTED_STRUCT_LIST_ARGUMENT_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_LIST_INT8_U_REVERSE_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_ENUMS_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_NULLABLE_OPTIONAL_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_SIMPLE_STRUCT_ECHO_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TIMED_INVOKE_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_SIMPLE_OPTIONAL_ARGUMENT_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_EMIT_TEST_EVENT_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_EMIT_TEST_FABRIC_SCOPED_EVENT_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_BATCH_HELPER_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_SECOND_BATCH_HELPER_REQUEST_CMD 1 +#define UNIT_TESTING_ENABLE_TEST_DIFFERENT_VENDOR_MEI_REQUEST_CMD 1 + +// ValveConfigurationAndControl Cluster Commands +#define VALVE_CONFIGURATION_AND_CONTROL_ENABLE_OPEN_CMD 1 +#define VALVE_CONFIGURATION_AND_CONTROL_ENABLE_CLOSE_CMD 1 + +// WiFiNetworkDiagnostics Cluster Commands +#define WI_FI_NETWORK_DIAGNOSTICS_ENABLE_RESET_COUNTS_CMD 1 + +// WindowCovering Cluster Commands +#define WINDOW_COVERING_ENABLE_UP_OR_OPEN_CMD 1 +#define WINDOW_COVERING_ENABLE_DOWN_OR_CLOSE_CMD 1 +#define WINDOW_COVERING_ENABLE_STOP_MOTION_CMD 1 +#define WINDOW_COVERING_ENABLE_GO_TO_LIFT_VALUE_CMD 1 +#define WINDOW_COVERING_ENABLE_GO_TO_LIFT_PERCENTAGE_CMD 1 +#define WINDOW_COVERING_ENABLE_GO_TO_TILT_VALUE_CMD 1 +#define WINDOW_COVERING_ENABLE_GO_TO_TILT_PERCENTAGE_CMD 1 diff --git a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/IMClusterCommandHandler.cpp b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/IMClusterCommandHandler.cpp index 9f3b5e1b0030fc..11b0dc14a23f66 100644 --- a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/IMClusterCommandHandler.cpp +++ b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/IMClusterCommandHandler.cpp @@ -385,56 +385,6 @@ Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCom } // namespace EthernetNetworkDiagnostics -namespace GeneralDiagnostics { - -Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, - TLV::TLVReader & aDataTlv) -{ - CHIP_ERROR TLVError = CHIP_NO_ERROR; - bool wasHandled = false; - { - switch (aCommandPath.mCommandId) - { - case Commands::TestEventTrigger::Id: { - Commands::TestEventTrigger::DecodableType commandData; - TLVError = DataModel::Decode(aDataTlv, commandData); - if (TLVError == CHIP_NO_ERROR) - { - wasHandled = emberAfGeneralDiagnosticsClusterTestEventTriggerCallback(apCommandObj, aCommandPath, commandData); - } - break; - } - case Commands::TimeSnapshot::Id: { - Commands::TimeSnapshot::DecodableType commandData; - TLVError = DataModel::Decode(aDataTlv, commandData); - if (TLVError == CHIP_NO_ERROR) - { - wasHandled = emberAfGeneralDiagnosticsClusterTimeSnapshotCallback(apCommandObj, aCommandPath, commandData); - } - break; - } - default: { - // Unrecognized command ID, error status will apply. - ChipLogError(Zcl, "Unknown command " ChipLogFormatMEI " for cluster " ChipLogFormatMEI, - ChipLogValueMEI(aCommandPath.mCommandId), ChipLogValueMEI(aCommandPath.mClusterId)); - return Protocols::InteractionModel::Status::UnsupportedCommand; - } - } - } - - if (CHIP_NO_ERROR != TLVError || !wasHandled) - { - ChipLogProgress(Zcl, "Failed to dispatch command, TLVError=%" CHIP_ERROR_FORMAT, TLVError.Format()); - return Protocols::InteractionModel::Status::InvalidCommand; - } - - // We use success as a marker that no special handling is required - // This is to avoid having a std::optional which uses slightly more code. - return Protocols::InteractionModel::Status::Success; -} - -} // namespace GeneralDiagnostics - namespace GroupKeyManagement { Protocols::InteractionModel::Status DispatchServerCommand(CommandHandler * apCommandObj, const ConcreteCommandPath & aCommandPath, @@ -1080,9 +1030,6 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, TLV: case Clusters::EthernetNetworkDiagnostics::Id: errorStatus = Clusters::EthernetNetworkDiagnostics::DispatchServerCommand(apCommandObj, aCommandPath, aReader); break; - case Clusters::GeneralDiagnostics::Id: - errorStatus = Clusters::GeneralDiagnostics::DispatchServerCommand(apCommandObj, aCommandPath, aReader); - break; case Clusters::GroupKeyManagement::Id: errorStatus = Clusters::GroupKeyManagement::DispatchServerCommand(apCommandObj, aCommandPath, aReader); break; diff --git a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/gen_config.h b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/gen_config.h index de76a99b95284f..4aaa5bfa362ced 100644 --- a/scripts/tools/zap/tests/outputs/lighting-app/app-templates/gen_config.h +++ b/scripts/tools/zap/tests/outputs/lighting-app/app-templates/gen_config.h @@ -209,3 +209,121 @@ #define ZCL_USING_OCCUPANCY_SENSING_CLUSTER_SERVER #define MATTER_DM_PLUGIN_OCCUPANCY_SENSING_SERVER #define MATTER_DM_PLUGIN_OCCUPANCY_SENSING + +/**** Cluster Commands Flag ****/ +// AdministratorCommissioning Cluster Commands +#define ADMINISTRATOR_COMMISSIONING_ENABLE_OPEN_COMMISSIONING_WINDOW_CMD 1 +#define ADMINISTRATOR_COMMISSIONING_ENABLE_OPEN_BASIC_COMMISSIONING_WINDOW_CMD 1 +#define ADMINISTRATOR_COMMISSIONING_ENABLE_REVOKE_COMMISSIONING_CMD 1 + +// ColorControl Cluster Commands +#define COLOR_CONTROL_ENABLE_MOVE_TO_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_STEP_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_TO_SATURATION_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_SATURATION_CMD 1 +#define COLOR_CONTROL_ENABLE_STEP_SATURATION_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_TO_HUE_AND_SATURATION_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_TO_COLOR_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_COLOR_CMD 1 +#define COLOR_CONTROL_ENABLE_STEP_COLOR_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_TO_COLOR_TEMPERATURE_CMD 1 +#define COLOR_CONTROL_ENABLE_ENHANCED_MOVE_TO_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_ENHANCED_MOVE_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_ENHANCED_STEP_HUE_CMD 1 +#define COLOR_CONTROL_ENABLE_ENHANCED_MOVE_TO_HUE_AND_SATURATION_CMD 1 +#define COLOR_CONTROL_ENABLE_COLOR_LOOP_SET_CMD 1 +#define COLOR_CONTROL_ENABLE_STOP_MOVE_STEP_CMD 1 +#define COLOR_CONTROL_ENABLE_MOVE_COLOR_TEMPERATURE_CMD 1 +#define COLOR_CONTROL_ENABLE_STEP_COLOR_TEMPERATURE_CMD 1 + +// DiagnosticLogs Cluster Commands +#define DIAGNOSTIC_LOGS_ENABLE_RETRIEVE_LOGS_REQUEST_CMD 1 + +// EthernetNetworkDiagnostics Cluster Commands +#define ETHERNET_NETWORK_DIAGNOSTICS_ENABLE_RESET_COUNTS_CMD 1 + +// GeneralCommissioning Cluster Commands +#define GENERAL_COMMISSIONING_ENABLE_ARM_FAIL_SAFE_CMD 1 +#define GENERAL_COMMISSIONING_ENABLE_SET_REGULATORY_CONFIG_CMD 1 +#define GENERAL_COMMISSIONING_ENABLE_COMMISSIONING_COMPLETE_CMD 1 + +// GeneralDiagnostics Cluster Commands +#define GENERAL_DIAGNOSTICS_ENABLE_TEST_EVENT_TRIGGER_CMD 1 +#define GENERAL_DIAGNOSTICS_ENABLE_TIME_SNAPSHOT_CMD 1 + +// GroupKeyManagement Cluster Commands +#define GROUP_KEY_MANAGEMENT_ENABLE_KEY_SET_WRITE_CMD 1 +#define GROUP_KEY_MANAGEMENT_ENABLE_KEY_SET_READ_CMD 1 +#define GROUP_KEY_MANAGEMENT_ENABLE_KEY_SET_REMOVE_CMD 1 +#define GROUP_KEY_MANAGEMENT_ENABLE_KEY_SET_READ_ALL_INDICES_CMD 1 + +// Groups Cluster Commands +#define GROUPS_ENABLE_ADD_GROUP_CMD 1 +#define GROUPS_ENABLE_VIEW_GROUP_CMD 1 +#define GROUPS_ENABLE_GET_GROUP_MEMBERSHIP_CMD 1 +#define GROUPS_ENABLE_REMOVE_GROUP_CMD 1 +#define GROUPS_ENABLE_REMOVE_ALL_GROUPS_CMD 1 +#define GROUPS_ENABLE_ADD_GROUP_IF_IDENTIFYING_CMD 1 + +// Identify Cluster Commands +#define IDENTIFY_ENABLE_IDENTIFY_CMD 1 +#define IDENTIFY_ENABLE_TRIGGER_EFFECT_CMD 1 + +// LevelControl Cluster Commands +#define LEVEL_CONTROL_ENABLE_MOVE_TO_LEVEL_CMD 1 +#define LEVEL_CONTROL_ENABLE_MOVE_CMD 1 +#define LEVEL_CONTROL_ENABLE_STEP_CMD 1 +#define LEVEL_CONTROL_ENABLE_STOP_CMD 1 +#define LEVEL_CONTROL_ENABLE_MOVE_TO_LEVEL_WITH_ON_OFF_CMD 1 +#define LEVEL_CONTROL_ENABLE_MOVE_WITH_ON_OFF_CMD 1 +#define LEVEL_CONTROL_ENABLE_STEP_WITH_ON_OFF_CMD 1 +#define LEVEL_CONTROL_ENABLE_STOP_WITH_ON_OFF_CMD 1 + +// NetworkCommissioning Cluster Commands +#define NETWORK_COMMISSIONING_ENABLE_SCAN_NETWORKS_CMD 1 +#define NETWORK_COMMISSIONING_ENABLE_ADD_OR_UPDATE_WI_FI_NETWORK_CMD 1 +#define NETWORK_COMMISSIONING_ENABLE_ADD_OR_UPDATE_THREAD_NETWORK_CMD 1 +#define NETWORK_COMMISSIONING_ENABLE_REMOVE_NETWORK_CMD 1 +#define NETWORK_COMMISSIONING_ENABLE_CONNECT_NETWORK_CMD 1 +#define NETWORK_COMMISSIONING_ENABLE_REORDER_NETWORK_CMD 1 + +// OtaSoftwareUpdateRequestor Cluster Commands +#define OTA_SOFTWARE_UPDATE_REQUESTOR_ENABLE_ANNOUNCE_OTA_PROVIDER_CMD 1 + +// OnOff Cluster Commands +#define ON_OFF_ENABLE_OFF_CMD 1 +#define ON_OFF_ENABLE_ON_CMD 1 +#define ON_OFF_ENABLE_TOGGLE_CMD 1 +#define ON_OFF_ENABLE_OFF_WITH_EFFECT_CMD 1 +#define ON_OFF_ENABLE_ON_WITH_RECALL_GLOBAL_SCENE_CMD 1 +#define ON_OFF_ENABLE_ON_WITH_TIMED_OFF_CMD 1 + +// OperationalCredentials Cluster Commands +#define OPERATIONAL_CREDENTIALS_ENABLE_ATTESTATION_REQUEST_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_CERTIFICATE_CHAIN_REQUEST_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_CSR_REQUEST_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_ADD_NOC_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_UPDATE_NOC_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_UPDATE_FABRIC_LABEL_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_REMOVE_FABRIC_CMD 1 +#define OPERATIONAL_CREDENTIALS_ENABLE_ADD_TRUSTED_ROOT_CERTIFICATE_CMD 1 + +// ScenesManagement Cluster Commands +#define SCENES_MANAGEMENT_ENABLE_ADD_SCENE_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_VIEW_SCENE_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_REMOVE_SCENE_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_REMOVE_ALL_SCENES_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_STORE_SCENE_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_RECALL_SCENE_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_GET_SCENE_MEMBERSHIP_CMD 1 +#define SCENES_MANAGEMENT_ENABLE_COPY_SCENE_CMD 1 + +// SoftwareDiagnostics Cluster Commands +#define SOFTWARE_DIAGNOSTICS_ENABLE_RESET_WATERMARKS_CMD 1 + +// ThreadNetworkDiagnostics Cluster Commands +#define THREAD_NETWORK_DIAGNOSTICS_ENABLE_RESET_COUNTS_CMD 1 + +// WiFiNetworkDiagnostics Cluster Commands +#define WI_FI_NETWORK_DIAGNOSTICS_ENABLE_RESET_COUNTS_CMD 1 diff --git a/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp b/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp index e04410d29788c2..0face9c27d078d 100644 --- a/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp +++ b/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp @@ -29,12 +29,16 @@ #include #include #include +#include +#include +#include #include #include #include #include #include #include +#include using namespace chip; using namespace chip::app; @@ -86,13 +90,41 @@ void ReportAttributeOnAllEndpoints(AttributeId attribute) } } -class GeneralDiagosticsAttrAccess : public AttributeAccessInterface +TestEventTriggerDelegate * GetTriggerDelegateOnMatchingKey(ByteSpan enableKey) +{ + if (enableKey.size() != TestEventTriggerDelegate::kEnableKeyLength) + { + return nullptr; + } + + if (IsByteSpanAllZeros(enableKey)) + { + return nullptr; + } + + auto * triggerDelegate = chip::Server::GetInstance().GetTestEventTriggerDelegate(); + + if (triggerDelegate == nullptr || !triggerDelegate->DoesEnableKeyMatch(enableKey)) + { + return nullptr; + } + + return triggerDelegate; +} + +class GeneralDiagosticsGlobalInstance : public AttributeAccessInterface, + public CommandHandlerInterface, + public DeviceLayer::ConnectivityManagerDelegate { public: // Register for the GeneralDiagnostics cluster on all endpoints. - GeneralDiagosticsAttrAccess() : AttributeAccessInterface(Optional::Missing(), GeneralDiagnostics::Id) {} + GeneralDiagosticsGlobalInstance() : + AttributeAccessInterface(Optional::Missing(), GeneralDiagnostics::Id), + CommandHandlerInterface(Optional::Missing(), GeneralDiagnostics::Id) + {} CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; + void InvokeCommand(HandlerContext & handlerContext) override; private: template @@ -102,11 +134,108 @@ class GeneralDiagosticsAttrAccess : public AttributeAccessInterface CHIP_ERROR ReadListIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), AttributeValueEncoder & aEncoder); CHIP_ERROR ReadNetworkInterfaces(AttributeValueEncoder & aEncoder); + + void HandleTestEventTrigger(HandlerContext & ctx, const Commands::TestEventTrigger::DecodableType & commandData); + void HandleTimeSnapshot(HandlerContext & ctx, const Commands::TimeSnapshot::DecodableType & commandData); + +#ifdef GENERAL_DIAGNOSTICS_ENABLE_PAYLOAD_TEST_REQUEST_CMD + void HandlePayloadTestRequest(HandlerContext & ctx, const Commands::PayloadTestRequest::DecodableType & commandData); +#endif + + // Gets called when any network interface on the Node is updated. + void OnNetworkInfoChanged() override + { + ChipLogDetail(Zcl, "GeneralDiagnosticsDelegate: OnNetworkInfoChanged"); + + ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::NetworkInterfaces::Id); + } }; +CHIP_ERROR GeneralDiagosticsGlobalInstance::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +{ + if (aPath.mClusterId != GeneralDiagnostics::Id) + { + // We shouldn't have been called at all. + return CHIP_ERROR_INVALID_ARGUMENT; + } + + switch (aPath.mAttributeId) + { + case NetworkInterfaces::Id: { + return ReadNetworkInterfaces(aEncoder); + } + case ActiveHardwareFaults::Id: { + return ReadListIfSupported(&DiagnosticDataProvider::GetActiveHardwareFaults, aEncoder); + } + case ActiveRadioFaults::Id: { + return ReadListIfSupported(&DiagnosticDataProvider::GetActiveRadioFaults, aEncoder); + } + case ActiveNetworkFaults::Id: { + return ReadListIfSupported(&DiagnosticDataProvider::GetActiveNetworkFaults, aEncoder); + } + case RebootCount::Id: { + return ReadIfSupported(&DiagnosticDataProvider::GetRebootCount, aEncoder); + } + case UpTime::Id: { + System::Clock::Seconds64 system_time_seconds = + std::chrono::duration_cast(Server::GetInstance().TimeSinceInit()); + return aEncoder.Encode(static_cast(system_time_seconds.count())); + } + case TotalOperationalHours::Id: { + return ReadIfSupported(&DiagnosticDataProvider::GetTotalOperationalHours, aEncoder); + } + case BootReason::Id: { + return ReadIfSupported(&DiagnosticDataProvider::GetBootReason, aEncoder); + } + case TestEventTriggersEnabled::Id: { + bool isTestEventTriggersEnabled = IsTestEventTriggerEnabled(); + return aEncoder.Encode(isTestEventTriggersEnabled); + } + // Note: Attribute ID 0x0009 was removed (#30002). + + case FeatureMap::Id: { + uint32_t features = 0; + +#if CHIP_CONFIG_MAX_PATHS_PER_INVOKE > 1 + features |= to_underlying(Clusters::GeneralDiagnostics::Feature::kDataModelTest); +#endif // CHIP_CONFIG_MAX_PATHS_PER_INVOKE > 1 + + return aEncoder.Encode(features); + } + + case ClusterRevision::Id: { + return aEncoder.Encode(kCurrentClusterRevision); + } + } + return CHIP_NO_ERROR; +} + +void GeneralDiagosticsGlobalInstance::InvokeCommand(HandlerContext & handlerContext) +{ + switch (handlerContext.mRequestPath.mCommandId) + { + case Commands::TestEventTrigger::Id: + CommandHandlerInterface::HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleTestEventTrigger(ctx, commandData); }); + break; + + case Commands::TimeSnapshot::Id: + CommandHandlerInterface::HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandleTimeSnapshot(ctx, commandData); }); + break; + +#ifdef GENERAL_DIAGNOSTICS_ENABLE_PAYLOAD_TEST_REQUEST_CMD + case Commands::PayloadTestRequest::Id: + CommandHandlerInterface::HandleCommand( + handlerContext, [this](HandlerContext & ctx, const auto & commandData) { HandlePayloadTestRequest(ctx, commandData); }); + break; +#endif + } +} + template -CHIP_ERROR GeneralDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), - AttributeValueEncoder & aEncoder) +CHIP_ERROR GeneralDiagosticsGlobalInstance::ReadIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), + AttributeValueEncoder & aEncoder) { T data; CHIP_ERROR err = (GetDiagnosticDataProvider().*getter)(data); @@ -123,8 +252,8 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadIfSupported(CHIP_ERROR (DiagnosticDa } template -CHIP_ERROR GeneralDiagosticsAttrAccess::ReadListIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), - AttributeValueEncoder & aEncoder) +CHIP_ERROR GeneralDiagosticsGlobalInstance::ReadListIfSupported(CHIP_ERROR (DiagnosticDataProvider::*getter)(T &), + AttributeValueEncoder & aEncoder) { CHIP_ERROR err = CHIP_NO_ERROR; T faultList; @@ -148,7 +277,7 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadListIfSupported(CHIP_ERROR (Diagnost return err; } -CHIP_ERROR GeneralDiagosticsAttrAccess::ReadNetworkInterfaces(AttributeValueEncoder & aEncoder) +CHIP_ERROR GeneralDiagosticsGlobalInstance::ReadNetworkInterfaces(AttributeValueEncoder & aEncoder) { CHIP_ERROR err = CHIP_NO_ERROR; DeviceLayer::NetworkInterface * netifs; @@ -174,82 +303,93 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadNetworkInterfaces(AttributeValueEnco return err; } -GeneralDiagosticsAttrAccess gAttrAccess; - -CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +void GeneralDiagosticsGlobalInstance::HandleTestEventTrigger(HandlerContext & ctx, + const Commands::TestEventTrigger::DecodableType & commandData) { - if (aPath.mClusterId != GeneralDiagnostics::Id) + auto * triggerDelegate = GetTriggerDelegateOnMatchingKey(commandData.enableKey); + if (triggerDelegate == nullptr) { - // We shouldn't have been called at all. - return CHIP_ERROR_INVALID_ARGUMENT; + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::ConstraintError); + return; } - switch (aPath.mAttributeId) - { - case NetworkInterfaces::Id: { - return ReadNetworkInterfaces(aEncoder); - } - case ActiveHardwareFaults::Id: { - return ReadListIfSupported(&DiagnosticDataProvider::GetActiveHardwareFaults, aEncoder); - } - case ActiveRadioFaults::Id: { - return ReadListIfSupported(&DiagnosticDataProvider::GetActiveRadioFaults, aEncoder); - } - case ActiveNetworkFaults::Id: { - return ReadListIfSupported(&DiagnosticDataProvider::GetActiveNetworkFaults, aEncoder); - } - case RebootCount::Id: { - return ReadIfSupported(&DiagnosticDataProvider::GetRebootCount, aEncoder); - } - case UpTime::Id: { - System::Clock::Seconds64 system_time_seconds = - std::chrono::duration_cast(Server::GetInstance().TimeSinceInit()); - return aEncoder.Encode(static_cast(system_time_seconds.count())); - } - case TotalOperationalHours::Id: { - return ReadIfSupported(&DiagnosticDataProvider::GetTotalOperationalHours, aEncoder); - } - case BootReason::Id: { - return ReadIfSupported(&DiagnosticDataProvider::GetBootReason, aEncoder); - } - case TestEventTriggersEnabled::Id: { - bool isTestEventTriggersEnabled = IsTestEventTriggerEnabled(); - return aEncoder.Encode(isTestEventTriggersEnabled); - } - // Note: Attribute ID 0x0009 was removed (#30002). + CHIP_ERROR handleEventTriggerResult = triggerDelegate->HandleEventTriggers(commandData.eventTrigger); - case FeatureMap::Id: { - uint32_t features = 0; + // When HandleEventTrigger fails, we simply convert any error to INVALID_COMMAND + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, + (handleEventTriggerResult != CHIP_NO_ERROR) ? Status::InvalidCommand : Status::Success); +} -#if CHIP_CONFIG_MAX_PATHS_PER_INVOKE > 1 - features |= to_underlying(Clusters::GeneralDiagnostics::Feature::kDataModelTest); -#endif // CHIP_CONFIG_MAX_PATHS_PER_INVOKE > 1 +void GeneralDiagosticsGlobalInstance::HandleTimeSnapshot(HandlerContext & ctx, + const Commands::TimeSnapshot::DecodableType & commandData) +{ + ChipLogError(Zcl, "Received TimeSnapshot command!"); - return aEncoder.Encode(features); - } + Commands::TimeSnapshotResponse::Type response; - case ClusterRevision::Id: { - return aEncoder.Encode(kCurrentClusterRevision); + System::Clock::Microseconds64 posix_time_us{ 0 }; + + // Only consider real time if time sync cluster is actually enabled. Avoids + // likelihood of frequently reporting unsynced time. +#ifdef ZCL_USING_TIME_SYNCHRONIZATION_CLUSTER_SERVER + CHIP_ERROR posix_time_err = System::SystemClock().GetClock_RealTime(posix_time_us); + if (posix_time_err != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Failed to get POSIX real time: %" CHIP_ERROR_FORMAT, posix_time_err.Format()); + posix_time_us = System::Clock::Microseconds64{ 0 }; } +#endif // ZCL_USING_TIME_SYNCHRONIZATION_CLUSTER_SERVER - default: - break; + System::Clock::Milliseconds64 system_time_ms = + std::chrono::duration_cast(Server::GetInstance().TimeSinceInit()); + + response.systemTimeMs = static_cast(system_time_ms.count()); + if (posix_time_us.count() != 0) + { + response.posixTimeMs.SetNonNull( + static_cast(std::chrono::duration_cast(posix_time_us).count())); } - return CHIP_NO_ERROR; + ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); } -class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelegate +#ifdef GENERAL_DIAGNOSTICS_ENABLE_PAYLOAD_TEST_REQUEST_CMD +void GeneralDiagosticsGlobalInstance::HandlePayloadTestRequest(HandlerContext & ctx, + const Commands::PayloadTestRequest::DecodableType & commandData) { - // Gets called when any network interface on the Node is updated. - void OnNetworkInfoChanged() override + // Max allowed is 2048. + if (commandData.count > 2048) { - ChipLogDetail(Zcl, "GeneralDiagnosticsDelegate: OnNetworkInfoChanged"); + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::ConstraintError); + return; + } - ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::NetworkInterfaces::Id); + // Ensure Test Event triggers are enabled and key matches. + auto * triggerDelegate = GetTriggerDelegateOnMatchingKey(commandData.enableKey); + if (triggerDelegate == nullptr) + { + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::ConstraintError); + return; } -}; -GeneralDiagnosticsDelegate gDiagnosticDelegate; + Commands::PayloadTestResponse::Type response; + Platform::ScopedMemoryBufferWithSize payload; + if (!payload.Calloc(commandData.count)) + { + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::ResourceExhausted); + return; + } + + memset(payload.Get(), commandData.value, payload.AllocatedSize()); + response.payload = ByteSpan{ payload.Get(), payload.AllocatedSize() }; + + if (ctx.mCommandHandler.AddResponseData(ctx.mRequestPath, response) != CHIP_NO_ERROR) + { + ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::ResourceExhausted); + } +} +#endif // GENERAL_DIAGNOSTICS_ENABLE_PAYLOAD_TEST_REQUEST_CMD + +GeneralDiagosticsGlobalInstance gGeneralDiagosticsInstance; } // anonymous namespace @@ -373,126 +513,14 @@ void GeneralDiagnosticsServer::OnNetworkFaultsDetect(const GeneralFaultsDoesEnableKeyMatch(enableKey)) - { - return nullptr; - } - - return triggerDelegate; -} - -} // namespace - -bool emberAfGeneralDiagnosticsClusterTestEventTriggerCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, - const Commands::TestEventTrigger::DecodableType & commandData) -{ - auto * triggerDelegate = GetTriggerDelegateOnMatchingKey(commandData.enableKey); - if (triggerDelegate == nullptr) - { - commandObj->AddStatus(commandPath, Status::ConstraintError); - return true; - } - - CHIP_ERROR handleEventTriggerResult = triggerDelegate->HandleEventTriggers(commandData.eventTrigger); - - // When HandleEventTrigger fails, we simply convert any error to INVALID_COMMAND - commandObj->AddStatus(commandPath, (handleEventTriggerResult != CHIP_NO_ERROR) ? Status::InvalidCommand : Status::Success); - return true; -} - -bool emberAfGeneralDiagnosticsClusterTimeSnapshotCallback(CommandHandler * commandObj, ConcreteCommandPath const & commandPath, - Commands::TimeSnapshot::DecodableType const & commandData) -{ - ChipLogError(Zcl, "Received TimeSnapshot command!"); - - Commands::TimeSnapshotResponse::Type response; - - System::Clock::Microseconds64 posix_time_us{ 0 }; - - // Only consider real time if time sync cluster is actually enabled. Avoids - // likelihood of frequently reporting unsynced time. -#ifdef ZCL_USING_TIME_SYNCHRONIZATION_CLUSTER_SERVER - CHIP_ERROR posix_time_err = System::SystemClock().GetClock_RealTime(posix_time_us); - if (posix_time_err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "Failed to get POSIX real time: %" CHIP_ERROR_FORMAT, posix_time_err.Format()); - posix_time_us = System::Clock::Microseconds64{ 0 }; - } -#endif // ZCL_USING_TIME_SYNCHRONIZATION_CLUSTER_SERVER - - System::Clock::Milliseconds64 system_time_ms = - std::chrono::duration_cast(Server::GetInstance().TimeSinceInit()); - - response.systemTimeMs = static_cast(system_time_ms.count()); - if (posix_time_us.count() != 0) - { - response.posixTimeMs.SetNonNull( - static_cast(std::chrono::duration_cast(posix_time_us).count())); - } - commandObj->AddResponse(commandPath, response); - return true; -} - -bool emberAfGeneralDiagnosticsClusterPayloadTestRequestCallback(CommandHandler * commandObj, - const ConcreteCommandPath & commandPath, - const Commands::PayloadTestRequest::DecodableType & commandData) -{ - // Max allowed is 2048. - if (commandData.count > 2048) - { - commandObj->AddStatus(commandPath, Status::ConstraintError); - return true; - } - - // Ensure Test Event triggers are enabled and key matches. - auto * triggerDelegate = GetTriggerDelegateOnMatchingKey(commandData.enableKey); - if (triggerDelegate == nullptr) - { - commandObj->AddStatus(commandPath, Status::ConstraintError); - return true; - } - - Commands::PayloadTestResponse::Type response; - Platform::ScopedMemoryBufferWithSize payload; - if (!payload.Calloc(commandData.count)) - { - commandObj->AddStatus(commandPath, Status::ResourceExhausted); - return true; - } - - memset(payload.Get(), commandData.value, payload.AllocatedSize()); - response.payload = ByteSpan{ payload.Get(), payload.AllocatedSize() }; - - if (commandObj->AddResponseData(commandPath, response) != CHIP_NO_ERROR) - { - commandObj->AddStatus(commandPath, Status::ResourceExhausted); - } - - return true; -} - void MatterGeneralDiagnosticsPluginServerInitCallback() { BootReasonEnum bootReason; - AttributeAccessInterfaceRegistry::Instance().Register(&gAttrAccess); - ConnectivityMgr().SetDelegate(&gDiagnosticDelegate); + AttributeAccessInterfaceRegistry::Instance().Register(&gGeneralDiagosticsInstance); + CommandHandlerInterfaceRegistry::Instance().RegisterCommandHandler(&gGeneralDiagosticsInstance); + + ConnectivityMgr().SetDelegate(&gGeneralDiagosticsInstance); if (GetDiagnosticDataProvider().GetBootReason(bootReason) == CHIP_NO_ERROR) { diff --git a/src/app/common/templates/config-data.yaml b/src/app/common/templates/config-data.yaml index 53ca4e9525ebe7..72e548842d72ca 100644 --- a/src/app/common/templates/config-data.yaml +++ b/src/app/common/templates/config-data.yaml @@ -50,6 +50,7 @@ CommandHandlerInterfaceOnlyClusters: - Water Heater Management - Water Heater Mode - General Commissioning + - General Diagnostics - Software Diagnostics # We need a more configurable way of deciding which clusters have which init functions.... diff --git a/src/app/zap-templates/templates/app/gen_config.zapt b/src/app/zap-templates/templates/app/gen_config.zapt index 87dce18a6673b1..a7bcee23cc3889 100644 --- a/src/app/zap-templates/templates/app/gen_config.zapt +++ b/src/app/zap-templates/templates/app/gen_config.zapt @@ -63,3 +63,14 @@ {{/if}} {{/all_user_clusters}} + +/**** Cluster Commands Flag ****/ +{{#all_user_clusters_with_incoming_commands}} + {{#if (isServer clusterSide)}} + // {{asUpperCamelCase clusterName}} Cluster Commands + {{#all_incoming_commands_for_cluster clusterName clusterSide}} +#define {{as_delimited_macro clusterName}}_ENABLE_{{as_delimited_macro commandName}}_CMD 1 + {{/all_incoming_commands_for_cluster}} + + {{/if}} +{{/all_user_clusters_with_incoming_commands}} diff --git a/zzz_generated/app-common/app-common/zap-generated/callback.h b/zzz_generated/app-common/app-common/zap-generated/callback.h index e9015c7c45589b..871d52be3f0aec 100644 --- a/zzz_generated/app-common/app-common/zap-generated/callback.h +++ b/zzz_generated/app-common/app-common/zap-generated/callback.h @@ -5958,24 +5958,6 @@ bool emberAfOtaSoftwareUpdateRequestorClusterAnnounceOTAProviderCallback( bool emberAfDiagnosticLogsClusterRetrieveLogsRequestCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::DiagnosticLogs::Commands::RetrieveLogsRequest::DecodableType & commandData); -/** - * @brief General Diagnostics Cluster TestEventTrigger Command callback (from client) - */ -bool emberAfGeneralDiagnosticsClusterTestEventTriggerCallback( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::GeneralDiagnostics::Commands::TestEventTrigger::DecodableType & commandData); -/** - * @brief General Diagnostics Cluster TimeSnapshot Command callback (from client) - */ -bool emberAfGeneralDiagnosticsClusterTimeSnapshotCallback( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::GeneralDiagnostics::Commands::TimeSnapshot::DecodableType & commandData); -/** - * @brief General Diagnostics Cluster PayloadTestRequest Command callback (from client) - */ -bool emberAfGeneralDiagnosticsClusterPayloadTestRequestCallback( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::GeneralDiagnostics::Commands::PayloadTestRequest::DecodableType & commandData); /** * @brief Thread Network Diagnostics Cluster ResetCounts Command callback (from client) */