From 184451442ee12a229a47a2e9e6434d160e92db34 Mon Sep 17 00:00:00 2001 From: Song Guo Date: Thu, 3 Jun 2021 03:35:30 +0800 Subject: [PATCH] [cluster] Add TestUnknownCommand command to test cluster[TE3] (#7269) * [zap] Add TestUnknownCommand * Run Codegen --- .../chip-tool/commands/clusters/Commands.h | 31 +++++++++++++++ src/app/common/gen/client-command-macro.h | 9 +++++ src/app/common/gen/command-id.h | 1 + src/app/zap-templates/zcl/test-cluster.xml | 6 +++ .../data_model/controller-clusters.zap | 8 ++++ .../data_model/gen/CHIPClusters.cpp | 39 +++++++++++++++++++ src/controller/data_model/gen/CHIPClusters.h | 8 ++-- .../data_model/gen/chip-zcl-zpro-codec-api.h | 1 + src/controller/data_model/gen/encoder.cpp | 2 + .../data_model/gen/endpoint_config.h | 3 +- .../python/chip/clusters/CHIPClusters.cpp | 8 ++++ .../python/chip/clusters/CHIPClusters.py | 9 +++++ .../Framework/CHIP/gen/CHIPClustersObjc.h | 1 + .../Framework/CHIP/gen/CHIPClustersObjc.mm | 26 +++++++++++++ 14 files changed, 148 insertions(+), 4 deletions(-) diff --git a/examples/chip-tool/commands/clusters/Commands.h b/examples/chip-tool/commands/clusters/Commands.h index 4a4c5d642e9fde..1b58c7ec17c2ee 100644 --- a/examples/chip-tool/commands/clusters/Commands.h +++ b/examples/chip-tool/commands/clusters/Commands.h @@ -14640,6 +14640,7 @@ class ReadTemperatureMeasurementClusterRevision : public ModelCommand | * Test | 0x00 | | * TestNotHandled | 0x01 | | * TestSpecific | 0x02 | +| * TestUnknownCommand | 0x03 | |------------------------------------------------------------------------------| | Attributes: | | | * Boolean | 0x0000 | @@ -14752,6 +14753,35 @@ class TestClusterTestSpecific : public ModelCommand new chip::Callback::Callback(OnDefaultFailureResponse, this); }; +/* + * Command TestUnknownCommand + */ +class TestClusterTestUnknownCommand : public ModelCommand +{ +public: + TestClusterTestUnknownCommand() : ModelCommand("test-unknown-command") { ModelCommand::AddArguments(); } + ~TestClusterTestUnknownCommand() + { + delete onSuccessCallback; + delete onFailureCallback; + } + + CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override + { + ChipLogProgress(chipTool, "Sending cluster (0x050F) command (0x03) on endpoint %" PRIu16, endpointId); + + chip::Controller::TestClusterCluster cluster; + cluster.Associate(device, endpointId); + return cluster.TestUnknownCommand(onSuccessCallback->Cancel(), onFailureCallback->Cancel()); + } + +private: + chip::Callback::Callback * onSuccessCallback = + new chip::Callback::Callback(OnDefaultSuccessResponse, this); + chip::Callback::Callback * onFailureCallback = + new chip::Callback::Callback(OnDefaultFailureResponse, this); +}; + /* * Discover Attributes */ @@ -18334,6 +18364,7 @@ void registerClusterTestCluster(Commands & commands) make_unique(), make_unique(), make_unique(), + make_unique(), make_unique(), make_unique(), make_unique(), diff --git a/src/app/common/gen/client-command-macro.h b/src/app/common/gen/client-command-macro.h index 39b8915795fec2..b7339b73764862 100644 --- a/src/app/common/gen/client-command-macro.h +++ b/src/app/common/gen/client-command-macro.h @@ -6067,6 +6067,15 @@ \ ZCL_TEST_SPECIFIC_COMMAND_ID, "", ); +/** @brief Command description for TestUnknownCommand + * + * Command: TestUnknownCommand + */ +#define emberAfFillCommandTest \ + ClusterClusterTestUnknownCommand() emberAfFillExternalBuffer(mask, \ + \ + ZCL_TEST_UNKNOWN_COMMAND_COMMAND_ID, "", ); + /** @brief Command description for MatchProtocolAddress * * Command: MatchProtocolAddress diff --git a/src/app/common/gen/command-id.h b/src/app/common/gen/command-id.h index ca68b3024d0e1f..4ff012d5a835a0 100644 --- a/src/app/common/gen/command-id.h +++ b/src/app/common/gen/command-id.h @@ -502,6 +502,7 @@ #define ZCL_TEST_SPECIFIC_RESPONSE_COMMAND_ID (0x00) #define ZCL_TEST_NOT_HANDLED_COMMAND_ID (0x01) #define ZCL_TEST_SPECIFIC_COMMAND_ID (0x02) +#define ZCL_TEST_UNKNOWN_COMMAND_COMMAND_ID (0x03) // Commands for cluster: Generic Tunnel #define ZCL_MATCH_PROTOCOL_ADDRESS_COMMAND_ID (0x00) diff --git a/src/app/zap-templates/zcl/test-cluster.xml b/src/app/zap-templates/zcl/test-cluster.xml index d600403eef301c..61241589090e60 100644 --- a/src/app/zap-templates/zcl/test-cluster.xml +++ b/src/app/zap-templates/zcl/test-cluster.xml @@ -73,6 +73,12 @@ limitations under the License. + + + Simple command that should not be added to the server. + + + Simple response for TestWithResponse with a simple return value diff --git a/src/controller/data_model/controller-clusters.zap b/src/controller/data_model/controller-clusters.zap index 5be7a14a4d89e2..db3fd4beca331f 100644 --- a/src/controller/data_model/controller-clusters.zap +++ b/src/controller/data_model/controller-clusters.zap @@ -6775,6 +6775,14 @@ "source": "client", "incoming": 0, "outgoing": 1 + }, + { + "name": "TestUnknownCommand", + "code": 3, + "mfgCode": null, + "source": "client", + "incoming": 0, + "outgoing": 1 } ], "attributes": [ diff --git a/src/controller/data_model/gen/CHIPClusters.cpp b/src/controller/data_model/gen/CHIPClusters.cpp index 819db69166cb08..5ff7d8ebfc6b55 100644 --- a/src/controller/data_model/gen/CHIPClusters.cpp +++ b/src/controller/data_model/gen/CHIPClusters.cpp @@ -7358,6 +7358,45 @@ CHIP_ERROR TestClusterCluster::TestSpecific(Callback::Cancelable * onSuccessCall return err; } +CHIP_ERROR TestClusterCluster::TestUnknownCommand(Callback::Cancelable * onSuccessCallback, + Callback::Cancelable * onFailureCallback) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + app::CommandSender * sender = nullptr; + TLV::TLVWriter * writer = nullptr; + uint8_t argSeqNumber = 0; + + // Used when encoding non-empty command. Suppress error message when encoding empty commands. + (void) writer; + (void) argSeqNumber; + + VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE); + + app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kTestUnknownCommandCommandId, + (chip::app::CommandPathFlags::kEndpointIdValid) }; + + SuccessOrExit(err = chip::app::InteractionModelEngine::GetInstance()->NewCommandSender(&sender)); + + SuccessOrExit(err = sender->PrepareCommand(&cmdParams)); + + // Command takes no arguments. + + SuccessOrExit(err = sender->FinishCommand()); + + // #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate. + mDevice->AddIMResponseHandler(sender, onSuccessCallback, onFailureCallback); + + err = mDevice->SendCommands(sender); + +exit: + // On error, we are responsible to close the sender. + if (err != CHIP_NO_ERROR && sender != nullptr) + { + sender->Shutdown(); + } + return err; +} + // TestCluster Cluster Attributes CHIP_ERROR TestClusterCluster::DiscoverAttributes(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback) diff --git a/src/controller/data_model/gen/CHIPClusters.h b/src/controller/data_model/gen/CHIPClusters.h index ca3672fdc25636..813e1f31a4ae06 100644 --- a/src/controller/data_model/gen/CHIPClusters.h +++ b/src/controller/data_model/gen/CHIPClusters.h @@ -1143,6 +1143,7 @@ class DLL_EXPORT TestClusterCluster : public ClusterBase CHIP_ERROR Test(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback); CHIP_ERROR TestNotHandled(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback); CHIP_ERROR TestSpecific(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback); + CHIP_ERROR TestUnknownCommand(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback); // Cluster Attributes CHIP_ERROR DiscoverAttributes(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback); @@ -1201,9 +1202,10 @@ class DLL_EXPORT TestClusterCluster : public ClusterBase chip::ByteSpan value); private: - static constexpr CommandId kTestCommandId = 0x00; - static constexpr CommandId kTestNotHandledCommandId = 0x01; - static constexpr CommandId kTestSpecificCommandId = 0x02; + static constexpr CommandId kTestCommandId = 0x00; + static constexpr CommandId kTestNotHandledCommandId = 0x01; + static constexpr CommandId kTestSpecificCommandId = 0x02; + static constexpr CommandId kTestUnknownCommandCommandId = 0x03; }; class DLL_EXPORT ThermostatCluster : public ClusterBase diff --git a/src/controller/data_model/gen/chip-zcl-zpro-codec-api.h b/src/controller/data_model/gen/chip-zcl-zpro-codec-api.h index 767be3eecfd859..fd9e0610fd635b 100644 --- a/src/controller/data_model/gen/chip-zcl-zpro-codec-api.h +++ b/src/controller/data_model/gen/chip-zcl-zpro-codec-api.h @@ -2478,6 +2478,7 @@ encodeTemperatureMeasurementClusterReadClusterRevisionAttribute(uint8_t seqNum, | * Test | 0x00 | | * TestNotHandled | 0x01 | | * TestSpecific | 0x02 | +| * TestUnknownCommand | 0x03 | |------------------------------------------------------------------------------| | Attributes: | | | * Boolean | 0x0000 | diff --git a/src/controller/data_model/gen/encoder.cpp b/src/controller/data_model/gen/encoder.cpp index 1efa6838c8775f..f2b51b8162b9d6 100644 --- a/src/controller/data_model/gen/encoder.cpp +++ b/src/controller/data_model/gen/encoder.cpp @@ -315,6 +315,7 @@ using namespace chip::Encoding::LittleEndian; #define ZCL_TEST_COMMAND_ID (0x00) #define ZCL_TEST_NOT_HANDLED_COMMAND_ID (0x01) #define ZCL_TEST_SPECIFIC_COMMAND_ID (0x02) +#define ZCL_TEST_UNKNOWN_COMMAND_COMMAND_ID (0x03) #define THERMOSTAT_CLUSTER_ID 0x0201 #define ZCL_CLEAR_WEEKLY_SCHEDULE_COMMAND_ID (0x03) @@ -3602,6 +3603,7 @@ PacketBufferHandle encodeTemperatureMeasurementClusterReadClusterRevisionAttribu | * Test | 0x00 | | * TestNotHandled | 0x01 | | * TestSpecific | 0x02 | +| * TestUnknownCommand | 0x03 | |------------------------------------------------------------------------------| | Attributes: | | | * Boolean | 0x0000 | diff --git a/src/controller/data_model/gen/endpoint_config.h b/src/controller/data_model/gen/endpoint_config.h index faf9da2b254532..b8cdc594acdad4 100644 --- a/src/controller/data_model/gen/endpoint_config.h +++ b/src/controller/data_model/gen/endpoint_config.h @@ -375,7 +375,7 @@ // Array of EmberAfCommandMetadata structs. #define ZAP_COMMAND_MASK(mask) COMMAND_MASK_##mask -#define EMBER_AF_GENERATED_COMMAND_COUNT (211) +#define EMBER_AF_GENERATED_COMMAND_COUNT (212) #define GENERATED_COMMANDS \ { \ \ @@ -656,6 +656,7 @@ { 0x050F, 0x00, ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* TestSpecificResponse */ \ { 0x050F, 0x01, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* TestNotHandled */ \ { 0x050F, 0x02, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* TestSpecific */ \ + { 0x050F, 0x03, ZAP_COMMAND_MASK(OUTGOING_CLIENT) }, /* TestUnknownCommand */ \ \ /* Endpoint: 1, Cluster: Binding (client) */ \ { 0xF000, 0x00, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* Bind */ \ diff --git a/src/controller/python/chip/clusters/CHIPClusters.cpp b/src/controller/python/chip/clusters/CHIPClusters.cpp index 6914fd07e6b0c9..24195432f7082b 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.cpp +++ b/src/controller/python/chip/clusters/CHIPClusters.cpp @@ -2951,6 +2951,14 @@ CHIP_ERROR chip_ime_AppendCommand_TestCluster_TestSpecific(chip::Controller::Dev cluster.Associate(device, ZCLendpointId); return cluster.TestSpecific(nullptr, nullptr); } +CHIP_ERROR chip_ime_AppendCommand_TestCluster_TestUnknownCommand(chip::Controller::Device * device, chip::EndpointId ZCLendpointId, + chip::GroupId) +{ + VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + chip::Controller::TestClusterCluster cluster; + cluster.Associate(device, ZCLendpointId); + return cluster.TestUnknownCommand(nullptr, nullptr); +} CHIP_ERROR chip_ime_ReadAttribute_TestCluster_Boolean(chip::Controller::Device * device, chip::EndpointId ZCLendpointId, chip::GroupId /* ZCLgroupId */) diff --git a/src/controller/python/chip/clusters/CHIPClusters.py b/src/controller/python/chip/clusters/CHIPClusters.py index a003377fc92b8d..a75b9cabc1c8f7 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.py +++ b/src/controller/python/chip/clusters/CHIPClusters.py @@ -588,6 +588,8 @@ def ListClusterCommands(self): }, "TestSpecific": { }, + "TestUnknownCommand": { + }, }, "Thermostat": { "ClearWeeklySchedule": { @@ -1453,6 +1455,10 @@ def ClusterTestCluster_CommandTestSpecific(self, device: ctypes.c_void_p, ZCLend return self._chipLib.chip_ime_AppendCommand_TestCluster_TestSpecific( device, ZCLendpoint, ZCLgroupid ) + def ClusterTestCluster_CommandTestUnknownCommand(self, device: ctypes.c_void_p, ZCLendpoint: int, ZCLgroupid: int): + return self._chipLib.chip_ime_AppendCommand_TestCluster_TestUnknownCommand( + device, ZCLendpoint, ZCLgroupid + ) def ClusterThermostat_CommandClearWeeklySchedule(self, device: ctypes.c_void_p, ZCLendpoint: int, ZCLgroupid: int): return self._chipLib.chip_ime_AppendCommand_Thermostat_ClearWeeklySchedule( device, ZCLendpoint, ZCLgroupid @@ -2913,6 +2919,9 @@ def InitLib(self, chipLib): # Cluster TestCluster Command TestSpecific self._chipLib.chip_ime_AppendCommand_TestCluster_TestSpecific.argtypes = [ctypes.c_void_p, ctypes.c_uint8, ctypes.c_uint16] self._chipLib.chip_ime_AppendCommand_TestCluster_TestSpecific.restype = ctypes.c_uint32 + # Cluster TestCluster Command TestUnknownCommand + self._chipLib.chip_ime_AppendCommand_TestCluster_TestUnknownCommand.argtypes = [ctypes.c_void_p, ctypes.c_uint8, ctypes.c_uint16] + self._chipLib.chip_ime_AppendCommand_TestCluster_TestUnknownCommand.restype = ctypes.c_uint32 # Cluster TestCluster ReadAttribute Boolean self._chipLib.chip_ime_ReadAttribute_TestCluster_Boolean.argtypes = [ctypes.c_void_p, ctypes.c_uint8, ctypes.c_uint16] self._chipLib.chip_ime_ReadAttribute_TestCluster_Boolean.restype = ctypes.c_uint32 diff --git a/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.h b/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.h index eb1be7abc986fe..ea5b258d783344 100644 --- a/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.h +++ b/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.h @@ -957,6 +957,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)test:(ResponseHandler)responseHandler; - (void)testNotHandled:(ResponseHandler)responseHandler; - (void)testSpecific:(ResponseHandler)responseHandler; +- (void)testUnknownCommand:(ResponseHandler)responseHandler; - (void)readAttributeBooleanWithResponseHandler:(ResponseHandler)responseHandler; - (void)writeAttributeBooleanWithValue:(uint8_t)value responseHandler:(ResponseHandler)responseHandler; diff --git a/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm b/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm index 160f92db100c72..f67f097105af8f 100644 --- a/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm +++ b/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm @@ -13587,6 +13587,32 @@ - (void)testSpecific:(ResponseHandler)responseHandler responseHandler([CHIPError errorForCHIPErrorCode:err], nil); } } +- (void)testUnknownCommand:(ResponseHandler)responseHandler +{ + CHIPDefaultSuccessCallbackBridge * onSuccess = new CHIPDefaultSuccessCallbackBridge(responseHandler, [self callbackQueue]); + if (!onSuccess) { + responseHandler([CHIPError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE], nil); + return; + } + + CHIPDefaultFailureCallbackBridge * onFailure = new CHIPDefaultFailureCallbackBridge(responseHandler, [self callbackQueue]); + if (!onFailure) { + delete onSuccess; + responseHandler([CHIPError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE], nil); + return; + } + + __block CHIP_ERROR err; + dispatch_sync([self chipWorkQueue], ^{ + err = self.cppCluster.TestUnknownCommand(onSuccess->Cancel(), onFailure->Cancel()); + }); + + if (err != CHIP_NO_ERROR) { + delete onSuccess; + delete onFailure; + responseHandler([CHIPError errorForCHIPErrorCode:err], nil); + } +} - (void)readAttributeBooleanWithResponseHandler:(ResponseHandler)responseHandler {