Skip to content

Commit 5ddd570

Browse files
Revert type DayStruct.Date to epoch
1 parent ad74009 commit 5ddd570

File tree

25 files changed

+62
-1239
lines changed

25 files changed

+62
-1239
lines changed

examples/all-clusters-app/all-clusters-common/all-clusters-app.matter

+1-15
Original file line numberDiff line numberDiff line change
@@ -4513,15 +4513,8 @@ cluster EnergyCalendar = 154 {
45134513
optional AuxiliaryLoadBitmap auxiliaryLoad = 3;
45144514
}
45154515

4516-
struct DateStruct {
4517-
nullable int8u year = 0;
4518-
nullable int8u month = 1;
4519-
nullable int8u day = 2;
4520-
nullable int8u dayOfWeek = 3;
4521-
}
4522-
45234516
struct DayStruct {
4524-
optional DateStruct date = 0;
4517+
optional epoch_s date = 0;
45254518
optional TransitionDayOfWeekBitmap daysOfWeek = 1;
45264519
TransitionStruct transitions[] = 2;
45274520
optional int32u calendarID = 3;
@@ -6798,13 +6791,6 @@ cluster MeterIdentification = 2822 {
67986791
kPowerThreshold = 0x1;
67996792
}
68006793

6801-
struct DateStruct {
6802-
nullable int8u year = 0;
6803-
nullable int8u month = 1;
6804-
nullable int8u day = 2;
6805-
nullable int8u dayOfWeek = 3;
6806-
}
6807-
68086794
readonly attribute nullable MeterTypeEnum meterType = 0;
68096795
readonly attribute nullable char_string<16> utilityName = 1;
68106796
readonly attribute nullable char_string<16> pointOfDelivery = 2;

examples/all-clusters-app/all-clusters-common/include/energy-calendar-instance.h

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class CalendarProviderInstance : public CalendarProvider
6767
DataModel::Nullable<Structs::PeakPeriodStruct::Type> mNextPeak;
6868

6969
void JsonToCalendarPeriodStruct(Json::Value & root, Structs::CalendarPeriodStruct::Type & value);
70-
void JsonToDateStruct(Json::Value & root, Structs::DateStruct::Type & value);
7170
void JsonToDayStruct(Json::Value & root, Structs::DayStruct::Type & value);
7271
void JsonToPeakPeriodStruct(Json::Value & root, Structs::PeakPeriodStruct::Type & value);
7372

examples/all-clusters-app/all-clusters-common/src/energy-calendar-instance.cpp

+10-44
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using namespace chip::app::Clusters;
3030
using namespace chip::app::Clusters::EnergyCalendar;
3131
using namespace chip::app::Clusters::EnergyCalendar::Attributes;
3232

33-
constexpr uint32_t kOneDay = 24 * 60 * 60;
33+
constexpr uint32_t kSecInOneDay = 60 * 60 * 24;
3434

3535
static void ParceDay(uint32_t date, uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, uint8_t & weekDay)
3636
{
@@ -247,7 +247,7 @@ void chip::app::Clusters::EnergyCalendar::CalendarProviderInstance::ErrorMessage
247247
DataModel::Nullable<Structs::DayStruct::Type> CalendarProviderInstance::GetDay(uint32_t date)
248248
{
249249
DataModel::Nullable<Structs::DayStruct::Type> result = std::nullopt;
250-
Structs::DateStruct::Type dt;
250+
uint32_t dt;
251251

252252
uint16_t year;
253253
uint8_t month;
@@ -260,16 +260,11 @@ DataModel::Nullable<Structs::DayStruct::Type> CalendarProviderInstance::GetDay(u
260260
{
261261
if (day.date.HasValue())
262262
{
263-
dt = day.date.Value();
264-
if (!dt.year.IsNull() && dt.year.Value() != (uint8_t)(year - 1900))
265-
continue;
266-
if (!dt.month.IsNull() && dt.month.Value() != month)
267-
continue;
268-
if (!dt.day.IsNull() && dt.day.Value() != dayOfMonth)
269-
continue;
270-
if (!dt.dayOfWeek.IsNull() && dt.dayOfWeek.Value() != dayOfWeek)
271-
continue;
272-
return day;
263+
dt = static_cast<uint32_t>(day.date.Value() - (day.date.Value() % kSecInOneDay));
264+
if (dt == date)
265+
{
266+
return day;
267+
}
273268
}
274269
}
275270

@@ -304,7 +299,7 @@ DataModel::Nullable<Structs::DayStruct::Type> CalendarProviderInstance::GetDay(u
304299
}
305300
}
306301

307-
return result;
302+
return result;
308303
}
309304

310305
void CalendarProviderInstance::JsonToCalendarPeriodStruct(Json::Value & root, Structs::CalendarPeriodStruct::Type & value)
@@ -323,41 +318,12 @@ void CalendarProviderInstance::JsonToCalendarPeriodStruct(Json::Value & root, St
323318
}
324319
}
325320

326-
void CalendarProviderInstance::JsonToDateStruct(Json::Value & root, Structs::DateStruct::Type & value)
327-
{
328-
Json::Value t = root.get("Year", Json::Value());
329-
if (!t.empty() && t.isUInt() && t.asUInt() <= 0xff)
330-
{
331-
value.year.SetNonNull(t.asUInt());
332-
}
333-
334-
t = root.get("Month", Json::Value());
335-
if (!t.empty() && t.isUInt() && t.asUInt() >= 1 && t.asUInt() <= 12)
336-
{
337-
value.month.SetNonNull(t.asUInt());
338-
}
339-
340-
t = root.get("Day", Json::Value());
341-
if (!t.empty() && t.isUInt() && t.asUInt() >= 1 && t.asUInt() <= 31)
342-
{
343-
value.day.SetNonNull(t.asUInt());
344-
}
345-
346-
t = root.get("DayOfWeek", Json::Value());
347-
if (!t.empty() && t.isUInt() && t.asUInt() >= 1 && t.asUInt() <= 7)
348-
{
349-
value.dayOfWeek.SetNonNull(t.asUInt());
350-
}
351-
}
352-
353321
void CalendarProviderInstance::JsonToDayStruct(Json::Value & root, Structs::DayStruct::Type & value)
354322
{
355323
Json::Value t = root.get("Date", Json::Value());
356-
if (!t.empty())
324+
if (!t.empty() && t.isUInt())
357325
{
358-
Structs::DateStruct::Type date;
359-
JsonToDateStruct(t, date);
360-
value.date.SetValue(date);
326+
value.date.SetValue(t.asUInt());
361327
}
362328

363329
t = root.get("DaysOfWeek", Json::Value());

src/app/clusters/energy-calendar-server/energy-calendar-server.cpp

+2-11
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ bool CalendarProvider::CheckPeriods(DataModel::List<Structs::CalendarPeriodStruc
304304
bool CalendarProvider::CheckSpecialDays(DataModel::List<Structs::DayStruct::Type> & specialDays)
305305
{
306306
uint32_t epoch = 0;
307-
uint32_t dt;
308307

309308
VerifyOrReturnLogSend(specialDays.size() <= 50, mEndpoint, "Special Days list size must be no more 50");
310309
for (auto & day : specialDays)
@@ -313,20 +312,12 @@ bool CalendarProvider::CheckSpecialDays(DataModel::List<Structs::DayStruct::Type
313312
VerifyOrReturnLogSend(!day.calendarID.HasValue(), mEndpoint, "Day in Special Days cannot have CalendarID value");
314313

315314
VerifyOrReturnLogSend(day.date.HasValue(), mEndpoint, "Day in Special Days must have Date value");
316-
317-
Structs::DateStruct::Type date = day.date.Value();
318-
VerifyOrReturnLogSend(!date.year.IsNull(), mEndpoint, "Day in Special Days must have Year value");
319-
VerifyOrReturnLogSend(!date.month.IsNull(), mEndpoint, "Day in Special Days must have Month value");
320-
VerifyOrReturnLogSend(!date.day.IsNull(), mEndpoint, "Day in Special Days must have Day value");
321-
VerifyOrReturnLogSend(date.dayOfWeek.IsNull(), mEndpoint, "Day in Special Days must have not DayOfWeek value");
322-
323-
CalendarToChipEpochTime(date.year.Value(), date.month.Value(), date.day.Value(), 0, 0, 0, dt);
324-
VerifyOrReturnLogSend(dt > epoch, mEndpoint, "Days in Special Days must be order");
315+
VerifyOrReturnLogSend(day.date.Value() > epoch, mEndpoint, "Days in Special Days must be order");
325316
if(!CheckDay(day))
326317
{
327318
return false;
328319
}
329-
epoch = dt;
320+
epoch = day.date.Value();
330321
}
331322

332323
return true;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ limitations under the License.
5555

5656
<struct name="DayStruct" apiMaturity="provisional">
5757
<cluster code="0x009A"/>
58-
<item fieldId="0" name="Date" type="DateStruct" optional="true"/>
58+
<item fieldId="0" name="Date" type="epoch_s" optional="true"/>
5959
<item fieldId="1" name="DaysOfWeek" type="TransitionDayOfWeekBitmap" optional="true" min="0x00" max="0x7F"/>
6060
<item fieldId="2" name="Transitions" array="true" type="TransitionStruct" length="48" minLength="1"/>
6161
<item fieldId="3" name="CalendarID" type="int32u" optional="true"/>

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

-11
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,4 @@ 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"/> <!-- Energy Calendar -->
38-
<!-- <cluster code="0xXXXX"/> Other cluster, using Date type -->
39-
40-
<item fieldId="0" name="Year" type="int8u" isNullable="true" optional="false"/>
41-
<item fieldId="1" name="Month" type="int8u" min="1" max="12" isNullable="true" optional="false"/>
42-
<item fieldId="2" name="Day" type="int8u" min="1" max="31" isNullable="true" optional="false"/>
43-
<item fieldId="3" name="DayOfWeek" type="int8u" min="1" max="7" isNullable="true" optional="false"/>
44-
</struct>
4534
</configurator>

src/controller/data_model/controller-clusters.matter

+1-15
Original file line numberDiff line numberDiff line change
@@ -5045,15 +5045,8 @@ cluster EnergyCalendar = 154 {
50455045
optional AuxiliaryLoadBitmap auxiliaryLoad = 3;
50465046
}
50475047

5048-
struct DateStruct {
5049-
nullable int8u year = 0;
5050-
nullable int8u month = 1;
5051-
nullable int8u day = 2;
5052-
nullable int8u dayOfWeek = 3;
5053-
}
5054-
50555048
struct DayStruct {
5056-
optional DateStruct date = 0;
5049+
optional epoch_s date = 0;
50575050
optional TransitionDayOfWeekBitmap daysOfWeek = 1;
50585051
TransitionStruct transitions[] = 2;
50595052
optional int32u calendarID = 3;
@@ -9387,13 +9380,6 @@ cluster MeterIdentification = 2822 {
93879380
kPowerThreshold = 0x1;
93889381
}
93899382

9390-
struct DateStruct {
9391-
nullable int8u year = 0;
9392-
nullable int8u month = 1;
9393-
nullable int8u day = 2;
9394-
nullable int8u dayOfWeek = 3;
9395-
}
9396-
93979383
readonly attribute nullable MeterTypeEnum meterType = 0;
93989384
readonly attribute nullable char_string<16> utilityName = 1;
93999385
readonly attribute nullable char_string<16> pointOfDelivery = 2;

0 commit comments

Comments
 (0)