3 * Copyright (c) 2020 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * Copyright (c) 2020 Silicon Labs
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
26 * http://www.apache.org/licenses/LICENSE-2.0
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 /***************************************************************************/
38 *******************************************************************************
39 ******************************************************************************/
43 #define SECONDS_IN_MINUTE 60
44 #define SECONDS_IN_HOUR 3600
45 #define SECONDS_IN_DAY (SECONDS_IN_MINUTE * 60 * 24)
46 #define SECONDS_IN_WEEK (SECONDS_IN_DAY * 7)
47 #define DURATION_FOREVER_U32 0xFFFFFFFFU
50 * @brief ZCL Date comparison function.
51 * The results are undefined for dates that contain the do not care value
52 * in any of the subfields.
53 * @return -1, if val1 is smaller
54 * 0, if they are the same
55 * 1, if val2 is smaller
57 int8_t emberAfCompareDates(EmberAfDate * date1, EmberAfDate * date2);
60 * @brief function that copies a ZigBee Date into a buffer
62 void emberAfCopyDate(uint8_t * data, uint16_t index, EmberAfDate * src);
65 * @brief Decode the given uint32_t into a ZCL Date object where
66 * the uint32_t is formatted as follows:
68 * (0xFF000000 & value) = year
69 * (0x00FF0000 & value) = month
70 * (0x0000FF00 & value) = day of month
71 * (0x000000FF & value) = day of week
74 void emberAfDecodeDate(uint32_t src, EmberAfDate * dest);
77 * @brief Encode and return the given ZCL Date object as an uint32_t.
78 * Refer to emberAFDecodeDate for details on how the information is stored
81 uint32_t emberAfEncodeDate(EmberAfDate * date);
84 * @brief Fills the a time structure based on the passed UTC time.
87 void emberAfFillTimeStructFromUtc(uint32_t utcTime, EmberAfTimeStruct * returnTime);
89 * @brief Returns the number of days in the month specified in the EmberAfTimeStruct.
92 uint8_t emberAfGetNumberDaysInMonth(EmberAfTimeStruct * time);
95 * @brief Calculate a UTC time from the passed time structure.
98 uint32_t emberAfGetUtcFromTimeStruct(EmberAfTimeStruct * time);
101 * @brief Determine the week day (Monday=0 ... Sunday=6) based on
102 * a specified UTC time.
104 uint8_t emberAfGetWeekdayFromUtc(uint32_t utcTime);
107 * @brief Prints out a human readable date form from the given ZCL data type.
109 void emberAfPrintDate(const EmberAfDate * date);
110 void emberAfPrintDateln(const EmberAfDate * date);
113 * @brief Sets current time.
114 * Convenience function for setting the time to a value.
115 * If the time server cluster is implemented on this device,
116 * then this call will be passed along to the time cluster server
117 * which will update the time. Otherwise the emberAfSetTimeCallback
118 * is called, which in the case of the stub does nothing.
120 * @param utcTime: A ZigBee time, the number of seconds since the
123 void emberAfSetTime(uint32_t utcTime);
126 * @brief Retrieves current time.
128 * Convienience function for retrieving the current time.
129 * If the time server cluster is implemented, then the time
130 * is retrieved from that cluster's time attribute. Otherwise,
131 * the emberAfGetCurrentTimeCallback is called.
133 * A real time is expected to in the ZigBee time format, the number
134 * of seconds since the year 2000.
136 uint32_t emberAfGetCurrentTime(void);
139 * @brief Prints time.
141 * Convenience function for all clusters to print time.
142 * This function expects to be passed a ZigBee time which
143 * is the number of seconds since the year 2000. If
144 * EMBER_AF_PRINT_CORE is defined, this function will print
145 * a human readable time from the passed value. If not, this
146 * function will print nothing.
148 * @param utcTime: A ZigBee time, the number of seconds since the
151 void emberAfPrintTime(uint32_t utcTime);
154 * @brief Prints the time in ISO 8601 format
155 * yyyy-mm-dd hh:mm:ss
157 * @param utcTime: A ZigBee time, the number of seconds since the
160 void emberAfPrintTimeIsoFormat(uint32_t utcTime);