Skip to content

Commit

Permalink
Fix sample
Browse files Browse the repository at this point in the history
  • Loading branch information
tennessee-google committed Dec 8, 2023
1 parent 5aacb5d commit ec16361
Show file tree
Hide file tree
Showing 24 changed files with 209 additions and 95 deletions.
6 changes: 3 additions & 3 deletions examples/chef/devices/rootnode_onofflight_samplemei.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1491,8 +1491,8 @@ cluster FixedLabel = 64 {
cluster SampleMei = 4294048800 {
revision 1; // NOTE: Default/not specifically set

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

Expand Down Expand Up @@ -1830,7 +1830,7 @@ endpoint 1 {
}

server cluster SampleMei {
emits event Pinged;
emits event PingCountEvent;
ram attribute flipFlop default = false;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
Expand Down
20 changes: 9 additions & 11 deletions src/app/clusters/sample-mei-server/sample-mei-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ SampleMeiContent::SampleMeiContent() : SampleMeiContent(kInvalidEndpointId) {}
SampleMeiContent::SampleMeiContent(EndpointId aEndpoint)
{
endpoint = aEndpoint;
pingCount = 10000;

// Attribute default values
flipflop = false;
Expand All @@ -68,10 +69,10 @@ SampleMeiContent::SampleMeiContent(EndpointId aEndpoint)
// *****************************************************************************
// SampleMeiServer

static uint8_t gPinged = 0;
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 @@ -82,19 +83,16 @@ void SampleMeiServer::InvokeCommand(HandlerContext & ctxt)
switch (ctxt.mRequestPath.mCommandId)
{
case Commands::Ping::Id:
HandleCommand<Commands::Ping::DecodableType>(ctxt, [endpoint](HandlerContext & ctx, const auto & req) {
HandleCommand<Commands::Ping::DecodableType>(ctxt, [this, endpoint, fabricIndex, endpointIndex, ctxt](HandlerContext & ctx, const auto & req) {
ChipLogProgress(Zcl, "Ping Command on Ep %d", endpoint);
Events::Pinged::Type event{ .arg1 = ++gPinged, .fabricIndex = 1 };
chip::EventNumber n = gPinged;
if (CHIP_NO_ERROR != LogEvent(event, 1 /*endpoint*/, n))
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)
{
// TBD
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::Success);
}
else
{
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::Success);
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:
Expand Down
2 changes: 2 additions & 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,10 +32,12 @@ class SampleMeiContent
{
public:
EndpointId endpoint;
uint32_t pingCount;

// Attribute List
bool flipflop; /* Attributes::FlipFlop::Id */


SampleMeiContent(EndpointId endpoint);
SampleMeiContent();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ limitations under the License.
</command>

<!-- Events -->
<event side="server" code="0x0000" name="Pinged" priority="info" isFabricSensitive="true" optional="false">
<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="arg1" type="int8u"/>
<field id="1" name="count" type="int32u"/>
</event>
</cluster>
</configurator>
4 changes: 2 additions & 2 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -8632,8 +8632,8 @@ internal cluster FaultInjection = 4294048774 {
cluster SampleMei = 4294048800 {
revision 1; // NOTE: Default/not specifically set

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4713,39 +4713,39 @@ public String toString() {
return output.toString();
}
}
public static class SampleMeiClusterPingedEvent {
public Integer arg1;
public static class SampleMeiClusterPingCountEventEvent {
public Long count;
public Integer fabricIndex;
private static final long ARG1_ID = 1L;
private static final long COUNT_ID = 1L;
private static final long FABRIC_INDEX_ID = 254L;

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

public StructType encodeTlv() {
ArrayList<StructElement> values = new ArrayList<>();
values.add(new StructElement(ARG1_ID, new UIntType(arg1)));
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 SampleMeiClusterPingedEvent decodeTlv(BaseTLVType tlvValue) {
public static SampleMeiClusterPingCountEventEvent decodeTlv(BaseTLVType tlvValue) {
if (tlvValue == null || tlvValue.type() != TLVType.Struct) {
return null;
}
Integer arg1 = null;
Long count = null;
Integer fabricIndex = null;
for (StructElement element: ((StructType)tlvValue).value()) {
if (element.contextTagNum() == ARG1_ID) {
if (element.contextTagNum() == COUNT_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
arg1 = castingValue.value(Integer.class);
count = castingValue.value(Long.class);
}
} else if (element.contextTagNum() == FABRIC_INDEX_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
Expand All @@ -4754,18 +4754,18 @@ public static SampleMeiClusterPingedEvent decodeTlv(BaseTLVType tlvValue) {
}
}
}
return new SampleMeiClusterPingedEvent(
arg1,
return new SampleMeiClusterPingCountEventEvent(
count,
fabricIndex
);
}

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

public enum Event {
Pinged(0L),;
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 @@ -164,7 +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/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.devicecontroller.cluster.eventstructs

import matter.devicecontroller.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 @@ -164,7 +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/SampleMeiClusterPingCountEventEvent.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
31 changes: 16 additions & 15 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.

6 changes: 3 additions & 3 deletions src/controller/python/chip/clusters/Objects.py

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

Loading

0 comments on commit ec16361

Please sign in to comment.