Issue 187 enable skipped ztest suites (#189)
* Fix some ztests that were skipped * Expose bacapp_same_value() * Fix bacapp, ptransfer tests * Fix bugs in Load_Control object & tests * refactor days functions from datetime module * fix legacy ctests * Add bacnet/basic/sys/days.[ch] to Zephyr build * Update ztest to match from Zephyr v2.6.0; update ringbuf, datetime to build * Fixup ztest test for object/acc * Fix bvlc_address_from_ascii; enable/fix bvlc test * Comment cleanup * test/bacnet/basic/object/lc partially enabled * Fix bacapp_decode_data_len return status on erroneous input * fix ztest include fatal error * fix ztest strsignal reference fatal error * fix zassert_mem_equal reference syntax error * fix zassert_mem_equal reference syntax error Co-authored-by: Gregory Shue <gregory.shue@legrand.us> Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
+17
-12
@@ -437,7 +437,10 @@ int bacapp_decode_data_len(
|
||||
case BACNET_APPLICATION_TAG_DATE:
|
||||
case BACNET_APPLICATION_TAG_TIME:
|
||||
case BACNET_APPLICATION_TAG_OBJECT_ID:
|
||||
len = (int)len_value_type;
|
||||
len = (int) (~0U >> 1);
|
||||
if ( len_value_type < (uint32_t) len) {
|
||||
len = (int)len_value_type;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -835,9 +838,10 @@ int bacapp_encode_data(uint8_t *apdu, BACNET_APPLICATION_DATA_VALUE *value)
|
||||
bool bacapp_copy(BACNET_APPLICATION_DATA_VALUE *dest_value,
|
||||
BACNET_APPLICATION_DATA_VALUE *src_value)
|
||||
{
|
||||
bool status = true; /*return value */
|
||||
bool status = false; /* return value, assume failure */
|
||||
|
||||
if (dest_value && src_value) {
|
||||
status = true; /* assume successful for now */
|
||||
dest_value->tag = src_value->tag;
|
||||
switch (src_value->tag) {
|
||||
#if defined(BACAPP_NULL)
|
||||
@@ -1686,13 +1690,6 @@ void bacapp_property_value_list_init(BACNET_PROPERTY_VALUE *value, size_t count)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/* generic - can be used by other unit tests
|
||||
returns true if matching or same, false if different */
|
||||
bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE *value,
|
||||
@@ -1701,6 +1698,9 @@ bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE *value,
|
||||
bool status = false; /*return value */
|
||||
|
||||
/* does the tag match? */
|
||||
if ((value == NULL) || (test_value == NULL)) {
|
||||
return false;
|
||||
}
|
||||
if (test_value->tag == value->tag)
|
||||
status = true;
|
||||
if (status) {
|
||||
@@ -1805,7 +1805,14 @@ bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE *value,
|
||||
return status;
|
||||
}
|
||||
|
||||
void testBACnetApplicationData_Safe(Test *pTest)
|
||||
#ifdef TEST_BACNET_APPLICATION_DATA
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static void testBACnetApplicationData_Safe(Test *pTest)
|
||||
{
|
||||
int i;
|
||||
uint8_t apdu[MAX_APDU];
|
||||
@@ -2292,7 +2299,6 @@ void testBACnetApplicationData(Test *pTest)
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TEST_BACNET_APPLICATION_DATA
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
@@ -2315,4 +2321,3 @@ int main(void)
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST_BACNET_APPLICATION_DATA */
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -256,22 +256,11 @@ extern "C" {
|
||||
#define bacapp_print_value(x,y) false
|
||||
#endif
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
#include "bacnet/datetime.h"
|
||||
BACNET_STACK_EXPORT
|
||||
bool bacapp_same_value(
|
||||
BACNET_APPLICATION_DATA_VALUE * value,
|
||||
BACNET_APPLICATION_DATA_VALUE * test_value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void testBACnetApplicationDataLength(
|
||||
Test * pTest);
|
||||
BACNET_STACK_EXPORT
|
||||
void testBACnetApplicationData(
|
||||
Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -40,6 +40,16 @@
|
||||
#include "bacnet/wp.h"
|
||||
#include "bacnet/basic/services.h"
|
||||
|
||||
#ifndef LOAD_CONTROL_DEBUG
|
||||
#define LOAD_CONTROL_DEBUG 0
|
||||
#endif
|
||||
#if LOAD_CONTROL_DEBUG
|
||||
#include <sys/PRINTF.h>
|
||||
#define PRINTF(...) printk(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
/* number of demo objects */
|
||||
#ifndef MAX_LOAD_CONTROLS
|
||||
#define MAX_LOAD_CONTROLS 4
|
||||
@@ -212,7 +222,10 @@ unsigned Load_Control_Count(void)
|
||||
/* that correlates to the correct index */
|
||||
uint32_t Load_Control_Index_To_Instance(unsigned index)
|
||||
{
|
||||
return index;
|
||||
if (index < MAX_LOAD_CONTROLS) {
|
||||
return index;
|
||||
}
|
||||
return MAX_LOAD_CONTROLS;
|
||||
}
|
||||
|
||||
/* we simply have 0-n object instances. Yours might be */
|
||||
@@ -857,11 +870,25 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
BACNET_DATE
|
||||
TempDate; /* build here in case of error in time half of datetime */
|
||||
|
||||
PRINTF("Load_Control_Write_Property(wp_data=%p)\n", wp_data);
|
||||
if (wp_data == NULL) {
|
||||
PRINTF("Load_Control_Write_Property() failure detected point A\n");
|
||||
return false;
|
||||
}
|
||||
if (wp_data->application_data_len < 0) {
|
||||
PRINTF("Load_Control_Write_Property() failure detected point A.2\n");
|
||||
/* error while decoding - a smaller larger than we can handle */
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* decode the some of the request */
|
||||
len = bacapp_decode_application_data(
|
||||
wp_data->application_data, wp_data->application_data_len, &value);
|
||||
/* FIXME: len < application_data_len: more data? */
|
||||
if (len < 0) {
|
||||
PRINTF("Load_Control_Write_Property() failure detected point B\n");
|
||||
/* error while decoding - a value larger than we can handle */
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
@@ -870,6 +897,7 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
/* only array properties can have array options */
|
||||
if ((wp_data->object_property != PROP_SHED_LEVELS) &&
|
||||
(wp_data->array_index != BACNET_ARRAY_ALL)) {
|
||||
PRINTF("Load_Control_Write_Property() failure detected point C\n");
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
|
||||
return false;
|
||||
@@ -881,6 +909,7 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
wp_data->application_data_len, &value,
|
||||
PROP_REQUESTED_SHED_LEVEL);
|
||||
if (len == BACNET_STATUS_ERROR) {
|
||||
PRINTF("Load_Control_Write_Property() failure detected point D\n");
|
||||
/* error! */
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||
@@ -906,6 +935,7 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
value.type.Real;
|
||||
status = true;
|
||||
} else {
|
||||
PRINTF("Load_Control_Write_Property() failure detected point E\n");
|
||||
/* error! */
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||
@@ -919,6 +949,7 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
status = write_property_type_valid(wp_data, &value,
|
||||
BACNET_APPLICATION_TAG_DATE);
|
||||
if (!status) {
|
||||
PRINTF("Load_Control_Write_Property() failure detected point F\n");
|
||||
/* don't continue if we don't have a valid date */
|
||||
break;
|
||||
}
|
||||
@@ -937,6 +968,7 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
Start_Time_Property_Written[object_index] = true;
|
||||
}
|
||||
} else {
|
||||
PRINTF("Load_Control_Write_Property() failure detected point G\n");
|
||||
status = false;
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
@@ -949,6 +981,8 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
if (status) {
|
||||
Shed_Duration[object_index] = value.type.Unsigned_Int;
|
||||
Load_Control_Request_Written[object_index] = true;
|
||||
} else {
|
||||
PRINTF("Load_Control_Write_Property() failure detected point H\n");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -993,11 +1027,13 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
PRINTF("Load_Control_Write_Property() failure detected point Z\n");
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
break;
|
||||
}
|
||||
|
||||
PRINTF("Load_Control_Write_Property() returning status=%d\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -100,8 +101,9 @@ OBJECT_DEVICE_T *objects_device_new(uint32_t device_instance)
|
||||
return pDevice;
|
||||
}
|
||||
|
||||
OBJECT_DEVICE_T *objects_device_delete(int index)
|
||||
bool objects_device_delete(int index)
|
||||
{
|
||||
bool result = false;
|
||||
OBJECT_DEVICE_T *pDevice = NULL;
|
||||
BACNET_OBJECT_ID *pObject;
|
||||
|
||||
@@ -121,7 +123,8 @@ OBJECT_DEVICE_T *objects_device_delete(int index)
|
||||
Keylist_Delete(pDevice->Object_List);
|
||||
}
|
||||
free(pDevice);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return pDevice;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
OBJECT_DEVICE_T *objects_device_delete(int index);
|
||||
bool objects_device_delete(int index);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
OBJECT_DEVICE_T *objects_device_new(uint32_t device_instance);
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||
* @date 1997
|
||||
* @brief computes days from date, days of the week, days in a month,
|
||||
* days in a year
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Public domain algorithms from ACM
|
||||
*
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "bacnet/basic/sys/days.h"
|
||||
|
||||
/**
|
||||
* Determines if a year is a leap year using Gregorian algorithm
|
||||
*
|
||||
* @param year - years after Christ birth (0..9999 AD)
|
||||
* @return true if leap year
|
||||
*/
|
||||
bool days_is_leap_year(uint16_t year)
|
||||
{
|
||||
if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0))
|
||||
return true;
|
||||
|
||||
return (false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the number of days in given month and year
|
||||
*
|
||||
* @param year - years after Christ birth (0..9999 AD)
|
||||
* @param month - months (1=Jan...12=Dec)
|
||||
* @return number of days in a given month and year, or 0 on error
|
||||
*/
|
||||
uint8_t days_per_month(uint16_t year, uint8_t month)
|
||||
{
|
||||
/* note: start with a zero in the first element to save us from a
|
||||
month - 1 calculation in the lookup */
|
||||
uint8_t month_days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
|
||||
31 };
|
||||
|
||||
if ((month == 2) && days_is_leap_year(year))
|
||||
return (29);
|
||||
else if (month >= 1 && month <= 12)
|
||||
return (month_days[month]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the number of days in given year
|
||||
*
|
||||
* @param year - years after Christ birth (0..9999 AD)
|
||||
* @return number of days in a given year
|
||||
*/
|
||||
uint32_t days_per_year(uint16_t year)
|
||||
{
|
||||
uint32_t days = 365;
|
||||
|
||||
if (days_is_leap_year(year)) {
|
||||
days++;
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the number of days (1..365) for a given date
|
||||
*
|
||||
* @param year - years after Christ birth (0..9999 AD)
|
||||
* @param month - months (1=Jan...12=Dec)
|
||||
* @param day - day of month (1-31)
|
||||
* @param days - number of days of the year (1..365)
|
||||
*/
|
||||
uint16_t days_of_year(uint16_t year, uint8_t month, uint8_t day)
|
||||
{
|
||||
uint16_t days = 0; /* return value */
|
||||
uint8_t mm = 0; /* months counter */
|
||||
|
||||
for (mm = 1; mm < month; mm++) {
|
||||
days += days_per_month(year, mm);
|
||||
}
|
||||
days += day;
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the number of days remaining in the year for a given date
|
||||
*
|
||||
* @param year - years after Christ birth (0..9999 AD)
|
||||
* @param month - months (1=Jan...12=Dec)
|
||||
* @param day - day of month (1-31)
|
||||
* @param days - number of days of the year (1..365)
|
||||
*/
|
||||
uint16_t days_of_year_remaining(uint16_t year, uint8_t month, uint8_t day)
|
||||
{
|
||||
uint16_t days = 0; /* return value */
|
||||
uint8_t mm = 0; /* months counter */
|
||||
|
||||
days = days_per_month(year, month) - day;
|
||||
for (mm = 12; mm > month; mm--) {
|
||||
days += days_per_month(year, mm);
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts days of year into date (year, month, day)
|
||||
*
|
||||
* @param days - number of days of the year (1..365)
|
||||
* @param year - years after Christ birth (0..9999 AD)
|
||||
* @param pMonth - months (1=Jan...12=Dec)
|
||||
* @param pDay - day of month (1-31)
|
||||
*/
|
||||
void days_of_year_to_month_day(
|
||||
uint32_t days, uint16_t year, uint8_t *pMonth, uint8_t *pDay)
|
||||
{
|
||||
uint8_t month = 1;
|
||||
uint8_t day = 0;
|
||||
|
||||
while (days > (uint32_t)days_per_month(year, month)) {
|
||||
days -= days_per_month(year, month);
|
||||
month++;
|
||||
}
|
||||
day = (uint8_t)(day + days);
|
||||
|
||||
if (pMonth) {
|
||||
*pMonth = month;
|
||||
}
|
||||
if (pDay) {
|
||||
*pDay = day;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts days apart between two dates
|
||||
*
|
||||
* @param year1 - years after Christ birth (0..9999 AD)
|
||||
* @param month1 - months (1=Jan...12=Dec)
|
||||
* @param day1 - day of month (1-31)
|
||||
* @return number of days apart, or 0 if same dates
|
||||
*/
|
||||
uint32_t days_apart(uint16_t year1,
|
||||
uint8_t month1,
|
||||
uint8_t day1,
|
||||
uint16_t year2,
|
||||
uint8_t month2,
|
||||
uint8_t day2)
|
||||
{
|
||||
uint32_t days = 0; /* return value */
|
||||
uint32_t days1 = 0;
|
||||
uint32_t days2 = 0;
|
||||
uint16_t yy = 0; /* year */
|
||||
|
||||
if (year2 > year1) {
|
||||
days = days_of_year_remaining(year1, month1, day1);
|
||||
for (yy = year1 + 1; yy < year2; yy++) {
|
||||
days += 365;
|
||||
if (days_is_leap_year(yy)) {
|
||||
days++;
|
||||
}
|
||||
}
|
||||
days += days_of_year(year2, month2, day2);
|
||||
} else if (year2 < year1) {
|
||||
days = days_of_year_remaining(year2, month2, day2);
|
||||
for (yy = year2 + 1; yy < year1; yy++) {
|
||||
days += 365;
|
||||
if (days_is_leap_year(yy)) {
|
||||
days++;
|
||||
}
|
||||
}
|
||||
days += days_of_year(year1, month1, day1);
|
||||
} else {
|
||||
days1 = days_of_year(year1, month1, day1);
|
||||
days2 = days_of_year(year2, month2, day2);
|
||||
if (days2 > days1) {
|
||||
days = days2 - days1;
|
||||
} else {
|
||||
days = days1 - days2;
|
||||
}
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts date to days since epoch (Jan 0, epoch year)
|
||||
*
|
||||
* @param year - years after Christ birth (0..9999 AD)
|
||||
* @param month - months (1=Jan...12=Dec)
|
||||
* @param day - day of month (1-31)
|
||||
* @return number of days since epoch, or 0 if out of range
|
||||
*/
|
||||
uint32_t days_since_epoch(uint16_t epoch_year,
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day)
|
||||
{
|
||||
uint32_t days = 0; /* return value */
|
||||
uint16_t yy = 0; /* year */
|
||||
uint8_t mm = 0; /* months counter */
|
||||
uint8_t monthdays = 0; /* days in a month */
|
||||
|
||||
/* validate the date conforms to our range */
|
||||
monthdays = days_per_month(year, month);
|
||||
if ((year >= epoch_year) && (year <= 9999) &&
|
||||
(monthdays > 0) && (day >= 1) && (day <= monthdays)) {
|
||||
for (yy = epoch_year; yy < year; yy++) {
|
||||
days += 365;
|
||||
if (days_is_leap_year(yy)) {
|
||||
days++;
|
||||
}
|
||||
}
|
||||
for (mm = 1; mm < month; mm++) {
|
||||
days += days_per_month(year, mm);
|
||||
}
|
||||
days += day;
|
||||
}
|
||||
|
||||
return (days);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts epoch days into date (year, month, day)
|
||||
*
|
||||
* @param days - number of days since epoch
|
||||
* @param pYear - years after Christ birth (2000..9999 AD)
|
||||
* @param pMonth - months (1=Jan...12=Dec)
|
||||
* @param pDay - day of month (1-31)
|
||||
* @return nothing
|
||||
*/
|
||||
void days_since_epoch_to_date(
|
||||
uint16_t epoch_year,
|
||||
uint32_t days,
|
||||
uint16_t * pYear,
|
||||
uint8_t * pMonth,
|
||||
uint8_t * pDay)
|
||||
{
|
||||
uint8_t month = 1;
|
||||
uint8_t day = 0;
|
||||
uint16_t year;
|
||||
|
||||
year = epoch_year;
|
||||
while (days > days_per_year(year)) {
|
||||
days -= days_per_year(year);
|
||||
year++;
|
||||
}
|
||||
while (days > days_per_month(year, month)) {
|
||||
days -= days_per_month(year, month);
|
||||
month++;
|
||||
}
|
||||
day += days;
|
||||
/* load values into the pointers */
|
||||
if (pYear) {
|
||||
*pYear = year;
|
||||
}
|
||||
if (pMonth) {
|
||||
*pMonth = month;
|
||||
}
|
||||
if (pDay) {
|
||||
*pDay = day;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given date is valid
|
||||
*
|
||||
* @param year - years after Christ birth (0..9999 AD)
|
||||
* @param month - months (1=Jan...12=Dec)
|
||||
* @param day - day of month (1-31)
|
||||
* @return true if the date is valid
|
||||
*/
|
||||
bool days_date_is_valid(uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day)
|
||||
{
|
||||
uint8_t month_days = 0;
|
||||
bool valid = false; /* return value */
|
||||
|
||||
/* get the number of days in the month, and check for valid month too */
|
||||
month_days = days_per_month(year, month);
|
||||
if ((month_days > 0) && (day > 0) && (day <= month_days)) {
|
||||
valid = true;
|
||||
}
|
||||
|
||||
return (valid);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||
* @date 1997
|
||||
* @brief This file contains the function prototypes for the days calculations
|
||||
*/
|
||||
#ifndef DAYS_H
|
||||
#define DAYS_H
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "bacnet/bacnet_stack_exports.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool days_is_leap_year(uint16_t year);
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t days_per_month(uint16_t year, uint8_t month);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t days_per_year(uint16_t year);
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t days_of_year(uint16_t year, uint8_t month, uint8_t day);
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t days_of_year_remaining(uint16_t year, uint8_t month, uint8_t day);
|
||||
BACNET_STACK_EXPORT
|
||||
void days_of_year_to_month_day(
|
||||
uint32_t days, uint16_t year, uint8_t *pMonth, uint8_t *pDay);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t days_apart(uint16_t year1,
|
||||
uint8_t month1,
|
||||
uint8_t day1,
|
||||
uint16_t year2,
|
||||
uint8_t month2,
|
||||
uint8_t day2);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t days_since_epoch(uint16_t epoch_year,
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day);
|
||||
BACNET_STACK_EXPORT
|
||||
void days_since_epoch_to_date(
|
||||
uint16_t epoch_year,
|
||||
uint32_t days,
|
||||
uint16_t * pYear,
|
||||
uint8_t * pMonth,
|
||||
uint8_t * pDay);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool days_date_is_valid(uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
@@ -2140,7 +2140,7 @@ bool bvlc_address_get(BACNET_IP_ADDRESS *addr,
|
||||
*/
|
||||
bool bvlc_address_from_ascii(BACNET_IP_ADDRESS *addr, const char *addrstr)
|
||||
{
|
||||
unsigned char tmp = 0;
|
||||
uint16_t tmp = 0;
|
||||
char c = 0;
|
||||
unsigned char i = 0, j = 0;
|
||||
uint8_t charsread = 0;
|
||||
@@ -2151,6 +2151,7 @@ bool bvlc_address_from_ascii(BACNET_IP_ADDRESS *addr, const char *addrstr)
|
||||
if (!addrstr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
j = 0;
|
||||
do {
|
||||
@@ -2160,10 +2161,13 @@ bool bvlc_address_from_ascii(BACNET_IP_ADDRESS *addr, const char *addrstr)
|
||||
return false;
|
||||
}
|
||||
if ((c == '.') || (c == 0) || (c == ' ')) {
|
||||
addr->address[i] = tmp;
|
||||
addr->address[i] = (uint8_t) tmp;
|
||||
tmp = 0;
|
||||
} else if ((c >= '0') && (c <= '9')) {
|
||||
tmp = (tmp * 10) + (c - '0');
|
||||
if (tmp > UINT8_MAX) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
+159
-129
@@ -37,18 +37,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include "bacnet/basic/sys/days.h"
|
||||
#include "bacnet/datetime.h"
|
||||
#include "bacnet/bacdcode.h"
|
||||
|
||||
/** @file datetime.c Manipulate BACnet Date and Time values */
|
||||
|
||||
/* define our epic beginnings */
|
||||
#define BACNET_EPOCH_YEAR 1900
|
||||
/* 1/1/1900 is a Monday */
|
||||
#define BACNET_EPOCH_DOW BACNET_WEEKDAY_MONDAY
|
||||
|
||||
/* BACnet Date */
|
||||
/* year = years since 1900 */
|
||||
/* year = years since 1900 through 2155 */
|
||||
/* month 1=Jan */
|
||||
/* day = day of month 1..31 */
|
||||
/* wday 1=Monday...7=Sunday */
|
||||
@@ -60,40 +56,21 @@
|
||||
time or date may be interpreted as "any" or "don't care"
|
||||
*/
|
||||
|
||||
bool datetime_is_leap_year(uint16_t year)
|
||||
{
|
||||
if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0)) {
|
||||
return (true);
|
||||
} else {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t datetime_month_days(uint16_t year, uint8_t month)
|
||||
{
|
||||
/* note: start with a zero in the first element to save us from a
|
||||
month - 1 calculation in the lookup */
|
||||
int month_days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
/* return value */
|
||||
uint8_t days = 0;
|
||||
|
||||
/* February */
|
||||
if ((month == 2) && datetime_is_leap_year(year)) {
|
||||
days = 29;
|
||||
} else if (month >= 1 && month <= 12) {
|
||||
days = (uint8_t)month_days[month];
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given date is valid
|
||||
*
|
||||
* @param year - years after Christ birth (1900..2155 AD)
|
||||
* @param month - months (1=Jan...12=Dec)
|
||||
* @param day - day of month (1-31)
|
||||
* @return true if the date is valid
|
||||
*/
|
||||
bool datetime_ymd_is_valid(uint16_t year, uint8_t month, uint8_t day)
|
||||
{
|
||||
bool status = false; /* true if value date */
|
||||
uint8_t monthdays = 0; /* days in a month */
|
||||
|
||||
monthdays = datetime_month_days(year, month);
|
||||
if ((year >= BACNET_EPOCH_YEAR) && (monthdays > 0) && (day >= 1) &&
|
||||
monthdays = days_per_month(year, month);
|
||||
if ((year >= BACNET_DATE_YEAR_EPOCH) && (monthdays > 0) && (day >= 1) &&
|
||||
(day <= monthdays)) {
|
||||
status = true;
|
||||
}
|
||||
@@ -101,6 +78,12 @@ bool datetime_ymd_is_valid(uint16_t year, uint8_t month, uint8_t day)
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given date is valid
|
||||
*
|
||||
* @param bdate - BACnet date structure
|
||||
* @return true if the date is valid
|
||||
*/
|
||||
bool datetime_date_is_valid(BACNET_DATE *bdate)
|
||||
{
|
||||
bool status = false; /* true if value date */
|
||||
@@ -112,14 +95,22 @@ bool datetime_date_is_valid(BACNET_DATE *bdate)
|
||||
return status;
|
||||
}
|
||||
|
||||
static uint32_t day_of_year(uint16_t year, uint8_t month, uint8_t day)
|
||||
/**
|
||||
* Converts date to day of the year
|
||||
*
|
||||
* @param year - years after Christ birth (1900..2155 AD)
|
||||
* @param month - months (1=Jan...12=Dec)
|
||||
* @param day - day of month (1-31)
|
||||
* @return number of days since Jan 1 (inclusive) of the given year
|
||||
*/
|
||||
uint32_t datetime_ymd_day_of_year(uint16_t year, uint8_t month, uint8_t day)
|
||||
{
|
||||
uint32_t days = 0; /* return value */
|
||||
uint8_t months = 0; /* loop counter for months */
|
||||
|
||||
if (datetime_ymd_is_valid(year, month, day)) {
|
||||
for (months = 1; months < month; months++) {
|
||||
days += datetime_month_days(year, months);
|
||||
days += days_per_month(year, months);
|
||||
}
|
||||
days += day;
|
||||
}
|
||||
@@ -127,63 +118,62 @@ static uint32_t day_of_year(uint16_t year, uint8_t month, uint8_t day)
|
||||
return (days);
|
||||
}
|
||||
|
||||
static void day_of_year_into_md(
|
||||
uint32_t days, uint16_t year, uint8_t *pMonth, uint8_t *pDay)
|
||||
{
|
||||
uint8_t month = 1;
|
||||
uint8_t day = 0;
|
||||
|
||||
while (days > (uint32_t)datetime_month_days(year, month)) {
|
||||
days -= datetime_month_days(year, month);
|
||||
month++;
|
||||
}
|
||||
|
||||
day = (uint8_t)(day + days);
|
||||
|
||||
if (pMonth) {
|
||||
*pMonth = month;
|
||||
}
|
||||
if (pDay) {
|
||||
*pDay = day;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts date to day of the year
|
||||
*
|
||||
* @param days - number of days since Jan 1 (inclusive) of the given year
|
||||
* @param year - years after Christ birth (1900..2155 AD)
|
||||
* @param bdate - BACnet date structure
|
||||
*/
|
||||
void datetime_day_of_year_into_date(
|
||||
uint32_t days, uint16_t year, BACNET_DATE *bdate)
|
||||
{
|
||||
uint8_t month = 0;
|
||||
uint8_t day = 0;
|
||||
|
||||
day_of_year_into_md(days, year, &month, &day);
|
||||
days_of_year_to_month_day(days, year, &month, &day);
|
||||
datetime_set_date(bdate, year, month, day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts date to day of the year
|
||||
*
|
||||
* @param bdate - BACnet date structure
|
||||
* @return number of days since Jan 1 (inclusive) of the given year
|
||||
*/
|
||||
uint32_t datetime_day_of_year(BACNET_DATE *bdate)
|
||||
{
|
||||
uint32_t days = 0;
|
||||
|
||||
if (bdate) {
|
||||
days = day_of_year(bdate->year, bdate->month, bdate->day);
|
||||
days = datetime_ymd_day_of_year(bdate->year, bdate->month, bdate->day);
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
static uint32_t days_since_epoch(uint16_t year, uint8_t month, uint8_t day)
|
||||
/**
|
||||
* Converts days since BACnet epoch
|
||||
*
|
||||
* @param year - years after Christ birth (1900..2155 AD)
|
||||
* @param month - months (1=Jan...12=Dec)
|
||||
* @param day - day of month (1-31)
|
||||
* @return number of days since epoch, or 0 if out of range
|
||||
*/
|
||||
uint32_t datetime_ymd_to_days_since_epoch(
|
||||
uint16_t year, uint8_t month, uint8_t day)
|
||||
{
|
||||
uint32_t days = 0; /* return value */
|
||||
uint16_t years = 0; /* loop counter for years */
|
||||
|
||||
if (datetime_ymd_is_valid(year, month, day)) {
|
||||
for (years = BACNET_EPOCH_YEAR; years < year; years++) {
|
||||
for (years = BACNET_DATE_YEAR_EPOCH; years < year; years++) {
|
||||
days += 365;
|
||||
if (datetime_is_leap_year(years)) {
|
||||
if (days_is_leap_year(years)) {
|
||||
days++;
|
||||
}
|
||||
}
|
||||
days += day_of_year(year, month, day);
|
||||
days += datetime_ymd_day_of_year(year, month, day);
|
||||
/* 'days since' is one less */
|
||||
days -= 1;
|
||||
}
|
||||
@@ -191,37 +181,52 @@ static uint32_t days_since_epoch(uint16_t year, uint8_t month, uint8_t day)
|
||||
return (days);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts date to days since BACnet epoch
|
||||
*
|
||||
* @param bdate - BACnet date structure
|
||||
* @return number of days since epoch, or 0 if out of range
|
||||
*/
|
||||
uint32_t datetime_days_since_epoch(BACNET_DATE *bdate)
|
||||
{
|
||||
uint32_t days = 0;
|
||||
|
||||
if (bdate) {
|
||||
days = days_since_epoch(bdate->year, bdate->month, bdate->day);
|
||||
days = datetime_ymd_to_days_since_epoch(
|
||||
bdate->year, bdate->month, bdate->day);
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
static void days_since_epoch_into_ymd(
|
||||
/**
|
||||
* Converts days since BACnet epoch to YMD date
|
||||
*
|
||||
* @param days - number of days since epoch, or 0 if out of range
|
||||
* @param pYear - [out] years after Christ birth (1900..2155 AD)
|
||||
* @param pMonth - [out] months (1=Jan...12=Dec)
|
||||
* @param pDay - [out] day of month (1-31)
|
||||
*/
|
||||
void datetime_ymd_from_days_since_epoch(
|
||||
uint32_t days, uint16_t *pYear, uint8_t *pMonth, uint8_t *pDay)
|
||||
{
|
||||
uint16_t year = BACNET_EPOCH_YEAR;
|
||||
uint16_t year = BACNET_DATE_YEAR_EPOCH;
|
||||
uint8_t month = 1;
|
||||
uint8_t day = 1;
|
||||
|
||||
while (days >= 365) {
|
||||
if ((datetime_is_leap_year(year)) && (days == 365)) {
|
||||
if ((days_is_leap_year(year)) && (days == 365)) {
|
||||
break;
|
||||
}
|
||||
days -= 365;
|
||||
if (datetime_is_leap_year(year)) {
|
||||
if (days_is_leap_year(year)) {
|
||||
--days;
|
||||
}
|
||||
year++;
|
||||
}
|
||||
|
||||
while (days >= (uint32_t)datetime_month_days(year, month)) {
|
||||
days -= datetime_month_days(year, month);
|
||||
while (days >= (uint32_t)days_per_month(year, month)) {
|
||||
days -= days_per_month(year, month);
|
||||
month++;
|
||||
}
|
||||
|
||||
@@ -240,27 +245,45 @@ static void days_since_epoch_into_ymd(
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts days since BACnet epoch to date
|
||||
*
|
||||
* @param days - number of days since epoch, or 0 if out of range
|
||||
* @param bdate - BACnet date structure
|
||||
*/
|
||||
void datetime_days_since_epoch_into_date(uint32_t days, BACNET_DATE *bdate)
|
||||
{
|
||||
uint16_t year = 0;
|
||||
uint8_t month = 0;
|
||||
uint8_t day = 0;
|
||||
|
||||
days_since_epoch_into_ymd(days, &year, &month, &day);
|
||||
datetime_ymd_from_days_since_epoch(days, &year, &month, &day);
|
||||
datetime_set_date(bdate, year, month, day);
|
||||
}
|
||||
|
||||
/* Jan 1, 1900 is a Monday */
|
||||
/* wday 1=Monday...7=Sunday */
|
||||
/**
|
||||
* Determines the day of week based on BACnet epoch: Jan 1, 1900 was a Monday
|
||||
*
|
||||
* @param year - years after Christ birth (1900..2155 AD)
|
||||
* @param month - months (1=Jan...12=Dec)
|
||||
* @param day - day of month (1-31)
|
||||
* @return BACnet day of week where 1=Monday...7=Sunday
|
||||
*/
|
||||
uint8_t datetime_day_of_week(uint16_t year, uint8_t month, uint8_t day)
|
||||
{
|
||||
uint8_t dow = (uint8_t)BACNET_EPOCH_DOW;
|
||||
uint8_t dow = (uint8_t)BACNET_DAY_OF_WEEK_EPOCH;
|
||||
|
||||
dow += (days_since_epoch(year, month, day) % 7);
|
||||
dow += (datetime_ymd_to_days_since_epoch(year, month, day) % 7);
|
||||
|
||||
return dow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given time is valid
|
||||
*
|
||||
* @param btime - pointer to a BACNET_TIME structure
|
||||
* @return true if the time is valid
|
||||
*/
|
||||
bool datetime_time_is_valid(BACNET_TIME *btime)
|
||||
{
|
||||
bool status = false;
|
||||
@@ -522,18 +545,18 @@ void datetime_set_values(BACNET_DATE_TIME *bdatetime,
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t seconds_since_midnight(
|
||||
uint32_t datetime_hms_to_seconds_since_midnight(
|
||||
uint8_t hours, uint8_t minutes, uint8_t seconds)
|
||||
{
|
||||
return ((hours * 60 * 60) + (minutes * 60) + seconds);
|
||||
}
|
||||
|
||||
static uint16_t minutes_since_midnight(uint8_t hours, uint8_t minutes)
|
||||
uint16_t datetime_hm_to_minutes_since_midnight(uint8_t hours, uint8_t minutes)
|
||||
{
|
||||
return ((hours * 60) + minutes);
|
||||
}
|
||||
|
||||
static void seconds_since_midnight_into_hms(
|
||||
void datetime_hms_from_seconds_since_midnight(
|
||||
uint32_t seconds, uint8_t *pHours, uint8_t *pMinutes, uint8_t *pSeconds)
|
||||
{
|
||||
uint8_t hour = 0;
|
||||
@@ -564,7 +587,7 @@ void datetime_seconds_since_midnight_into_time(
|
||||
uint32_t seconds, BACNET_TIME *btime)
|
||||
{
|
||||
if (btime) {
|
||||
seconds_since_midnight_into_hms(
|
||||
datetime_hms_from_seconds_since_midnight(
|
||||
seconds, &btime->hour, &btime->min, &btime->sec);
|
||||
btime->hundredths = 0;
|
||||
}
|
||||
@@ -581,7 +604,8 @@ uint32_t datetime_seconds_since_midnight(BACNET_TIME *btime)
|
||||
uint32_t seconds = 0;
|
||||
|
||||
if (btime) {
|
||||
seconds = seconds_since_midnight(btime->hour, btime->min, btime->sec);
|
||||
seconds = datetime_hms_to_seconds_since_midnight(
|
||||
btime->hour, btime->min, btime->sec);
|
||||
}
|
||||
|
||||
return seconds;
|
||||
@@ -598,7 +622,8 @@ uint16_t datetime_minutes_since_midnight(BACNET_TIME *btime)
|
||||
uint32_t minutes = 0;
|
||||
|
||||
if (btime) {
|
||||
minutes = minutes_since_midnight(btime->hour, btime->min);
|
||||
minutes =
|
||||
datetime_hm_to_minutes_since_midnight(btime->hour, btime->min);
|
||||
}
|
||||
|
||||
return minutes;
|
||||
@@ -616,8 +641,9 @@ void datetime_add_minutes(BACNET_DATE_TIME *bdatetime, int32_t minutes)
|
||||
int32_t days = 0;
|
||||
|
||||
/* convert bdatetime to seconds and days */
|
||||
bdatetime_minutes = seconds_since_midnight(bdatetime->time.hour,
|
||||
bdatetime->time.min, bdatetime->time.sec) /
|
||||
bdatetime_minutes =
|
||||
datetime_hms_to_seconds_since_midnight(
|
||||
bdatetime->time.hour, bdatetime->time.min, bdatetime->time.sec) /
|
||||
60;
|
||||
bdatetime_days = datetime_days_since_epoch(&bdatetime->date);
|
||||
|
||||
@@ -648,7 +674,7 @@ void datetime_add_minutes(BACNET_DATE_TIME *bdatetime, int32_t minutes)
|
||||
}
|
||||
|
||||
/* convert bdatetime from seconds and days */
|
||||
seconds_since_midnight_into_hms(bdatetime_minutes * 60,
|
||||
datetime_hms_from_seconds_since_midnight(bdatetime_minutes * 60,
|
||||
&bdatetime->time.hour, &bdatetime->time.min, NULL);
|
||||
datetime_days_since_epoch_into_date(bdatetime_days, &bdatetime->date);
|
||||
}
|
||||
@@ -666,7 +692,7 @@ uint64_t datetime_seconds_since_epoch(BACNET_DATE_TIME *bdatetime)
|
||||
|
||||
if (bdatetime) {
|
||||
days = datetime_days_since_epoch(&bdatetime->date);
|
||||
seconds = seconds_since_midnight(24, 0, 0);
|
||||
seconds = datetime_hms_to_seconds_since_midnight(24, 0, 0);
|
||||
seconds *= days;
|
||||
seconds += datetime_seconds_since_midnight(&bdatetime->time);
|
||||
}
|
||||
@@ -688,7 +714,7 @@ void datetime_since_epoch_seconds(BACNET_DATE_TIME *bdatetime, uint64_t seconds)
|
||||
uint32_t day_seconds = 0;
|
||||
|
||||
if (bdatetime) {
|
||||
day_seconds = seconds_since_midnight(24, 0, 0);
|
||||
day_seconds = datetime_hms_to_seconds_since_midnight(24, 0, 0);
|
||||
days = seconds / day_seconds;
|
||||
seconds_after_midnight = seconds - (days * day_seconds);
|
||||
datetime_seconds_since_midnight_into_time(
|
||||
@@ -704,7 +730,7 @@ bool datetime_wildcard_year(BACNET_DATE *bdate)
|
||||
bool wildcard_present = false;
|
||||
|
||||
if (bdate) {
|
||||
if (bdate->year == (BACNET_EPOCH_YEAR + 0xFF)) {
|
||||
if (bdate->year == (BACNET_DATE_YEAR_EPOCH + 0xFF)) {
|
||||
wildcard_present = true;
|
||||
}
|
||||
}
|
||||
@@ -716,7 +742,7 @@ bool datetime_wildcard_year(BACNET_DATE *bdate)
|
||||
void datetime_wildcard_year_set(BACNET_DATE *bdate)
|
||||
{
|
||||
if (bdate) {
|
||||
bdate->year = BACNET_EPOCH_YEAR + 0xFF;
|
||||
bdate->year = BACNET_DATE_YEAR_EPOCH + 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -919,7 +945,7 @@ bool datetime_wildcard_present(BACNET_DATE_TIME *bdatetime)
|
||||
void datetime_date_wildcard_set(BACNET_DATE *bdate)
|
||||
{
|
||||
if (bdate) {
|
||||
bdate->year = BACNET_EPOCH_YEAR + 0xFF;
|
||||
bdate->year = BACNET_DATE_YEAR_EPOCH + 0xFF;
|
||||
bdate->month = 0xFF;
|
||||
bdate->day = 0xFF;
|
||||
bdate->wday = 0xFF;
|
||||
@@ -1101,8 +1127,7 @@ bool datetime_date_init_ascii(BACNET_DATE *bdate, const char *ascii)
|
||||
int year, month, day, wday;
|
||||
int count = 0;
|
||||
|
||||
count =
|
||||
sscanf(ascii, "%4d/%3d/%3d:%3d", &year, &month, &day, &wday);
|
||||
count = sscanf(ascii, "%4d/%3d/%3d:%3d", &year, &month, &day, &wday);
|
||||
if (count == 3) {
|
||||
datetime_set_date(bdate, (uint16_t)year, (uint8_t)month, (uint8_t)day);
|
||||
status = true;
|
||||
@@ -1132,8 +1157,7 @@ bool datetime_time_init_ascii(BACNET_TIME *btime, const char *ascii)
|
||||
int hour, min, sec, hundredths;
|
||||
int count = 0;
|
||||
|
||||
count = sscanf(
|
||||
ascii, "%3d:%3d:%3d.%3d", &hour, &min, &sec, &hundredths);
|
||||
count = sscanf(ascii, "%3d:%3d:%3d.%3d", &hour, &min, &sec, &hundredths);
|
||||
if (count == 4) {
|
||||
btime->hour = (uint8_t)hour;
|
||||
btime->min = (uint8_t)min;
|
||||
@@ -1177,7 +1201,7 @@ static void testBACnetDateTimeWildcard(Test *pTest)
|
||||
BACNET_DATE_TIME bdatetime;
|
||||
bool status = false;
|
||||
|
||||
datetime_set_values(&bdatetime, BACNET_EPOCH_YEAR, 1, 1, 0, 0, 0, 0);
|
||||
datetime_set_values(&bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0);
|
||||
status = datetime_wildcard(&bdatetime);
|
||||
ct_test(pTest, status == false);
|
||||
|
||||
@@ -1192,27 +1216,30 @@ static void testBACnetDateTimeAdd(Test *pTest)
|
||||
uint32_t minutes = 0;
|
||||
int diff = 0;
|
||||
|
||||
datetime_set_values(&bdatetime, BACNET_EPOCH_YEAR, 1, 1, 0, 0, 0, 0);
|
||||
datetime_set_values(&bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0);
|
||||
datetime_copy(&test_bdatetime, &bdatetime);
|
||||
datetime_add_minutes(&bdatetime, minutes);
|
||||
diff = datetime_compare(&test_bdatetime, &bdatetime);
|
||||
ct_test(pTest, diff == 0);
|
||||
|
||||
datetime_set_values(&bdatetime, BACNET_EPOCH_YEAR, 1, 1, 0, 0, 0, 0);
|
||||
datetime_set_values(&bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0);
|
||||
datetime_add_minutes(&bdatetime, 60);
|
||||
datetime_set_values(&test_bdatetime, BACNET_EPOCH_YEAR, 1, 1, 1, 0, 0, 0);
|
||||
datetime_set_values(
|
||||
&test_bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 1, 0, 0, 0);
|
||||
diff = datetime_compare(&test_bdatetime, &bdatetime);
|
||||
ct_test(pTest, diff == 0);
|
||||
|
||||
datetime_set_values(&bdatetime, BACNET_EPOCH_YEAR, 1, 1, 0, 0, 0, 0);
|
||||
datetime_set_values(&bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0);
|
||||
datetime_add_minutes(&bdatetime, (24 * 60));
|
||||
datetime_set_values(&test_bdatetime, BACNET_EPOCH_YEAR, 1, 2, 0, 0, 0, 0);
|
||||
datetime_set_values(
|
||||
&test_bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 2, 0, 0, 0, 0);
|
||||
diff = datetime_compare(&test_bdatetime, &bdatetime);
|
||||
ct_test(pTest, diff == 0);
|
||||
|
||||
datetime_set_values(&bdatetime, BACNET_EPOCH_YEAR, 1, 1, 0, 0, 0, 0);
|
||||
datetime_set_values(&bdatetime, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0);
|
||||
datetime_add_minutes(&bdatetime, (31 * 24 * 60));
|
||||
datetime_set_values(&test_bdatetime, BACNET_EPOCH_YEAR, 2, 1, 0, 0, 0, 0);
|
||||
datetime_set_values(
|
||||
&test_bdatetime, BACNET_DATE_YEAR_EPOCH, 2, 1, 0, 0, 0, 0);
|
||||
diff = datetime_compare(&test_bdatetime, &bdatetime);
|
||||
ct_test(pTest, diff == 0);
|
||||
|
||||
@@ -1238,11 +1265,12 @@ static void testBACnetDateTimeSeconds(Test *pTest)
|
||||
for (hour = 0; hour < 24; hour++) {
|
||||
for (minute = 0; minute < 60; minute += 3) {
|
||||
for (second = 0; second < 60; second += 17) {
|
||||
seconds = seconds_since_midnight(hour, minute, second);
|
||||
seconds_since_midnight_into_hms(
|
||||
seconds = datetime_hms_to_seconds_since_midnight(
|
||||
hour, minute, second);
|
||||
datetime_hms_from_seconds_since_midnight(
|
||||
seconds, &test_hour, &test_minute, &test_second);
|
||||
test_seconds =
|
||||
seconds_since_midnight(test_hour, test_minute, test_second);
|
||||
test_seconds = datetime_hms_to_seconds_since_midnight(
|
||||
test_hour, test_minute, test_second);
|
||||
ct_test(pTest, seconds == test_seconds);
|
||||
}
|
||||
}
|
||||
@@ -1254,14 +1282,14 @@ static void testBACnetDate(Test *pTest)
|
||||
BACNET_DATE bdate1, bdate2;
|
||||
int diff = 0;
|
||||
|
||||
datetime_set_date(&bdate1, BACNET_EPOCH_YEAR, 1, 1);
|
||||
datetime_set_date(&bdate1, BACNET_DATE_YEAR_EPOCH, 1, 1);
|
||||
datetime_copy_date(&bdate2, &bdate1);
|
||||
diff = datetime_compare_date(&bdate1, &bdate2);
|
||||
ct_test(pTest, diff == 0);
|
||||
datetime_set_date(&bdate2, BACNET_EPOCH_YEAR, 1, 2);
|
||||
datetime_set_date(&bdate2, BACNET_DATE_YEAR_EPOCH, 1, 2);
|
||||
diff = datetime_compare_date(&bdate1, &bdate2);
|
||||
ct_test(pTest, diff < 0);
|
||||
datetime_set_date(&bdate2, BACNET_EPOCH_YEAR, 2, 1);
|
||||
datetime_set_date(&bdate2, BACNET_DATE_YEAR_EPOCH, 2, 1);
|
||||
diff = datetime_compare_date(&bdate1, &bdate2);
|
||||
ct_test(pTest, diff < 0);
|
||||
datetime_set_date(&bdate2, 1901, 1, 1);
|
||||
@@ -1297,7 +1325,7 @@ static void testBACnetDate(Test *pTest)
|
||||
datetime_set_date(&bdate2, 2006, 7, 15);
|
||||
diff = datetime_compare_date(&bdate1, &bdate2);
|
||||
ct_test(pTest, diff > 0);
|
||||
datetime_set_date(&bdate2, BACNET_EPOCH_YEAR, 7, 15);
|
||||
datetime_set_date(&bdate2, BACNET_DATE_YEAR_EPOCH, 7, 15);
|
||||
diff = datetime_compare_date(&bdate1, &bdate2);
|
||||
ct_test(pTest, diff > 0);
|
||||
datetime_set_date(&bdate2, 2008, 7, 15);
|
||||
@@ -1366,12 +1394,12 @@ static void testBACnetDateTime(Test *pTest)
|
||||
BACNET_TIME btime;
|
||||
int diff = 0;
|
||||
|
||||
datetime_set_values(&bdatetime1, BACNET_EPOCH_YEAR, 1, 1, 0, 0, 0, 0);
|
||||
datetime_set_values(&bdatetime1, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0);
|
||||
datetime_copy(&bdatetime2, &bdatetime1);
|
||||
diff = datetime_compare(&bdatetime1, &bdatetime2);
|
||||
ct_test(pTest, diff == 0);
|
||||
datetime_set_time(&btime, 0, 0, 0, 0);
|
||||
datetime_set_date(&bdate, BACNET_EPOCH_YEAR, 1, 1);
|
||||
datetime_set_date(&bdate, BACNET_DATE_YEAR_EPOCH, 1, 1);
|
||||
datetime_set(&bdatetime1, &bdate, &btime);
|
||||
diff = datetime_compare(&bdatetime1, &bdatetime2);
|
||||
ct_test(pTest, diff == 0);
|
||||
@@ -1456,17 +1484,17 @@ static void testDayOfYear(Test *pTest)
|
||||
BACNET_DATE bdate;
|
||||
BACNET_DATE test_bdate;
|
||||
|
||||
days = day_of_year(1900, 1, 1);
|
||||
days = datetime_ymd_day_of_year(1900, 1, 1);
|
||||
ct_test(pTest, days == 1);
|
||||
day_of_year_into_md(days, 1900, &month, &day);
|
||||
days_of_year_to_month_day(days, 1900, &month, &day);
|
||||
ct_test(pTest, month == 1);
|
||||
ct_test(pTest, day == 1);
|
||||
|
||||
for (year = 1900; year <= 2154; year++) {
|
||||
for (month = 1; month <= 12; month++) {
|
||||
for (day = 1; day <= datetime_month_days(year, month); day++) {
|
||||
days = day_of_year(year, month, day);
|
||||
day_of_year_into_md(days, year, &test_month, &test_day);
|
||||
for (day = 1; day <= days_per_month(year, month); day++) {
|
||||
days = datetime_ymd_day_of_year(year, month, day);
|
||||
days_of_year_to_month_day(days, year, &test_month, &test_day);
|
||||
ct_test(pTest, month == test_month);
|
||||
ct_test(pTest, day == test_day);
|
||||
}
|
||||
@@ -1474,7 +1502,7 @@ static void testDayOfYear(Test *pTest)
|
||||
}
|
||||
for (year = 1900; year <= 2154; year++) {
|
||||
for (month = 1; month <= 12; month++) {
|
||||
for (day = 1; day <= datetime_month_days(year, month); day++) {
|
||||
for (day = 1; day <= days_per_month(year, month); day++) {
|
||||
datetime_set_date(&bdate, year, month, day);
|
||||
days = datetime_day_of_year(&bdate);
|
||||
datetime_day_of_year_into_date(days, year, &test_bdate);
|
||||
@@ -1513,12 +1541,13 @@ static void testDateEpochConversionCompare(Test *pTest,
|
||||
static void testDateEpochConversion(Test *pTest)
|
||||
{
|
||||
/* min */
|
||||
testDateEpochConversionCompare(pTest, BACNET_EPOCH_YEAR, 1, 1, 0, 0, 0, 0);
|
||||
testDateEpochConversionCompare(
|
||||
pTest, BACNET_DATE_YEAR_EPOCH, 1, 1, 0, 0, 0, 0);
|
||||
/* middle */
|
||||
testDateEpochConversionCompare(pTest, 2020, 6, 26, 12, 30, 30, 0);
|
||||
/* max */
|
||||
testDateEpochConversionCompare(
|
||||
pTest, BACNET_EPOCH_YEAR + 0xFF - 1, 12, 31, 23, 59, 59, 0);
|
||||
pTest, BACNET_DATE_YEAR_EPOCH + 0xFF - 1, 12, 31, 23, 59, 59, 0);
|
||||
}
|
||||
|
||||
static void testDateEpoch(Test *pTest)
|
||||
@@ -1528,18 +1557,19 @@ static void testDateEpoch(Test *pTest)
|
||||
uint8_t month = 0, test_month = 0;
|
||||
uint8_t day = 0, test_day = 0;
|
||||
|
||||
days = days_since_epoch(BACNET_EPOCH_YEAR, 1, 1);
|
||||
days = datetime_ymd_to_days_since_epoch(BACNET_DATE_YEAR_EPOCH, 1, 1);
|
||||
ct_test(pTest, days == 0);
|
||||
days_since_epoch_into_ymd(days, &year, &month, &day);
|
||||
ct_test(pTest, year == BACNET_EPOCH_YEAR);
|
||||
datetime_ymd_from_days_since_epoch(days, &year, &month, &day);
|
||||
ct_test(pTest, year == BACNET_DATE_YEAR_EPOCH);
|
||||
ct_test(pTest, month == 1);
|
||||
ct_test(pTest, day == 1);
|
||||
|
||||
for (year = BACNET_EPOCH_YEAR; year < (BACNET_EPOCH_YEAR + 0xFF); year++) {
|
||||
for (year = BACNET_DATE_YEAR_EPOCH; year < (BACNET_DATE_YEAR_EPOCH + 0xFF);
|
||||
year++) {
|
||||
for (month = 1; month <= 12; month++) {
|
||||
for (day = 1; day <= datetime_month_days(year, month); day++) {
|
||||
days = days_since_epoch(year, month, day);
|
||||
days_since_epoch_into_ymd(
|
||||
for (day = 1; day <= days_per_month(year, month); day++) {
|
||||
days = datetime_ymd_to_days_since_epoch(year, month, day);
|
||||
datetime_ymd_from_days_since_epoch(
|
||||
days, &test_year, &test_month, &test_day);
|
||||
ct_test(pTest, year == test_year);
|
||||
ct_test(pTest, month == test_month);
|
||||
|
||||
+217
-281
@@ -1,26 +1,26 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2012 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*********************************************************************/
|
||||
*
|
||||
* Copyright (C) 2012 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*********************************************************************/
|
||||
#ifndef DATE_TIME_H
|
||||
#define DATE_TIME_H
|
||||
|
||||
@@ -28,6 +28,11 @@
|
||||
#include <stdbool.h>
|
||||
#include "bacnet/bacnet_stack_exports.h"
|
||||
|
||||
/* define our epic beginnings */
|
||||
#define BACNET_DATE_YEAR_EPOCH 1900
|
||||
/* 1/1/1900 is a Monday */
|
||||
#define BACNET_DAY_OF_WEEK_EPOCH BACNET_WEEKDAY_MONDAY
|
||||
|
||||
typedef enum BACnet_Weekday {
|
||||
BACNET_WEEKDAY_MONDAY = 1,
|
||||
BACNET_WEEKDAY_TUESDAY = 2,
|
||||
@@ -40,10 +45,10 @@ typedef enum BACnet_Weekday {
|
||||
|
||||
/* date */
|
||||
typedef struct BACnet_Date {
|
||||
uint16_t year; /* AD */
|
||||
uint8_t month; /* 1=Jan */
|
||||
uint8_t day; /* 1..31 */
|
||||
uint8_t wday; /* 1=Monday-7=Sunday */
|
||||
uint16_t year; /* AD */
|
||||
uint8_t month; /* 1=Jan */
|
||||
uint8_t day; /* 1..31 */
|
||||
uint8_t wday; /* 1=Monday-7=Sunday */
|
||||
} BACNET_DATE;
|
||||
|
||||
/* time */
|
||||
@@ -67,284 +72,215 @@ typedef struct BACnet_Date_Range {
|
||||
|
||||
/* week and days */
|
||||
typedef struct BACnet_Weeknday {
|
||||
uint8_t month; /* 1=Jan 13=odd 14=even FF=any */
|
||||
uint8_t weekofmonth; /* 1=days 1-7, 2=days 8-14, 3=days 15-21, 4=days 22-28, 5=days 29-31, 6=last 7 days, FF=any week */
|
||||
uint8_t dayofweek; /* 1=Monday-7=Sunday, FF=any */
|
||||
uint8_t month; /* 1=Jan 13=odd 14=even FF=any */
|
||||
uint8_t weekofmonth; /* 1=days 1-7, 2=days 8-14, 3=days 15-21, 4=days 22-28,
|
||||
5=days 29-31, 6=last 7 days, FF=any week */
|
||||
uint8_t dayofweek; /* 1=Monday-7=Sunday, FF=any */
|
||||
} BACNET_WEEKNDAY;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* utility initialization functions */
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_set_date(
|
||||
BACNET_DATE * bdate,
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_set_time(
|
||||
BACNET_TIME * btime,
|
||||
uint8_t hour,
|
||||
uint8_t minute,
|
||||
uint8_t seconds,
|
||||
uint8_t hundredths);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_set(
|
||||
BACNET_DATE_TIME * bdatetime,
|
||||
BACNET_DATE * bdate,
|
||||
BACNET_TIME * btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_set_values(
|
||||
BACNET_DATE_TIME * bdatetime,
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day,
|
||||
uint8_t hour,
|
||||
uint8_t minute,
|
||||
uint8_t seconds,
|
||||
uint8_t hundredths);
|
||||
/* utility test for validity */
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_is_valid(
|
||||
BACNET_DATE * bdate,
|
||||
BACNET_TIME * btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_time_is_valid(
|
||||
BACNET_TIME * btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_date_is_valid(
|
||||
BACNET_DATE * bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
/* date and time calculations and summaries */
|
||||
uint32_t datetime_days_since_epoch(
|
||||
BACNET_DATE * bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_days_since_epoch_into_date(
|
||||
uint32_t days,
|
||||
BACNET_DATE * bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t datetime_day_of_year(
|
||||
BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_day_of_year_into_date(
|
||||
uint32_t days,
|
||||
uint16_t year,
|
||||
BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_is_leap_year(
|
||||
uint16_t year);
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t datetime_month_days(
|
||||
uint16_t year,
|
||||
uint8_t month);
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t datetime_day_of_week(
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_ymd_is_valid(
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day);
|
||||
/* utility initialization functions */
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_set_date(
|
||||
BACNET_DATE *bdate, uint16_t year, uint8_t month, uint8_t day);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_set_time(BACNET_TIME *btime,
|
||||
uint8_t hour,
|
||||
uint8_t minute,
|
||||
uint8_t seconds,
|
||||
uint8_t hundredths);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_set(
|
||||
BACNET_DATE_TIME *bdatetime, BACNET_DATE *bdate, BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_set_values(BACNET_DATE_TIME *bdatetime,
|
||||
uint16_t year,
|
||||
uint8_t month,
|
||||
uint8_t day,
|
||||
uint8_t hour,
|
||||
uint8_t minute,
|
||||
uint8_t seconds,
|
||||
uint8_t hundredths);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t datetime_hms_to_seconds_since_midnight(
|
||||
uint8_t hours, uint8_t minutes, uint8_t seconds);
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t datetime_hm_to_minutes_since_midnight(uint8_t hours, uint8_t minutes);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_hms_from_seconds_since_midnight(
|
||||
uint32_t seconds, uint8_t *pHours, uint8_t *pMinutes, uint8_t *pSeconds);
|
||||
/* utility test for validity */
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_is_valid(BACNET_DATE *bdate, BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_time_is_valid(BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_date_is_valid(BACNET_DATE *bdate);
|
||||
/* date and time calculations and summaries */
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_ymd_from_days_since_epoch(
|
||||
uint32_t days, uint16_t *pYear, uint8_t *pMonth, uint8_t *pDay);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t datetime_days_since_epoch(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_days_since_epoch_into_date(uint32_t days, BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t datetime_day_of_year(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t datetime_ymd_to_days_since_epoch(
|
||||
uint16_t year, uint8_t month, uint8_t day);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_day_of_year_into_date(
|
||||
uint32_t days, uint16_t year, BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_is_leap_year(uint16_t year);
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t datetime_month_days(uint16_t year, uint8_t month);
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t datetime_day_of_week(uint16_t year, uint8_t month, uint8_t day);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_ymd_is_valid(uint16_t year, uint8_t month, uint8_t day);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t datetime_ymd_day_of_year(uint16_t year, uint8_t month, uint8_t day);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_seconds_since_midnight_into_time(
|
||||
uint32_t seconds,
|
||||
BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t datetime_seconds_since_midnight(
|
||||
BACNET_TIME * btime);
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t datetime_minutes_since_midnight(
|
||||
BACNET_TIME * btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_seconds_since_midnight_into_time(
|
||||
uint32_t seconds, BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t datetime_seconds_since_midnight(BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
uint16_t datetime_minutes_since_midnight(BACNET_TIME *btime);
|
||||
|
||||
/* utility comparison functions:
|
||||
if the date/times are the same, return is 0
|
||||
if date1 is before date2, returns negative
|
||||
if date1 is after date2, returns positive */
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_compare_date(
|
||||
BACNET_DATE * date1,
|
||||
BACNET_DATE * date2);
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_compare_time(
|
||||
BACNET_TIME * time1,
|
||||
BACNET_TIME * time2);
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_compare(
|
||||
BACNET_DATE_TIME * datetime1,
|
||||
BACNET_DATE_TIME * datetime2);
|
||||
/* utility comparison functions:
|
||||
if the date/times are the same, return is 0
|
||||
if date1 is before date2, returns negative
|
||||
if date1 is after date2, returns positive */
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_compare_date(BACNET_DATE *date1, BACNET_DATE *date2);
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_compare_time(BACNET_TIME *time1, BACNET_TIME *time2);
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_compare(BACNET_DATE_TIME *datetime1, BACNET_DATE_TIME *datetime2);
|
||||
|
||||
/* full comparison functions:
|
||||
* taking into account FF fields in date and time structures,
|
||||
* do a full comparison of two values */
|
||||
int datetime_wildcard_compare_date(
|
||||
BACNET_DATE * date1,
|
||||
BACNET_DATE * date2);
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_wildcard_compare_time(
|
||||
BACNET_TIME * time1,
|
||||
BACNET_TIME * time2);
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_wildcard_compare(
|
||||
BACNET_DATE_TIME * datetime1,
|
||||
BACNET_DATE_TIME * datetime2);
|
||||
/* full comparison functions:
|
||||
* taking into account FF fields in date and time structures,
|
||||
* do a full comparison of two values */
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_wildcard_compare_date(BACNET_DATE *date1, BACNET_DATE *date2);
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_wildcard_compare_time(BACNET_TIME *time1, BACNET_TIME *time2);
|
||||
BACNET_STACK_EXPORT
|
||||
int datetime_wildcard_compare(
|
||||
BACNET_DATE_TIME *datetime1, BACNET_DATE_TIME *datetime2);
|
||||
|
||||
/* utility copy functions */
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_copy_date(
|
||||
BACNET_DATE * dest,
|
||||
BACNET_DATE * src);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_copy_time(
|
||||
BACNET_TIME * dest,
|
||||
BACNET_TIME * src);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_copy(
|
||||
BACNET_DATE_TIME * dest,
|
||||
BACNET_DATE_TIME * src);
|
||||
/* utility copy functions */
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_copy_date(BACNET_DATE *dest, BACNET_DATE *src);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_copy_time(BACNET_TIME *dest, BACNET_TIME *src);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_copy(BACNET_DATE_TIME *dest, BACNET_DATE_TIME *src);
|
||||
|
||||
/* utility add or subtract minutes function */
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_add_minutes(
|
||||
BACNET_DATE_TIME * bdatetime,
|
||||
int32_t minutes);
|
||||
/* utility add or subtract minutes function */
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_add_minutes(BACNET_DATE_TIME *bdatetime, int32_t minutes);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint64_t datetime_seconds_since_epoch(
|
||||
BACNET_DATE_TIME * bdatetime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_since_epoch_seconds(
|
||||
BACNET_DATE_TIME * bdatetime,
|
||||
uint64_t seconds);
|
||||
BACNET_STACK_EXPORT
|
||||
uint64_t datetime_seconds_since_epoch(BACNET_DATE_TIME *bdatetime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_since_epoch_seconds(
|
||||
BACNET_DATE_TIME *bdatetime, uint64_t seconds);
|
||||
|
||||
/* date and time wildcards */
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_year(
|
||||
BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_year_set(
|
||||
BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_month(
|
||||
BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_month_set(
|
||||
BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_day(
|
||||
BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_day_set(
|
||||
BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_weekday(
|
||||
BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_weekday_set(
|
||||
BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_hour(
|
||||
BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_hour_set(
|
||||
BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_minute(
|
||||
BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_minute_set(
|
||||
BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_second(
|
||||
BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_second_set(
|
||||
BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_hundredths(
|
||||
BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_hundredths_set(
|
||||
BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard(
|
||||
BACNET_DATE_TIME * bdatetime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_present(
|
||||
BACNET_DATE_TIME * bdatetime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_set(
|
||||
BACNET_DATE_TIME * bdatetime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_date_wildcard_set(
|
||||
BACNET_DATE * bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_time_wildcard_set(
|
||||
BACNET_TIME * btime);
|
||||
/* date and time wildcards */
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_year(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_year_set(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_month(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_month_set(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_day(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_day_set(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_weekday(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_weekday_set(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_hour(BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_hour_set(BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_minute(BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_minute_set(BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_second(BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_second_set(BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_hundredths(BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_hundredths_set(BACNET_TIME *btime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard(BACNET_DATE_TIME *bdatetime);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_wildcard_present(BACNET_DATE_TIME *bdatetime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_wildcard_set(BACNET_DATE_TIME *bdatetime);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_date_wildcard_set(BACNET_DATE *bdate);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_time_wildcard_set(BACNET_TIME *btime);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_local_to_utc(
|
||||
BACNET_DATE_TIME * utc_time,
|
||||
BACNET_DATE_TIME * local_time,
|
||||
int16_t utc_offset_minutes,
|
||||
int8_t dst_adjust_minutes);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_utc_to_local(
|
||||
BACNET_DATE_TIME * local_time,
|
||||
BACNET_DATE_TIME * utc_time,
|
||||
int16_t utc_offset_minutes,
|
||||
int8_t dst_adjust_minutes);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_local_to_utc(BACNET_DATE_TIME *utc_time,
|
||||
BACNET_DATE_TIME *local_time,
|
||||
int16_t utc_offset_minutes,
|
||||
int8_t dst_adjust_minutes);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_utc_to_local(BACNET_DATE_TIME *local_time,
|
||||
BACNET_DATE_TIME *utc_time,
|
||||
int16_t utc_offset_minutes,
|
||||
int8_t dst_adjust_minutes);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_date_init_ascii(
|
||||
BACNET_DATE *bdate,
|
||||
const char *ascii);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_time_init_ascii(
|
||||
BACNET_TIME *btime,
|
||||
const char *ascii);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_date_init_ascii(BACNET_DATE *bdate, const char *ascii);
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_time_init_ascii(BACNET_TIME *btime, const char *ascii);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacapp_encode_datetime(
|
||||
uint8_t * apdu,
|
||||
BACNET_DATE_TIME * value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacapp_encode_datetime(uint8_t *apdu, BACNET_DATE_TIME *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacapp_encode_context_datetime(
|
||||
uint8_t * apdu,
|
||||
uint8_t tag_number,
|
||||
BACNET_DATE_TIME * value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacapp_encode_context_datetime(
|
||||
uint8_t *apdu, uint8_t tag_number, BACNET_DATE_TIME *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacapp_decode_datetime(
|
||||
uint8_t * apdu,
|
||||
BACNET_DATE_TIME * value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacapp_decode_datetime(uint8_t *apdu, BACNET_DATE_TIME *value);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int bacapp_decode_context_datetime(
|
||||
uint8_t * apdu,
|
||||
uint8_t tag_number,
|
||||
BACNET_DATE_TIME * value);
|
||||
BACNET_STACK_EXPORT
|
||||
int bacapp_decode_context_datetime(
|
||||
uint8_t *apdu, uint8_t tag_number, BACNET_DATE_TIME *value);
|
||||
|
||||
/* implementation agnostic functions - create your own! */
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_local(
|
||||
BACNET_DATE * bdate,
|
||||
BACNET_TIME * btime,
|
||||
int16_t * utc_offset_minutes,
|
||||
bool * dst_active);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_init(void);
|
||||
/* implementation agnostic functions - create your own! */
|
||||
BACNET_STACK_EXPORT
|
||||
bool datetime_local(BACNET_DATE *bdate,
|
||||
BACNET_TIME *btime,
|
||||
int16_t *utc_offset_minutes,
|
||||
bool *dst_active);
|
||||
BACNET_STACK_EXPORT
|
||||
void datetime_init(void);
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include "ctest.h"
|
||||
BACNET_STACK_EXPORT
|
||||
void testDateTime(
|
||||
Test * pTest);
|
||||
BACNET_STACK_EXPORT
|
||||
void testDateTime(Test *pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -293,12 +293,12 @@ bool lighting_command_same(
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#ifdef TEST_LIGHTING_COMMAND
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testBACnetLightingCommand(Test *pTest, BACNET_LIGHTING_COMMAND *data)
|
||||
static void testBACnetLightingCommand(Test *pTest, BACNET_LIGHTING_COMMAND *data)
|
||||
{
|
||||
bool status = false;
|
||||
BACNET_LIGHTING_COMMAND test_data;
|
||||
@@ -320,7 +320,7 @@ void testBACnetLightingCommand(Test *pTest, BACNET_LIGHTING_COMMAND *data)
|
||||
status = lighting_command_same(&test_data, data);
|
||||
}
|
||||
|
||||
void testBACnetLightingCommandAll(Test *pTest)
|
||||
static void testBACnetLightingCommandAll(Test *pTest)
|
||||
{
|
||||
BACNET_LIGHTING_COMMAND data;
|
||||
|
||||
@@ -345,7 +345,6 @@ void testBACnetLightingCommandAll(Test *pTest)
|
||||
testBACnetLightingCommand(pTest, &data);
|
||||
}
|
||||
|
||||
#ifdef TEST_LIGHTING_COMMAND
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
@@ -365,4 +364,3 @@ int main(void)
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* BAC_TEST */
|
||||
|
||||
@@ -295,7 +295,7 @@ int timesync_decode_timesync_recipients(
|
||||
return BACNET_STATUS_ABORT;
|
||||
}
|
||||
apdu_len += len;
|
||||
} else if (decode_is_context_tag(&apdu[apdu_len], 1)) {
|
||||
} else if (decode_is_opening_tag_number(&apdu[apdu_len], 1)) {
|
||||
apdu_len += 1;
|
||||
pRecipient->tag = 1;
|
||||
/* network-number Unsigned16 */
|
||||
@@ -339,6 +339,10 @@ int timesync_decode_timesync_recipients(
|
||||
octetstring_copy_value(&pRecipient->type.address.mac[0],
|
||||
sizeof(pRecipient->type.address.mac), &octet_string);
|
||||
}
|
||||
if (!decode_is_closing_tag_number(&apdu[apdu_len], 1)) {
|
||||
return BACNET_STATUS_ABORT;
|
||||
}
|
||||
apdu_len += 1;
|
||||
} else {
|
||||
return BACNET_STATUS_ABORT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user