From 2effa898dc268764f73171d1e363023bbd77010c Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Thu, 15 Sep 2011 15:43:22 +0200 Subject: Added configuration file parameter -c. --- src/daemon/dlt-daemon.c | 29 ++++++++++++++----- src/daemon/dlt-daemon.h | 1 + testscripts/dlt.conf | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 testscripts/dlt.conf diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index ec09b38..41ef12b 100755 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -152,6 +152,7 @@ void usage() printf(" -f filename Enable filtering of messages\n"); printf(" -u size Size of the ringbuffer in bytes (Default: 10024)\n"); printf(" -i directory Directory where to store the persistant configuration (Default: /tmp)\n"); + printf(" -c filename DLT daemon configuration file (Default: /etc/dlt.conf)\n"); } /* usage() */ /** @@ -172,7 +173,7 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[]) opterr = 0; - while ((c = getopt (argc, argv, "hvasxdlrmnf:o:e:b:y:u:i:")) != -1) + while ((c = getopt (argc, argv, "hvasxdlrmnf:o:e:b:y:u:i:c:")) != -1) { switch (c) { @@ -256,6 +257,11 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[]) strncpy(daemon_local->flags.ivalue,optarg,sizeof(daemon_local->flags.ivalue)); break; } + case 'c': + { + strncpy(daemon_local->flags.cvalue,optarg,sizeof(daemon_local->flags.cvalue)); + break; + } case 'h': { usage(); @@ -263,7 +269,7 @@ int option_handling(DltDaemonLocal *daemon_local,int argc, char* argv[]) } case '?': { - if (optopt == 'f' || optopt == 'o' || optopt == 'e' || optopt == 'b' || optopt == 'y' || optopt == 'u') + if (optopt == 'f' || optopt == 'o' || optopt == 'e' || optopt == 'b' || optopt == 'y' || optopt == 'u' || optopt == 'c') { fprintf (stderr, "Option -%c requires an argument.\n", optopt); } @@ -300,9 +306,18 @@ int option_file_parser(DltDaemonLocal *daemon_local) char line[1024]; char token[1024]; char value[1024]; - char * pch; - - pFile = fopen ("/home/alex/dlt.conf","r"); + char *pch; + const char *filename; + + + /* open configuration file */ + if(daemon_local->flags.cvalue[0]) + filename = daemon_local->flags.cvalue; + else + filename = "/etc/dlt.conf"; + printf("Load configuration from file: %s\n",filename); + pFile = fopen (filename,"r"); + if (pFile!=NULL) { while(1) @@ -333,7 +348,7 @@ int option_file_parser(DltDaemonLocal *daemon_local) pch = strtok (NULL, " =\r\n"); } - if(token[0]) + if(token[0] && value[0]) { /* parse arguments here */ printf("%s = %s\n",token,value); @@ -414,7 +429,7 @@ int option_file_parser(DltDaemonLocal *daemon_local) } else { - printf("Configuration file cannot be opened\n"); + fprintf(stderr, "Cannot open configuration file: %s\n",filename); } return 0; diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index 04eef6e..97357e1 100755 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -105,6 +105,7 @@ typedef struct char yvalue[256]; /**< (String: Devicename) Additional support for serial device */ char uvalue[256]; /**< (String: Ringbuffer) Size of the ringbuffer in bytes (Default: 10024) */ char ivalue[256]; /**< (String: Directory) Directory where to store the persistant configuration (Default: /tmp) */ + char cvalue[256]; /**< (String: Directory) Filename of DLT configuration file (Default: /etc/dlt.conf) */ } DltDaemonFlags; /** diff --git a/testscripts/dlt.conf b/testscripts/dlt.conf new file mode 100644 index 0000000..e9101e4 --- /dev/null +++ b/testscripts/dlt.conf @@ -0,0 +1,75 @@ +# Configuration file of DLT daemon +# +# Configurations made here will overwrite settings by command line + +######################################################################## +# General configuration # +######################################################################## + +# Start daemon in dubug mode, so that all internal debug information is printed out on the console +Verbose = 1 + +# Daemonize DLT daemon, if it is started as daemon +# Daemonize = 1 + +# Send DLT messages with serial header +# SendSerialHeader = 1 + +# Send automatic get log info response during context registration +# SendContextRegistration = 1 + +# Set ECU ID (Default: ECU1) +ECUId = ENAE + +# Enable filtering of messages +# FilterFilename = ~/tmp/filter + +# Size of the ringbuffer in bytes (Default: 10024) +# RingbufferSize = 10024 + +# Directory where to store the persistant configuration (Default: /tmp) +PersistanceStoragePath = ~/tmp + +######################################################################## +# Local file output configuration # +######################################################################## + +# Store DLT messages to local log file +# LocalLogFilename = ~/tmp/local_log.dlt + +######################################################################## +# Local console output configuration # +######################################################################## + +# Print DLT messages; payload as ASCII +PrintASCII = 1 + +# Print DLT messages; payload as hex +# PrintHex = 1 + +# Print DLT messages; only headers +# PrintHeadersOnly = 1 + + +######################################################################## +# Client Serial port configuration # +######################################################################## + +# Additional support for serial device +# If a device name is set serial port is enabled. +# RS232DeviceName = /dev/ttyS0 + +# Serial device baudrate (Default: 115200) +# RS232Baudrate = 115200 + +# Sync to serial header on serial connection +# RS232SyncSerialHeader = 1 + +######################################################################## +# TCP Serial port configuration # +######################################################################## + +# Sync to serial header on all TCP connections +# TCPSyncSerialHeader = 1 + + -- cgit v1.2.1