Skip to content

Commit

Permalink
Add fabric sync related changed into bridge device info cluster (proj…
Browse files Browse the repository at this point in the history
  • Loading branch information
tehampson authored and rochaferraz committed Jul 31, 2024
1 parent a38203d commit fdcb785
Show file tree
Hide file tree
Showing 37 changed files with 865 additions and 6 deletions.
11 changes: 11 additions & 0 deletions examples/placeholder/linux/apps/app1/config.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2320,6 +2320,10 @@ cluster BridgedDeviceBasicInformation = 57 {
kFabric = 5;
}

bitmap Feature : bitmap32 {
kBridgedICDSupport = 0x100000;
}

struct ProductAppearanceStruct {
ProductFinishEnum finish = 0;
nullable ColorEnum primaryColor = 1;
Expand All @@ -2339,6 +2343,10 @@ cluster BridgedDeviceBasicInformation = 57 {
boolean reachableNewValue = 0;
}

info event ActiveChanged = 128 {
int32u promisedActiveDuration = 0;
}

readonly attribute optional char_string<32> vendorName = 1;
readonly attribute optional vendor_id vendorID = 2;
readonly attribute optional char_string<32> productName = 3;
Expand All @@ -2361,6 +2369,9 @@ cluster BridgedDeviceBasicInformation = 57 {
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

/** The server SHALL attempt to keep the devices specified active for StayActiveDuration milliseconds when they are next active. */
command KeepActive(): DefaultSuccess = 128;
}

/** This cluster exposes interactions with a switch device, for the purpose of using those interactions by other devices.
Expand Down
11 changes: 11 additions & 0 deletions examples/placeholder/linux/apps/app2/config.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,10 @@ cluster BridgedDeviceBasicInformation = 57 {
kFabric = 5;
}

bitmap Feature : bitmap32 {
kBridgedICDSupport = 0x100000;
}

struct ProductAppearanceStruct {
ProductFinishEnum finish = 0;
nullable ColorEnum primaryColor = 1;
Expand All @@ -2296,6 +2300,10 @@ cluster BridgedDeviceBasicInformation = 57 {
boolean reachableNewValue = 0;
}

info event ActiveChanged = 128 {
int32u promisedActiveDuration = 0;
}

readonly attribute optional char_string<32> vendorName = 1;
readonly attribute optional vendor_id vendorID = 2;
readonly attribute optional char_string<32> productName = 3;
Expand All @@ -2318,6 +2326,9 @@ cluster BridgedDeviceBasicInformation = 57 {
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

/** The server SHALL attempt to keep the devices specified active for StayActiveDuration milliseconds when they are next active. */
command KeepActive(): DefaultSuccess = 128;
}

/** This cluster exposes interactions with a switch device, for the purpose of using those interactions by other devices.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ limitations under the License.
<server tick="false" init="false">true</server>
<globalAttribute side="either" code="0xFFFD" value="3"/>

<features>
<feature bit="20" code="BIS" name="BridgedICDSupport" summary="Support Bridged ICD Devices.">
<optionalConform/>
</feature>
</features>

<attribute side="server" code="1" define="VENDOR_NAME" type="char_string" length="32" optional="true">VendorName</attribute>
<attribute side="server" code="2" define="VENDOR_ID" type="vendor_id" optional="true">VendorID</attribute>
<attribute side="server" code="3" define="PRODUCT_NAME" type="char_string" length="32" optional="true">ProductName</attribute>
Expand All @@ -88,6 +94,10 @@ limitations under the License.
<attribute side="server" code="18" define="UNIQUE_ID" type="char_string" length="32" optional="false">UniqueID</attribute>
<attribute side="server" code="20" define="PRODUCT_APPEARANCE" type="ProductAppearanceStruct" optional="true">ProductAppearance</attribute>

<command source="client" code="0x80" name="KeepActive" optional="true" apiMaturity="provisional">
<description> The server SHALL attempt to keep the devices specified active for StayActiveDuration milliseconds when they are next active.</description>
</command>

<event side="server" code="0x00" name="StartUp" priority="critical" optional="true">
<description>The StartUp event SHALL be emitted by a Node as soon as reasonable after completing a boot or reboot process.</description>
<field id="0" name="SoftwareVersion" type="int32u"/>
Expand All @@ -102,6 +112,10 @@ limitations under the License.
<description>This event SHALL be generated when there is a change in the Reachable attribute.</description>
<field id="0" name="ReachableNewValue" type="boolean"/>
</event>
<event side="server" code="0x80" name="ActiveChanged" priority="info" optional="true" apiMaturity="provisional">
<description>This event (when supported) SHALL be generated the next time a bridged device becomes active after a KeepActive command is received.</description>
<field id="0" name="PromisedActiveDuration" type="int32u"/>
</event>

</cluster>
</configurator>
11 changes: 11 additions & 0 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,10 @@ cluster BridgedDeviceBasicInformation = 57 {
kFabric = 5;
}

bitmap Feature : bitmap32 {
kBridgedICDSupport = 0x100000;
}

struct ProductAppearanceStruct {
ProductFinishEnum finish = 0;
nullable ColorEnum primaryColor = 1;
Expand All @@ -2244,6 +2248,10 @@ cluster BridgedDeviceBasicInformation = 57 {
boolean reachableNewValue = 0;
}

info event ActiveChanged = 128 {
int32u promisedActiveDuration = 0;
}

readonly attribute optional char_string<32> vendorName = 1;
readonly attribute optional vendor_id vendorID = 2;
readonly attribute optional char_string<32> productName = 3;
Expand All @@ -2266,6 +2274,9 @@ cluster BridgedDeviceBasicInformation = 57 {
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

/** The server SHALL attempt to keep the devices specified active for StayActiveDuration milliseconds when they are next active. */
command KeepActive(): DefaultSuccess = 128;
}

/** This cluster exposes interactions with a switch device, for the purpose of using those interactions by other devices.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14963,6 +14963,22 @@ public long initWithDevice(long devicePtr, int endpointId) {
return 0L;
}

public void keepActive(DefaultClusterCallback callback) {
keepActive(callback, 0);
}

public void keepActive(DefaultClusterCallback callback, int timedInvokeTimeoutMs) {
final long commandId = 128L;

ArrayList<StructElement> elements = new ArrayList<>();
StructType commandArgs = new StructType(elements);
invoke(new InvokeCallbackImpl(callback) {
@Override
public void onResponse(StructType invokeStructValue) {
callback.onSuccess();
}}, commandId, commandArgs, timedInvokeTimeoutMs);
}

public interface ProductAppearanceAttributeCallback extends BaseAttributeCallback {
void onSuccess(ChipStructs.BridgedDeviceBasicInformationClusterProductAppearanceStruct value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,52 @@ public String toString() {
return output.toString();
}
}
public static class BridgedDeviceBasicInformationClusterActiveChangedEvent {
public Long promisedActiveDuration;
private static final long PROMISED_ACTIVE_DURATION_ID = 0L;

public BridgedDeviceBasicInformationClusterActiveChangedEvent(
Long promisedActiveDuration
) {
this.promisedActiveDuration = promisedActiveDuration;
}

public StructType encodeTlv() {
ArrayList<StructElement> values = new ArrayList<>();
values.add(new StructElement(PROMISED_ACTIVE_DURATION_ID, new UIntType(promisedActiveDuration)));

return new StructType(values);
}

public static BridgedDeviceBasicInformationClusterActiveChangedEvent decodeTlv(BaseTLVType tlvValue) {
if (tlvValue == null || tlvValue.type() != TLVType.Struct) {
return null;
}
Long promisedActiveDuration = null;
for (StructElement element: ((StructType)tlvValue).value()) {
if (element.contextTagNum() == PROMISED_ACTIVE_DURATION_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
promisedActiveDuration = castingValue.value(Long.class);
}
}
}
return new BridgedDeviceBasicInformationClusterActiveChangedEvent(
promisedActiveDuration
);
}

@Override
public String toString() {
StringBuilder output = new StringBuilder();
output.append("BridgedDeviceBasicInformationClusterActiveChangedEvent {\n");
output.append("\tpromisedActiveDuration: ");
output.append(promisedActiveDuration);
output.append("\n");
output.append("}\n");
return output.toString();
}
}
public static class SwitchClusterSwitchLatchedEvent {
public Integer newPosition;
private static final long NEW_POSITION_ID = 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4455,7 +4455,8 @@ public enum Event {
StartUp(0L),
ShutDown(1L),
Leave(2L),
ReachableChanged(3L),;
ReachableChanged(3L),
ActiveChanged(128L),;
private final long id;
Event(long id) {
this.id = id;
Expand All @@ -4475,7 +4476,8 @@ public static Event value(long id) throws NoSuchFieldError {
}
}

public enum Command {;
public enum Command {
KeepActive(128L),;
private final long id;
Command(long id) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24028,6 +24028,18 @@ public Map<String, Map<String, InteractionInfo>> getCommandMap() {

Map<String, InteractionInfo> bridgedDeviceBasicInformationClusterInteractionInfoMap = new LinkedHashMap<>();

Map<String, CommandParameterInfo> bridgedDeviceBasicInformationkeepActiveCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo bridgedDeviceBasicInformationkeepActiveInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.BridgedDeviceBasicInformationCluster) cluster)
.keepActive((DefaultClusterCallback) callback
);
},
() -> new DelegatedDefaultClusterCallback(),
bridgedDeviceBasicInformationkeepActiveCommandParams
);
bridgedDeviceBasicInformationClusterInteractionInfoMap.put("keepActive", bridgedDeviceBasicInformationkeepActiveInteractionInfo);

commandMap.put("bridgedDeviceBasicInformation", bridgedDeviceBasicInformationClusterInteractionInfoMap);

Map<String, InteractionInfo> switchClusterInteractionInfoMap = new LinkedHashMap<>();
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 BridgedDeviceBasicInformationClusterActiveChangedEvent(val promisedActiveDuration: ULong) {
override fun toString(): String = buildString {
append("BridgedDeviceBasicInformationClusterActiveChangedEvent {\n")
append("\tpromisedActiveDuration : $promisedActiveDuration\n")
append("}\n")
}

fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) {
tlvWriter.apply {
startStructure(tlvTag)
put(ContextSpecificTag(TAG_PROMISED_ACTIVE_DURATION), promisedActiveDuration)
endStructure()
}
}

companion object {
private const val TAG_PROMISED_ACTIVE_DURATION = 0

fun fromTlv(
tlvTag: Tag,
tlvReader: TlvReader,
): BridgedDeviceBasicInformationClusterActiveChangedEvent {
tlvReader.enterStructure(tlvTag)
val promisedActiveDuration =
tlvReader.getULong(ContextSpecificTag(TAG_PROMISED_ACTIVE_DURATION))

tlvReader.exitContainer()

return BridgedDeviceBasicInformationClusterActiveChangedEvent(promisedActiveDuration)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ eventstructs_sources = [
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/BooleanStateClusterStateChangeEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/BooleanStateConfigurationClusterAlarmsStateChangedEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/BooleanStateConfigurationClusterSensorFaultEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/BridgedDeviceBasicInformationClusterActiveChangedEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/BridgedDeviceBasicInformationClusterReachableChangedEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/BridgedDeviceBasicInformationClusterStartUpEvent.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/eventstructs/CommissionerControlClusterCommissioningRequestResultEvent.kt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import java.util.logging.Logger
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.transform
import matter.controller.BooleanSubscriptionState
import matter.controller.InvokeRequest
import matter.controller.InvokeResponse
import matter.controller.MatterController
import matter.controller.ReadData
import matter.controller.ReadRequest
Expand All @@ -36,6 +38,7 @@ import matter.controller.WriteRequests
import matter.controller.WriteResponse
import matter.controller.cluster.structs.*
import matter.controller.model.AttributePath
import matter.controller.model.CommandPath
import matter.tlv.AnonymousTag
import matter.tlv.TlvReader
import matter.tlv.TlvWriter
Expand Down Expand Up @@ -97,6 +100,24 @@ class BridgedDeviceBasicInformationCluster(
object SubscriptionEstablished : AttributeListAttributeSubscriptionState()
}

suspend fun keepActive(timedInvokeTimeout: Duration? = null) {
val commandId: UInt = 128u

val tlvWriter = TlvWriter()
tlvWriter.startStructure(AnonymousTag)
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}")
}

suspend fun readVendorNameAttribute(): String? {
val ATTRIBUTE_ID: UInt = 1u

Expand Down
Loading

0 comments on commit fdcb785

Please sign in to comment.