Added BACnet UTC Time Sync service encoding and decoding.
This commit is contained in:
+59
-6
@@ -38,9 +38,9 @@
|
||||
#include "bacapp.h"
|
||||
#include "timesync.h"
|
||||
|
||||
/* encode service - use -1 for limit for unlimited */
|
||||
|
||||
int timesync_encode_apdu(uint8_t * apdu,
|
||||
/* encode service */
|
||||
int timesync_encode_apdu_service(uint8_t * apdu,
|
||||
BACNET_UNCONFIRMED_SERVICE service,
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time)
|
||||
{
|
||||
@@ -49,7 +49,7 @@ int timesync_encode_apdu(uint8_t * apdu,
|
||||
|
||||
if (apdu && my_date && my_time) {
|
||||
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
|
||||
apdu[1] = SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION;
|
||||
apdu[1] = service;
|
||||
apdu_len = 2;
|
||||
len = encode_tagged_date(&apdu[apdu_len], my_date);
|
||||
apdu_len += len;
|
||||
@@ -60,6 +60,26 @@ int timesync_encode_apdu(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int timesync_utc_encode_apdu(uint8_t * apdu,
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time)
|
||||
{
|
||||
return timesync_encode_apdu_service(apdu,
|
||||
SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
|
||||
my_date,
|
||||
my_time);
|
||||
}
|
||||
|
||||
int timesync_encode_apdu(uint8_t * apdu,
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time)
|
||||
{
|
||||
return timesync_encode_apdu_service(apdu,
|
||||
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
|
||||
my_date,
|
||||
my_time);
|
||||
}
|
||||
|
||||
/* decode the service request only */
|
||||
int timesync_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
@@ -92,7 +112,8 @@ int timesync_decode_service_request(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int timesync_decode_apdu(uint8_t * apdu,
|
||||
int timesync_decode_apdu_service(uint8_t * apdu,
|
||||
BACNET_UNCONFIRMED_SERVICE service,
|
||||
unsigned apdu_len,
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time)
|
||||
@@ -104,7 +125,7 @@ int timesync_decode_apdu(uint8_t * apdu,
|
||||
/* optional checking - most likely was already done prior to this call */
|
||||
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
|
||||
return -1;
|
||||
if (apdu[1] != SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION)
|
||||
if (apdu[1] != service)
|
||||
return -1;
|
||||
/* optional limits - must be used as a pair */
|
||||
if (apdu_len > 2) {
|
||||
@@ -115,6 +136,30 @@ int timesync_decode_apdu(uint8_t * apdu,
|
||||
return len;
|
||||
}
|
||||
|
||||
int timesync_utc_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time)
|
||||
{
|
||||
return timesync_decode_apdu_service(apdu,
|
||||
SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
|
||||
apdu_len,
|
||||
my_date,
|
||||
my_time);
|
||||
}
|
||||
|
||||
int timesync_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time)
|
||||
{
|
||||
return timesync_decode_apdu_service(apdu,
|
||||
SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
|
||||
apdu_len,
|
||||
my_date,
|
||||
my_time);
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
@@ -137,6 +182,14 @@ void testTimeSyncData(Test * pTest,
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, bacapp_same_time(my_time, &test_time));
|
||||
ct_test(pTest, bacapp_same_date(my_date, &test_date));
|
||||
|
||||
len = timesync_utc_encode_apdu(&apdu[0], my_date, my_time);
|
||||
ct_test(pTest, len != 0);
|
||||
apdu_len = len;
|
||||
len = timesync_utc_decode_apdu(&apdu[0], apdu_len, &test_date, &test_time);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, bacapp_same_time(my_time, &test_time));
|
||||
ct_test(pTest, bacapp_same_date(my_date, &test_date));
|
||||
}
|
||||
|
||||
void testTimeSync(Test * pTest)
|
||||
|
||||
+20
-15
@@ -31,37 +31,42 @@
|
||||
License.
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
#ifndef REINITIALIZE_DEVICE_H
|
||||
#define REINITIALIZE_DEVICE_H
|
||||
#ifndef TIMESYNC_H
|
||||
#define TIMESYNC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "bacdef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* encode service */
|
||||
int rd_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_REINITIALIZED_STATE state,
|
||||
BACNET_CHARACTER_STRING * password);
|
||||
|
||||
int timesync_utc_encode_apdu(uint8_t * apdu,
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time);
|
||||
int timesync_encode_apdu(uint8_t * apdu,
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time);
|
||||
/* decode the service request only */
|
||||
int rd_decode_service_request(uint8_t * apdu,
|
||||
int timesync_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_REINITIALIZED_STATE * state,
|
||||
BACNET_CHARACTER_STRING * password);
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time);
|
||||
|
||||
int rd_decode_apdu(uint8_t * apdu,
|
||||
int timesync_utc_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id,
|
||||
BACNET_REINITIALIZED_STATE * state,
|
||||
BACNET_CHARACTER_STRING * password);
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time);
|
||||
int timesync_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
BACNET_DATE *my_date,
|
||||
BACNET_TIME *my_time);
|
||||
|
||||
#ifdef TEST
|
||||
#include "ctest.h"
|
||||
void test_ReinitializeDevice(Test * pTest);
|
||||
void testTimeSync(Test * pTest);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user