Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chef] Add Pinged event to samplemei #30890

Merged
merged 14 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 PingCountEvent = 0 {
int32u count = 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 PingCountEvent;
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
25 changes: 25 additions & 0 deletions 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": null,
"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": "PingCountEvent",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1
}
]
}
]
Expand Down
22 changes: 17 additions & 5 deletions 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 @@ -58,7 +59,8 @@ SampleMeiContent::SampleMeiContent() : SampleMeiContent(kInvalidEndpointId) {}

SampleMeiContent::SampleMeiContent(EndpointId aEndpoint)
{
endpoint = aEndpoint;
endpoint = aEndpoint;
pingCount = 10000;
erwinpan1 marked this conversation as resolved.
Show resolved Hide resolved

// Attribute default values
flipflop = false;
Expand All @@ -70,6 +72,7 @@ SampleMeiContent::SampleMeiContent(EndpointId aEndpoint)
void SampleMeiServer::InvokeCommand(HandlerContext & ctxt)
{
auto endpoint = ctxt.mRequestPath.mEndpointId;
auto fabricIndex = ctxt.mCommandHandler.GetAccessingFabricIndex();
auto endpointIndex = EndpointIndex(endpoint);
if (endpointIndex == std::numeric_limits<size_t>::max())
{
Expand All @@ -80,10 +83,19 @@ void SampleMeiServer::InvokeCommand(HandlerContext & ctxt)
switch (ctxt.mRequestPath.mCommandId)
{
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);
});
HandleCommand<Commands::Ping::DecodableType>(
ctxt, [this, endpoint, fabricIndex, endpointIndex, ctxt](HandlerContext & ctx, const auto & req) {
erwinpan1 marked this conversation as resolved.
Show resolved Hide resolved
ChipLogProgress(Zcl, "Ping Command on Ep %d", endpoint);
Events::PingCountEvent::Type event{ .count = content[endpointIndex].pingCount++, .fabricIndex = fabricIndex };
chip::EventNumber placeholderEventNumber;
CHIP_ERROR err = LogEvent(event, endpoint, placeholderEventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Failed to record event on endpoint %d: %" CHIP_ERROR_FORMAT, static_cast<int>(endpoint),
err.Format());
}
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::Success);
});
return;
case Commands::AddArguments::Id:
HandleCommand<Commands::AddArguments::DecodableType>(ctxt, [endpoint](HandlerContext & ctx, const auto & req) {
Expand Down
1 change: 1 addition & 0 deletions src/app/clusters/sample-mei-server/sample-mei-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SampleMeiContent
{
public:
EndpointId endpoint;
uint32_t pingCount;

// Attribute List
bool flipflop; /* Attributes::FlipFlop::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="PingCountEvent" priority="info" isFabricSensitive="true" optional="false">
<description>Example events generated by Ping command</description>
<field id="1" name="count" type="int32u"/>
</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 @@ -8803,6 +8803,11 @@ internal cluster FaultInjection = 4294048774 {
cluster SampleMei = 4294048800 {
revision 1; // NOTE: Default/not specifically set

fabric_sensitive info event PingCountEvent = 0 {
int32u count = 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 @@ -4835,4 +4835,65 @@ public String toString() {
return output.toString();
}
}
public static class SampleMeiClusterPingCountEventEvent {
public Long count;
public Integer fabricIndex;
private static final long COUNT_ID = 1L;
private static final long FABRIC_INDEX_ID = 254L;

public SampleMeiClusterPingCountEventEvent(
Long count,
Integer fabricIndex
) {
this.count = count;
this.fabricIndex = fabricIndex;
}

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

return new StructType(values);
}

public static SampleMeiClusterPingCountEventEvent decodeTlv(BaseTLVType tlvValue) {
if (tlvValue == null || tlvValue.type() != TLVType.Struct) {
return null;
}
Long count = null;
Integer fabricIndex = null;
for (StructElement element: ((StructType)tlvValue).value()) {
if (element.contextTagNum() == COUNT_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
count = castingValue.value(Long.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 SampleMeiClusterPingCountEventEvent(
count,
fabricIndex
);
}

@Override
public String toString() {
StringBuilder output = new StringBuilder();
output.append("SampleMeiClusterPingCountEventEvent {\n");
output.append("\tcount: ");
output.append(count);
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 @@ -16447,7 +16447,8 @@ public static Attribute value(long id) throws NoSuchFieldError {
}
}

public enum Event {;
public enum Event {
PingCountEvent(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 SampleMeiClusterPingCountEventEvent(val count: ULong, val fabricIndex: UInt) {
override fun toString(): String = buildString {
append("SampleMeiClusterPingCountEventEvent {\n")
append("\tcount : $count\n")
append("\tfabricIndex : $fabricIndex\n")
append("}\n")
}

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

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

fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SampleMeiClusterPingCountEventEvent {
tlvReader.enterStructure(tlvTag)
val count = tlvReader.getULong(ContextSpecificTag(TAG_COUNT))
val fabricIndex = tlvReader.getUInt(ContextSpecificTag(TAG_FABRIC_INDEX))

tlvReader.exitContainer()

return SampleMeiClusterPingCountEventEvent(count, fabricIndex)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,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/SampleMeiClusterPingCountEventEvent.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.controller.cluster.eventstructs

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

class SampleMeiClusterPingCountEventEvent(val count: UInt, val fabricIndex: UByte) {
override fun toString(): String = buildString {
append("SampleMeiClusterPingCountEventEvent {\n")
append("\tcount : $count\n")
append("\tfabricIndex : $fabricIndex\n")
append("}\n")
}

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

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

fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): SampleMeiClusterPingCountEventEvent {
tlvReader.enterStructure(tlvTag)
val count = tlvReader.getUInt(ContextSpecificTag(TAG_COUNT))
val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX))

tlvReader.exitContainer()

return SampleMeiClusterPingCountEventEvent(count, fabricIndex)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ matter_eventstructs_sources = [
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RefrigeratorAlarmClusterNotifyEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationalErrorEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/RvcOperationalStateClusterOperationCompletionEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SampleMeiClusterPingCountEventEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterCOAlarmEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectCOAlarmEvent.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/eventstructs/SmokeCoAlarmClusterInterconnectSmokeAlarmEvent.kt",
Expand Down
42 changes: 42 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
Loading