Created demo for TimeSync service and tested it on Win32.

This commit is contained in:
skarg
2006-02-21 21:54:37 +00:00
parent de4abea3c5
commit 4e5f4a68e4
12 changed files with 659 additions and 18 deletions
+4
View File
@@ -73,6 +73,10 @@ extern "C" {
uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t timeDuration, /* 0=optional */
BACNET_COMMUNICATION_ENABLE_DISABLE state, char *password); /* NULL=optional */
void Send_TimeSync(BACNET_DATE *bdate, BACNET_TIME *btime);
void Send_TimeSyncUTC(BACNET_DATE *bdate, BACNET_TIME *btime);
#ifdef __cplusplus
}
#endif /* __cplusplus */
+88
View File
@@ -0,0 +1,88 @@
/**************************************************************************
*
* Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include "config.h"
#include "txbuf.h"
#include "bacdef.h"
#include "bacdcode.h"
#include "timesync.h"
static void show_bacnet_date_time(
BACNET_DATE *bdate,
BACNET_TIME *btime)
{
/* show the date received */
fprintf(stderr, "%u", (unsigned)bdate->year);
fprintf(stderr, "/%u", (unsigned)bdate->month);
fprintf(stderr, "/%u", (unsigned)bdate->day);
/* show the time received */
fprintf(stderr, " %u", (unsigned)btime->hour);
fprintf(stderr, ":%u", (unsigned)btime->min);
fprintf(stderr, ":%u", (unsigned)btime->sec);
fprintf(stderr, ".%02u", (unsigned)btime->hundredths);
fprintf(stderr, "\r\n");
}
void handler_timesync(uint8_t * service_request,
uint16_t service_len, BACNET_ADDRESS * src)
{
int len = 0;
BACNET_DATE bdate;
BACNET_TIME btime;
(void) src;
(void) service_len;
len = timesync_decode_service_request(service_request,
service_len,
&bdate,
&btime);
fprintf(stderr, "Received TimeSyncronization Request\r\n");
show_bacnet_date_time(&bdate, &btime);
/* FIXME: set the time? */
return;
}
void handler_timesync_utc(uint8_t * service_request,
uint16_t service_len, BACNET_ADDRESS * src)
{
int len = 0;
BACNET_DATE bdate;
BACNET_TIME btime;
(void) src;
(void) service_len;
len = timesync_decode_service_request(service_request,
service_len,
&bdate,
&btime);
fprintf(stderr, "Received TimeSyncronization Request\r\n");
show_bacnet_date_time(&bdate, &btime);
/* FIXME: set the time? */
return;
}
+6
View File
@@ -90,6 +90,12 @@ extern "C" {
void handler_i_have(uint8_t * service_request,
uint16_t service_len, BACNET_ADDRESS * src);
void handler_timesync(uint8_t * service_request,
uint16_t service_len, BACNET_ADDRESS * src);
void handler_timesync_utc(uint8_t * service_request,
uint16_t service_len, BACNET_ADDRESS * src);
#ifdef __cplusplus
}
+93
View File
@@ -0,0 +1,93 @@
/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include "config.h"
#include "config.h"
#include "txbuf.h"
#include "bacdef.h"
#include "bacdcode.h"
#include "address.h"
#include "tsm.h"
#include "npdu.h"
#include "apdu.h"
#include "device.h"
#include "datalink.h"
#include "dcc.h"
#include "timesync.h"
/* some demo stuff needed */
#include "handlers.h"
#include "txbuf.h"
void Send_TimeSync(BACNET_DATE *bdate, BACNET_TIME *btime)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
if (!dcc_communication_enabled())
return;
/* we could use unicast or broadcast */
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */
pdu_len += timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
bdate, btime);
/* send it out the datalink */
bytes_sent = datalink_send_pdu(&dest,
&Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send Time-Synchronization Request (%s)!\n",
strerror(errno));
}
void Send_TimeSyncUTC(BACNET_DATE *bdate, BACNET_TIME *btime)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
if (!dcc_communication_enabled())
return;
/* we could use unicast or broadcast */
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
MESSAGE_PRIORITY_NORMAL);
/* encode the APDU portion of the packet */
pdu_len += timesync_utc_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
bdate, btime);
/* send it out the datalink */
bytes_sent = datalink_send_pdu(&dest,
&Handler_Transmit_Buffer[0], pdu_len);
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send UTC-Time-Synchronization Request (%s)!\n",
strerror(errno));
}