Feature/bacnet time sync override (#215)
* add --time and --date options to command line time sync for override * remove PRINT_ENABLED compile overreach * fix bacstr.c for non-PRINT_ENABLED compile Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
+18
-1
@@ -156,6 +156,8 @@ int main(int argc, char *argv[])
|
||||
const unsigned timeout = 100; /* milliseconds */
|
||||
BACNET_DATE bdate;
|
||||
BACNET_TIME btime;
|
||||
bool override_date = false;
|
||||
bool override_time = false;
|
||||
struct mstimer apdu_timer;
|
||||
long dnet = -1;
|
||||
BACNET_MAC_ADDRESS mac = { 0 };
|
||||
@@ -204,6 +206,20 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strcmp(argv[argi], "--date") == 0) {
|
||||
if (++argi < argc) {
|
||||
if (datetime_date_init_ascii(&bdate, argv[argi])) {
|
||||
override_date = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strcmp(argv[argi], "--time") == 0) {
|
||||
if (++argi < argc) {
|
||||
if (datetime_time_init_ascii(&btime, argv[argi])) {
|
||||
override_time = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (global_broadcast) {
|
||||
datalink_get_broadcast_address(&dest);
|
||||
@@ -244,7 +260,8 @@ int main(int argc, char *argv[])
|
||||
atexit(datalink_cleanup);
|
||||
mstimer_init();
|
||||
/* send the request */
|
||||
datetime_local(&bdate, &btime, NULL, NULL);
|
||||
datetime_local(override_date?NULL:&bdate,override_time?NULL:&btime,
|
||||
NULL, NULL);
|
||||
Send_TimeSync_Remote(&dest, &bdate, &btime);
|
||||
mstimer_set(&apdu_timer, apdu_timeout());
|
||||
/* loop forever - not necessary for time sync, but we can watch */
|
||||
|
||||
@@ -1543,10 +1543,8 @@ bool bacapp_parse_application_data(BACNET_APPLICATION_TAG tag_number,
|
||||
#endif
|
||||
#if defined(BACAPP_OCTET_STRING)
|
||||
case BACNET_APPLICATION_TAG_OCTET_STRING:
|
||||
#if PRINT_ENABLED /* Apparently ain't necessarily so. */
|
||||
status =
|
||||
octetstring_init_ascii_hex(&value->type.Octet_String, argv);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
#if defined(BACAPP_CHARACTER_STRING)
|
||||
@@ -1557,9 +1555,7 @@ bool bacapp_parse_application_data(BACNET_APPLICATION_TAG tag_number,
|
||||
#endif
|
||||
#if defined(BACAPP_BIT_STRING)
|
||||
case BACNET_APPLICATION_TAG_BIT_STRING:
|
||||
#if PRINT_ENABLED
|
||||
status = bitstring_init_ascii(&value->type.Bit_String, argv);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
#if defined(BACAPP_ENUMERATED)
|
||||
|
||||
+3
-9
@@ -34,14 +34,12 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h> /* for strlen */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "bacnet/config.h"
|
||||
#include "bacnet/bacstr.h"
|
||||
#include "bacnet/bits.h"
|
||||
#if PRINT_ENABLED
|
||||
#include <stdlib.h> /* for strtol */
|
||||
#include <ctype.h> /* for isalnum */
|
||||
#endif
|
||||
|
||||
/* TODO: For some reason my Zephyr build for non-native targets does not
|
||||
* see a definition for strnlen(), but it is visible in when
|
||||
@@ -319,7 +317,6 @@ bool bitstring_same(
|
||||
return false;
|
||||
}
|
||||
|
||||
#if PRINT_ENABLED
|
||||
/**
|
||||
* Converts an null terminated ASCII string to an bitstring.
|
||||
*
|
||||
@@ -371,7 +368,6 @@ bool bitstring_init_ascii(BACNET_BIT_STRING *bit_string, const char *ascii)
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define CHARACTER_STRING_CAPACITY (MAX_CHARACTER_STRING_BYTES - 1)
|
||||
/**
|
||||
@@ -981,7 +977,6 @@ bool octetstring_init(
|
||||
return status;
|
||||
}
|
||||
|
||||
#if PRINT_ENABLED
|
||||
/** @brief Converts an null terminated ASCII Hex string to an octet string.
|
||||
*
|
||||
* @param octet_string Pointer to the octed string.
|
||||
@@ -1031,7 +1026,6 @@ bool octetstring_init_ascii_hex(
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Copy an octed string from source to destination.
|
||||
|
||||
@@ -190,14 +190,12 @@ extern "C" {
|
||||
BACNET_OCTET_STRING * octet_string,
|
||||
uint8_t * value,
|
||||
size_t length);
|
||||
#ifdef PRINT_ENABLED
|
||||
/* converts an null terminated ASCII Hex string to an octet string.
|
||||
returns true if successfully converted and fits; false if too long */
|
||||
BACNET_STACK_EXPORT
|
||||
bool octetstring_init_ascii_hex(
|
||||
BACNET_OCTET_STRING * octet_string,
|
||||
const char *ascii_hex);
|
||||
#endif
|
||||
BACNET_STACK_EXPORT
|
||||
bool octetstring_copy(
|
||||
BACNET_OCTET_STRING * dest,
|
||||
|
||||
@@ -1113,7 +1113,6 @@ int bacapp_decode_context_datetime(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
#if PRINT_ENABLED
|
||||
/**
|
||||
* @brief Parse an ascii string for the date 2021/12/31 or 2021/12/31:1
|
||||
* @param bdate - #BACNET_DATE structure
|
||||
@@ -1141,9 +1140,7 @@ bool datetime_date_init_ascii(BACNET_DATE *bdate, const char *ascii)
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PRINT_ENABLED
|
||||
/**
|
||||
* @brief Parse an ascii string for the time formatted 23:59:59.99
|
||||
* @param btime - #BACNET_TIME structure
|
||||
@@ -1180,7 +1177,6 @@ bool datetime_time_init_ascii(BACNET_TIME *btime, const char *ascii)
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BAC_TEST
|
||||
#include <assert.h>
|
||||
|
||||
@@ -266,7 +266,6 @@ int bacapp_decode_context_timestamp(
|
||||
return len;
|
||||
}
|
||||
|
||||
#if PRINT_ENABLED
|
||||
/**
|
||||
* @brief Parse an ascii string for the timestamp
|
||||
* @param btime - #BACNET_TIME structure
|
||||
@@ -347,7 +346,6 @@ bool bacapp_timestamp_init_ascii(BACNET_TIMESTAMP *timestamp, const char *ascii)
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BAC_TEST
|
||||
|
||||
|
||||
Reference in New Issue
Block a user