Enhanced date and time parsing for WriteProperty demo.
This commit is contained in:
+51
-1
@@ -536,7 +536,9 @@ bool bacapp_parse_application_data(BACNET_APPLICATION_TAG tag_number,
|
|||||||
} else if (tag_number == BACNET_APPLICATION_TAG_DATE) {
|
} else if (tag_number == BACNET_APPLICATION_TAG_DATE) {
|
||||||
count =
|
count =
|
||||||
sscanf(argv, "%d/%d/%d:%d", &year, &month, &day, &wday);
|
sscanf(argv, "%d/%d/%d:%d", &year, &month, &day, &wday);
|
||||||
if (count == 4) {
|
if (count == 3) {
|
||||||
|
datetime_set_date(&value->type.Date, year, month, day);
|
||||||
|
} else if (count == 4) {
|
||||||
value->type.Date.year = year;
|
value->type.Date.year = year;
|
||||||
value->type.Date.month = month;
|
value->type.Date.month = month;
|
||||||
value->type.Date.day = day;
|
value->type.Date.day = day;
|
||||||
@@ -552,6 +554,16 @@ bool bacapp_parse_application_data(BACNET_APPLICATION_TAG tag_number,
|
|||||||
value->type.Time.min = min;
|
value->type.Time.min = min;
|
||||||
value->type.Time.sec = sec;
|
value->type.Time.sec = sec;
|
||||||
value->type.Time.hundredths = hundredths;
|
value->type.Time.hundredths = hundredths;
|
||||||
|
} else if (count == 3) {
|
||||||
|
value->type.Time.hour = hour;
|
||||||
|
value->type.Time.min = min;
|
||||||
|
value->type.Time.sec = sec;
|
||||||
|
value->type.Time.hundredths = 0;
|
||||||
|
} else if (count == 2) {
|
||||||
|
value->type.Time.hour = hour;
|
||||||
|
value->type.Time.min = min;
|
||||||
|
value->type.Time.sec = 0;
|
||||||
|
value->type.Time.hundredths = 0;
|
||||||
} else
|
} else
|
||||||
status = false;
|
status = false;
|
||||||
} else if (tag_number == BACNET_APPLICATION_TAG_OBJECT_ID) {
|
} else if (tag_number == BACNET_APPLICATION_TAG_OBJECT_ID) {
|
||||||
@@ -918,6 +930,26 @@ void testBACnetApplicationData(Test * pTest)
|
|||||||
ct_test(pTest, value.type.Date.wday == 1);
|
ct_test(pTest, value.type.Date.wday == 1);
|
||||||
ct_test(pTest, testBACnetApplicationDataValue(&value));
|
ct_test(pTest, testBACnetApplicationDataValue(&value));
|
||||||
|
|
||||||
|
/* Happy Valentines Day! */
|
||||||
|
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
|
||||||
|
"2007/2/14", &value);
|
||||||
|
ct_test(pTest, status == true);
|
||||||
|
ct_test(pTest, value.type.Date.year == 2007);
|
||||||
|
ct_test(pTest, value.type.Date.month == 2);
|
||||||
|
ct_test(pTest, value.type.Date.day == 14);
|
||||||
|
ct_test(pTest, value.type.Date.wday == BACNET_WEEKDAY_WEDNESDAY);
|
||||||
|
ct_test(pTest, testBACnetApplicationDataValue(&value));
|
||||||
|
|
||||||
|
/* Wildcard Values */
|
||||||
|
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
|
||||||
|
"2155/255/255:255", &value);
|
||||||
|
ct_test(pTest, status == true);
|
||||||
|
ct_test(pTest, value.type.Date.year == 2155);
|
||||||
|
ct_test(pTest, value.type.Date.month == 255);
|
||||||
|
ct_test(pTest, value.type.Date.day == 255);
|
||||||
|
ct_test(pTest, value.type.Date.wday == 255);
|
||||||
|
ct_test(pTest, testBACnetApplicationDataValue(&value));
|
||||||
|
|
||||||
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
|
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
|
||||||
"23:59:59.12", &value);
|
"23:59:59.12", &value);
|
||||||
ct_test(pTest, status == true);
|
ct_test(pTest, status == true);
|
||||||
@@ -927,6 +959,24 @@ void testBACnetApplicationData(Test * pTest)
|
|||||||
ct_test(pTest, value.type.Time.hundredths == 12);
|
ct_test(pTest, value.type.Time.hundredths == 12);
|
||||||
ct_test(pTest, testBACnetApplicationDataValue(&value));
|
ct_test(pTest, testBACnetApplicationDataValue(&value));
|
||||||
|
|
||||||
|
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
|
||||||
|
"23:59:59", &value);
|
||||||
|
ct_test(pTest, status == true);
|
||||||
|
ct_test(pTest, value.type.Time.hour == 23);
|
||||||
|
ct_test(pTest, value.type.Time.min == 59);
|
||||||
|
ct_test(pTest, value.type.Time.sec == 59);
|
||||||
|
ct_test(pTest, value.type.Time.hundredths == 0);
|
||||||
|
ct_test(pTest, testBACnetApplicationDataValue(&value));
|
||||||
|
|
||||||
|
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
|
||||||
|
"23:59", &value);
|
||||||
|
ct_test(pTest, status == true);
|
||||||
|
ct_test(pTest, value.type.Time.hour == 23);
|
||||||
|
ct_test(pTest, value.type.Time.min == 59);
|
||||||
|
ct_test(pTest, value.type.Time.sec == 0);
|
||||||
|
ct_test(pTest, value.type.Time.hundredths == 0);
|
||||||
|
ct_test(pTest, testBACnetApplicationDataValue(&value));
|
||||||
|
|
||||||
status =
|
status =
|
||||||
bacapp_parse_application_data(BACNET_APPLICATION_TAG_OBJECT_ID,
|
bacapp_parse_application_data(BACNET_APPLICATION_TAG_OBJECT_ID,
|
||||||
"0:100", &value);
|
"0:100", &value);
|
||||||
|
|||||||
Binary file not shown.
@@ -37,6 +37,16 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BACNET_WEEKDAY_MONDAY = 1,
|
||||||
|
BACNET_WEEKDAY_TUESDAY = 2,
|
||||||
|
BACNET_WEEKDAY_WEDNESDAY = 3,
|
||||||
|
BACNET_WEEKDAY_THURSDAY = 4,
|
||||||
|
BACNET_WEEKDAY_FRIDAY = 5,
|
||||||
|
BACNET_WEEKDAY_SATURDAY = 6,
|
||||||
|
BACNET_WEEKDAY_SUNDAY = 7
|
||||||
|
} BACNET_WEEKDAY;
|
||||||
|
|
||||||
/* date */
|
/* date */
|
||||||
typedef struct BACnet_Date {
|
typedef struct BACnet_Date {
|
||||||
uint16_t year; /* AD */
|
uint16_t year; /* AD */
|
||||||
|
|||||||
Reference in New Issue
Block a user