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