Skip to content

Commit

Permalink
Add draft version of samplemei implementing event
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinpan1 committed Dec 8, 2023
1 parent 1583a24 commit 59e7c07
Show file tree
Hide file tree
Showing 24 changed files with 494 additions and 6 deletions.
7 changes: 7 additions & 0 deletions examples/chef/devices/rootnode_onofflight_samplemei.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,11 @@ cluster FixedLabel = 64 {
cluster SampleMei = 4294048800 {
revision 1; // NOTE: Default/not specifically set

fabric_sensitive info event Pinged = 0 {
int8u arg1 = 1;
fabric_idx fabricIndex = 254;
}

attribute boolean flipFlop = 0;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
Expand Down Expand Up @@ -1825,9 +1830,11 @@ endpoint 1 {
}

server cluster SampleMei {
emits event Pinged;
ram attribute flipFlop default = false;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 0;
ram attribute clusterRevision default = 1;
Expand Down
28 changes: 27 additions & 1 deletion examples/chef/devices/rootnode_onofflight_samplemei.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3538,6 +3538,22 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "EventList",
"code": 65530,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AttributeList",
"code": 65531,
Expand Down Expand Up @@ -3586,6 +3602,15 @@
"maxInterval": 65534,
"reportableChange": 0
}
],
"events": [
{
"name": "Pinged",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1
}
]
}
]
Expand All @@ -3606,5 +3631,6 @@
"endpointId": 1,
"networkId": 0
}
]
],
"log": []
}
14 changes: 13 additions & 1 deletion src/app/clusters/sample-mei-server/sample-mei-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <app-common/zap-generated/ids/Commands.h>
#include <app/CommandHandler.h>
#include <app/ConcreteCommandPath.h>
#include <app/EventLogging.h>
#include <app/InteractionModelEngine.h>
#include <app/reporting/reporting.h>
#include <app/util/af.h>
Expand Down Expand Up @@ -67,6 +68,7 @@ SampleMeiContent::SampleMeiContent(EndpointId aEndpoint)
// *****************************************************************************
// SampleMeiServer

static uint8_t gPinged = 0;
void SampleMeiServer::InvokeCommand(HandlerContext & ctxt)
{
auto endpoint = ctxt.mRequestPath.mEndpointId;
Expand All @@ -82,7 +84,17 @@ void SampleMeiServer::InvokeCommand(HandlerContext & ctxt)
case Commands::Ping::Id:
HandleCommand<Commands::Ping::DecodableType>(ctxt, [endpoint](HandlerContext & ctx, const auto & req) {
ChipLogProgress(Zcl, "Ping Command on Ep %d", endpoint);
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::Success);
Events::Pinged::Type event{ .arg1 = gPinged++, .fabricIndex = 1 };
chip::EventNumber n = gPinged;
if (CHIP_NO_ERROR != LogEvent(event, 1 /*endpoint*/, n))
{
// TBD
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::Success);
}
else
{
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::Success);
}
});
return;
case Commands::AddArguments::Id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ limitations under the License.
Simple command without any parameters and without a response.
</description>
</command>

<!-- Events -->
<event side="server" code="0x0000" name="Pinged" priority="info" isFabricSensitive="true" optional="false">
<description>Example events generated by Ping command</description>
<field id="1" name="arg1" type="int8u"/>
</event>
</cluster>
</configurator>
5 changes: 5 additions & 0 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -8632,6 +8632,11 @@ internal cluster FaultInjection = 4294048774 {
cluster SampleMei = 4294048800 {
revision 1; // NOTE: Default/not specifically set

fabric_sensitive info event Pinged = 0 {
int8u arg1 = 1;
fabric_idx fabricIndex = 254;
}

attribute boolean flipFlop = 0;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4713,4 +4713,65 @@ public String toString() {
return output.toString();
}
}
public static class SampleMeiClusterPingedEvent {
public Integer arg1;
public Integer fabricIndex;
private static final long ARG1_ID = 1L;
private static final long FABRIC_INDEX_ID = 254L;

public SampleMeiClusterPingedEvent(
Integer arg1,
Integer fabricIndex
) {
this.arg1 = arg1;
this.fabricIndex = fabricIndex;
}

public StructType encodeTlv() {
ArrayList<StructElement> values = new ArrayList<>();
values.add(new StructElement(ARG1_ID, new UIntType(arg1)));
values.add(new StructElement(FABRIC_INDEX_ID, new UIntType(fabricIndex)));

return new StructType(values);
}

public static SampleMeiClusterPingedEvent decodeTlv(BaseTLVType tlvValue) {
if (tlvValue == null || tlvValue.type() != TLVType.Struct) {
return null;
}
Integer arg1 = null;
Integer fabricIndex = null;
for (StructElement element: ((StructType)tlvValue).value()) {
if (element.contextTagNum() == ARG1_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
arg1 = castingValue.value(Integer.class);
}
} else if (element.contextTagNum() == FABRIC_INDEX_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
fabricIndex = castingValue.value(Integer.class);
}
}
}
return new SampleMeiClusterPingedEvent(
arg1,
fabricIndex
);
}

@Override
public String toString() {
StringBuilder output = new StringBuilder();
output.append("SampleMeiClusterPingedEvent {\n");
output.append("\targ1: ");
output.append(arg1);
output.append("\n");
output.append("\tfabricIndex: ");
output.append(fabricIndex);
output.append("\n");
output.append("}\n");
return output.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16337,7 +16337,8 @@ public static Attribute value(long id) throws NoSuchFieldError {
}
}

public enum Event {;
public enum Event {
Pinged(0L),;
private final long id;
Event(long id) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package chip.devicecontroller.cluster.eventstructs

import chip.devicecontroller.cluster.*
import matter.tlv.ContextSpecificTag
import matter.tlv.Tag
import matter.tlv.TlvReader
import matter.tlv.TlvWriter

class SampleMeiClusterPingedEvent(val arg1: UInt, val fabricIndex: UInt) {
override fun toString(): String = buildString {
append("SampleMeiClusterPingedEvent {\n")
append("\targ1 : $arg1\n")
append("\tfabricIndex : $fabricIndex\n")
append("}\n")
}

fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) {
tlvWriter.apply {
startStructure(tlvTag)
put(ContextSpecificTag(TAG_ARG1), arg1)
put(ContextSpecificTag(TAG_FABRIC_INDEX), fabricIndex)
endStructure()
}
}

companion object {
private const val TAG_ARG1 = 1
private const val TAG_FABRIC_INDEX = 254

fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SampleMeiClusterPingedEvent {
tlvReader.enterStructure(tlvTag)
val arg1 = tlvReader.getUInt(ContextSpecificTag(TAG_ARG1))
val fabricIndex = tlvReader.getUInt(ContextSpecificTag(TAG_FABRIC_INDEX))

tlvReader.exitContainer()

return SampleMeiClusterPingedEvent(arg1, fabricIndex)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ eventstructs_sources = [
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/SampleMeiClusterPingedEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package matter.devicecontroller.cluster.eventstructs

import matter.devicecontroller.cluster.*
import matter.tlv.ContextSpecificTag
import matter.tlv.Tag
import matter.tlv.TlvReader
import matter.tlv.TlvWriter

class SampleMeiClusterPingedEvent(val arg1: UByte, val fabricIndex: UByte) {
override fun toString(): String = buildString {
append("SampleMeiClusterPingedEvent {\n")
append("\targ1 : $arg1\n")
append("\tfabricIndex : $fabricIndex\n")
append("}\n")
}

fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) {
tlvWriter.apply {
startStructure(tlvTag)
put(ContextSpecificTag(TAG_ARG1), arg1)
put(ContextSpecificTag(TAG_FABRIC_INDEX), fabricIndex)
endStructure()
}
}

companion object {
private const val TAG_ARG1 = 1
private const val TAG_FABRIC_INDEX = 254

fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SampleMeiClusterPingedEvent {
tlvReader.enterStructure(tlvTag)
val arg1 = tlvReader.getUByte(ContextSpecificTag(TAG_ARG1))
val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX))

tlvReader.exitContainer()

return SampleMeiClusterPingedEvent(arg1, fabricIndex)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ matter_eventstructs_sources = [
"${chip_root}/src/controller/java/generated/java/matter/devicecontroller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/devicecontroller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/devicecontroller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/devicecontroller/cluster/eventstructs/SampleMeiClusterPingedEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/devicecontroller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/devicecontroller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/devicecontroller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt",
Expand Down
41 changes: 41 additions & 0 deletions src/controller/java/zap-generated/CHIPEventTLVValueDecoder.cpp

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

Loading

0 comments on commit 59e7c07

Please sign in to comment.