Skip to content

Commit

Permalink
Revert type DayStruct.Date to epoch
Browse files Browse the repository at this point in the history
Revert implementing Date type as struct
  • Loading branch information
Michail-Antropov committed Sep 2, 2024
1 parent 977b624 commit af34956
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 824 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ const MockNodeConfig gTestNodeConfig({
MOCK_ATTRIBUTE_CONFIG_NON_NULLABLE(ZCL_VOLTAGE_MV_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NON_NULLABLE(ZCL_ENERGY_MWH_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NON_NULLABLE(ZCL_TOD_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NON_NULLABLE(ZCL_DATE_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NON_NULLABLE(ZCL_EPOCH_US_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NON_NULLABLE(ZCL_EPOCH_S_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NON_NULLABLE(ZCL_POSIX_MS_ATTRIBUTE_TYPE),
Expand Down Expand Up @@ -401,6 +402,7 @@ const MockNodeConfig gTestNodeConfig({
MOCK_ATTRIBUTE_CONFIG_NULLABLE(ZCL_VOLTAGE_MV_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NULLABLE(ZCL_ENERGY_MWH_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NULLABLE(ZCL_TOD_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NULLABLE(ZCL_DATE_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NULLABLE(ZCL_EPOCH_US_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NULLABLE(ZCL_EPOCH_S_ATTRIBUTE_TYPE),
MOCK_ATTRIBUTE_CONFIG_NULLABLE(ZCL_POSIX_MS_ATTRIBUTE_TYPE),
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap-templates/zcl/data-model/chip/chip-types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ limitations under the License.
<type id="0xE7" description="Percentage units 0.01%" name="percent100ths" size="2" analog="true" />

<type id="0xE0" description="Time of day" name="tod" size="4" analog="true" />
<!-- <type id="0xE1" description="Date" name="date" size="4" analog="true" /> -->
<type id="0xE1" description="Date" name="date" size="4" analog="true" />
<type id="0xE3" description="Epoch Microseconds" name="epoch_us" size="8" analog="true" />
<type id="0xE4" description="Epoch Seconds" name="epoch_s" size="4" analog="true" />
<type id="0xE5" description="Posix Time Milliseconds" name="posix_ms" size="8" analog="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ limitations under the License.

<struct name="DayStruct" apiMaturity="provisional">
<cluster code="0x009A"/>
<item fieldId="0" name="Date" type="DateStruct" optional="true"/>
<item fieldId="0" name="Date" type="epoch_s" optional="true"/>
<item fieldId="1" name="DaysOfWeek" type="TransitionDayOfWeekBitmap" optional="true" min="0x00" max="0x7F"/>
<item fieldId="2" name="Transitions" array="true" type="TransitionStruct" length="48" minLength="1"/>
<item fieldId="3" name="CalendarID" type="int32u" optional="true"/>
Expand Down
9 changes: 1 addition & 8 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -5444,15 +5444,8 @@ cluster EnergyCalendar = 154 {
optional AuxiliaryLoadBitmap auxiliaryLoad = 3;
}

struct DateStruct {
nullable int8u year = 0;
nullable int8u month = 1;
nullable int8u day = 2;
nullable int8u dayOfWeek = 3;
}

struct DayStruct {
optional DateStruct date = 0;
optional epoch_s date = 0;
optional TransitionDayOfWeekBitmap daysOfWeek = 1;
TransitionStruct transitions[] = 2;
optional int32u calendarID = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8850,99 +8850,8 @@ public String toString() {
return output.toString();
}
}
public static class EnergyCalendarClusterDateStruct {
public @Nullable Integer year;
public @Nullable Integer month;
public @Nullable Integer day;
public @Nullable Integer dayOfWeek;
private static final long YEAR_ID = 0L;
private static final long MONTH_ID = 1L;
private static final long DAY_ID = 2L;
private static final long DAY_OF_WEEK_ID = 3L;

public EnergyCalendarClusterDateStruct(
@Nullable Integer year,
@Nullable Integer month,
@Nullable Integer day,
@Nullable Integer dayOfWeek
) {
this.year = year;
this.month = month;
this.day = day;
this.dayOfWeek = dayOfWeek;
}

public StructType encodeTlv() {
ArrayList<StructElement> values = new ArrayList<>();
values.add(new StructElement(YEAR_ID, year != null ? new UIntType(year) : new NullType()));
values.add(new StructElement(MONTH_ID, month != null ? new UIntType(month) : new NullType()));
values.add(new StructElement(DAY_ID, day != null ? new UIntType(day) : new NullType()));
values.add(new StructElement(DAY_OF_WEEK_ID, dayOfWeek != null ? new UIntType(dayOfWeek) : new NullType()));

return new StructType(values);
}

public static EnergyCalendarClusterDateStruct decodeTlv(BaseTLVType tlvValue) {
if (tlvValue == null || tlvValue.type() != TLVType.Struct) {
return null;
}
@Nullable Integer year = null;
@Nullable Integer month = null;
@Nullable Integer day = null;
@Nullable Integer dayOfWeek = null;
for (StructElement element: ((StructType)tlvValue).value()) {
if (element.contextTagNum() == YEAR_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
year = castingValue.value(Integer.class);
}
} else if (element.contextTagNum() == MONTH_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
month = castingValue.value(Integer.class);
}
} else if (element.contextTagNum() == DAY_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
day = castingValue.value(Integer.class);
}
} else if (element.contextTagNum() == DAY_OF_WEEK_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
dayOfWeek = castingValue.value(Integer.class);
}
}
}
return new EnergyCalendarClusterDateStruct(
year,
month,
day,
dayOfWeek
);
}

@Override
public String toString() {
StringBuilder output = new StringBuilder();
output.append("EnergyCalendarClusterDateStruct {\n");
output.append("\tyear: ");
output.append(year);
output.append("\n");
output.append("\tmonth: ");
output.append(month);
output.append("\n");
output.append("\tday: ");
output.append(day);
output.append("\n");
output.append("\tdayOfWeek: ");
output.append(dayOfWeek);
output.append("\n");
output.append("}\n");
return output.toString();
}
}
public static class EnergyCalendarClusterDayStruct {
public Optional<ChipStructs.EnergyCalendarClusterDateStruct> date;
public Optional<Long> date;
public Optional<Integer> daysOfWeek;
public ArrayList<ChipStructs.EnergyCalendarClusterTransitionStruct> transitions;
public Optional<Long> calendarID;
Expand All @@ -8952,7 +8861,7 @@ public static class EnergyCalendarClusterDayStruct {
private static final long CALENDAR_I_D_ID = 3L;

public EnergyCalendarClusterDayStruct(
Optional<ChipStructs.EnergyCalendarClusterDateStruct> date,
Optional<Long> date,
Optional<Integer> daysOfWeek,
ArrayList<ChipStructs.EnergyCalendarClusterTransitionStruct> transitions,
Optional<Long> calendarID
Expand All @@ -8965,7 +8874,7 @@ public EnergyCalendarClusterDayStruct(

public StructType encodeTlv() {
ArrayList<StructElement> values = new ArrayList<>();
values.add(new StructElement(DATE_ID, date.<BaseTLVType>map((nonOptionaldate) -> nonOptionaldate.encodeTlv()).orElse(new EmptyType())));
values.add(new StructElement(DATE_ID, date.<BaseTLVType>map((nonOptionaldate) -> new UIntType(nonOptionaldate)).orElse(new EmptyType())));
values.add(new StructElement(DAYS_OF_WEEK_ID, daysOfWeek.<BaseTLVType>map((nonOptionaldaysOfWeek) -> new UIntType(nonOptionaldaysOfWeek)).orElse(new EmptyType())));
values.add(new StructElement(TRANSITIONS_ID, ArrayType.generateArrayType(transitions, (elementtransitions) -> elementtransitions.encodeTlv())));
values.add(new StructElement(CALENDAR_I_D_ID, calendarID.<BaseTLVType>map((nonOptionalcalendarID) -> new UIntType(nonOptionalcalendarID)).orElse(new EmptyType())));
Expand All @@ -8977,15 +8886,15 @@ public static EnergyCalendarClusterDayStruct decodeTlv(BaseTLVType tlvValue) {
if (tlvValue == null || tlvValue.type() != TLVType.Struct) {
return null;
}
Optional<ChipStructs.EnergyCalendarClusterDateStruct> date = Optional.empty();
Optional<Long> date = Optional.empty();
Optional<Integer> daysOfWeek = Optional.empty();
ArrayList<ChipStructs.EnergyCalendarClusterTransitionStruct> transitions = null;
Optional<Long> calendarID = Optional.empty();
for (StructElement element: ((StructType)tlvValue).value()) {
if (element.contextTagNum() == DATE_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.Struct) {
StructType castingValue = element.value(StructType.class);
date = Optional.of(ChipStructs.EnergyCalendarClusterDateStruct.decodeTlv(castingValue));
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
date = Optional.of(castingValue.value(Long.class));
}
} else if (element.contextTagNum() == DAYS_OF_WEEK_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ structs_sources = [
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterCalendarPeriodStruct.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterDateStruct.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterDayStruct.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterPeakPeriodStruct.kt",
"${chip_root}/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/EnergyCalendarClusterTransitionStruct.kt",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import matter.tlv.TlvReader
import matter.tlv.TlvWriter

class EnergyCalendarClusterDayStruct(
val date: Optional<EnergyCalendarClusterDateStruct>,
val date: Optional<ULong>,
val daysOfWeek: Optional<UInt>,
val transitions: List<EnergyCalendarClusterTransitionStruct>,
val calendarID: Optional<ULong>,
Expand All @@ -44,7 +44,7 @@ class EnergyCalendarClusterDayStruct(
startStructure(tlvTag)
if (date.isPresent) {
val optdate = date.get()
optdate.toTlv(ContextSpecificTag(TAG_DATE), this)
put(ContextSpecificTag(TAG_DATE), optdate)
}
if (daysOfWeek.isPresent) {
val optdaysOfWeek = daysOfWeek.get()
Expand Down Expand Up @@ -73,9 +73,7 @@ class EnergyCalendarClusterDayStruct(
tlvReader.enterStructure(tlvTag)
val date =
if (tlvReader.isNextTag(ContextSpecificTag(TAG_DATE))) {
Optional.of(
EnergyCalendarClusterDateStruct.fromTlv(ContextSpecificTag(TAG_DATE), tlvReader)
)
Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_DATE)))
} else {
Optional.empty()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ matter_structs_sources = [
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementAccuracyStruct.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/ElectricalPowerMeasurementClusterMeasurementRangeStruct.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyCalendarClusterCalendarPeriodStruct.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyCalendarClusterDateStruct.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyCalendarClusterDayStruct.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyCalendarClusterPeakPeriodStruct.kt",
"${chip_root}/src/controller/java/generated/java/matter/controller/cluster/structs/EnergyCalendarClusterTransitionStruct.kt",
Expand Down
Loading

0 comments on commit af34956

Please sign in to comment.