52 #define pr_fmt(fmt) "Common control: "fmt 60 #include <sys/types.h> 61 #include <sys/socket.h> 69 #define DLT_CTRL_APID "DLTC" 70 #define DLT_CTRL_CTID "DLTC" 71 #define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH "/tmp/dlt-ctrl.sock" 72 #define DLT_RECEIVE_TEXTBUFSIZE 1024 89 static pthread_mutex_t
answer_lock = PTHREAD_MUTEX_INITIALIZER;
113 char *ecuid_conf =
NULL;
128 pr_error(
"Cannot read ECUid from dlt.conf\n");
156 pr_error(
"Timeout to small. Set to default: %d",
169 const char *filename =
NULL;
171 if (*config_data !=
NULL)
175 filename = CONFIGURATION_FILES_DIR
"/dlt.conf";
176 pFile = fopen(filename,
"r");
183 if (fgets(line, value_length - 1, pFile) !=
NULL)
185 if (strncmp(line, config_id, strlen(config_id)) == 0)
187 pch = strtok(line,
" =\r\n");
195 strncpy(token, pch,
sizeof(token) - 1);
196 token[
sizeof(token) - 1] = 0;
200 strncpy(value, pch,
sizeof(value) - 1);
201 value[
sizeof(value) - 1] = 0;
204 pch = strtok(
NULL,
" =\r\n");
207 if (token[0] && value[0])
209 if (strcmp(token, config_id) == 0)
211 *(config_data) = (
char*)
213 strncpy(*config_data,
230 fprintf(stderr,
"Cannot open configuration file: %s\n", filename);
233 if (*config_data ==
NULL)
251 (
const char *)(msg->
headerbuffer +
sizeof(DltStorageHeader)),
252 msg->
headersize -
sizeof(DltStorageHeader), 0) == -1)
254 pr_error(
"Sending message header failed: %s\n", strerror(errno));
260 pr_error(
"Sending message failed: %s\n", strerror(errno));
287 shift =
sizeof(DltStorageHeader) +
288 sizeof(DltStandardHeader) +
299 pr_error(
"Cannot copy header extra parameter\n");
341 pr_error(
"Storage header initialization failed.\n");
347 (DltStandardHeader *) (header +
sizeof(DltStorageHeader));
352 #if (BYTE_ORDER == BIG_ENDIAN) 360 sizeof(DltStandardHeader) +
361 sizeof(DltExtendedHeader) +
366 if (len > UINT16_MAX)
368 pr_error(
"Message header is too long.\n");
394 pr_error(
"Data for message body is NULL\n");
402 pr_error(
"Cannot allocate memory for Dlt Message\n");
408 pr_error(
"Cannot initialize Dlt Message\n");
421 pr_error(
"Cannot allocate memory for data buffer\n");
465 pr_error(
"%s Invalid parameters (%p, %p)\n", __func__, client, cb);
472 pr_error(
"Failed to register callback (NULL)\n");
484 pr_error(
"set socket path didn't succeed\n");
504 pr_verbose(
"Ready to receive DLT answers.\n");
533 pr_error(
"Received message is null\n");
588 pr_error(
"Invalid input (%p).\n", body);
592 if (clock_gettime(CLOCK_REALTIME, &t) == -1)
594 pr_error(
"Cannot read system time.\n");
605 pr_error(
"Control message preparation failed\n");
616 pr_error(
"Sending message to daemon failed\n");
652 if (!response_analyzer || !ecuid)
654 pr_error(
"Invalid input (%p %p).\n", response_analyzer, ecuid);
664 pr_error(
"Connection initialization failed\n");
675 pr_error(
"Cannot create thread to communicate with DLT daemon.\n");
static int prepare_extra_headers(DltMessage *msg, uint8_t *header)
Prepare the extra headers of a DLT message.
DltStorageHeader * storageheader
#define DLT_MSIN_CONTROL_REQUEST
#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH
#define DLT_HTYP_PROTOCOL_VERSION1
void dlt_set_id(char *id, const char *text)
void dlt_client_register_message_callback(int(*registerd_callback)(DltMessage *message, void *data))
static void * dlt_control_listen_to_daemon(void *data)
Daemon listener function.
int dlt_parse_config_param(char *config_id, char **config_data)
DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose)
void set_verbosity(int v)
#define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp)
static int(* response_analyzer_cb)(char *, void *, int)
Analyze the daemon answer.
#define DLT_RECEIVE_TEXTBUFSIZE
static pthread_cond_t answer_cond
static pthread_mutex_t answer_lock
DltReturnValue dlt_message_init(DltMessage *msg, int verbose)
int dlt_control_deinit(void)
Control communication clean-up.
DltExtendedHeader * extendedheader
DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose)
static char local_ecuid[DLT_CTRL_ECUID_LEN]
static char data[kDataSize]
#define DLT_CTRL_ECUID_LEN
static int callback_return
DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
DltReturnValue dlt_client_init(DltClient *client, int verbose)
int dlt_client_set_socket_path(DltClient *client, char *socket_path)
DltReturnValue dlt_client_cleanup(DltClient *client, int verbose)
static DltMessage * dlt_control_prepare_message(DltControlMsgBody *data)
Prepare a DLT message.
uint32_t dlt_uptime(void)
DltReturnValue dlt_client_connect(DltClient *client, int verbose)
static pthread_t daemon_connect_thread
static int dlt_control_init_connection(DltClient *client, void *cb)
Initialize the connection with the daemon.
uint8_t headerbuffer[sizeof(DltStorageHeader)+sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]
#define pr_error(fmt,...)
#define DLT_IS_HTYP_WEID(htyp)
DltStandardHeaderExtra headerextra
static int prepare_headers(DltMessage *msg, uint8_t *header)
Prepare the headers of a DLT message.
DltReturnValue dlt_message_payload(DltMessage *msg, char *text, int textlength, int type, int verbose)
static long local_timeout
int dlt_control_send_message(DltControlMsgBody *body, int timeout)
Send a message to the daemon and wait for the asynchronous answer.
DltStandardHeader * standardheader
DltReturnValue dlt_message_free(DltMessage *msg, int verbose)
#define pr_verbose(fmt,...)
int dlt_control_init(int(*response_analyzer)(char *, void *, int), char *ecuid, int verbosity)
Control communication initialization.
DltReturnValue dlt_message_header(DltMessage *msg, char *text, int textlength, int verbose)
#define DLT_DAEMON_FLAG_MAX
static int dlt_control_callback(DltMessage *message, void *data)
Internal callback for DLT response.
static int dlt_control_send_message_to_socket(int sock, DltMessage *msg)
Send a message to the daemon through the socket.
void set_ecuid(char *ecuid)