Added set time callback with optional offset for BACnet TimeSynchronization services (#691)
This commit is contained in:
@@ -66,6 +66,21 @@ static void show_bacnet_date_time(BACNET_DATE *bdate, BACNET_TIME *btime)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Callback for timesync set */
|
||||
static handler_timesync_set_callback_t handler_timesync_set_callback;
|
||||
|
||||
static int32_t Time_Offset; /* Time offset in ms */
|
||||
|
||||
int32_t handler_timesync_offset(void)
|
||||
{
|
||||
return Time_Offset;
|
||||
}
|
||||
|
||||
void handler_timesync_offset_set(int32_t offset)
|
||||
{
|
||||
Time_Offset = offset;
|
||||
}
|
||||
|
||||
void handler_timesync(
|
||||
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src)
|
||||
{
|
||||
@@ -80,12 +95,12 @@ void handler_timesync(
|
||||
if (len > 0) {
|
||||
if (datetime_is_valid(&bdate, &btime)) {
|
||||
/* fixme: only set the time if off by some amount */
|
||||
if (handler_timesync_set_callback) {
|
||||
handler_timesync_set_callback(&bdate, &btime, false);
|
||||
}
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "Received TimeSyncronization Request\r\n");
|
||||
fprintf(stderr, "Received Local TimeSyncronization Request\r\n");
|
||||
show_bacnet_date_time(&bdate, &btime);
|
||||
#else
|
||||
/* FIXME: set the time?
|
||||
Maybe only set the time if off by some amount */
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -106,12 +121,13 @@ void handler_timesync_utc(
|
||||
service_request, service_len, &bdate, &btime);
|
||||
if (len > 0) {
|
||||
if (datetime_is_valid(&bdate, &btime)) {
|
||||
if (handler_timesync_set_callback) {
|
||||
handler_timesync_set_callback(&bdate, &btime, true);
|
||||
}
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "Received TimeSyncronization Request\r\n");
|
||||
fprintf(stderr, "Received UTC TimeSyncronization Request\r\n");
|
||||
show_bacnet_date_time(&bdate, &btime);
|
||||
#endif
|
||||
/* FIXME: set the time?
|
||||
only set the time if off by some amount */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,3 +292,14 @@ void handler_timesync_init(void)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Configures and enables a timesync callback function
|
||||
*
|
||||
* @param cb - pointer to #handler_timesync_set_callback_t
|
||||
*/
|
||||
void handler_timesync_set_callback_set(
|
||||
handler_timesync_set_callback_t cb)
|
||||
{
|
||||
handler_timesync_set_callback = cb;
|
||||
}
|
||||
|
||||
@@ -39,10 +39,19 @@
|
||||
#include "bacnet/datetime.h"
|
||||
#include "bacnet/wp.h"
|
||||
|
||||
typedef void (*handler_timesync_set_callback_t)(
|
||||
BACNET_DATE *bdate,
|
||||
BACNET_TIME *btime,
|
||||
bool utc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int32_t handler_timesync_offset(void);
|
||||
BACNET_STACK_EXPORT
|
||||
void handler_timesync_offset_set(int32_t offset);
|
||||
/* time synchronization handlers */
|
||||
BACNET_STACK_EXPORT
|
||||
void handler_timesync(
|
||||
@@ -81,7 +90,9 @@ extern "C" {
|
||||
bool handler_timesync_recipient_address_set(
|
||||
unsigned index,
|
||||
BACNET_ADDRESS * address);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void handler_timesync_set_callback_set(
|
||||
handler_timesync_set_callback_t cb);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
Reference in New Issue
Block a user