Skip to content

Commit

Permalink
[TestCluster] Add some commands for complex types (#10609)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and pull[bot] committed Oct 19, 2021
1 parent 8e4e8a5 commit 82a7dd6
Show file tree
Hide file tree
Showing 11 changed files with 746 additions and 2 deletions.
48 changes: 48 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -14220,6 +14220,54 @@
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "TestStructArgumentRequest",
"code": 7,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "TestNestedStructArgumentRequest",
"code": 8,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "TestListStructArgumentRequest",
"code": 9,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "TestListInt8UArgumentRequest",
"code": 10,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "TestNestedStructListgumentRequest",
"code": 11,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "TestListNestedStructListInt8UArgumentRequest",
"code": 12,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
}
],
"attributes": [
Expand Down
118 changes: 118 additions & 0 deletions src/app/clusters/test-cluster-server/test-cluster-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <lib/core/CHIPSafeCasts.h>
#include <lib/core/CHIPTLV.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

Expand Down Expand Up @@ -269,6 +270,123 @@ bool emberAfTestClusterClusterTestAddArgumentsCallback(CommandHandler * apComman
return true;
}

bool emberAfTestClusterClusterTestStructArgumentRequestCallback(
app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::TestStructArgumentRequest::DecodableType & commandData)
{
emberAfSendImmediateDefaultResponse(commandData.arg1.b ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
}

bool emberAfTestClusterClusterTestNestedStructArgumentRequestCallback(
app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::TestNestedStructArgumentRequest::DecodableType & commandData)
{
emberAfSendImmediateDefaultResponse(commandData.arg1.c.b ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
}

bool emberAfTestClusterClusterTestListStructArgumentRequestCallback(
app::CommandHandler * commandObj, app::ConcreteCommandPath const & commandPath,
Commands::TestListStructArgumentRequest::DecodableType const & commandData)
{
bool shouldReturnTrue = true;

auto structIterator = commandData.arg1.begin();
while (structIterator.Next())
{
auto & structValue = structIterator.GetValue();
shouldReturnTrue = shouldReturnTrue && structValue.b;
}

if (CHIP_NO_ERROR != structIterator.GetStatus())
{
shouldReturnTrue = false;
}

emberAfSendImmediateDefaultResponse(shouldReturnTrue ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
}

bool emberAfTestClusterClusterTestListInt8UArgumentRequestCallback(
app::CommandHandler * commandObj, app::ConcreteCommandPath const & commandPath,
Commands::TestListInt8UArgumentRequest::DecodableType const & commandData)
{
bool shouldReturnTrue = true;

auto uint8Iterator = commandData.arg1.begin();
while (uint8Iterator.Next())
{
auto & value = uint8Iterator.GetValue();
shouldReturnTrue = shouldReturnTrue && (value != 0);
}

if (CHIP_NO_ERROR != uint8Iterator.GetStatus())
{
shouldReturnTrue = false;
}

emberAfSendImmediateDefaultResponse(shouldReturnTrue ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
}

bool emberAfTestClusterClusterTestNestedStructListArgumentRequestCallback(
app::CommandHandler * commandObj, app::ConcreteCommandPath const & commandPath,
Commands::TestNestedStructListArgumentRequest::DecodableType const & commandData)
{
bool shouldReturnTrue = commandData.arg1.c.b;

auto structIterator = commandData.arg1.d.begin();
while (structIterator.Next())
{
auto & structValue = structIterator.GetValue();
shouldReturnTrue = shouldReturnTrue && structValue.b;
}

if (CHIP_NO_ERROR != structIterator.GetStatus())
{
shouldReturnTrue = false;
}

emberAfSendImmediateDefaultResponse(shouldReturnTrue ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
}

bool emberAfTestClusterClusterTestListNestedStructListArgumentRequestCallback(
app::CommandHandler * commandObj, app::ConcreteCommandPath const & commandPath,
Commands::TestListNestedStructListArgumentRequest::DecodableType const & commandData)
{
bool shouldReturnTrue = true;

auto structIterator = commandData.arg1.begin();
while (structIterator.Next())
{
auto & structValue = structIterator.GetValue();
shouldReturnTrue = shouldReturnTrue && structValue.c.b;

auto subStructIterator = structValue.d.begin();
while (subStructIterator.Next())
{
auto & subStructValue = subStructIterator.GetValue();
shouldReturnTrue = shouldReturnTrue && subStructValue.b;
}

if (CHIP_NO_ERROR != subStructIterator.GetStatus())
{
shouldReturnTrue = false;
break;
}
}

if (CHIP_NO_ERROR != structIterator.GetStatus())
{
shouldReturnTrue = false;
}

emberAfSendImmediateDefaultResponse(shouldReturnTrue ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
}

// -----------------------------------------------------------------------------
// Plugin initialization

Expand Down
2 changes: 1 addition & 1 deletion src/app/zap-templates/templates/app/callback.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void emberAf{{asUpperCamelCase label}}ClusterClientTickCallback(chip::EndpointId
{{#if (isServer source)}}
bool emberAf{{asUpperCamelCase parent.label}}Cluster{{asUpperCamelCase name}}Callback(chip::EndpointId endpoint,
chip::app::CommandSender * commandObj
{{#zcl_command_arguments}}, {{asUnderlyingZclType type}} {{asSymbol label}}{{/zcl_command_arguments}});
{{#zcl_command_arguments}}, {{#if isArray}}{{asUnderlyingZclType type}}{{else}}{{#if_is_struct type}}{{zapTypeToDecodableClusterObjectType type ns=parent.parent.label}}{{else}}{{asUnderlyingZclType type}}{{/if_is_struct}}{{/if}} {{asSymbol label}}{{/zcl_command_arguments}});
{{else}}
bool emberAf{{asUpperCamelCase parent.label}}Cluster{{asUpperCamelCase name}}Callback(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath,
Expand Down
70 changes: 70 additions & 0 deletions src/app/zap-templates/zcl/data-model/chip/test-cluster.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,76 @@ limitations under the License.
<arg name="arg6" type="BOOLEAN"/>
</command>

<!--
This command expect a success response if:
* 'b' field of arg1 is true
-->
<command source="client" code="0x07" name="TestStructArgumentRequest" optional="false">
<description>
Command that takes an argument which is struct
</description>
<arg name="arg1" type="SimpleStruct"/>
</command>

<!--
This command expect a success response if:
* 'b' field of arg1.c is true
-->
<command source="client" code="0x08" name="TestNestedStructArgumentRequest" optional="false">
<description>
Command that takes an argument which is nested struct
</description>
<arg name="arg1" type="NestedStruct"/>
</command>

<!--
This command expect a success response if either of the following is true:
* arg1 is an empty list
* the field 'b' of all the SimpleStruct contained in arg1 are true
-->
<command source="client" code="0x09" name="TestListStructArgumentRequest" optional="false">
<description>
Command that takes an argument which is a list of struct
</description>
<arg name="arg1" type="SimpleStruct" array="true"/>
</command>

<!--
This command expect a success response if either of the following is true:
* arg1 is an empty list
* no element is 0
-->
<command source="client" code="0x0A" name="TestListInt8UArgumentRequest" optional="false">
<description>
Command that takes an argument which is a list of INT8U
</description>
<arg name="arg1" type="INT8U" array="true"/>
</command>

<!--
This command expect a success response if either of the following is true:
* arg1.d is an empty list
* the field 'b' of all the SimpleStruct contained in arg1 are true
-->
<command source="client" code="0x0B" name="TestNestedStructListArgumentRequest" optional="false">
<description>
Command that takes an argument which is a Nested Struct List
</description>
<arg name="arg1" type="NestedStructList"/>
</command>

<!--
This command expect a success response if either of the following is true:
* arg1 is an empty list
* the field 'b' of all the SimpleStruct contained in arg1 are true
-->
<command source="client" code="0x0C" name="TestListNestedStructListArgumentRequest" optional="false">
<description>
Command that takes an argument which is a list of Nested Struct List
</description>
<arg name="arg1" type="NestedStructList" array="true"/>
</command>

<command source="server" code="0x00" name="TestSpecificResponse" optional="false" disableDefaultResponse="true">
<description>
Simple response for TestWithResponse with a simple return value
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 82a7dd6

Please sign in to comment.