Skip to content

Commit

Permalink
[cluster] Add TestUnknownCommand command to test cluster[TE3] (#7269)
Browse files Browse the repository at this point in the history
* [zap] Add TestUnknownCommand

* Run Codegen
  • Loading branch information
erjiaqing authored and pull[bot] committed Jul 30, 2021
1 parent f8f962e commit 1844514
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 4 deletions.
31 changes: 31 additions & 0 deletions examples/chip-tool/commands/clusters/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -14640,6 +14640,7 @@ class ReadTemperatureMeasurementClusterRevision : public ModelCommand
| * Test | 0x00 |
| * TestNotHandled | 0x01 |
| * TestSpecific | 0x02 |
| * TestUnknownCommand | 0x03 |
|------------------------------------------------------------------------------|
| Attributes: | |
| * Boolean | 0x0000 |
Expand Down Expand Up @@ -14752,6 +14753,35 @@ class TestClusterTestSpecific : public ModelCommand
new chip::Callback::Callback<DefaultFailureCallback>(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<DefaultSuccessCallback> * onSuccessCallback =
new chip::Callback::Callback<DefaultSuccessCallback>(OnDefaultSuccessResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback =
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

/*
* Discover Attributes
*/
Expand Down Expand Up @@ -18334,6 +18364,7 @@ void registerClusterTestCluster(Commands & commands)
make_unique<TestClusterTest>(),
make_unique<TestClusterTestNotHandled>(),
make_unique<TestClusterTestSpecific>(),
make_unique<TestClusterTestUnknownCommand>(),
make_unique<DiscoverTestClusterAttributes>(),
make_unique<ReadTestClusterBoolean>(),
make_unique<WriteTestClusterBoolean>(),
Expand Down
9 changes: 9 additions & 0 deletions src/app/common/gen/client-command-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/app/common/gen/command-id.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/app/zap-templates/zcl/test-cluster.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ limitations under the License.
</description>
</command>

<command source="client" code="0x03" name="TestUnknownCommand" optional="true">
<description>
Simple command that should not be added to the server.
</description>
</command>

<command source="server" code="0x00" name="TestSpecificResponse" optional="false" disableDefaultResponse="true">
<description>
Simple response for TestWithResponse with a simple return value
Expand Down
8 changes: 8 additions & 0 deletions src/controller/data_model/controller-clusters.zap
Original file line number Diff line number Diff line change
Expand Up @@ -6775,6 +6775,14 @@
"source": "client",
"incoming": 0,
"outgoing": 1
},
{
"name": "TestUnknownCommand",
"code": 3,
"mfgCode": null,
"source": "client",
"incoming": 0,
"outgoing": 1
}
],
"attributes": [
Expand Down
39 changes: 39 additions & 0 deletions src/controller/data_model/gen/CHIPClusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/controller/data_model/gen/CHIPClusters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/controller/data_model/gen/chip-zcl-zpro-codec-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,7 @@ encodeTemperatureMeasurementClusterReadClusterRevisionAttribute(uint8_t seqNum,
| * Test | 0x00 |
| * TestNotHandled | 0x01 |
| * TestSpecific | 0x02 |
| * TestUnknownCommand | 0x03 |
|------------------------------------------------------------------------------|
| Attributes: | |
| * Boolean | 0x0000 |
Expand Down
2 changes: 2 additions & 0 deletions src/controller/data_model/gen/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -3602,6 +3603,7 @@ PacketBufferHandle encodeTemperatureMeasurementClusterReadClusterRevisionAttribu
| * Test | 0x00 |
| * TestNotHandled | 0x01 |
| * TestSpecific | 0x02 |
| * TestUnknownCommand | 0x03 |
|------------------------------------------------------------------------------|
| Attributes: | |
| * Boolean | 0x0000 |
Expand Down
3 changes: 2 additions & 1 deletion src/controller/data_model/gen/endpoint_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
{ \
\
Expand Down Expand Up @@ -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 */ \
Expand Down
8 changes: 8 additions & 0 deletions src/controller/python/chip/clusters/CHIPClusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */)
Expand Down
9 changes: 9 additions & 0 deletions src/controller/python/chip/clusters/CHIPClusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ def ListClusterCommands(self):
},
"TestSpecific": {
},
"TestUnknownCommand": {
},
},
"Thermostat": {
"ClearWeeklySchedule": {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/gen/CHIPClustersObjc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 1844514

Please sign in to comment.