From b2097a2acc84e57fa9e26318ceee63a5d31a9df7 Mon Sep 17 00:00:00 2001 From: skarg Date: Thu, 6 Nov 2014 16:16:48 +0000 Subject: [PATCH] Added command line option for setting the Device Name in the demo server project. --- bacnet-stack/demo/object/device.c | 5 ++++ bacnet-stack/demo/object/device.h | 1 + bacnet-stack/demo/server/main.c | 48 ++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index c2aaac07..0c1a25b2 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -742,6 +742,11 @@ bool Device_Set_Object_Name( return status; } +bool Device_Object_Name_ANSI_Init(const char * value) +{ + return characterstring_init_ansi(&My_Object_Name, value); +} + BACNET_DEVICE_STATUS Device_System_Status( void) { diff --git a/bacnet-stack/demo/object/device.h b/bacnet-stack/demo/object/device.h index 6dd0082c..979c3dcd 100644 --- a/bacnet-stack/demo/object/device.h +++ b/bacnet-stack/demo/object/device.h @@ -287,6 +287,7 @@ extern "C" { BACNET_OBJECT_TYPE object_type, uint32_t object_instance, BACNET_CHARACTER_STRING * object_name); + bool Device_Object_Name_ANSI_Init(const char * object_name); BACNET_DEVICE_STATUS Device_System_Status( void); diff --git a/bacnet-stack/demo/server/main.c b/bacnet-stack/demo/server/main.c index c029fecc..e79cfb88 100644 --- a/bacnet-stack/demo/server/main.c +++ b/bacnet-stack/demo/server/main.c @@ -45,6 +45,7 @@ #include "bacfile.h" #include "datalink.h" #include "dcc.h" +#include "filename.h" #include "getevent.h" #include "net.h" #include "txbuf.h" @@ -134,6 +135,27 @@ static void Init_Service_Handlers( #endif /* defined(INTRINSIC_REPORTING) */ } +static void print_usage(char *filename) +{ + printf("Usage: %s [device-instance [device-name]]\n", filename); + printf(" [--version][--help]\n"); +} + +static void print_help(char *filename) +{ + printf("Simulate a BACnet server device\n" + "device-instance:\n" + "BACnet Device Object Instance number that you are\n" + "trying simulate.\n" + "device-name:\n" + "The Device object-name is the text name for the device.\n" + "\nExample:\n"); + printf("To simulate Device 123, use the following command:\n" + "%s 123\n", filename); + printf("To simulate Device 123 named Fred, use following command:\n" + "%s 123 Fred\n", filename); +} + /** Main function of server demo. * * @see Device_Set_Object_Instance_Number, dlenv_init, Send_I_Am, @@ -164,7 +186,27 @@ int main( #if defined(BAC_UCI) int uciId = 0; struct uci_context *ctx; +#endif + int argi = 0; + char *filename = NULL; + filename = filename_remove_path(argv[0]); + for (argi = 1; argi < argc; argi++) { + if (strcmp(argv[argi], "--help") == 0) { + print_usage(filename); + print_help(filename); + return 0; + } + if (strcmp(argv[argi], "--version") == 0) { + printf("%s %s\n", filename, BACNET_VERSION_TEXT); + printf("Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying conditions.\n" + "There is NO warranty; not even for MERCHANTABILITY or\n" + "FITNESS FOR A PARTICULAR PURPOSE.\n"); + return 0; + } + } +#if defined(BAC_UCI) ctx = ucix_init("bacnet_dev"); if (!ctx) fprintf(stderr, "Failed to load config file bacnet_dev\n"); @@ -175,8 +217,12 @@ int main( } else { #endif /* defined(BAC_UCI) */ /* allow the device ID to be set */ - if (argc > 1) + if (argc > 1) { Device_Set_Object_Instance_Number(strtol(argv[1], NULL, 0)); + } + if (argc > 2) { + Device_Object_Name_ANSI_Init(argv[2]); + } #if defined(BAC_UCI) } ucix_cleanup(ctx);