summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManikandan C <Manikandan.Chockalingam@in.bosch.com>2016-02-10 13:46:35 +0530
committerGernot Wirschal <gernot.wirschal@bmw.de>2016-04-28 14:52:50 +0200
commita3dd0b954e8f020d535afb2c9e315cc33fea681e (patch)
treee54dd333fac5684467362c7784bd825ee340989e
parenta966393ad7003d02870bceffa08df5ddf4bbf864 (diff)
downloadDLT-daemon-a3dd0b954e8f020d535afb2c9e315cc33fea681e.tar.gz
CommonControl: Unix socket path and ecuid parsing for control applications
Signed-off-by: Manikandan C <Manikandan.Chockalingam@in.bosch.com> Change-Id: I023c6bccbe3977d50b77bb601df80643d8e2d82c
-rw-r--r--include/dlt/dlt_client.h1
-rw-r--r--src/console/CMakeLists.txt2
-rw-r--r--src/console/dlt-control-common.c108
-rw-r--r--src/console/dlt-control-common.h4
-rw-r--r--src/console/dlt-control.c16
-rw-r--r--src/console/dlt-passive-node-ctrl.c2
-rw-r--r--src/console/logstorage/dlt-logstorage-ctrl.c2
-rw-r--r--src/lib/dlt_client.c2
8 files changed, 119 insertions, 18 deletions
diff --git a/include/dlt/dlt_client.h b/include/dlt/dlt_client.h
index a4d3181..9af7421 100644
--- a/include/dlt/dlt_client.h
+++ b/include/dlt/dlt_client.h
@@ -94,6 +94,7 @@ typedef struct
int port; /**< Port for TCP connections (optional) */
char *serialDevice; /**< serialDevice Devicename of serial device */
char *socketPath; /**< socketPath Unix socket path */
+ char ecuid[4]; /**< ECUiD */
speed_t baudrate; /**< baudrate Baudrate of serial interface, as speed_t */
DltClientMode mode; /**< mode DltClientMode */
} DltClient;
diff --git a/src/console/CMakeLists.txt b/src/console/CMakeLists.txt
index f2b7c30..0fa2a1b 100644
--- a/src/console/CMakeLists.txt
+++ b/src/console/CMakeLists.txt
@@ -25,7 +25,7 @@ add_executable(dlt-receive ${dlt_receive_SRCS} ${dlt_most_SRCS})
target_link_libraries(dlt-receive dlt ${EXPAT_LIBRARIES})
set_target_properties(dlt-receive PROPERTIES LINKER_LANGUAGE C)
-set(dlt_control_SRCS dlt-control.c)
+set(dlt_control_SRCS dlt-control.c dlt-control-common.c)
add_executable(dlt-control ${dlt_control_SRCS} ${dlt_most_SRCS})
target_link_libraries(dlt-control dlt ${EXPAT_LIBRARIES})
set_target_properties(dlt-control PROPERTIES LINKER_LANGUAGE C)
diff --git a/src/console/dlt-control-common.c b/src/console/dlt-control-common.c
index c3d82cf..310b091 100644
--- a/src/console/dlt-control-common.c
+++ b/src/console/dlt-control-common.c
@@ -68,8 +68,7 @@
#define DLT_CTRL_APID "DLTC"
#define DLT_CTRL_CTID "DLTC"
-#define DLT_CTRL_SOCK "/tmp/dlt-ctrl.sock"
-
+#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH "/tmp/dlt-ctrl.sock"
#define DLT_RECEIVE_TEXTBUFSIZE 1024
/** @brief Analyze the daemon answer
@@ -93,6 +92,7 @@ static pthread_cond_t answer_cond = PTHREAD_COND_INITIALIZER;
static int local_verbose;
static char local_ecuid[DLT_CTRL_ECUID_LEN]; /* Name of ECU */
static long local_timeout;
+static char config_data[DLT_DAEMON_FLAG_MAX]; /* To copy dlt.conf values */
int get_verbosity(void)
{
@@ -111,11 +111,26 @@ char *get_ecuid(void)
void set_ecuid(char *ecuid)
{
+ char *ecuid_conf;
+
if (local_ecuid != ecuid)
{
- memset(local_ecuid, 0, DLT_CTRL_ECUID_LEN);
- strncpy(local_ecuid, ecuid, DLT_CTRL_ECUID_LEN);
- local_ecuid[DLT_CTRL_ECUID_LEN - 1] = '\0';
+ /* If user pass NULL, read ECUId from dlt.conf */
+ if (ecuid == NULL)
+ {
+ ecuid_conf = dlt_parse_config_param("ECUId");
+ memset(local_ecuid, 0, DLT_CTRL_ECUID_LEN);
+ strncpy(local_ecuid, ecuid_conf, DLT_CTRL_ECUID_LEN);
+ local_ecuid[DLT_CTRL_ECUID_LEN - 1] = '\0';
+
+ }
+ else
+ {
+ /* Set user passed ECUID */
+ memset(local_ecuid, 0, DLT_CTRL_ECUID_LEN);
+ strncpy(local_ecuid, ecuid, DLT_CTRL_ECUID_LEN);
+ local_ecuid[DLT_CTRL_ECUID_LEN - 1] = '\0';
+ }
}
}
@@ -139,6 +154,80 @@ void set_timeout(long t)
}
}
+char *dlt_parse_config_param(char *config_id)
+{
+ FILE * pFile = NULL;
+ int value_length = DLT_RECEIVE_TEXTBUFSIZE;
+ char line[DLT_RECEIVE_TEXTBUFSIZE-1] = {0};
+ char token[DLT_RECEIVE_TEXTBUFSIZE] = {0};
+ char value[DLT_RECEIVE_TEXTBUFSIZE] = {0};
+ char *pch = NULL;
+ const char *filename = NULL;
+
+ memset(config_data, 0, DLT_DAEMON_FLAG_MAX);
+ /* open configuration file */
+ filename = CONFIGURATION_FILES_DIR "/dlt.conf";
+ pFile = fopen(filename, "r");
+
+ if (pFile != NULL)
+ {
+ while (1)
+ {
+ /* fetch line from configuration file */
+ if (fgets(line, value_length - 1, pFile) != NULL)
+ {
+ if (strncmp(line, config_id, strlen(config_id)) == 0)
+ {
+ pch = strtok(line, " =\r\n");
+ token[0] = 0;
+ value[0] = 0;
+
+ while (pch != NULL)
+ {
+ if (token[0] == 0)
+ {
+ strncpy(token, pch, sizeof(token) - 1);
+ token[sizeof(token) - 1] = 0;
+ }
+ else
+ {
+ strncpy(value, pch, sizeof(value) - 1);
+ value[sizeof(value) - 1] = 0;
+ break;
+ }
+ pch = strtok(NULL, " =\r\n");
+ }
+
+ if (token[0] && value[0])
+ {
+ if (strcmp(token, config_id) == 0)
+ {
+ memset(config_data,
+ 0,
+ DLT_DAEMON_FLAG_MAX);
+ strncpy(config_data,
+ value,
+ DLT_DAEMON_FLAG_MAX-1);
+ }
+ }
+
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ fclose (pFile);
+ }
+ else
+ {
+ fprintf(stderr, "Cannot open configuration file: %s\n", filename);
+ }
+
+ return config_data;
+}
+
/** @brief Send a message to the daemon through the socket.
*
* The socket as to be opened and active before sending.
@@ -378,7 +467,14 @@ static int dlt_control_init_connection(DltClient *client, void *cb)
dlt_client_register_message_callback(callback);
- client->socketPath = DLT_CTRL_SOCK;
+ client->socketPath = dlt_parse_config_param("ControlSocketPath");
+ if (client->socketPath[0] == 0)
+ {
+ /* Failed to read from conf, copy default */
+ strncpy(client->socketPath,
+ DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH,
+ DLT_DAEMON_FLAG_MAX - 1);
+ }
client->mode = DLT_CLIENT_MODE_UNIX;
return dlt_client_connect(client, get_verbosity());
diff --git a/src/console/dlt-control-common.h b/src/console/dlt-control-common.h
index b8d712f..927a585 100644
--- a/src/console/dlt-control-common.h
+++ b/src/console/dlt-control-common.h
@@ -31,6 +31,7 @@
#define DLT_CTRL_TIMEOUT 10
#define DLT_CTRL_ECUID_LEN 10
+#define DLT_DAEMON_FLAG_MAX 256
#ifndef pr_fmt
# define pr_fmt(fmt) fmt
@@ -69,6 +70,9 @@ void set_ecuid(char *);
long get_timeout(void);
void set_timeout(long);
+/*Parse dlt.conf file and return the value of requested configuration*/
+char *dlt_parse_config_param(char *config_id);
+
/* Initialize the connection to the daemon */
int dlt_control_init(int (*response_analyser)(char *, void *, int),
char *ecuid,
diff --git a/src/console/dlt-control.c b/src/console/dlt-control.c
index e5cda97..b4808eb 100644
--- a/src/console/dlt-control.c
+++ b/src/console/dlt-control.c
@@ -66,9 +66,6 @@
#define DLT_RECEIVE_TEXTBUFSIZE 10024 /* Size of buffer for text output */
-#define DLT_CTRL_SOCK "/tmp/dlt-ctrl.sock"
-
-#define DLT_RECEIVE_ECU_ID "RECV"
#define DLT_GLOGINFO_APID_NUM_MAX 150
#define DLT_GLOGINFO_DATA_MAX 800
@@ -463,7 +460,7 @@ int main(int argc, char* argv[])
else if (dltdata.yflag == DLT_CLIENT_MODE_UNIX)
{
g_dltclient.mode = DLT_CLIENT_MODE_UNIX;
- g_dltclient.socketPath = DLT_CTRL_SOCK;
+ g_dltclient.socketPath = dlt_parse_config_param("ControlSocketPath");
}
else
{
@@ -513,11 +510,14 @@ int main(int argc, char* argv[])
if (dltdata.evalue)
{
dlt_set_id(dltdata.ecuid,dltdata.evalue);
+ dlt_set_id(g_dltclient.ecuid,dltdata.evalue);
+ }
+ else
+ {
+ dltdata.evalue = dlt_parse_config_param("ECUId");
+ dlt_set_id(dltdata.ecuid,dltdata.evalue);
+ dlt_set_id(g_dltclient.ecuid,dltdata.evalue);
}
- else
- {
- dlt_set_id(dltdata.ecuid,DLT_RECEIVE_ECU_ID);
- }
/* Connect to TCP socket or open serial device */
if (dlt_client_connect(&g_dltclient, dltdata.vflag) != DLT_RETURN_ERROR)
diff --git a/src/console/dlt-passive-node-ctrl.c b/src/console/dlt-passive-node-ctrl.c
index db12085..88a03a8 100644
--- a/src/console/dlt-passive-node-ctrl.c
+++ b/src/console/dlt-passive-node-ctrl.c
@@ -427,7 +427,7 @@ int main(int argc, char *argv[])
{
int ret = 0;
- set_ecuid(DLT_CTRL_DEFAULT_ECUID);
+ set_ecuid(NULL);
set_timeout(DLT_CTRL_TIMEOUT);
/* Get command line arguments */
diff --git a/src/console/logstorage/dlt-logstorage-ctrl.c b/src/console/logstorage/dlt-logstorage-ctrl.c
index 1e255b7..227acec 100644
--- a/src/console/logstorage/dlt-logstorage-ctrl.c
+++ b/src/console/logstorage/dlt-logstorage-ctrl.c
@@ -552,7 +552,7 @@ int main(int argc, char *argv[])
{
int ret = 0;
- set_ecuid(DLT_CTRL_DEFAULT_ECUID);
+ set_ecuid(NULL);
set_timeout(DLT_CTRL_TIMEOUT);
/* Get command line arguments */
diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c
index 2b37598..71a0069 100644
--- a/src/lib/dlt_client.c
+++ b/src/lib/dlt_client.c
@@ -456,7 +456,7 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti
msg.standardheader->mcnt = 0;
/* Set header extra parameters */
- dlt_set_id(msg.headerextra.ecu,"");
+ dlt_set_id(msg.headerextra.ecu,client->ecuid);
//msg.headerextra.seid = 0;
msg.headerextra.tmsp = dlt_uptime();