From aa4250becf9b5a4e0069601afde813276c556120 Mon Sep 17 00:00:00 2001 From: Pradip De Date: Tue, 18 Jun 2024 17:43:30 -0700 Subject: [PATCH] Add a String Echo Request and Echo Response Command to the Unit testing cluster The Command Request takes a string as argument that is echoed back in the Command response. The string can be large to enable Command testing for large payloads over a TCP-based session. Example ChipTool invocation: ./chip-tool unittesting string-echo-request "aaaaaaaaaaaaa" ./chip-tool unittesting string-echo-request "aaaaaaa...aaaaaa" --allow-large-payload true --- .../all-clusters-app.matter | 14 ++ .../all-clusters-common/all-clusters-app.zap | 16 ++ .../all-clusters-minimal-app.matter | 14 ++ .../all-clusters-minimal-app.zap | 16 ++ .../rootnode_contactsensor_27f76aeaf5.matter | 12 ++ .../test-cluster-server.cpp | 10 ++ src/app/tests/suites/TestCluster.yaml | 3 +- .../suites/TestUnitTestingClusterMei.yaml | 2 +- .../zcl/data-model/chip/test-cluster.xml | 17 ++ .../data_model/controller-clusters.matter | 12 ++ .../chip/devicecontroller/ChipClusters.java | 34 ++++ .../devicecontroller/ClusterIDMapping.java | 18 ++ .../devicecontroller/ClusterInfoMapping.java | 40 +++++ .../cluster/clusters/UnitTestingCluster.kt | 49 ++++++ .../python/chip/clusters/CHIPClusters.py | 7 + .../python/chip/clusters/Objects.py | 32 ++++ .../CHIP/zap-generated/MTRBaseClusters.h | 8 + .../CHIP/zap-generated/MTRBaseClusters.mm | 24 +++ .../CHIP/zap-generated/MTRClusterConstants.h | 2 + .../CHIP/zap-generated/MTRClusters.h | 1 + .../CHIP/zap-generated/MTRClusters.mm | 27 +++ .../zap-generated/MTRCommandPayloadsObjc.h | 49 ++++++ .../zap-generated/MTRCommandPayloadsObjc.mm | 158 ++++++++++++++++++ .../MTRCommandPayloads_Internal.h | 12 ++ .../app-common/zap-generated/callback.h | 6 + .../zap-generated/cluster-objects.cpp | 68 ++++++++ .../zap-generated/cluster-objects.h | 74 ++++++++ .../app-common/zap-generated/ids/Commands.h | 8 + .../zap-generated/cluster/Commands.h | 40 +++++ .../cluster/logging/DataModelLogger.cpp | 13 ++ .../cluster/logging/DataModelLogger.h | 2 + .../zap-generated/cluster/Commands.h | 63 +++++++ 32 files changed, 849 insertions(+), 2 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index 5400a81d0fb902..13fc057dd62f40 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -7034,6 +7034,10 @@ internal cluster UnitTesting = 4294048773 { int8u arg1[] = 0; } + response struct StringEchoResponse = 13 { + octet_string payload = 0; + } + request struct TestEnumsRequestRequest { vendor_id arg1 = 0; SimpleEnum arg2 = 1; @@ -7088,6 +7092,10 @@ internal cluster UnitTesting = 4294048773 { int8u fillCharacter = 2; } + request struct StringEchoRequestRequest { + octet_string payload = 0; + } + request struct TestDifferentVendorMeiRequestRequest { int8u arg1 = 0; } @@ -7167,6 +7175,10 @@ internal cluster UnitTesting = 4294048773 { command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22; /** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */ command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23; + /** Command that takes an argument which is an octet string. The response echoes + the string back. If the string is large then it would require a session that + supports large payloads. */ + command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24; /** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */ command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962; } @@ -9082,6 +9094,7 @@ endpoint 1 { handle command TestEmitTestFabricScopedEventResponse; handle command TestListNestedStructListArgumentRequest; handle command TestListInt8UReverseRequest; + handle command StringEchoResponse; handle command TestEnumsRequest; handle command TestNullableOptionalRequest; handle command SimpleStructEchoRequest; @@ -9091,6 +9104,7 @@ endpoint 1 { handle command TestEmitTestFabricScopedEventRequest; handle command TestBatchHelperRequest; handle command TestSecondBatchHelperRequest; + handle command StringEchoRequest; handle command TestDifferentVendorMeiRequest; handle command TestDifferentVendorMeiResponse; } diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index f0afbd78296bd2..c547030731c6cf 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -21987,6 +21987,22 @@ "source": "server", "isIncoming": 0, "isEnabled": 1 + }, + { + "name": "StringEchoRequest", + "code": 24, + "mfgCode": null, + "source": "client", + "isIncoming": 1, + "isEnabled": 1 + }, + { + "name": "StringEchoResponse", + "code": 13, + "mfgCode": null, + "source": "server", + "isIncoming": 0, + "isEnabled": 1 } ], "attributes": [ diff --git a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter index 962eed946b905a..303c1af63edbfa 100644 --- a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter +++ b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter @@ -5736,6 +5736,10 @@ internal cluster UnitTesting = 4294048773 { int8u arg1[] = 0; } + response struct StringEchoResponse = 13 { + octet_string payload = 0; + } + request struct TestEnumsRequestRequest { vendor_id arg1 = 0; SimpleEnum arg2 = 1; @@ -5790,6 +5794,10 @@ internal cluster UnitTesting = 4294048773 { int8u fillCharacter = 2; } + request struct StringEchoRequestRequest { + octet_string payload = 0; + } + request struct TestDifferentVendorMeiRequestRequest { int8u arg1 = 0; } @@ -5869,6 +5877,10 @@ internal cluster UnitTesting = 4294048773 { command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22; /** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */ command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23; + /** Command that takes an argument which is an octet string. The response echoes + the string back. If the string is large then it would require a session that + supports large payloads. */ + command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24; /** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */ command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962; } @@ -6786,6 +6798,7 @@ endpoint 1 { handle command TestEmitTestFabricScopedEventResponse; handle command TestListNestedStructListArgumentRequest; handle command TestListInt8UReverseRequest; + handle command StringEchoResponse; handle command TestEnumsRequest; handle command TestNullableOptionalRequest; handle command SimpleStructEchoRequest; @@ -6795,6 +6808,7 @@ endpoint 1 { handle command TestEmitTestFabricScopedEventRequest; handle command TestBatchHelperRequest; handle command TestSecondBatchHelperRequest; + handle command StringEchoRequest; handle command TestDifferentVendorMeiRequest; handle command TestDifferentVendorMeiResponse; } diff --git a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.zap b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.zap index 9e4c4ac08b252b..0f9b7495212b56 100644 --- a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.zap +++ b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.zap @@ -9136,6 +9136,22 @@ "source": "server", "isIncoming": 0, "isEnabled": 1 + }, + { + "name": "StringEchoRequest", + "code": 24, + "mfgCode": null, + "source": "client", + "isIncoming": 1, + "isEnabled": 1 + }, + { + "name": "StringEchoResponse", + "code": 13, + "mfgCode": null, + "source": "server", + "isIncoming": 0, + "isEnabled": 1 } ], "attributes": [ diff --git a/examples/chef/devices/rootnode_contactsensor_27f76aeaf5.matter b/examples/chef/devices/rootnode_contactsensor_27f76aeaf5.matter index 460aa6e5a5b44c..46f2f9de05ba19 100644 --- a/examples/chef/devices/rootnode_contactsensor_27f76aeaf5.matter +++ b/examples/chef/devices/rootnode_contactsensor_27f76aeaf5.matter @@ -1771,6 +1771,10 @@ internal cluster UnitTesting = 4294048773 { int8u arg1[] = 0; } + response struct StringEchoResponse = 13 { + octet_string payload = 0; + } + request struct TestEnumsRequestRequest { vendor_id arg1 = 0; SimpleEnum arg2 = 1; @@ -1825,6 +1829,10 @@ internal cluster UnitTesting = 4294048773 { int8u fillCharacter = 2; } + request struct StringEchoRequestRequest { + octet_string payload = 0; + } + request struct TestDifferentVendorMeiRequestRequest { int8u arg1 = 0; } @@ -1904,6 +1912,10 @@ internal cluster UnitTesting = 4294048773 { command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22; /** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */ command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23; + /** Command that takes an argument which is an octet string. The response echoes + the string back. If the string is large then it would require a session that + supports large payloads. */ + command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24; /** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */ command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962; } diff --git a/src/app/clusters/test-cluster-server/test-cluster-server.cpp b/src/app/clusters/test-cluster-server/test-cluster-server.cpp index 0d805347f792f9..4b6fc979336ab3 100644 --- a/src/app/clusters/test-cluster-server/test-cluster-server.cpp +++ b/src/app/clusters/test-cluster-server/test-cluster-server.cpp @@ -1041,6 +1041,16 @@ bool emberAfUnitTestingClusterSimpleStructEchoRequestCallback(CommandHandler * c return true; } +bool emberAfUnitTestingClusterStringEchoRequestCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, + const Commands::StringEchoRequest::DecodableType & commandData) +{ + Commands::StringEchoResponse::Type response; + response.payload = commandData.payload; + + commandObj->AddResponse(commandPath, response); + return true; +} + bool emberAfUnitTestingClusterTimedInvokeRequestCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, const Commands::TimedInvokeRequest::DecodableType & commandData) { diff --git a/src/app/tests/suites/TestCluster.yaml b/src/app/tests/suites/TestCluster.yaml index 540683a5422f13..308240a0dd537d 100644 --- a/src/app/tests/suites/TestCluster.yaml +++ b/src/app/tests/suites/TestCluster.yaml @@ -3911,6 +3911,7 @@ tests: 21, 22, 23, + 24, 4294049962, ] @@ -3918,7 +3919,7 @@ tests: command: "readAttribute" attribute: "GeneratedCommandList" response: - value: [0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 4294049979] + value: [0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 13, 4294049979] - label: "Validate presence of MEI attribute" command: "readAttribute" diff --git a/src/app/tests/suites/TestUnitTestingClusterMei.yaml b/src/app/tests/suites/TestUnitTestingClusterMei.yaml index 542c5568cbbbc7..35074f9fb34560 100644 --- a/src/app/tests/suites/TestUnitTestingClusterMei.yaml +++ b/src/app/tests/suites/TestUnitTestingClusterMei.yaml @@ -52,7 +52,7 @@ tests: attribute: "GeneratedCommandList" response: constraints: - contains: [0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 4294049979] + contains: [0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 13, 4294049979] - label: "Validate presence of MEI attribute" command: "readAttribute" diff --git a/src/app/zap-templates/zcl/data-model/chip/test-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/test-cluster.xml index d0312fdc9a8982..f010838f933b03 100644 --- a/src/app/zap-templates/zcl/data-model/chip/test-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/test-cluster.xml @@ -464,6 +464,16 @@ limitations under the License. + + + Command that takes an argument which is an octet string. The response echoes + the string back. If the string is large then it would require a session that + supports large payloads. + + + + @@ -605,6 +615,13 @@ limitations under the License. + + + Response to StringEchoRequest. Buffer in response is filled by the payload in the Request. + + + + Response to TestDifferentVendorMeiRequest, which is a command having a different MEI vendor ID than the cluster. diff --git a/src/controller/data_model/controller-clusters.matter b/src/controller/data_model/controller-clusters.matter index a8567d591b1f7a..60d2cf6599b8db 100644 --- a/src/controller/data_model/controller-clusters.matter +++ b/src/controller/data_model/controller-clusters.matter @@ -9623,6 +9623,10 @@ internal cluster UnitTesting = 4294048773 { int8u arg1[] = 0; } + response struct StringEchoResponse = 13 { + octet_string payload = 0; + } + request struct TestEnumsRequestRequest { vendor_id arg1 = 0; SimpleEnum arg2 = 1; @@ -9677,6 +9681,10 @@ internal cluster UnitTesting = 4294048773 { int8u fillCharacter = 2; } + request struct StringEchoRequestRequest { + octet_string payload = 0; + } + request struct TestDifferentVendorMeiRequestRequest { int8u arg1 = 0; } @@ -9756,6 +9764,10 @@ internal cluster UnitTesting = 4294048773 { command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22; /** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */ command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23; + /** Command that takes an argument which is an octet string. The response echoes + the string back. If the string is large then it would require a session that + supports large payloads. */ + command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24; /** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */ command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962; } diff --git a/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java b/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java index 4b762e1ef39f37..f0b0436a1694c1 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java @@ -64543,6 +64543,36 @@ public void onResponse(StructType invokeStructValue) { }}, commandId, commandArgs, timedInvokeTimeoutMs); } + public void stringEchoRequest(StringEchoResponseCallback callback, byte[] payload) { + stringEchoRequest(callback, payload, 0); + } + + public void stringEchoRequest(StringEchoResponseCallback callback, byte[] payload, int timedInvokeTimeoutMs) { + final long commandId = 24L; + + ArrayList elements = new ArrayList<>(); + final long payloadFieldID = 0L; + BaseTLVType payloadtlvValue = new ByteArrayType(payload); + elements.add(new StructElement(payloadFieldID, payloadtlvValue)); + + StructType commandArgs = new StructType(elements); + invoke(new InvokeCallbackImpl(callback) { + @Override + public void onResponse(StructType invokeStructValue) { + final long payloadFieldID = 0L; + byte[] payload = null; + for (StructElement element: invokeStructValue.value()) { + if (element.contextTagNum() == payloadFieldID) { + if (element.value(BaseTLVType.class).type() == TLVType.ByteArray) { + ByteArrayType castingValue = element.value(ByteArrayType.class); + payload = castingValue.value(byte[].class); + } + } + } + callback.onSuccess(payload); + }}, commandId, commandArgs, timedInvokeTimeoutMs); + } + public void testDifferentVendorMeiRequest(TestDifferentVendorMeiResponseCallback callback, Integer arg1) { testDifferentVendorMeiRequest(callback, arg1, 0); } @@ -64632,6 +64662,10 @@ public interface TestBatchHelperResponseCallback extends BaseClusterCallback { void onSuccess(byte[] buffer); } + public interface StringEchoResponseCallback extends BaseClusterCallback { + void onSuccess(byte[] payload); + } + public interface TestDifferentVendorMeiResponseCallback extends BaseClusterCallback { void onSuccess(Integer arg1, Long eventNumber); } diff --git a/src/controller/java/generated/java/chip/devicecontroller/ClusterIDMapping.java b/src/controller/java/generated/java/chip/devicecontroller/ClusterIDMapping.java index cc2cb937c66cad..7319aa479e37ce 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ClusterIDMapping.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ClusterIDMapping.java @@ -17318,6 +17318,7 @@ public enum Command { TestEmitTestFabricScopedEventRequest(21L), TestBatchHelperRequest(22L), TestSecondBatchHelperRequest(23L), + StringEchoRequest(24L), TestDifferentVendorMeiRequest(4294049962L),; private final long id; Command(long id) { @@ -17659,6 +17660,23 @@ public static TestSecondBatchHelperRequestCommandField value(int id) throws NoSu } throw new NoSuchFieldError(); } + }public enum StringEchoRequestCommandField {Payload(0),; + private final int id; + StringEchoRequestCommandField(int id) { + this.id = id; + } + + public int getID() { + return id; + } + public static StringEchoRequestCommandField value(int id) throws NoSuchFieldError { + for (StringEchoRequestCommandField field : StringEchoRequestCommandField.values()) { + if (field.getID() == id) { + return field; + } + } + throw new NoSuchFieldError(); + } }public enum TestDifferentVendorMeiRequestCommandField {Arg1(0),; private final int id; TestDifferentVendorMeiRequestCommandField(int id) { diff --git a/src/controller/java/generated/java/chip/devicecontroller/ClusterInfoMapping.java b/src/controller/java/generated/java/chip/devicecontroller/ClusterInfoMapping.java index 2573b42c0184f7..710ad85424cf80 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ClusterInfoMapping.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ClusterInfoMapping.java @@ -20285,6 +20285,28 @@ public void onError(Exception error) { } } + public static class DelegatedUnitTestingClusterStringEchoResponseCallback implements ChipClusters.UnitTestingCluster.StringEchoResponseCallback, DelegatedClusterCallback { + private ClusterCommandCallback callback; + @Override + public void setCallbackDelegate(ClusterCommandCallback callback) { + this.callback = callback; + } + + @Override + public void onSuccess(byte[] payload) { + Map responseValues = new LinkedHashMap<>(); + + CommandResponseInfo payloadResponseValue = new CommandResponseInfo("payload", "byte[]"); + responseValues.put(payloadResponseValue, payload); + callback.onSuccess(responseValues); + } + + @Override + public void onError(Exception error) { + callback.onFailure(error); + } + } + public static class DelegatedUnitTestingClusterTestDifferentVendorMeiResponseCallback implements ChipClusters.UnitTestingCluster.TestDifferentVendorMeiResponseCallback, DelegatedClusterCallback { private ClusterCommandCallback callback; @Override @@ -28737,6 +28759,24 @@ public Map> getCommandMap() { ); unitTestingClusterInteractionInfoMap.put("testSecondBatchHelperRequest", unitTestingtestSecondBatchHelperRequestInteractionInfo); + Map unitTestingstringEchoRequestCommandParams = new LinkedHashMap(); + + CommandParameterInfo unitTestingstringEchoRequestpayloadCommandParameterInfo = new CommandParameterInfo("payload", byte[].class, byte[].class); + unitTestingstringEchoRequestCommandParams.put("payload",unitTestingstringEchoRequestpayloadCommandParameterInfo); + InteractionInfo unitTestingstringEchoRequestInteractionInfo = new InteractionInfo( + (cluster, callback, commandArguments) -> { + ((ChipClusters.UnitTestingCluster) cluster) + .stringEchoRequest((ChipClusters.UnitTestingCluster.StringEchoResponseCallback) callback + , (byte[]) + commandArguments.get("payload") + + ); + }, + () -> new DelegatedUnitTestingClusterStringEchoResponseCallback(), + unitTestingstringEchoRequestCommandParams + ); + unitTestingClusterInteractionInfoMap.put("stringEchoRequest", unitTestingstringEchoRequestInteractionInfo); + Map unitTestingtestDifferentVendorMeiRequestCommandParams = new LinkedHashMap(); CommandParameterInfo unitTestingtestDifferentVendorMeiRequestarg1CommandParameterInfo = new CommandParameterInfo("arg1", Integer.class, Integer.class); diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt index 84bb0f701529e8..b50ab4468820d1 100644 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt +++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/UnitTestingCluster.kt @@ -121,6 +121,8 @@ class UnitTestingCluster(private val controller: MatterController, private val e class TestBatchHelperResponse(val buffer: ByteArray) + class StringEchoResponse(val payload: ByteArray) + class TestDifferentVendorMeiResponse(val arg1: UByte, val eventNumber: ULong) class ListInt8uAttribute(val value: List) @@ -2337,6 +2339,53 @@ class UnitTestingCluster(private val controller: MatterController, private val e return TestBatchHelperResponse(buffer_decoded) } + suspend fun stringEchoRequest( + payload: ByteArray, + timedInvokeTimeout: Duration? = null, + ): StringEchoResponse { + val commandId: UInt = 24u + + val tlvWriter = TlvWriter() + tlvWriter.startStructure(AnonymousTag) + + val TAG_PAYLOAD_REQ: Int = 0 + tlvWriter.put(ContextSpecificTag(TAG_PAYLOAD_REQ), payload) + tlvWriter.endStructure() + + val request: InvokeRequest = + InvokeRequest( + CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), + tlvPayload = tlvWriter.getEncoded(), + timedRequest = timedInvokeTimeout, + ) + + val response: InvokeResponse = controller.invoke(request) + logger.log(Level.FINE, "Invoke command succeeded: ${response}") + + val tlvReader = TlvReader(response.payload) + tlvReader.enterStructure(AnonymousTag) + val TAG_PAYLOAD: Int = 0 + var payload_decoded: ByteArray? = null + + while (!tlvReader.isEndOfContainer()) { + val tag = tlvReader.peekElement().tag + + if (tag == ContextSpecificTag(TAG_PAYLOAD)) { + payload_decoded = tlvReader.getByteArray(tag) + } else { + tlvReader.skipElement() + } + } + + if (payload_decoded == null) { + throw IllegalStateException("payload not found in TLV") + } + + tlvReader.exitContainer() + + return StringEchoResponse(payload_decoded) + } + suspend fun testDifferentVendorMeiRequest( arg1: UByte, timedInvokeTimeout: Duration? = null, diff --git a/src/controller/python/chip/clusters/CHIPClusters.py b/src/controller/python/chip/clusters/CHIPClusters.py index 37ead8e634611a..a163d37de675c9 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.py +++ b/src/controller/python/chip/clusters/CHIPClusters.py @@ -14114,6 +14114,13 @@ class ChipClusters: "fillCharacter": "int", }, }, + 0x00000018: { + "commandId": 0x00000018, + "commandName": "StringEchoRequest", + "args": { + "payload": "bytes", + }, + }, 0xFFF200AA: { "commandId": 0xFFF200AA, "commandName": "TestDifferentVendorMeiRequest", diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py index 4c17fd99af2d21..a81dced46c589c 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -49380,6 +49380,22 @@ def descriptor(cls) -> ClusterObjectDescriptor: arg1: 'typing.List[uint]' = field(default_factory=lambda: []) + @dataclass + class StringEchoResponse(ClusterCommand): + cluster_id: typing.ClassVar[int] = 0xFFF1FC05 + command_id: typing.ClassVar[int] = 0x0000000D + is_client: typing.ClassVar[bool] = False + response_type: typing.ClassVar[str] = None + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor(Label="payload", Tag=0, Type=bytes), + ]) + + payload: 'bytes' = b"" + @dataclass class TestEnumsRequest(ClusterCommand): cluster_id: typing.ClassVar[int] = 0xFFF1FC05 @@ -49577,6 +49593,22 @@ def descriptor(cls) -> ClusterObjectDescriptor: sizeOfResponseBuffer: 'uint' = 0 fillCharacter: 'uint' = 0 + @dataclass + class StringEchoRequest(ClusterCommand): + cluster_id: typing.ClassVar[int] = 0xFFF1FC05 + command_id: typing.ClassVar[int] = 0x00000018 + is_client: typing.ClassVar[bool] = True + response_type: typing.ClassVar[str] = 'StringEchoResponse' + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor(Label="payload", Tag=0, Type=bytes), + ]) + + payload: 'bytes' = b"" + @dataclass class TestDifferentVendorMeiRequest(ClusterCommand): cluster_id: typing.ClassVar[int] = 0xFFF1FC05 diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h index 1513b8c0f54540..a00ea9aed79605 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h @@ -15901,6 +15901,14 @@ MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) * Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */ - (void)testSecondBatchHelperRequestWithParams:(MTRUnitTestingClusterTestSecondBatchHelperRequestParams *)params completion:(void (^)(MTRUnitTestingClusterTestBatchHelperResponseParams * _Nullable data, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; +/** + * Command StringEchoRequest + * + * Command that takes an argument which is an octet string. The response echoes + the string back. If the string is large then it would require a session that + supports large payloads. + */ +- (void)stringEchoRequestWithParams:(MTRUnitTestingClusterStringEchoRequestParams *)params completion:(void (^)(MTRUnitTestingClusterStringEchoResponseParams * _Nullable data, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; /** * Command TestDifferentVendorMeiRequest * diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm index 694f35228a4701..2103baa5ab86db 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm @@ -114537,6 +114537,30 @@ - (void)testSecondBatchHelperRequestWithParams:(MTRUnitTestingClusterTestSecondB queue:self.callbackQueue completion:responseHandler]; } +- (void)stringEchoRequestWithParams:(MTRUnitTestingClusterStringEchoRequestParams *)params completion:(void (^)(MTRUnitTestingClusterStringEchoResponseParams * _Nullable data, NSError * _Nullable error))completion +{ + if (params == nil) { + params = [[MTRUnitTestingClusterStringEchoRequestParams + alloc] init]; + } + + auto responseHandler = ^(id _Nullable response, NSError * _Nullable error) { + completion(response, error); + }; + + auto * timedInvokeTimeoutMs = params.timedInvokeTimeoutMs; + + using RequestType = UnitTesting::Commands::StringEchoRequest::Type; + [self.device _invokeKnownCommandWithEndpointID:self.endpointID + clusterID:@(RequestType::GetClusterId()) + commandID:@(RequestType::GetCommandId()) + commandPayload:params + timedInvokeTimeout:timedInvokeTimeoutMs + serverSideProcessingTimeout:params.serverSideProcessingTimeout + responseClass:MTRUnitTestingClusterStringEchoResponseParams.class + queue:self.callbackQueue + completion:responseHandler]; +} - (void)testDifferentVendorMeiRequestWithParams:(MTRUnitTestingClusterTestDifferentVendorMeiRequestParams *)params completion:(void (^)(MTRUnitTestingClusterTestDifferentVendorMeiResponseParams * _Nullable data, NSError * _Nullable error))completion { if (params == nil) { diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h b/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h index b6c6dc2aba2dc2..9d8914a5505742 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h @@ -7017,6 +7017,7 @@ typedef NS_ENUM(uint32_t, MTRCommandIDType) { MTRCommandIDTypeClusterUnitTestingCommandTestListNestedStructListArgumentRequestID MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) = 0x0000000C, MTRCommandIDTypeClusterUnitTestingCommandTestBatchHelperResponseID MTR_PROVISIONALLY_AVAILABLE = 0x0000000C, MTRCommandIDTypeClusterUnitTestingCommandTestListInt8UReverseRequestID MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) = 0x0000000D, + MTRCommandIDTypeClusterUnitTestingCommandStringEchoResponseID MTR_PROVISIONALLY_AVAILABLE = 0x0000000D, MTRCommandIDTypeClusterUnitTestingCommandTestEnumsRequestID MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) = 0x0000000E, MTRCommandIDTypeClusterUnitTestingCommandTestNullableOptionalRequestID MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) = 0x0000000F, MTRCommandIDTypeClusterUnitTestingCommandTestComplexNullableOptionalRequestID MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) = 0x00000010, @@ -7027,6 +7028,7 @@ typedef NS_ENUM(uint32_t, MTRCommandIDType) { MTRCommandIDTypeClusterUnitTestingCommandTestEmitTestFabricScopedEventRequestID MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) = 0x00000015, MTRCommandIDTypeClusterUnitTestingCommandTestBatchHelperRequestID MTR_PROVISIONALLY_AVAILABLE = 0x00000016, MTRCommandIDTypeClusterUnitTestingCommandTestSecondBatchHelperRequestID MTR_PROVISIONALLY_AVAILABLE = 0x00000017, + MTRCommandIDTypeClusterUnitTestingCommandStringEchoRequestID MTR_PROVISIONALLY_AVAILABLE = 0x00000018, MTRCommandIDTypeClusterUnitTestingCommandTestDifferentVendorMeiRequestID MTR_PROVISIONALLY_AVAILABLE = 0xFFF200AA, MTRCommandIDTypeClusterUnitTestingCommandTestDifferentVendorMeiResponseID MTR_PROVISIONALLY_AVAILABLE = 0xFFF200BB, diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRClusters.h b/src/darwin/Framework/CHIP/zap-generated/MTRClusters.h index c47d2bf28caa4c..114205ae5df9e0 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRClusters.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRClusters.h @@ -7247,6 +7247,7 @@ MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) - (void)testEmitTestFabricScopedEventRequestWithParams:(MTRUnitTestingClusterTestEmitTestFabricScopedEventRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedDataValueDictionaries expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(void (^)(MTRUnitTestingClusterTestEmitTestFabricScopedEventResponseParams * _Nullable data, NSError * _Nullable error))completion MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)); - (void)testBatchHelperRequestWithParams:(MTRUnitTestingClusterTestBatchHelperRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedDataValueDictionaries expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(void (^)(MTRUnitTestingClusterTestBatchHelperResponseParams * _Nullable data, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; - (void)testSecondBatchHelperRequestWithParams:(MTRUnitTestingClusterTestSecondBatchHelperRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedDataValueDictionaries expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(void (^)(MTRUnitTestingClusterTestBatchHelperResponseParams * _Nullable data, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; +- (void)stringEchoRequestWithParams:(MTRUnitTestingClusterStringEchoRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedDataValueDictionaries expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(void (^)(MTRUnitTestingClusterStringEchoResponseParams * _Nullable data, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; - (void)testDifferentVendorMeiRequestWithParams:(MTRUnitTestingClusterTestDifferentVendorMeiRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedDataValueDictionaries expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(void (^)(MTRUnitTestingClusterTestDifferentVendorMeiResponseParams * _Nullable data, NSError * _Nullable error))completion MTR_PROVISIONALLY_AVAILABLE; - (NSDictionary * _Nullable)readAttributeBooleanWithParams:(MTRReadParams * _Nullable)params MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)); diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm b/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm index f04fd07262ea1f..823821d7e238ad 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm @@ -21287,6 +21287,33 @@ - (void)testSecondBatchHelperRequestWithParams:(MTRUnitTestingClusterTestSecondB completion:responseHandler]; } +- (void)stringEchoRequestWithParams:(MTRUnitTestingClusterStringEchoRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedValues expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(void (^)(MTRUnitTestingClusterStringEchoResponseParams * _Nullable data, NSError * _Nullable error))completion +{ + if (params == nil) { + params = [[MTRUnitTestingClusterStringEchoRequestParams + alloc] init]; + } + + auto responseHandler = ^(id _Nullable response, NSError * _Nullable error) { + completion(response, error); + }; + + auto * timedInvokeTimeoutMs = params.timedInvokeTimeoutMs; + + using RequestType = UnitTesting::Commands::StringEchoRequest::Type; + [self.device _invokeKnownCommandWithEndpointID:self.endpointID + clusterID:@(RequestType::GetClusterId()) + commandID:@(RequestType::GetCommandId()) + commandPayload:params + expectedValues:expectedValues + expectedValueInterval:expectedValueIntervalMs + timedInvokeTimeout:timedInvokeTimeoutMs + serverSideProcessingTimeout:params.serverSideProcessingTimeout + responseClass:MTRUnitTestingClusterStringEchoResponseParams.class + queue:self.callbackQueue + completion:responseHandler]; +} + - (void)testDifferentVendorMeiRequestWithParams:(MTRUnitTestingClusterTestDifferentVendorMeiRequestParams *)params expectedValues:(NSArray *> * _Nullable)expectedValues expectedValueInterval:(NSNumber * _Nullable)expectedValueIntervalMs completion:(void (^)(MTRUnitTestingClusterTestDifferentVendorMeiResponseParams * _Nullable data, NSError * _Nullable error))completion { if (params == nil) { diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h index d95ac77034ce61..28051bd2275600 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h @@ -12554,6 +12554,25 @@ MTR_DEPRECATED("Please use MTRUnitTestingClusterTestListInt8UReverseRequestParam @property (nonatomic, copy, nullable) NSNumber * serverSideProcessingTimeout; @end +MTR_PROVISIONALLY_AVAILABLE +@interface MTRUnitTestingClusterStringEchoResponseParams : NSObject + +@property (nonatomic, copy) NSData * _Nonnull payload MTR_PROVISIONALLY_AVAILABLE; + +/** + * Initialize an MTRUnitTestingClusterStringEchoResponseParams with a response-value dictionary + * of the sort that MTRDeviceResponseHandler would receive. + * + * Will return nil and hand out an error if the response-value dictionary is not + * a command data response or is not the right command response. + * + * Will return nil and hand out an error if the data response does not match the known + * schema for this command. + */ +- (nullable instancetype)initWithResponseValue:(NSDictionary *)responseValue + error:(NSError * __autoreleasing *)error MTR_PROVISIONALLY_AVAILABLE; +@end + MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) @interface MTRUnitTestingClusterTestEnumsRequestParams : NSObject @@ -13154,6 +13173,36 @@ MTR_PROVISIONALLY_AVAILABLE @property (nonatomic, copy, nullable) NSNumber * serverSideProcessingTimeout; @end +MTR_PROVISIONALLY_AVAILABLE +@interface MTRUnitTestingClusterStringEchoRequestParams : NSObject + +@property (nonatomic, copy) NSData * _Nonnull payload MTR_PROVISIONALLY_AVAILABLE; +/** + * Controls whether the command is a timed command (using Timed Invoke). + * + * If nil (the default value), a regular invoke is done for commands that do + * not require a timed invoke and a timed invoke with some default timed request + * timeout is done for commands that require a timed invoke. + * + * If not nil, a timed invoke is done, with the provided value used as the timed + * request timeout. The value should be chosen small enough to provide the + * desired security properties but large enough that it will allow a round-trip + * from the sever to the client (for the status response and actual invoke + * request) within the timeout window. + * + */ +@property (nonatomic, copy, nullable) NSNumber * timedInvokeTimeoutMs; + +/** + * Controls how much time, in seconds, we will allow for the server to process the command. + * + * The command will then time out if that much time, plus an allowance for retransmits due to network failures, passes. + * + * If nil, the framework will try to select an appropriate timeout value itself. + */ +@property (nonatomic, copy, nullable) NSNumber * serverSideProcessingTimeout; +@end + MTR_PROVISIONALLY_AVAILABLE @interface MTRUnitTestingClusterTestDifferentVendorMeiRequestParams : NSObject diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm index 08b00b6e4555f0..01a7844ada5f32 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm @@ -34596,6 +34596,85 @@ @implementation MTRTestClusterClusterTestListInt8UReverseRequestParams @dynamic timedInvokeTimeoutMs; @dynamic serverSideProcessingTimeout; @end +@implementation MTRUnitTestingClusterStringEchoResponseParams +- (instancetype)init +{ + if (self = [super init]) { + + _payload = [NSData data]; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone; +{ + auto other = [[MTRUnitTestingClusterStringEchoResponseParams alloc] init]; + + other.payload = self.payload; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = [NSString stringWithFormat:@"<%@: payload:%@; >", NSStringFromClass([self class]), [_payload base64EncodedStringWithOptions:0]]; + return descriptionString; +} + +- (nullable instancetype)initWithResponseValue:(NSDictionary *)responseValue + error:(NSError * __autoreleasing *)error +{ + if (!(self = [super init])) { + return nil; + } + + using DecodableType = chip::app::Clusters::UnitTesting::Commands::StringEchoResponse::DecodableType; + chip::System::PacketBufferHandle buffer = [MTRBaseDevice _responseDataForCommand:responseValue + clusterID:DecodableType::GetClusterId() + commandID:DecodableType::GetCommandId() + error:error]; + if (buffer.IsNull()) { + return nil; + } + + chip::TLV::TLVReader reader; + reader.Init(buffer->Start(), buffer->DataLength()); + + CHIP_ERROR err = reader.Next(chip::TLV::AnonymousTag()); + if (err == CHIP_NO_ERROR) { + DecodableType decodedStruct; + err = chip::app::DataModel::Decode(reader, decodedStruct); + if (err == CHIP_NO_ERROR) { + err = [self _setFieldsFromDecodableStruct:decodedStruct]; + if (err == CHIP_NO_ERROR) { + return self; + } + } + } + + NSString * errorStr = [NSString stringWithFormat:@"Command payload decoding failed: %s", err.AsString()]; + MTR_LOG_ERROR("%s", errorStr.UTF8String); + if (error != nil) { + NSDictionary * userInfo = @{ NSLocalizedFailureReasonErrorKey : NSLocalizedString(errorStr, nil) }; + *error = [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeSchemaMismatch userInfo:userInfo]; + } + return nil; +} + +@end + +@implementation MTRUnitTestingClusterStringEchoResponseParams (InternalMethods) + +- (CHIP_ERROR)_setFieldsFromDecodableStruct:(const chip::app::Clusters::UnitTesting::Commands::StringEchoResponse::DecodableType &)decodableStruct +{ + { + self.payload = AsData(decodableStruct.payload); + } + return CHIP_NO_ERROR; +} + +@end + @implementation MTRUnitTestingClusterTestEnumsRequestParams - (instancetype)init { @@ -35715,6 +35794,85 @@ - (CHIP_ERROR)_encodeToTLVReader:(chip::System::PacketBufferTLVReader &)reader } @end +@implementation MTRUnitTestingClusterStringEchoRequestParams +- (instancetype)init +{ + if (self = [super init]) { + + _payload = [NSData data]; + _timedInvokeTimeoutMs = nil; + _serverSideProcessingTimeout = nil; + } + return self; +} + +- (id)copyWithZone:(NSZone * _Nullable)zone; +{ + auto other = [[MTRUnitTestingClusterStringEchoRequestParams alloc] init]; + + other.payload = self.payload; + other.timedInvokeTimeoutMs = self.timedInvokeTimeoutMs; + other.serverSideProcessingTimeout = self.serverSideProcessingTimeout; + + return other; +} + +- (NSString *)description +{ + NSString * descriptionString = [NSString stringWithFormat:@"<%@: payload:%@; >", NSStringFromClass([self class]), [_payload base64EncodedStringWithOptions:0]]; + return descriptionString; +} + +@end + +@implementation MTRUnitTestingClusterStringEchoRequestParams (InternalMethods) + +- (CHIP_ERROR)_encodeToTLVReader:(chip::System::PacketBufferTLVReader &)reader +{ + chip::app::Clusters::UnitTesting::Commands::StringEchoRequest::Type encodableStruct; + ListFreer listFreer; + { + encodableStruct.payload = AsByteSpan(self.payload); + } + + auto buffer = chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSizeWithoutReserve, 0); + if (buffer.IsNull()) { + return CHIP_ERROR_NO_MEMORY; + } + + chip::System::PacketBufferTLVWriter writer; + // Commands never need chained buffers, since they cannot be chunked. + writer.Init(std::move(buffer), /* useChainedBuffers = */ false); + + ReturnErrorOnFailure(chip::app::DataModel::Encode(writer, chip::TLV::AnonymousTag(), encodableStruct)); + + ReturnErrorOnFailure(writer.Finalize(&buffer)); + + reader.Init(std::move(buffer)); + return reader.Next(chip::TLV::kTLVType_Structure, chip::TLV::AnonymousTag()); +} + +- (NSDictionary * _Nullable)_encodeAsDataValue:(NSError * __autoreleasing *)error +{ + chip::System::PacketBufferTLVReader reader; + CHIP_ERROR err = [self _encodeToTLVReader:reader]; + if (err != CHIP_NO_ERROR) { + if (error) { + *error = [MTRError errorForCHIPErrorCode:err]; + } + return nil; + } + + auto decodedObj = MTRDecodeDataValueDictionaryFromCHIPTLV(&reader); + if (decodedObj == nil) { + if (error) { + *error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE]; + } + } + return decodedObj; +} +@end + @implementation MTRUnitTestingClusterTestDifferentVendorMeiRequestParams - (instancetype)init { diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloads_Internal.h b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloads_Internal.h index f281c8e89570d1..963560ada35033 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloads_Internal.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloads_Internal.h @@ -2194,6 +2194,12 @@ NS_ASSUME_NONNULL_BEGIN @end +@interface MTRUnitTestingClusterStringEchoResponseParams (InternalMethods) + +- (CHIP_ERROR)_setFieldsFromDecodableStruct:(const chip::app::Clusters::UnitTesting::Commands::StringEchoResponse::DecodableType &)decodableStruct; + +@end + @interface MTRUnitTestingClusterTestEnumsRequestParams (InternalMethods) - (NSDictionary * _Nullable)_encodeAsDataValue:(NSError * __autoreleasing *)error; @@ -2254,6 +2260,12 @@ NS_ASSUME_NONNULL_BEGIN @end +@interface MTRUnitTestingClusterStringEchoRequestParams (InternalMethods) + +- (NSDictionary * _Nullable)_encodeAsDataValue:(NSError * __autoreleasing *)error; + +@end + @interface MTRUnitTestingClusterTestDifferentVendorMeiRequestParams (InternalMethods) - (NSDictionary * _Nullable)_encodeAsDataValue:(NSError * __autoreleasing *)error; 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 1619aeb30881d7..104f2a09bfb362 100644 --- a/zzz_generated/app-common/app-common/zap-generated/callback.h +++ b/zzz_generated/app-common/app-common/zap-generated/callback.h @@ -6786,6 +6786,12 @@ bool emberAfUnitTestingClusterTestBatchHelperRequestCallback( bool emberAfUnitTestingClusterTestSecondBatchHelperRequestCallback( chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::UnitTesting::Commands::TestSecondBatchHelperRequest::DecodableType & commandData); +/** + * @brief Unit Testing Cluster StringEchoRequest Command callback (from client) + */ +bool emberAfUnitTestingClusterStringEchoRequestCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::UnitTesting::Commands::StringEchoRequest::DecodableType & commandData); /** * @brief Unit Testing Cluster TestDifferentVendorMeiRequest Command callback (from client) */ diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp index 54bcec37353ef1..98acaaca61920c 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp @@ -29724,6 +29724,40 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } } // namespace TestListInt8UReverseRequest. +namespace StringEchoResponse { +CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const +{ + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kPayload), payload); + return encoder.Finalize(); +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + detail::StructDecodeIterator __iterator(reader); + while (true) + { + auto __element = __iterator.Next(); + if (std::holds_alternative(__element)) + { + return std::get(__element); + } + + CHIP_ERROR err = CHIP_NO_ERROR; + const uint8_t __context_tag = std::get(__element); + + if (__context_tag == to_underlying(Fields::kPayload)) + { + err = DataModel::Decode(reader, payload); + } + else + { + } + + ReturnErrorOnFailure(err); + } +} +} // namespace StringEchoResponse. namespace TestEnumsRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { @@ -30140,6 +30174,40 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } } } // namespace TestSecondBatchHelperRequest. +namespace StringEchoRequest { +CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const +{ + DataModel::WrappedStructEncoder encoder{ aWriter, aTag }; + encoder.Encode(to_underlying(Fields::kPayload), payload); + return encoder.Finalize(); +} + +CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) +{ + detail::StructDecodeIterator __iterator(reader); + while (true) + { + auto __element = __iterator.Next(); + if (std::holds_alternative(__element)) + { + return std::get(__element); + } + + CHIP_ERROR err = CHIP_NO_ERROR; + const uint8_t __context_tag = std::get(__element); + + if (__context_tag == to_underlying(Fields::kPayload)) + { + err = DataModel::Decode(reader, payload); + } + else + { + } + + ReturnErrorOnFailure(err); + } +} +} // namespace StringEchoRequest. namespace TestDifferentVendorMeiRequest { CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const { diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index 84f19b11e4f105..4d9b6f5639602e 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -43022,6 +43022,11 @@ struct Type; struct DecodableType; } // namespace TestListInt8UReverseRequest +namespace StringEchoResponse { +struct Type; +struct DecodableType; +} // namespace StringEchoResponse + namespace TestEnumsRequest { struct Type; struct DecodableType; @@ -43072,6 +43077,11 @@ struct Type; struct DecodableType; } // namespace TestSecondBatchHelperRequest +namespace StringEchoRequest { +struct Type; +struct DecodableType; +} // namespace StringEchoRequest + namespace TestDifferentVendorMeiRequest { struct Type; struct DecodableType; @@ -44059,6 +44069,38 @@ struct DecodableType CHIP_ERROR Decode(TLV::TLVReader & reader); }; }; // namespace TestListInt8UReverseRequest +namespace StringEchoResponse { +enum class Fields : uint8_t +{ + kPayload = 0, +}; + +struct Type +{ +public: + // Use GetCommandId instead of commandId directly to avoid naming conflict with CommandIdentification in ExecutionOfACommand + static constexpr CommandId GetCommandId() { return Commands::StringEchoResponse::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::UnitTesting::Id; } + + chip::ByteSpan payload; + + CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; + + using ResponseType = DataModel::NullObjectType; + + static constexpr bool MustUseTimedInvoke() { return false; } +}; + +struct DecodableType +{ +public: + static constexpr CommandId GetCommandId() { return Commands::StringEchoResponse::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::UnitTesting::Id; } + + chip::ByteSpan payload; + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; +}; // namespace StringEchoResponse namespace TestEnumsRequest { enum class Fields : uint8_t { @@ -44429,6 +44471,38 @@ struct DecodableType CHIP_ERROR Decode(TLV::TLVReader & reader); }; }; // namespace TestSecondBatchHelperRequest +namespace StringEchoRequest { +enum class Fields : uint8_t +{ + kPayload = 0, +}; + +struct Type +{ +public: + // Use GetCommandId instead of commandId directly to avoid naming conflict with CommandIdentification in ExecutionOfACommand + static constexpr CommandId GetCommandId() { return Commands::StringEchoRequest::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::UnitTesting::Id; } + + chip::ByteSpan payload; + + CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const; + + using ResponseType = Clusters::UnitTesting::Commands::StringEchoResponse::DecodableType; + + static constexpr bool MustUseTimedInvoke() { return false; } +}; + +struct DecodableType +{ +public: + static constexpr CommandId GetCommandId() { return Commands::StringEchoRequest::Id; } + static constexpr ClusterId GetClusterId() { return Clusters::UnitTesting::Id; } + + chip::ByteSpan payload; + CHIP_ERROR Decode(TLV::TLVReader & reader); +}; +}; // namespace StringEchoRequest namespace TestDifferentVendorMeiRequest { enum class Fields : uint8_t { diff --git a/zzz_generated/app-common/app-common/zap-generated/ids/Commands.h b/zzz_generated/app-common/app-common/zap-generated/ids/Commands.h index 7e0003ebe52fc4..cff6ad343f0db3 100644 --- a/zzz_generated/app-common/app-common/zap-generated/ids/Commands.h +++ b/zzz_generated/app-common/app-common/zap-generated/ids/Commands.h @@ -1902,6 +1902,10 @@ namespace TestListInt8UReverseRequest { static constexpr CommandId Id = 0x0000000D; } // namespace TestListInt8UReverseRequest +namespace StringEchoResponse { +static constexpr CommandId Id = 0x0000000D; +} // namespace StringEchoResponse + namespace TestEnumsRequest { static constexpr CommandId Id = 0x0000000E; } // namespace TestEnumsRequest @@ -1942,6 +1946,10 @@ namespace TestSecondBatchHelperRequest { static constexpr CommandId Id = 0x00000017; } // namespace TestSecondBatchHelperRequest +namespace StringEchoRequest { +static constexpr CommandId Id = 0x00000018; +} // namespace StringEchoRequest + namespace TestDifferentVendorMeiRequest { static constexpr CommandId Id = 0xFFF200AA; } // namespace TestDifferentVendorMeiRequest diff --git a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h index 2cdd59a303bb63..479be90b55fd42 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h @@ -13902,6 +13902,7 @@ class ElectricalMeasurementGetMeasurementProfileCommand : public ClusterCommand | * TestEmitTestFabricScopedEventRequest | 0x15 | | * TestBatchHelperRequest | 0x16 | | * TestSecondBatchHelperRequest | 0x17 | +| * StringEchoRequest | 0x18 | | * TestDifferentVendorMeiRequest | 0xFFF200AA| |------------------------------------------------------------------------------| | Attributes: | | @@ -14965,6 +14966,44 @@ class UnitTestingTestSecondBatchHelperRequest : public ClusterCommand chip::app::Clusters::UnitTesting::Commands::TestSecondBatchHelperRequest::Type mRequest; }; +/* + * Command StringEchoRequest + */ +class UnitTestingStringEchoRequest : public ClusterCommand +{ +public: + UnitTestingStringEchoRequest(CredentialIssuerCommands * credsIssuerConfig) : + ClusterCommand("string-echo-request", credsIssuerConfig) + { + AddArgument("Payload", &mRequest.payload); + ClusterCommand::AddArguments(); + } + + CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector endpointIds) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::UnitTesting::Id; + constexpr chip::CommandId commandId = chip::app::Clusters::UnitTesting::Commands::StringEchoRequest::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on endpoint %u", clusterId, + commandId, endpointIds.at(0)); + return ClusterCommand::SendCommand(device, endpointIds.at(0), clusterId, commandId, mRequest); + } + + CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::UnitTesting::Id; + constexpr chip::CommandId commandId = chip::app::Clusters::UnitTesting::Commands::StringEchoRequest::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on Group %u", clusterId, commandId, + groupId); + + return ClusterCommand::SendGroupCommand(groupId, fabricIndex, clusterId, commandId, mRequest); + } + +private: + chip::app::Clusters::UnitTesting::Commands::StringEchoRequest::Type mRequest; +}; + /* * Command TestDifferentVendorMeiRequest */ @@ -26971,6 +27010,7 @@ void registerClusterUnitTesting(Commands & commands, CredentialIssuerCommands * make_unique(credsIssuerConfig), // make_unique(credsIssuerConfig), // make_unique(credsIssuerConfig), // + make_unique(credsIssuerConfig), // make_unique(credsIssuerConfig), // // // Attributes diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp index a9d3f942abcd7c..b7bcdcb7e8e7ba 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp @@ -8277,6 +8277,14 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, DataModelLogger::LogString(indent, "}"); return CHIP_NO_ERROR; } +CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, + const UnitTesting::Commands::StringEchoResponse::DecodableType & value) +{ + DataModelLogger::LogString(label, indent, "{"); + ReturnErrorOnFailure(DataModelLogger::LogValue("payload", indent + 1, value.payload)); + DataModelLogger::LogString(indent, "}"); + return CHIP_NO_ERROR; +} CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const UnitTesting::Commands::TestDifferentVendorMeiResponse::DecodableType & value) { @@ -19199,6 +19207,11 @@ CHIP_ERROR DataModelLogger::LogCommand(const chip::app::ConcreteCommandPath & pa ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); return DataModelLogger::LogValue("TestBatchHelperResponse", 1, value); } + case UnitTesting::Commands::StringEchoResponse::Id: { + UnitTesting::Commands::StringEchoResponse::DecodableType value; + ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); + return DataModelLogger::LogValue("StringEchoResponse", 1, value); + } case UnitTesting::Commands::TestDifferentVendorMeiResponse::Id: { UnitTesting::Commands::TestDifferentVendorMeiResponse::DecodableType value; ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h index ab1040c7069e3b..44801e57ca16df 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.h @@ -828,6 +828,8 @@ LogValue(const char * label, size_t indent, const chip::app::Clusters::UnitTesting::Commands::TestEmitTestFabricScopedEventResponse::DecodableType & value); static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::UnitTesting::Commands::TestBatchHelperResponse::DecodableType & value); +static CHIP_ERROR LogValue(const char * label, size_t indent, + const chip::app::Clusters::UnitTesting::Commands::StringEchoResponse::DecodableType & value); static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::UnitTesting::Commands::TestDifferentVendorMeiResponse::DecodableType & value); static CHIP_ERROR LogValue(const char * label, size_t indent, diff --git a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h index dfac8e499e1449..c1b6c5781d0256 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h @@ -172417,6 +172417,7 @@ class SubscribeAttributeElectricalMeasurementClusterRevision : public SubscribeA | * TestEmitTestFabricScopedEventRequest | 0x15 | | * TestBatchHelperRequest | 0x16 | | * TestSecondBatchHelperRequest | 0x17 | +| * StringEchoRequest | 0x18 | | * TestDifferentVendorMeiRequest | 0xFFF200AA| |------------------------------------------------------------------------------| | Attributes: | | @@ -174250,6 +174251,65 @@ class UnitTestingTestSecondBatchHelperRequest : public ClusterCommand { chip::app::Clusters::UnitTesting::Commands::TestSecondBatchHelperRequest::Type mRequest; }; +#endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL +/* + * Command StringEchoRequest + */ +class UnitTestingStringEchoRequest : public ClusterCommand { +public: + UnitTestingStringEchoRequest() + : ClusterCommand("string-echo-request") + { +#if MTR_ENABLE_PROVISIONAL + AddArgument("Payload", &mRequest.payload); +#endif // MTR_ENABLE_PROVISIONAL + ClusterCommand::AddArguments(); + } + + CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override + { + constexpr chip::ClusterId clusterId = chip::app::Clusters::UnitTesting::Id; + constexpr chip::CommandId commandId = chip::app::Clusters::UnitTesting::Commands::StringEchoRequest::Id; + + ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on endpoint %u", clusterId, commandId, endpointId); + + dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL); + __auto_type * cluster = [[MTRBaseClusterUnitTesting alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue]; + __auto_type * params = [[MTRUnitTestingClusterStringEchoRequestParams alloc] init]; + params.timedInvokeTimeoutMs = mTimedInteractionTimeoutMs.HasValue() ? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()] : nil; +#if MTR_ENABLE_PROVISIONAL + params.payload = [NSData dataWithBytes:mRequest.payload.data() length:mRequest.payload.size()]; +#endif // MTR_ENABLE_PROVISIONAL + uint16_t repeatCount = mRepeatCount.ValueOr(1); + uint16_t __block responsesNeeded = repeatCount; + while (repeatCount--) { + [cluster stringEchoRequestWithParams:params completion: + ^(MTRUnitTestingClusterStringEchoResponseParams * _Nullable values, NSError * _Nullable error) { + NSLog(@"Values: %@", values); + if (error == nil) { + constexpr chip::CommandId responseId = chip::app::Clusters::UnitTesting::Commands::StringEchoResponse::Id; + RemoteDataModelLogger::LogCommandAsJSON(@(endpointId), @(clusterId), @(responseId), values); + } + responsesNeeded--; + if (error != nil) { + mError = error; + LogNSError("Error", error); + constexpr chip::CommandId responseId = chip::app::Clusters::UnitTesting::Commands::StringEchoResponse::Id; + RemoteDataModelLogger::LogCommandErrorAsJSON(@(endpointId), @(clusterId), @(responseId), error); + } + if (responsesNeeded == 0) { + SetCommandExitStatus(mError); + } + }]; + } + return CHIP_NO_ERROR; + } + +private: + chip::app::Clusters::UnitTesting::Commands::StringEchoRequest::Type mRequest; +}; + #endif // MTR_ENABLE_PROVISIONAL #if MTR_ENABLE_PROVISIONAL /* @@ -193146,6 +193206,9 @@ void registerClusterUnitTesting(Commands & commands) #if MTR_ENABLE_PROVISIONAL make_unique(), // #endif // MTR_ENABLE_PROVISIONAL +#if MTR_ENABLE_PROVISIONAL + make_unique(), // +#endif // MTR_ENABLE_PROVISIONAL #if MTR_ENABLE_PROVISIONAL make_unique(), // #endif // MTR_ENABLE_PROVISIONAL