Updated Local Time and Date to show hundredths of seconds. Fixed Daylight_Savings_Status to get updated. Changed Local Time and Date to be static. Thanks Piotr!
This commit is contained in:
@@ -42,6 +42,8 @@
|
|||||||
#if defined(BACFILE)
|
#if defined(BACFILE)
|
||||||
#include "bacfile.h" /* object list dependency */
|
#include "bacfile.h" /* object list dependency */
|
||||||
#endif
|
#endif
|
||||||
|
/* os specfic includes */
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
#if defined(__BORLANDC__)
|
#if defined(__BORLANDC__)
|
||||||
/* seems to not be defined in time.h as specified by The Open Group */
|
/* seems to not be defined in time.h as specified by The Open Group */
|
||||||
@@ -149,8 +151,8 @@ static char Description[16] = "server";
|
|||||||
/* static uint8_t Max_Segments_Accepted = 0; */
|
/* static uint8_t Max_Segments_Accepted = 0; */
|
||||||
/* VT_Classes_Supported */
|
/* VT_Classes_Supported */
|
||||||
/* Active_VT_Sessions */
|
/* Active_VT_Sessions */
|
||||||
BACNET_TIME Local_Time; /* rely on OS, if there is one */
|
static BACNET_TIME Local_Time; /* rely on OS, if there is one */
|
||||||
BACNET_DATE Local_Date; /* rely on OS, if there is one */
|
static BACNET_DATE Local_Date; /* rely on OS, if there is one */
|
||||||
/* NOTE: BACnet UTC Offset is inverse of common practice.
|
/* NOTE: BACnet UTC Offset is inverse of common practice.
|
||||||
If your UTC offset is -5hours of GMT,
|
If your UTC offset is -5hours of GMT,
|
||||||
then BACnet UTC offset is +5hours.
|
then BACnet UTC offset is +5hours.
|
||||||
@@ -494,9 +496,8 @@ char *Device_Valid_Object_Id(
|
|||||||
|
|
||||||
static void Update_Current_Time(void)
|
static void Update_Current_Time(void)
|
||||||
{
|
{
|
||||||
time_t timer;
|
struct tm *tblock = NULL;
|
||||||
struct tm *tblock;
|
struct timeval tv;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
struct tm
|
struct tm
|
||||||
|
|
||||||
@@ -510,22 +511,29 @@ int tm_wday Day of week [0,6] (Sunday =0).
|
|||||||
int tm_yday Day of year [0,365].
|
int tm_yday Day of year [0,365].
|
||||||
int tm_isdst Daylight Savings flag.
|
int tm_isdst Daylight Savings flag.
|
||||||
*/
|
*/
|
||||||
|
if (gettimeofday(&tv, NULL) == 0) {
|
||||||
timer = time(NULL);
|
tblock = localtime(&tv.tv_sec);
|
||||||
tblock = localtime(&timer);
|
}
|
||||||
datetime_set_date(
|
if (tblock) {
|
||||||
&Local_Date,
|
datetime_set_date(
|
||||||
(uint16_t) tblock->tm_year+1900,
|
&Local_Date,
|
||||||
(uint8_t) tblock->tm_mon+1,
|
(uint16_t) tblock->tm_year+1900,
|
||||||
(uint8_t) tblock->tm_mday);
|
(uint8_t) tblock->tm_mon+1,
|
||||||
datetime_set_time(
|
(uint8_t) tblock->tm_mday);
|
||||||
&Local_Time,
|
datetime_set_time(
|
||||||
(uint8_t) tblock->tm_hour,
|
&Local_Time,
|
||||||
(uint8_t) tblock->tm_min,
|
(uint8_t) tblock->tm_hour,
|
||||||
(uint8_t) tblock->tm_sec, 0);
|
(uint8_t) tblock->tm_min,
|
||||||
if (tblock->tm_isdst) {
|
(uint8_t) tblock->tm_sec,
|
||||||
Daylight_Savings_Status = true;
|
(uint8_t)(tv.tv_usec / 10000));
|
||||||
|
if (tblock->tm_isdst) {
|
||||||
|
Daylight_Savings_Status = true;
|
||||||
|
} else {
|
||||||
|
Daylight_Savings_Status = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
datetime_date_wildcard_set(&Local_Date);
|
||||||
|
datetime_time_wildcard_set(&Local_Time);
|
||||||
Daylight_Savings_Status = false;
|
Daylight_Savings_Status = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -616,6 +624,7 @@ int Device_Encode_Property_APDU(
|
|||||||
apdu_len = encode_application_date(&apdu[0], &Local_Date);
|
apdu_len = encode_application_date(&apdu[0], &Local_Date);
|
||||||
break;
|
break;
|
||||||
case PROP_DAYLIGHT_SAVINGS_STATUS:
|
case PROP_DAYLIGHT_SAVINGS_STATUS:
|
||||||
|
Update_Current_Time();
|
||||||
apdu_len =
|
apdu_len =
|
||||||
encode_application_boolean(&apdu[0], Daylight_Savings_Status);
|
encode_application_boolean(&apdu[0], Daylight_Savings_Status);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user