Skip to content

Commit f30c3d9

Browse files
Add complex type Date and using it in DayStruct
1 parent fc25a71 commit f30c3d9

File tree

23 files changed

+1010
-59
lines changed

23 files changed

+1010
-59
lines changed

src/app/zap-templates/zcl/data-model/chip/chip-types.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ limitations under the License.
6464
<type id="0xE7" description="Percentage units 0.01%" name="percent100ths" size="2" analog="true" />
6565

6666
<type id="0xE0" description="Time of day" name="tod" size="4" analog="true" />
67-
<type id="0xE1" description="Date" name="date" size="4" analog="true" />
67+
<!-- <type id="0xE1" description="Date" name="date" size="4" analog="true" /> -->
6868
<type id="0xE3" description="Epoch Microseconds" name="epoch_us" size="8" analog="true" />
6969
<type id="0xE4" description="Epoch Seconds" name="epoch_s" size="4" analog="true" />
7070
<type id="0xE5" description="Posix Time Milliseconds" name="posix_ms" size="8" analog="true" />

src/app/zap-templates/zcl/data-model/chip/energy-calendar-cluster.xml

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,31 @@ limitations under the License.
4444
<item name="High" value="0x03"/>
4545
</enum>
4646

47-
<struct name="PeakPeriodStruct">
47+
<struct name="PeakPeriodStruct" apiMaturity="provisional">
4848
<cluster code="0x009A"/>
4949
<item fieldId="0" name="Severity" type="PeakPeriodSeverityEnum" min="0x00" max="0x03"/>
5050
<item fieldId="1" name="PeakPeriod" type="int16u" default="0"/>
5151
<item fieldId="2" name="StartTime" type="epoch_s" isNullable="true"/>
5252
<item fieldId="3" name="EndTime" type="epoch_s" isNullable="true"/>
5353
</struct>
5454

55-
<struct name="TransitionStruct">
55+
<struct name="TransitionStruct" apiMaturity="provisional">
5656
<cluster code="0x009A"/>
5757
<item fieldId="0" name="TransitionTime" type="int16u" max="1499"/>
5858
<item fieldId="1" name="PriceTier" type="int32u" optional="true"/>
5959
<item fieldId="2" name="FriendlyCredit" type="boolean" optional="true"/>
6060
<item fieldId="3" name="AuxiliaryLoad" type="AuxiliaryLoadBitmap" optional="true" min="0x00" max="0xFF"/>
6161
</struct>
6262

63-
<struct name="DayStruct">
63+
<struct name="DayStruct" apiMaturity="provisional">
6464
<cluster code="0x009A"/>
65-
<item fieldId="0" name="Date" type="date" optional="true"/>
65+
<item fieldId="0" name="Date" type="DateStruct" optional="true"/>
6666
<item fieldId="1" name="DaysOfWeek" type="TransitionDayOfWeekBitmap" optional="true" min="0x00" max="0x7F"/>
6767
<item fieldId="2" name="Transitions" type="TransitionStruct" array="true" length="48" minLength="1"/>
6868
<item fieldId="3" name="CalendarID" type="int32u" optional="true"/>
6969
</struct>
7070

71-
<struct name="CalendarPeriodStruct">
71+
<struct name="CalendarPeriodStruct" apiMaturity="provisional">
7272
<cluster code="0x009A"/>
7373
<item fieldId="0" name="StartDate" type="epoch_s" isNullable="true"/>
7474
<item fieldId="1" name="Days" type="DayStruct" array="true" length="7" minLength="1"/>
@@ -84,16 +84,16 @@ limitations under the License.
8484
<description>The Energy Calendar Cluster provides a mechanism for communicating schedules associated with various forms of energy consumption.</description>
8585
<globalAttribute side="either" code="0xFFFD" value="3"/>
8686
<features>
87-
<feature bit="0" code="PTIER" name="PricingTier" summary="Supports information about pricing tiers">
87+
<feature apiMaturity="provisional" bit="0" code="PTIER" name="PricingTier" summary="Supports information about pricing tiers">
8888
<optionalConform choice="a" more="true" min="1"/>
8989
</feature>
90-
<feature bit="1" code="FCRED" name="FriendlyCredit" summary="Supports information about when friendly credit periods begin and end">
90+
<feature apiMaturity="provisional" bit="1" code="FCRED" name="FriendlyCredit" summary="Supports information about when friendly credit periods begin and end">
9191
<optionalConform choice="a" more="true" min="1"/>
9292
</feature>
93-
<feature bit="2" code="AUXLD" name="AuxiliaryLoad" summary="Supports information about when auxiliary loads should be enabled or disabled">
93+
<feature apiMaturity="provisional" bit="2" code="AUXLD" name="AuxiliaryLoad" summary="Supports information about when auxiliary loads should be enabled or disabled">
9494
<optionalConform choice="a" more="true" min="1"/>
9595
</feature>
96-
<feature bit="3" code="PEAKP" name="PeakPeriod" summary="Supports information about peak periods">
96+
<feature apiMaturity="provisional" bit="3" code="PEAKP" name="PeakPeriod" summary="Supports information about peak periods">
9797
<optionalConform/>
9898
</feature>
9999
</features>

src/app/zap-templates/zcl/data-model/chip/global-structs.xml

+10
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,14 @@ TODO: Make these structures global rather than defining them for each cluster.
3131
<item fieldId="1" name="FloorNumber" type="int16s" isNullable="true" optional="false"/>
3232
<item fieldId="2" name="AreaType" type="AreaTypeTag" isNullable="true" optional="false"/>
3333
</struct>
34+
35+
<struct name="DateStruct">
36+
<cluster code="0x009A"/> <!-- Energy Calendar -->
37+
<cluster code="0x0B06"/> <!-- Without this scripts/tools/zap_regen_all.py pushes global DateStruct to EnergyCalendar namespace -->
38+
39+
<item fieldId="0" name="Year" type="int8u" isNullable="true" optional="false"/>
40+
<item fieldId="1" name="Month" type="int8u" min="1" max="12" isNullable="true" optional="false"/>
41+
<item fieldId="2" name="Day" type="int8u" min="1" max="31" isNullable="true" optional="false"/>
42+
<item fieldId="3" name="DayOfWeek" type="int8u" min="1" max="7" isNullable="true" optional="false"/>
43+
</struct>
3444
</configurator>

src/controller/data_model/controller-clusters.matter

+8-1
Original file line numberDiff line numberDiff line change
@@ -5113,8 +5113,15 @@ cluster EnergyCalendar = 154 {
51135113
optional AuxiliaryLoadBitmap auxiliaryLoad = 3;
51145114
}
51155115

5116+
struct DateStruct {
5117+
nullable int8u year = 0;
5118+
nullable int8u month = 1;
5119+
nullable int8u day = 2;
5120+
nullable int8u dayOfWeek = 3;
5121+
}
5122+
51165123
struct DayStruct {
5117-
optional date date = 0;
5124+
optional DateStruct date = 0;
51185125
optional TransitionDayOfWeekBitmap daysOfWeek = 1;
51195126
TransitionStruct transitions[] = 2;
51205127
optional int32u calendarID = 3;

src/controller/java/generated/java/chip/devicecontroller/ChipStructs.java

+98-7
Original file line numberDiff line numberDiff line change
@@ -8501,8 +8501,99 @@ public String toString() {
85018501
return output.toString();
85028502
}
85038503
}
8504+
public static class EnergyCalendarClusterDateStruct {
8505+
public @Nullable Integer year;
8506+
public @Nullable Integer month;
8507+
public @Nullable Integer day;
8508+
public @Nullable Integer dayOfWeek;
8509+
private static final long YEAR_ID = 0L;
8510+
private static final long MONTH_ID = 1L;
8511+
private static final long DAY_ID = 2L;
8512+
private static final long DAY_OF_WEEK_ID = 3L;
8513+
8514+
public EnergyCalendarClusterDateStruct(
8515+
@Nullable Integer year,
8516+
@Nullable Integer month,
8517+
@Nullable Integer day,
8518+
@Nullable Integer dayOfWeek
8519+
) {
8520+
this.year = year;
8521+
this.month = month;
8522+
this.day = day;
8523+
this.dayOfWeek = dayOfWeek;
8524+
}
8525+
8526+
public StructType encodeTlv() {
8527+
ArrayList<StructElement> values = new ArrayList<>();
8528+
values.add(new StructElement(YEAR_ID, year != null ? new UIntType(year) : new NullType()));
8529+
values.add(new StructElement(MONTH_ID, month != null ? new UIntType(month) : new NullType()));
8530+
values.add(new StructElement(DAY_ID, day != null ? new UIntType(day) : new NullType()));
8531+
values.add(new StructElement(DAY_OF_WEEK_ID, dayOfWeek != null ? new UIntType(dayOfWeek) : new NullType()));
8532+
8533+
return new StructType(values);
8534+
}
8535+
8536+
public static EnergyCalendarClusterDateStruct decodeTlv(BaseTLVType tlvValue) {
8537+
if (tlvValue == null || tlvValue.type() != TLVType.Struct) {
8538+
return null;
8539+
}
8540+
@Nullable Integer year = null;
8541+
@Nullable Integer month = null;
8542+
@Nullable Integer day = null;
8543+
@Nullable Integer dayOfWeek = null;
8544+
for (StructElement element: ((StructType)tlvValue).value()) {
8545+
if (element.contextTagNum() == YEAR_ID) {
8546+
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
8547+
UIntType castingValue = element.value(UIntType.class);
8548+
year = castingValue.value(Integer.class);
8549+
}
8550+
} else if (element.contextTagNum() == MONTH_ID) {
8551+
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
8552+
UIntType castingValue = element.value(UIntType.class);
8553+
month = castingValue.value(Integer.class);
8554+
}
8555+
} else if (element.contextTagNum() == DAY_ID) {
8556+
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
8557+
UIntType castingValue = element.value(UIntType.class);
8558+
day = castingValue.value(Integer.class);
8559+
}
8560+
} else if (element.contextTagNum() == DAY_OF_WEEK_ID) {
8561+
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
8562+
UIntType castingValue = element.value(UIntType.class);
8563+
dayOfWeek = castingValue.value(Integer.class);
8564+
}
8565+
}
8566+
}
8567+
return new EnergyCalendarClusterDateStruct(
8568+
year,
8569+
month,
8570+
day,
8571+
dayOfWeek
8572+
);
8573+
}
8574+
8575+
@Override
8576+
public String toString() {
8577+
StringBuilder output = new StringBuilder();
8578+
output.append("EnergyCalendarClusterDateStruct {\n");
8579+
output.append("\tyear: ");
8580+
output.append(year);
8581+
output.append("\n");
8582+
output.append("\tmonth: ");
8583+
output.append(month);
8584+
output.append("\n");
8585+
output.append("\tday: ");
8586+
output.append(day);
8587+
output.append("\n");
8588+
output.append("\tdayOfWeek: ");
8589+
output.append(dayOfWeek);
8590+
output.append("\n");
8591+
output.append("}\n");
8592+
return output.toString();
8593+
}
8594+
}
85048595
public static class EnergyCalendarClusterDayStruct {
8505-
public Optional<Long> date;
8596+
public Optional<ChipStructs.EnergyCalendarClusterDateStruct> date;
85068597
public Optional<Integer> daysOfWeek;
85078598
public ArrayList<ChipStructs.EnergyCalendarClusterTransitionStruct> transitions;
85088599
public Optional<Long> calendarID;
@@ -8512,7 +8603,7 @@ public static class EnergyCalendarClusterDayStruct {
85128603
private static final long CALENDAR_I_D_ID = 3L;
85138604

85148605
public EnergyCalendarClusterDayStruct(
8515-
Optional<Long> date,
8606+
Optional<ChipStructs.EnergyCalendarClusterDateStruct> date,
85168607
Optional<Integer> daysOfWeek,
85178608
ArrayList<ChipStructs.EnergyCalendarClusterTransitionStruct> transitions,
85188609
Optional<Long> calendarID
@@ -8525,7 +8616,7 @@ public EnergyCalendarClusterDayStruct(
85258616

85268617
public StructType encodeTlv() {
85278618
ArrayList<StructElement> values = new ArrayList<>();
8528-
values.add(new StructElement(DATE_ID, date.<BaseTLVType>map((nonOptionaldate) -> new UIntType(nonOptionaldate)).orElse(new EmptyType())));
8619+
values.add(new StructElement(DATE_ID, date.<BaseTLVType>map((nonOptionaldate) -> nonOptionaldate.encodeTlv()).orElse(new EmptyType())));
85298620
values.add(new StructElement(DAYS_OF_WEEK_ID, daysOfWeek.<BaseTLVType>map((nonOptionaldaysOfWeek) -> new UIntType(nonOptionaldaysOfWeek)).orElse(new EmptyType())));
85308621
values.add(new StructElement(TRANSITIONS_ID, ArrayType.generateArrayType(transitions, (elementtransitions) -> elementtransitions.encodeTlv())));
85318622
values.add(new StructElement(CALENDAR_I_D_ID, calendarID.<BaseTLVType>map((nonOptionalcalendarID) -> new UIntType(nonOptionalcalendarID)).orElse(new EmptyType())));
@@ -8537,15 +8628,15 @@ public static EnergyCalendarClusterDayStruct decodeTlv(BaseTLVType tlvValue) {
85378628
if (tlvValue == null || tlvValue.type() != TLVType.Struct) {
85388629
return null;
85398630
}
8540-
Optional<Long> date = Optional.empty();
8631+
Optional<ChipStructs.EnergyCalendarClusterDateStruct> date = Optional.empty();
85418632
Optional<Integer> daysOfWeek = Optional.empty();
85428633
ArrayList<ChipStructs.EnergyCalendarClusterTransitionStruct> transitions = null;
85438634
Optional<Long> calendarID = Optional.empty();
85448635
for (StructElement element: ((StructType)tlvValue).value()) {
85458636
if (element.contextTagNum() == DATE_ID) {
8546-
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
8547-
UIntType castingValue = element.value(UIntType.class);
8548-
date = Optional.of(castingValue.value(Long.class));
8637+
if (element.value(BaseTLVType.class).type() == TLVType.Struct) {
8638+
StructType castingValue = element.value(StructType.class);
8639+
date = Optional.of(ChipStructs.EnergyCalendarClusterDateStruct.decodeTlv(castingValue));
85498640
}
85508641
} else if (element.contextTagNum() == DAYS_OF_WEEK_ID) {
85518642
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {

src/controller/java/generated/java/chip/devicecontroller/cluster/files.gni

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ structs_sources = [
6565
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt",
6666
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt",
6767
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterCalendarPeriodStruct.kt",
68+
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterDateStruct.kt",
6869
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterDayStruct.kt",
6970
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterPeakPeriodStruct.kt",
7071
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterTransitionStruct.kt",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package chip.devicecontroller.cluster.structs
18+
19+
import chip.devicecontroller.cluster.*
20+
import matter.tlv.ContextSpecificTag
21+
import matter.tlv.Tag
22+
import matter.tlv.TlvReader
23+
import matter.tlv.TlvWriter
24+
25+
class EnergyCalendarClusterDateStruct(
26+
val year: UInt?,
27+
val month: UInt?,
28+
val day: UInt?,
29+
val dayOfWeek: UInt?,
30+
) {
31+
override fun toString(): String = buildString {
32+
append("EnergyCalendarClusterDateStruct {\n")
33+
append("\tyear : $year\n")
34+
append("\tmonth : $month\n")
35+
append("\tday : $day\n")
36+
append("\tdayOfWeek : $dayOfWeek\n")
37+
append("}\n")
38+
}
39+
40+
fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) {
41+
tlvWriter.apply {
42+
startStructure(tlvTag)
43+
if (year != null) {
44+
put(ContextSpecificTag(TAG_YEAR), year)
45+
} else {
46+
putNull(ContextSpecificTag(TAG_YEAR))
47+
}
48+
if (month != null) {
49+
put(ContextSpecificTag(TAG_MONTH), month)
50+
} else {
51+
putNull(ContextSpecificTag(TAG_MONTH))
52+
}
53+
if (day != null) {
54+
put(ContextSpecificTag(TAG_DAY), day)
55+
} else {
56+
putNull(ContextSpecificTag(TAG_DAY))
57+
}
58+
if (dayOfWeek != null) {
59+
put(ContextSpecificTag(TAG_DAY_OF_WEEK), dayOfWeek)
60+
} else {
61+
putNull(ContextSpecificTag(TAG_DAY_OF_WEEK))
62+
}
63+
endStructure()
64+
}
65+
}
66+
67+
companion object {
68+
private const val TAG_YEAR = 0
69+
private const val TAG_MONTH = 1
70+
private const val TAG_DAY = 2
71+
private const val TAG_DAY_OF_WEEK = 3
72+
73+
fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): EnergyCalendarClusterDateStruct {
74+
tlvReader.enterStructure(tlvTag)
75+
val year =
76+
if (!tlvReader.isNull()) {
77+
tlvReader.getUInt(ContextSpecificTag(TAG_YEAR))
78+
} else {
79+
tlvReader.getNull(ContextSpecificTag(TAG_YEAR))
80+
null
81+
}
82+
val month =
83+
if (!tlvReader.isNull()) {
84+
tlvReader.getUInt(ContextSpecificTag(TAG_MONTH))
85+
} else {
86+
tlvReader.getNull(ContextSpecificTag(TAG_MONTH))
87+
null
88+
}
89+
val day =
90+
if (!tlvReader.isNull()) {
91+
tlvReader.getUInt(ContextSpecificTag(TAG_DAY))
92+
} else {
93+
tlvReader.getNull(ContextSpecificTag(TAG_DAY))
94+
null
95+
}
96+
val dayOfWeek =
97+
if (!tlvReader.isNull()) {
98+
tlvReader.getUInt(ContextSpecificTag(TAG_DAY_OF_WEEK))
99+
} else {
100+
tlvReader.getNull(ContextSpecificTag(TAG_DAY_OF_WEEK))
101+
null
102+
}
103+
104+
tlvReader.exitContainer()
105+
106+
return EnergyCalendarClusterDateStruct(year, month, day, dayOfWeek)
107+
}
108+
}
109+
}

src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterDayStruct.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import matter.tlv.TlvReader
2525
import matter.tlv.TlvWriter
2626

2727
class EnergyCalendarClusterDayStruct(
28-
val date: Optional<ULong>,
28+
val date: Optional<EnergyCalendarClusterDateStruct>,
2929
val daysOfWeek: Optional<UInt>,
3030
val transitions: List<EnergyCalendarClusterTransitionStruct>,
3131
val calendarID: Optional<ULong>,
@@ -44,7 +44,7 @@ class EnergyCalendarClusterDayStruct(
4444
startStructure(tlvTag)
4545
if (date.isPresent) {
4646
val optdate = date.get()
47-
put(ContextSpecificTag(TAG_DATE), optdate)
47+
optdate.toTlv(ContextSpecificTag(TAG_DATE), this)
4848
}
4949
if (daysOfWeek.isPresent) {
5050
val optdaysOfWeek = daysOfWeek.get()
@@ -73,7 +73,9 @@ class EnergyCalendarClusterDayStruct(
7373
tlvReader.enterStructure(tlvTag)
7474
val date =
7575
if (tlvReader.isNextTag(ContextSpecificTag(TAG_DATE))) {
76-
Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_DATE)))
76+
Optional.of(
77+
EnergyCalendarClusterDateStruct.fromTlv(ContextSpecificTag(TAG_DATE), tlvReader)
78+
)
7779
} else {
7880
Optional.empty()
7981
}

src/controller/java/generated/java/matter/controller/cluster/files.gni

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ matter_structs_sources = [
6565
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt",
6666
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt",
6767
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyCalendarClusterCalendarPeriodStruct.kt",
68+
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyCalendarClusterDateStruct.kt",
6869
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyCalendarClusterDayStruct.kt",
6970
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyCalendarClusterPeakPeriodStruct.kt",
7071
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyCalendarClusterTransitionStruct.kt",

0 commit comments

Comments
 (0)