72 #if defined (__WIN32__) || defined (_MSC_VER) 73 #pragma warning(disable : 4996) 76 #include <sys/socket.h> 77 #include <arpa/inet.h> 113 dlt_vlog(LOG_INFO,
"Init dlt client struct with port %d\n", port);
135 char *env_daemon_port;
142 if (env_daemon_port !=
NULL)
144 tmp_port = atoi(env_daemon_port);
145 if ((tmp_port < IPPORT_RESERVED) || (tmp_port > USHRT_MAX))
148 "Specified port is out of possible range: %d.\n",
161 "Init dlt client struct with default port: %hu.\n",
170 char portnumbuffer[33];
171 struct addrinfo hints, *servinfo, *p;
172 struct sockaddr_un addr;
174 memset(&hints, 0,
sizeof(hints));
175 hints.ai_socktype = SOCK_STREAM;
182 switch (client->
mode)
185 snprintf(portnumbuffer, 32,
"%d", client->
port);
186 if ((rv = getaddrinfo(client->
servIP, portnumbuffer, &hints, &servinfo)) != 0) {
187 fprintf(stderr,
"getaddrinfo: %s\n", gai_strerror(rv));
191 for(p = servinfo; p !=
NULL; p = p->ai_next) {
192 if ((client->
sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) {
194 "socket() failed! %s\n",
199 if (connect(client->
sock, p->ai_addr, p->ai_addrlen) < 0) {
201 "connect() failed! %s\n",
211 freeaddrinfo(servinfo);
214 dlt_log(LOG_ERR,
"ERROR: failed to connect.\n");
220 printf(
"Connected to DLT daemon (%s)\n",client->
servIP);
228 fprintf(stderr,
"ERROR: Failed to open device %s\n", client->
serialDevice);
232 if (isatty(client->
sock))
234 #if !defined (__WIN32__) 237 fprintf(stderr,
"ERROR: Failed to configure serial device %s (%s) \n", client->
serialDevice, strerror(errno));
248 fprintf(stderr,
"ERROR: Device is not a serial device, device = %s (%s) \n", client->
serialDevice, strerror(errno));
259 if ((client->
sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
261 fprintf(stderr,
"ERROR: (unix) socket error: %s\n", strerror(errno));
265 memset(&addr, 0,
sizeof(addr));
266 addr.sun_family = AF_UNIX;
267 memcpy(addr.sun_path, client->
socketPath,
sizeof(addr.sun_path)-1);
269 if (connect(client->
sock,
270 (
struct sockaddr_un *)&addr,
273 fprintf(stderr,
"ERROR: (unix) connect error: %s\n", strerror(errno));
277 if (client->
sock < 0)
279 fprintf(stderr,
"ERROR: Failed to open device %s\n",
287 fprintf(stderr,
"ERROR: Mode not supported: %d\n", client->
mode);
294 fprintf(stderr,
"ERROR initializing receiver\n");
305 printf(
"Cleanup dlt client\n");
313 if (client->
sock!=-1)
370 (*message_callback_function)(&msg,
data);
416 if ((client==0) || (client->
sock<0) || (apid==0) || (ctid==0))
460 #if (BYTE_ORDER==BIG_ENDIAN) 480 sizeof(DltStorageHeader) +
481 sizeof(DltStandardHeader) +
493 sizeof(DltStandardHeader) +
494 sizeof(DltExtendedHeader) +
500 fprintf(stderr,
"Critical: Huge injection message discarded!\n");
544 payload = (uint8_t *) malloc(
sizeof(uint32_t) +
sizeof(uint32_t) + size);
552 memcpy(payload , &serviceID,
sizeof(serviceID));
553 offset+=
sizeof(uint32_t);
554 memcpy(payload+offset, &size,
sizeof(size));
555 offset+=
sizeof(uint32_t);
556 memcpy(payload+offset, buffer, size);
573 DltServiceSetLogLevel *req;
576 payload = (uint8_t *) malloc(
sizeof(DltServiceSetLogLevel));
583 req = (DltServiceSetLogLevel *) payload;
588 req->log_level=logLevel;
605 DltServiceGetLogInfoRequest *req;
607 int ret_main_loop = 0;
614 payload = (uint8_t *) malloc(
sizeof(DltServiceGetLogInfoRequest));
621 req = (DltServiceGetLogInfoRequest *) payload;
638 if (ret_main_loop == 1)
640 printf(
"DLT-daemon's response is invalid.\n");
648 DltServiceSetLogLevel *req;
651 payload = (uint8_t *) malloc(
sizeof(DltServiceSetLogLevel));
658 req = (DltServiceSetLogLevel *) payload;
663 req->log_level=traceStatus;
680 DltServiceSetDefaultLogLevel *req;
683 payload = (uint8_t *) malloc(
sizeof(DltServiceSetDefaultLogLevel));
690 req = (DltServiceSetDefaultLogLevel *) payload;
693 req->log_level=defaultLogLevel;
710 DltServiceSetDefaultLogLevel *req;
713 payload = (uint8_t *) malloc(
sizeof(DltServiceSetDefaultLogLevel));
720 req = (DltServiceSetDefaultLogLevel *) payload;
723 req->log_level = LogLevel;
740 DltServiceSetDefaultLogLevel *req;
743 payload = (uint8_t *) malloc(
sizeof(DltServiceSetDefaultLogLevel));
750 req = (DltServiceSetDefaultLogLevel *) payload;
753 req->log_level=defaultTraceStatus;
770 DltServiceSetVerboseMode *req;
773 payload = (uint8_t *) malloc(
sizeof(DltServiceSetVerboseMode));
780 req = (DltServiceSetVerboseMode *) payload;
783 req->new_status=timingPakets;
841 client->
servIP = strdup(ipaddr);
844 dlt_log(LOG_ERR,
"ERROR: failed to duplicate server IP\n");
855 dlt_log(LOG_ERR,
"ERROR: failed to duplicate serial device\n");
866 dlt_log(LOG_ERR,
"ERROR: failed to duplicate socket path\n");
int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int resync, int verbose)
DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPakets)
int dlt_receiver_receive_socket(DltReceiver *receiver)
int8_t found_serialheader
DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel)
#define DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL
DltStorageHeader * storageheader
#define DLT_CLIENT_TEXTBUFSIZE
#define DLT_MSIN_CONTROL_REQUEST
#define DLT_HTYP_PROTOCOL_VERSION1
void dlt_set_id(char *id, const char *text)
DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *ctid, uint8_t *payload, uint32_t size)
void dlt_client_register_message_callback(int(*registerd_callback)(DltMessage *message, void *data))
DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose)
int dlt_client_set_server_ip(DltClient *client, char *ipaddr)
#define DLT_SERVICE_ID_SET_TRACE_STATUS
#define DLT_CLIENT_ENV_DAEMON_TCP_PORT
DltReturnValue dlt_client_init_port(DltClient *client, int port, int verbose)
#define DLT_MESSAGE_ERROR_OK
#define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp)
DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size)
#define DLT_SERVICE_ID_SET_LOG_LEVEL
#define DLT_SERVICE_ID_GET_LOG_INFO
DltReturnValue dlt_log(int prio, char *s)
int dlt_client_get_log_info(DltClient *client)
int dlt_receiver_receive_fd(DltReceiver *receiver)
DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate)
#define DLT_SERVICE_ID_STORE_CONFIG
DltReturnValue dlt_message_init(DltMessage *msg, int verbose)
#define DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS
DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver)
DltExtendedHeader * extendedheader
int dlt_client_set_serial_device(DltClient *client, char *serial_device)
static char * service_id[]
DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose)
static char data[kDataSize]
DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize)
DltReturnValue dlt_client_send_reset_to_factory_default(DltClient *client)
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)
unsigned char buffer[BUFFER_SIZE]
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE.
#define DLT_CLIENT_DUMMY_CON_ID
uint32_t dlt_uptime(void)
DltReturnValue dlt_client_connect(DltClient *client, int verbose)
#define DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT
const char dltSerialHeader[DLT_ID_SIZE]
#define DLT_CLIENT_RCVBUFSIZE
#define DLT_CLIENT_INITIAL_BAUDRATE
uint8_t headerbuffer[sizeof(DltStorageHeader)+sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]
DltStandardHeaderExtra headerextra
static char str[DLT_CLIENT_TEXTBUFSIZE]
DltReturnValue dlt_client_send_inject_msg(DltClient *client, char *apid, char *ctid, uint32_t serviceID, uint8_t *buffer, uint32_t size)
DltReturnValue dlt_setup_serial(int fd, speed_t speed)
DltStandardHeader * standardheader
DltReturnValue dlt_message_free(DltMessage *msg, int verbose)
speed_t dlt_convert_serial_speed(int baudrate)
#define DLT_SERVICE_ID_SET_ALL_LOG_LEVEL
DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ctid, uint8_t logLevel)
#define DLT_CLIENT_DUMMY_APP_ID
DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defaultLogLevel)
DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char *ctid, uint8_t traceStatus)
#define DLT_DAEMON_TCP_PORT
#define DLT_SERVICE_ID_SET_TIMING_PACKETS
DltReturnValue dlt_vlog(int prio, const char *format,...)
static int(* message_callback_function)(DltMessage *message, void *data)
DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t defaultTraceStatus)
DltReturnValue dlt_client_send_store_config(DltClient *client)
DltReturnValue dlt_receiver_free(DltReceiver *receiver)