47 #if defined (__WIN32__) || defined (_MSC_VER) 50 #include <sys/socket.h> 55 #if defined (_MSC_VER) 62 #if defined (__MSDOS__) || defined (_MSC_VER) 63 #pragma warning(disable : 4996) 80 char *
message_type[] = {
"log",
"app_trace",
"nw_trace",
"control",
"",
"",
"",
""};
81 char *
log_info[] = {
"",
"fatal",
"error",
"warn",
"info",
"debug",
"verbose",
"",
"",
"",
"",
"",
"",
"",
"",
""};
82 char *
trace_type[] = {
"",
"variable",
"func_in",
"func_out",
"state",
"vfb",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""};
83 char *
nw_trace_type[] = {
"",
"ipc",
"can",
"flexray",
"most",
"vfb",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""};
84 char *
control_type[] = {
"",
"request",
"response",
"time",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""};
85 static char *
service_id[] = {
"",
"set_log_level",
"set_trace_status",
"get_log_info",
"get_default_log_level",
"store_config",
"reset_to_factory_default",
86 "set_com_interface_status",
"set_com_interface_max_bandwidth",
"set_verbose_mode",
"set_message_filtering",
"set_timing_packets",
87 "get_local_time",
"use_ecu_id",
"use_session_id",
"use_timestamp",
"use_extended_header",
"set_default_log_level",
"set_default_trace_status",
88 "get_software_version",
"message_buffer_overflow" 90 static char *
return_type[] = {
"ok",
"not_supported",
"error",
"",
"",
"",
"",
"",
"no_matching_context_id"};
109 for (num=0;num<size;num++)
116 printf(
"%.2x",((uint8_t*)ptr)[num]);
124 if ((ptr ==
NULL) || (text ==
NULL) || (textlength <= 0) || (size < 0))
130 if (textlength<(size*3))
133 snprintf(str, 254,
"String does not fit hex data (available=%d, required=%d) !\n", textlength, size*3);
138 for (num=0; num<size; num++)
142 snprintf(text,2,
" ");
146 snprintf(text,3,
"%.2x",((uint8_t*)ptr)[num]);
155 int required_size = 0;
158 if ((ptr ==
NULL) || (text ==
NULL) || (textlength <= 0) || (size < 0))
179 if (textlength<required_size)
181 snprintf(
str,
DLT_COMMON_BUFFER_LENGTH,
"String does not fit mixed data (available=%d, required=%d) !\n", textlength, required_size);
193 dlt_log(LOG_WARNING,
"line was truncated\n");
199 dlt_print_hex_string(text,textlength,(uint8_t*)(ptr+(lines*DLT_COMMON_HEX_CHARS)),DLT_COMMON_HEX_CHARS);
202 snprintf(text,2,
" ");
208 dlt_print_char_string(&text,textlength,(uint8_t*)(ptr+(lines*DLT_COMMON_HEX_CHARS)),DLT_COMMON_HEX_CHARS);
212 snprintf(text,2,
"\n");
217 snprintf(text,5,
"<BR>");
230 if ((ret < 0) || (ret >= 9))
232 dlt_log(LOG_WARNING,
"line number was truncated");
239 dlt_print_hex_string(text,textlength,(uint8_t*)(ptr+ ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)),rest);
240 text+=2*rest+(rest-1);
242 for (i=0;i<(DLT_COMMON_HEX_CHARS-rest);i++)
244 snprintf(text,4,
" xx");
248 snprintf(text,2,
" ");
254 dlt_print_char_string(&text,textlength,(uint8_t*)(ptr+ ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)),rest);
264 if ((text ==
NULL) || (ptr ==
NULL) || (*text ==
NULL) || (textlength <= 0) || (size < 0))
269 if (textlength < size)
272 snprintf(str, 254,
"String does not fit character data (available=%d, required=%d) !\n", textlength, size);
277 for (num=0; num<size; num++)
281 snprintf(*text,2,
".");
288 snprintf(*text,2,
"%c",((
char *)ptr)[num]);
292 snprintf(*text,2,
".");
320 for (i=0; i<len; i++)
381 for (num=0;num<length;num++)
383 if (text[num]==
'\r' || text[num]==
'\n')
418 if (filter ==
NULL || filename ==
NULL)
429 handle = fopen(filename,
"r");
440 while (!feof(handle))
443 if (fscanf(handle,
"%s",str1)!=1)
452 if (strcmp(str1,
"----")==0)
462 if (fscanf(handle,
"%s",str1)!=1)
470 printf(
" %s\r\n",str1);
471 if (strcmp(str1,
"----")==0)
498 if (filter ==
NULL || filename ==
NULL)
509 handle = fopen(filename,
"w");
517 for (num=0;num<filter->
counter;num++)
519 if (filter->
apid[num][0]==0)
521 fprintf(handle,
"---- ");
526 fprintf(handle,
"%s ",buf);
528 if (filter->
ctid[num][0]==0)
530 fprintf(handle,
"---- ");
535 fprintf(handle,
"%s ",buf);
550 if ((filter ==
NULL) || (apid ==
NULL))
555 for (num=0; num<filter->
counter; num++)
587 if ((filter ==
NULL) || (apid ==
NULL))
594 sprintf(
str,
"Maximum number (%d) of allowed filters reached, ignoring filter!\n",
DLT_FILTER_MAX);
624 if ((filter ==
NULL) || (apid ==
NULL) || (ctid ==
NULL))
632 for (j=0; j<filter->
counter; j++)
652 for (k=j; k<(filter->
counter-1); k++)
717 struct tm * timeinfo;
722 if ((msg ==
NULL) || (text ==
NULL) || (textlength <= 0))
738 timeinfo = localtime (&tt);
740 if (timeinfo !=
NULL)
742 strftime (buffer,
sizeof(buffer),
"%Y/%m/%d %H:%M:%S",timeinfo);
743 snprintf(text,textlength,
"%s.%.6d ",buffer,msg->
storageheader->microseconds);
752 snprintf(text+strlen(text),textlength-strlen(text),
"%10u ",msg->
headerextra.tmsp);
756 snprintf(text+strlen(text),textlength-strlen(text),
"---------- ");
763 snprintf(text+strlen(text),textlength-strlen(text),
"%.3d ",msg->
standardheader->mcnt);
782 snprintf(text+strlen(text),textlength-strlen(text),
" ");
789 snprintf(text+strlen(text),textlength-strlen(text),
"----");
792 snprintf(text+strlen(text),textlength-strlen(text),
" ");
803 snprintf(text+strlen(text),textlength-strlen(text),
"----");
806 snprintf(text+strlen(text),textlength-strlen(text),
" ");
815 snprintf(text+strlen(text),textlength-strlen(text),
" ");
840 snprintf(text+strlen(text),textlength-strlen(text),
" ");
848 snprintf(text+strlen(text),textlength-strlen(text),
"V");
852 snprintf(text+strlen(text),textlength-strlen(text),
"N");
855 snprintf(text+strlen(text),textlength-strlen(text),
" ");
861 snprintf(text+strlen(text),textlength-strlen(text),
"%d", msg->
extendedheader->noar);
869 snprintf(text+strlen(text),textlength-strlen(text),
"--- ");
874 snprintf(text+strlen(text),textlength-strlen(text),
"--- ");
879 snprintf(text+strlen(text),textlength-strlen(text),
"N ");
884 snprintf(text+strlen(text),textlength-strlen(text),
"-");
893 uint32_t
id=0, id_tmp=0;
901 int32_t *pdatalength;
906 uint32_t type_info=0,type_info_tmp=0;
910 if ((msg ==
NULL) || (text ==
NULL))
917 dlt_log(LOG_WARNING,
"String does not fit binary data!\n");
946 pdatalength = &datalength;
957 if (textlength<((datalength*3)+20))
960 snprintf(str, 254,
"String does not fit binary data (available=%d, required=%d) !\n", textlength, (datalength*3)+20);
970 snprintf(text+strlen(text),textlength-strlen(text),
"%s",
service_id[
id]);
976 snprintf(text+strlen(text),textlength-strlen(text),
"service(%u)",
id);
982 snprintf(text+strlen(text),textlength-strlen(text),
", ");
987 snprintf(text+strlen(text),textlength-strlen(text),
"%u, ",
id);
996 if ( (retval<3) || (retval==8))
998 snprintf(text+strlen(text),textlength-strlen(text),
"%s",
return_type[retval]);
1002 snprintf(text+strlen(text),textlength-strlen(text),
"%.2x",retval);
1007 snprintf(text+strlen(text),textlength-strlen(text),
", ");
1017 ((textlength-strlen(text))>4))
1019 snprintf(text+strlen(text),textlength-strlen(text),
" ...");
1040 snprintf(text+strlen(text),textlength-strlen(text),
" ");
1065 if ((msg ==
NULL) || (filter ==
NULL))
1076 for (num=0 ;num<filter->
counter; num++)
1097 if ((msg ==
NULL) || (buffer ==
NULL) || (length <= 0))
1154 if (length<
sizeof(DltStandardHeader))
1159 memcpy(msg->
headerbuffer+
sizeof(DltStorageHeader), buffer,
sizeof(DltStandardHeader));
1167 msg->
headersize =
sizeof(DltStorageHeader) +
sizeof(DltStandardHeader) + extra_size;
1187 if (length < (msg->
headersize -
sizeof(DltStorageHeader)))
1192 memcpy(msg->
headerbuffer+
sizeof(DltStorageHeader)+
sizeof(DltStandardHeader),buffer+
sizeof(DltStandardHeader),extra_size);
1290 memcpy(msg->
headerbuffer +
sizeof(DltStorageHeader) +
sizeof(DltStandardHeader)
1297 memcpy(msg->
headerbuffer +
sizeof(DltStorageHeader) +
sizeof(DltStandardHeader)
1356 if (fread(file->
msg.
headerbuffer,
sizeof(DltStorageHeader)+
sizeof(DltStandardHeader), 1, file->
handle)!=1)
1360 dlt_log(LOG_WARNING,
"Cannot read header from file!\n");
1372 dlt_log(LOG_WARNING,
"DLT storage header pattern not found!\n");
1377 file->
msg.
headersize =
sizeof(DltStorageHeader) +
sizeof(DltStandardHeader) +
1409 if (fread(dltSerialHeaderBuffer,
sizeof(dltSerialHeaderBuffer),1,file->
handle)!=1)
1414 dlt_log(LOG_WARNING,
"Cannot read header from file!\n");
1435 memmove(dltSerialHeaderBuffer,dltSerialHeaderBuffer+1,
sizeof(
dltSerialHeader)-1);
1436 if (fread(dltSerialHeaderBuffer+3,1,1,file->
handle)!=1)
1457 if (fread(file->
msg.
headerbuffer+
sizeof(DltStorageHeader),
sizeof(DltStandardHeader),1,file->
handle)!=1)
1461 dlt_log(LOG_WARNING,
"Cannot read header from file!\n");
1479 file->
msg.
headersize =
sizeof(DltStorageHeader) +
sizeof(DltStandardHeader) +
1511 if (fread(file->
msg.
headerbuffer+
sizeof(DltStorageHeader)+
sizeof(DltStandardHeader),
1515 dlt_log(LOG_WARNING,
"Cannot read standard header extra parameters from file!\n");
1533 dlt_log(LOG_WARNING,
"Cannot read extended header from file!\n");
1598 if(file ==
NULL || filename ==
NULL)
1615 file->
handle = fopen(filename,
"rb");
1623 if (0 != fseek(file->
handle, 0, SEEK_END))
1631 if (0 != fseek(file->
handle,0,SEEK_SET))
1754 file->
msg.
headersize - (int32_t)
sizeof(DltStorageHeader) - (int32_t)
sizeof(DltStandardHeader) + file->
msg.
datasize);
1913 if (fseek(file->
handle,file->
index[index],SEEK_SET)!=0)
1970 if(level < 0 || level > LOG_DEBUG)
1975 dlt_vlog(LOG_WARNING,
"Wrong parameter for level: %d\n", level);
1984 if(filename ==
NULL)
1986 dlt_log(LOG_WARNING,
"Wrong parameter: filename is NULL\n");
2004 dlt_vlog(LOG_WARNING,
"Wrong parameter for mode: %d\n", mode);
2031 static const char asSeverity[LOG_DEBUG+2][11] = {
"EMERGENCY",
"ALERT ",
"CRITICAL ",
"ERROR ",
"WARNING ",
"NOTICE ",
"INFO ",
"DEBUG ",
" "};
2032 static const char sFormatString[] =
"[%5d.%06d]~DLT~%5d~%s~%s";
2033 struct timespec sTimeSpec;
2043 if ((prio < 0) || (prio > LOG_DEBUG))
2045 prio = LOG_DEBUG + 1;
2048 clock_gettime(CLOCK_MONOTONIC, &sTimeSpec);
2053 printf(sFormatString, (
unsigned int)sTimeSpec.tv_sec, (
unsigned int)(sTimeSpec.tv_nsec/1000), getpid(), asSeverity[prio], s);
2057 #if !defined (__WIN32__) && !defined(_MSC_VER) 2058 openlog(
"DLT",LOG_PID,LOG_DAEMON);
2059 syslog(prio, sFormatString, (
unsigned int)sTimeSpec.tv_sec, (
unsigned int)(sTimeSpec.tv_nsec/1000), getpid(), asSeverity[prio], s);
2066 fprintf(
logging_handle,sFormatString, (
unsigned int)sTimeSpec.tv_sec, (
unsigned int)(sTimeSpec.tv_nsec/1000), getpid(), asSeverity[prio], s);
2080 char outputString[2048] = { 0 };
2090 va_start(args, format);
2091 vsnprintf(outputString, 2047, format, args);
2101 char *outputString =
NULL;
2111 if ( (outputString = (
char*) calloc(size + 1,
sizeof(
char))) ==
NULL )
2114 va_start(args, format);
2115 vsnprintf(outputString, size, format, args);
2121 outputString =
NULL;
2128 if (receiver ==
NULL)
2156 if (receiver ==
NULL)
2175 if (receiver ==
NULL)
2185 receiver->
buf = (
char *)receiver->
buffer;
2205 if (receiver ==
NULL)
2215 receiver->
buf = (
char *)receiver->
buffer;
2234 if (receiver ==
NULL)
2244 if (size > receiver->
bytesRcvd || size <= 0)
2252 receiver->
buf = receiver->
buf + size;
2259 if (receiver ==
NULL)
2279 unsigned int to_get,
2282 unsigned int min_size = to_get;
2286 min_size +=
sizeof(DltUserHeader);
2290 (receiver->
bytesRcvd < (int32_t)min_size) ||
2296 src = (
void *)receiver->
buf;
2298 if (flags & DLT_RCV_SKIP_HEADER) {
2299 src +=
sizeof(DltUserHeader);
2302 memcpy(dest, src, to_get);
2307 dlt_log(LOG_WARNING,
"Can't remove bytes from receiver\n");
2318 #if !defined(_MSC_VER) 2322 if (storageheader ==
NULL || ecu ==
NULL)
2328 #if defined(_MSC_VER) 2329 time(&(storageheader->seconds));
2331 gettimeofday(&tv,
NULL);
2335 storageheader->pattern[0] =
'D';
2336 storageheader->pattern[1] =
'L';
2337 storageheader->pattern[2] =
'T';
2338 storageheader->pattern[3] = 0x01;
2343 #if defined(_MSC_VER) 2344 storageheader->microseconds = 0;
2346 storageheader->seconds = (time_t)tv.tv_sec;
2347 storageheader->microseconds = (int32_t)tv.tv_usec;
2355 if (storageheader ==
NULL)
2358 return ((storageheader->pattern[0] ==
'D') &&
2359 (storageheader->pattern[1] ==
'L') &&
2360 (storageheader->pattern[2] ==
'T') &&
2361 (storageheader->pattern[3] == 1))
2385 buf->
shm = (
unsigned char *)ptr;
2399 memset(buf->
mem, 0, buf->
size);
2401 snprintf(str,
sizeof(str),
"Buffer: Size %d\n",buf->
size);
2415 buf->
shm = (
unsigned char *)ptr;
2424 snprintf(str,
sizeof(str),
"Buffer: Size %d\n",buf->
size);
2440 if(min_size == 0 || max_size == 0 || step_size == 0)
2443 if(min_size > max_size)
2446 if(step_size > max_size)
2457 snprintf(str,
sizeof(str),
"Buffer: Cannot allocate %d bytes\n",buf->
min_size);
2487 dlt_log(LOG_WARNING,
"Buffer: Buffer not initialized\n");
2502 dlt_log(LOG_WARNING,
"Buffer: Buffer not initialized\n");
2517 if((
int)(*write+size) <= buf->
size) {
2519 memcpy(buf->
mem+*write,data,size);
2524 memcpy(buf->
mem+*write, data, buf->
size-*write);
2525 memcpy(buf->
mem, data+buf->
size-*write, size-buf->
size+*write);
2526 *write += size-buf->
size;
2531 dlt_log(LOG_WARNING,
"Wrong parameter: Null pointer\n");
2539 if((
int)(*read+size) <= buf->
size) {
2541 memcpy(data,buf->
mem+*read,size);
2546 memcpy(data, buf->
mem+*read, buf->
size-*read);
2547 memcpy(data+buf->
size-*read, buf->
mem, size-buf->
size+*read);
2548 *read += size-buf->
size;
2553 dlt_log(LOG_WARNING,
"Wrong parameter: Null pointer\n");
2565 unsigned char *new_ptr;
2581 if(new_ptr ==
NULL) {
2582 snprintf(
str,
sizeof(
str),
"Buffer: Cannot increase size because allocate %d bytes failed\n",buf->
min_size);
2620 unsigned char *new_ptr;
2625 dlt_log(LOG_WARNING,
"Wrong parameter: Null pointer\n");
2637 if(new_ptr ==
NULL) {
2638 snprintf(
str,
sizeof(
str),
"Buffer: Cannot set to min size of %d bytes\n",buf->
min_size);
2652 ((
int*)(buf->
shm))[0] = 0;
2653 ((
int*)(buf->
shm))[1] = 0;
2654 ((
int*)(buf->
shm))[2] = 0;
2657 memset(buf->
mem, 0, buf->
size);
2659 dlt_log(LOG_DEBUG,
"Buffer: Buffer minimized.\n");
2669 dlt_log(LOG_WARNING,
"Wrong parameter: Null pointer\n");
2673 dlt_log(LOG_WARNING,
"Buffer: Buffer reset triggered.\n");
2676 ((
int*)(buf->
shm))[0] = 0;
2677 ((
int*)(buf->
shm))[1] = 0;
2678 ((
int*)(buf->
shm))[2] = 0;
2691 int dlt_buffer_push3(
DltBuffer *buf,
const unsigned char *data1,
unsigned int size1,
const unsigned char *data2,
unsigned int size2,
const unsigned char *data3,
unsigned int size3)
2694 int write, read, count;
2704 dlt_log(LOG_ERR,
"Buffer: Buffer not initialised\n");
2709 write = ((
int*) (buf->
shm))[0];
2710 read = ((
int*) (buf->
shm))[1];
2711 count = ((
int*) (buf->
shm))[2];
2714 if ((read > buf->
size) || (write > buf->
size))
2716 dlt_log(LOG_ERR,
"Buffer: Pointer out of range\n");
2723 free_size = read - write;
2724 else if (count && (write == read))
2727 free_size = buf->
size - write + read;
2741 write = ((
int*) (buf->
shm))[0];
2742 read = ((
int*) (buf->
shm))[1];
2749 head.
size = size1 + size2 + size3;
2761 ((
int*) (buf->
shm))[0] = write;
2762 ((
int*) (buf->
shm))[2] += 1;
2771 int write, read, count;
2781 dlt_log(LOG_ERR,
"Buffer: SHM not initialised\n");
2786 write = ((
int*)(buf->
shm))[0];
2787 read = ((
int*)(buf->
shm))[1];
2788 count = ((
int*)(buf->
shm))[2];
2791 if((read>buf->
size) || (write>buf->
size) || (count<0))
2793 dlt_log(LOG_ERR,
"Buffer: Pointer out of range\n");
2802 dlt_log(LOG_ERR,
"Buffer: SHM should be empty, but is not\n");
2810 used_size = write - read;
2812 used_size = buf->
size - read + write;
2816 dlt_log(LOG_ERR,
"Buffer: Size check 1 failed\n");
2825 if(memcmp((
unsigned char*)(head.
head),head_compare,
sizeof(head_compare))!=0)
2827 dlt_log(LOG_ERR,
"Buffer: Header head check failed\n");
2833 dlt_log(LOG_ERR,
"Buffer: Header status check failed\n");
2840 dlt_log(LOG_ERR,
"Buffer: Size check 2 failed\n");
2846 if(max_size && (head.
size > max_size)) {
2847 dlt_log(LOG_ERR,
"Buffer: Size check 3 failed\n");
2851 if(data !=
NULL && max_size)
2859 ((
int*)(buf->
shm))[1] = read;
2866 ((
int*)(buf->
shm))[1] = read+head.
size;
2872 ((
int*)(buf->
shm))[2] -= 1;
2874 if(((
int*)(buf->
shm))[2] == 0)
2907 snprintf(str,
sizeof(str),
"Buffer: Available size: %d\n",buf->
size);
2909 snprintf(str,
sizeof(str),
"Buffer: Buffer full start address: %lX\n",(
unsigned long)buf->
shm);
2911 snprintf(str,
sizeof(str),
"Buffer: Buffer start address: %lX\n",(
unsigned long)buf->
mem);
2918 int write, read, count;
2923 dlt_log(LOG_WARNING,
"Wrong parameter: Null pointer\n");
2931 write = ((
int*)(buf->
shm))[0];
2932 read = ((
int*)(buf->
shm))[1];
2933 count = ((
int*)(buf->
shm))[2];
2935 snprintf(str,
sizeof(str),
"Buffer: Write: %d\n",write);
2937 snprintf(str,
sizeof(str),
"Buffer: Read: %d\n",read);
2939 snprintf(str,
sizeof(str),
"Buffer: Count: %d\n",count);
2954 int write, read, count;
2964 write = ((
int*)(buf->
shm))[0];
2965 read = ((
int*)(buf->
shm))[1];
2966 count = ((
int*)(buf->
shm))[2];
2972 return (write - read);
2974 return (buf->
size - read + write);
2987 return ((
int*)(buf->
shm))[2];
2990 #if !defined (__WIN32__) 2994 #if !defined (__WIN32__) && !defined(_MSC_VER) 2995 struct termios config;
3002 if (tcgetattr(fd, &config) < 0)
3013 config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL |
3014 INLCR | PARMRK | INPCK | ISTRIP | IXON);
3031 config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
3037 config.c_cflag &= ~(CSIZE | PARENB);
3038 config.c_cflag |= CS8;
3043 config.c_cc[VMIN] = 1;
3044 config.c_cc[VTIME] = 0;
3049 if (cfsetispeed(&config, speed) < 0 || cfsetospeed(&config, speed) < 0)
3056 if (tcsetattr(fd, TCSAFLUSH, &config) < 0)
3069 #if !defined (__WIN32__) && !defined(_MSC_VER) && !defined(__CYGWIN__) 3241 if(buf ==
NULL && size > 0)
3243 dlt_log(LOG_WARNING,
"Wrong parameter: Null pointer\n");
3247 snprintf(buf,size,
"DLT Package Version: %s %s, Package Revision: %s, build on %s %s\n%s %s %s %s\n",
3253 if (buf ==
NULL && size > 0)
3255 dlt_log(LOG_WARNING,
"Wrong parameter: Null pointer\n");
3264 if (buf ==
NULL && size > 0)
3266 dlt_log(LOG_WARNING,
"Wrong parameter: Null pointer\n");
3277 #if defined (__WIN32__) || defined(_MSC_VER) 3279 return (uint32_t)(GetTickCount()*10);
3284 if (clock_gettime(CLOCK_MONOTONIC,&ts)==0)
3286 return ( (uint32_t)ts.tv_sec*10000 + (uint32_t)ts.tv_nsec/100000 );
3299 if ((message ==
NULL) || (text ==
NULL))
3305 printf(
"%s\n",text);
3312 if ((message ==
NULL) || (text ==
NULL))
3320 printf(
"[%s]\n",text);
3327 if ((message ==
NULL) || (text ==
NULL))
3335 printf(
"[%s]\n",text);
3342 if ((message ==
NULL) || (text ==
NULL))
3348 printf(
"%s \n",text);
3350 printf(
"[%s]\n",text);
3357 if ((message ==
NULL) || (text ==
NULL))
3363 printf(
"%s \n",text);
3365 printf(
"[%s]\n",text);
3376 int16_t length=0,length_tmp=0;
3377 uint16_t length2=0,length2_tmp=0,length3=0,length3_tmp=0;
3380 uint16_t value16u=0,value16u_tmp=0;
3381 uint32_t value32u=0,value32u_tmp=0;
3382 uint64_t value64u=0,value64u_tmp=0;
3385 int16_t value16i=0,value16i_tmp=0;
3386 int32_t value32i=0,value32i_tmp=0;
3387 int64_t value64i=0,value64i_tmp=0;
3390 int32_t value32f_tmp_int32i=0,value32f_tmp_int32i_swaped=0;
3392 int64_t value64f_tmp_int64i=0,value64f_tmp_int64i_swaped=0;
3394 uint32_t quantisation_tmp = 0;
3399 quantisation_tmp += quantisation_tmp;
3413 length=(int16_t)byteLength;
3422 if((*datalength)<length2)
3425 *datalength-=length2;
3442 if((*datalength)<length2)
3445 *datalength-=length2;
3451 snprintf(text+strlen(text),textlength-strlen(text),
"%d",value8u);
3460 char binary[10] = {
'\0'};
3462 for (i = (1 << 7); i > 0; i >>= 1)
3465 strcat(binary,
" ");
3466 strcat(binary, (i == (value8u & i)) ?
"1" :
"0");
3469 snprintf(text+strlen(text),textlength-strlen(text),
"0b%s",binary);
3476 char binary[20] = {
'\0'};
3478 for (i = (1 << 15); i > 0; i >>= 1)
3480 if (((1<<3) == i) || ((1<<7) == i) || ((1<<11) == i))
3481 strcat(binary,
" ");
3482 strcat(binary, (i == (value16u & i)) ?
"1" :
"0");
3485 snprintf(text+strlen(text),textlength-strlen(text),
"0b%s",binary);
3488 else if ((type_info & DLT_TYPE_INFO_UINT) && (
DLT_SCOD_HEX == (type_info & DLT_TYPE_INFO_SCOD)))
3495 snprintf(text+strlen(text),textlength-strlen(text),
"0x%02x",value8u);
3502 snprintf(text+strlen(text),textlength-strlen(text),
"0x%04x",value16u);
3509 snprintf(text+strlen(text),textlength-strlen(text),
"0x%08x",value32u);
3517 snprintf(text+strlen(text),textlength-strlen(text),
"0x%08x",value32u);
3522 snprintf(text+strlen(text),textlength-strlen(text),
"%08x",value32u);
3539 if((*datalength)<length2)
3542 *datalength-=length2;
3543 if((*datalength)<length3)
3546 *datalength-=length3;
3577 if((*datalength)<16)
3593 if (type_info & DLT_TYPE_INFO_SINT)
3599 snprintf(text+strlen(text),textlength-strlen(text),
"%d",value8i);
3607 snprintf(text+strlen(text),textlength-strlen(text),
"%d",value8u);
3613 if (type_info & DLT_TYPE_INFO_SINT)
3621 snprintf(text+strlen(text),textlength-strlen(text),
"%hd",value16i);
3631 snprintf(text+strlen(text),textlength-strlen(text),
"%hu",value16u);
3637 if (type_info & DLT_TYPE_INFO_SINT)
3645 snprintf(text+strlen(text),textlength-strlen(text),
"%d",value32i);
3655 snprintf(text+strlen(text),textlength-strlen(text),
"%u",value32u);
3661 if (type_info & DLT_TYPE_INFO_SINT)
3669 #if defined (__WIN32__) && !defined(_MSC_VER) 3670 snprintf(text+strlen(text),textlength-strlen(text),
"%I64d",value64i);
3672 snprintf(text+strlen(text),textlength-strlen(text),
"%"PRId64, value64i);
3683 #if defined (__WIN32__) && !defined(_MSC_VER) 3684 snprintf(text+strlen(text),textlength-strlen(text),
"%I64u",value64u);
3686 snprintf(text+strlen(text),textlength-strlen(text),
"%"PRId64,value64u);
3693 if (*datalength>=16)
3695 if((*datalength)<16)
3720 if((*datalength)<length2)
3723 *datalength-=length2;
3724 if((*datalength)<length3)
3727 *datalength-=length3;
3757 value32f_tmp_int32i=0;
3758 value32f_tmp_int32i_swaped=0;
3762 memcpy(&value32f_tmp_int32i,&value32f_tmp,
sizeof(
float32_t));
3764 memcpy(&value32f,&value32f_tmp_int32i_swaped,
sizeof(
float32_t));
3765 snprintf(text+strlen(text),textlength-strlen(text),
"%g",value32f);
3769 dlt_log(LOG_ERR,
"Invalid size of float32_t\n");
3780 value64f_tmp_int64i=0;
3781 value64f_tmp_int64i_swaped=0;
3785 memcpy(&value64f_tmp_int64i,&value64f_tmp,
sizeof(
float64_t));
3787 memcpy(&value64f,&value64f_tmp_int64i_swaped,
sizeof(
float64_t));
3789 snprintf(text+strlen(text),textlength-strlen(text),
"ILLEGAL");
3791 snprintf(text+strlen(text),textlength-strlen(text),
"%g",value64f);
3796 dlt_log(LOG_ERR,
"Invalid size of float64_t\n");
3803 if (*datalength>=16)
3805 if((*datalength)<16)
3831 if((*datalength)<length2)
3834 *datalength-=length2;
3836 if((*datalength)<length)
3840 *datalength-=length;
3860 dlt_log(LOG_ERR,
"Payload of DLT message corrupted\n");
3869 char* env_log_filename = getenv(
"DLT_LOG_FILENAME");
3871 if( env_log_filename !=
NULL )
3876 char* env_log_level_str = getenv(
"DLT_LOG_LEVEL");
3878 if( env_log_level_str !=
NULL )
3881 if( sscanf(env_log_level_str,
"%d", &level) )
3887 char* env_log_mode = getenv(
"DLT_LOG_MODE");
3889 if( env_log_mode !=
NULL )
3892 if( sscanf(env_log_mode,
"%d", &mode) )
3898 char* env_pipe_dir = getenv(
"DLT_PIPE_DIR");
3899 if( env_pipe_dir !=
NULL )
3908 char tmp[PATH_MAX+1];
3913 strncpy(tmp, dir, PATH_MAX);
3915 if(tmp[len - 1] ==
'/')
3921 for(p = tmp + 1; ((*p) && (ret == 0)) || ((ret == -1 && errno == EEXIST) && (p != end)); p++)
3926 ret = mkdir(tmp, S_IRWXU);
3931 if (ret == 0 || (ret == -1 && errno == EEXIST))
3933 ret = mkdir(tmp, S_IRWXU);
3936 if (ret == -1 && errno == EEXIST)
static char str[DLT_COMMON_BUFFER_LENGTH]
#define DLT_HEADER_SHOW_TIME
static char logging_filename[NAME_MAX+1]
DltReturnValue dlt_file_open(DltFile *file, const char *filename, int verbose)
#define DLT_MESSAGE_ERROR_UNKNOWN
int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int resync, int verbose)
#define DLT_RCV_SKIP_HEADER
DltReturnValue dlt_file_read_data(DltFile *file, int verbose)
DltReturnValue dlt_buffer_push(DltBuffer *buf, const unsigned char *data, unsigned int size)
int dlt_receiver_receive_socket(DltReceiver *receiver)
DltReturnValue dlt_file_read_header(DltFile *file, int verbose)
#define PRINT_FUNCTION_VERBOSE(_verbose)
DltReturnValue dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size, uint32_t step_size)
#define DLT_ENDIAN_GET_32(htyp, x)
int8_t found_serialheader
DltReturnValue dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose)
#define DLT_TYPE_INFO_SINT
DltStorageHeader * storageheader
uint32_t dlt_buffer_get_total_size(DltBuffer *buf)
DltReturnValue dlt_filter_save(DltFilter *filter, const char *filename, int verbose)
DltReturnValue dlt_file_message(DltFile *file, int index, int verbose)
#define DLT_COMMON_DUMMY_ECUID
void dlt_get_minor_version(char *buf, size_t size)
#define DLT_COMMON_ASCII_LIMIT_MAX_CHARS
void dlt_set_id(char *id, const char *text)
int dlt_buffer_reset(DltBuffer *buf)
void dlt_buffer_info(DltBuffer *buf)
DltReturnValue dlt_file_set_filter(DltFile *file, DltFilter *filter, int verbose)
#define DLT_COMMON_ASCII_CHAR_LT
DltReturnValue dlt_message_argument_print(DltMessage *msg, uint32_t type_info, uint8_t **ptr, int32_t *datalength, char *text, int textlength, int byteLength, int __attribute__((unused)) verbose)
#define DLT_GET_MSIN_MTIN(msin)
int dlt_receiver_check_and_get(DltReceiver *receiver, void *dest, unsigned int to_get, unsigned int flags)
DltReturnValue dlt_buffer_free_static(DltBuffer *buf)
#define _DLT_PACKAGE_VERSION_STATE
DltReturnValue dlt_file_read_raw(DltFile *file, int resync, int verbose)
DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose)
static char * return_type[]
#define DLT_HEADER_SHOW_VNVSTATUS
#define DLT_ENDIAN_GET_64(htyp, x)
DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char *ctid, int verbose)
#define DLT_HEADER_SHOW_ECUID
#define DLT_MESSAGE_ERROR_OK
#define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp)
DltReturnValue dlt_buffer_free_dynamic(DltBuffer *buf)
DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, int size, int html)
void dlt_clean_string(char *text, int length)
DltReturnValue dlt_file_read_header_extended(DltFile *file, int verbose)
DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size)
DltReturnValue dlt_message_filter_check(DltMessage *msg, DltFilter *filter, int verbose)
#define _DLT_PACKAGE_VERSION
#define _DLT_PACKAGE_MAJOR_VERSION
#define DLT_MSG_READ_VALUE(dst, src, length, type)
DltReturnValue dlt_log(int prio, char *s)
DltReturnValue dlt_file_read(DltFile *file, int verbose)
#define DLT_GET_MSIN_MSTP(msin)
DltReturnValue dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size)
int dlt_receiver_receive_fd(DltReceiver *receiver)
DltReturnValue dlt_print_hex_string(char *text, int textlength, uint8_t *ptr, int size)
#define DLT_TYPE_APP_TRACE
DltReturnValue dlt_filter_init(DltFilter *filter, int verbose)
DltReturnValue dlt_message_init(DltMessage *msg, int verbose)
#define DLT_HEADER_SHOW_TMSTP
DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver)
DltExtendedHeader * extendedheader
#define DLT_OUTPUT_ASCII_LIMITED
DltReturnValue dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose)
#define DLT_IS_MSIN_VERB(msin)
#define DLT_ENDIAN_GET_16(htyp, x)
#define DLT_HEADER_SHOW_CTID
DltReturnValue dlt_print_char_string(char **text, int textlength, uint8_t *ptr, int size)
DltReturnValue dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size)
int dlt_buffer_copy(DltBuffer *buf, unsigned char *data, int max_size)
#define DLT_OUTPUT_MIXED_FOR_HTML
static char * service_id[]
int dlt_buffer_get_used_size(DltBuffer *buf)
void dlt_buffer_write_block(DltBuffer *buf, int *write, const unsigned char *data, unsigned int size)
DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose)
#define DLT_HEADER_SHOW_MSGCNT
static char data[kDataSize]
#define DLT_MESSAGE_ERROR_CONTENT
DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize)
#define _DLT_SYSTEMD_ENABLE
#define DLT_IS_HTYP_UEH(htyp)
#define DLT_MSG_IS_NONVERBOSE(MSG)
DltReturnValue dlt_filter_free(DltFilter *filter, int verbose)
int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, int verbose)
#define DLT_COMMON_HEX_LINELEN
#define DLT_TYPE_NW_TRACE
int dlt_mkdir_recursive(const char *dir)
unsigned char buffer[BUFFER_SIZE]
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE.
uint32_t dlt_uptime(void)
int dlt_buffer_minimize_size(DltBuffer *buf)
#define _DLT_SYSTEMD_WATCHDOG_ENABLE
void dlt_log_set_filename(const char *filename)
DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verbose)
void dlt_buffer_status(DltBuffer *buf)
const char dltSerialHeader[DLT_ID_SIZE]
#define DLT_HEADER_SHOW_MSGSUBTYPE
void dlt_buffer_read_block(DltBuffer *buf, int *read, unsigned char *data, unsigned int size)
#define DLT_TYPE_INFO_FLOA
#define DLT_COMMON_CHARLEN
uint8_t headerbuffer[sizeof(DltStorageHeader)+sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]
#define DLT_HEADER_SHOW_MSGTYPE
#define _DLT_PACKAGE_MINOR_VERSION
#define DLT_IS_HTYP_WEID(htyp)
int dlt_buffer_remove(DltBuffer *buf)
#define DLT_TYPE_INFO_STRG
int dlt_buffer_get_message_count(DltBuffer *buf)
DltStandardHeaderExtra headerextra
char apid[DLT_FILTER_MAX][DLT_ID_SIZE]
DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *ctid, int verbose)
DltReturnValue dlt_file_init(DltFile *file, int verbose)
#define DLT_HEADER_SHOW_NONE
#define DLT_MSG_IS_CONTROL_RESPONSE(MSG)
#define DLT_IS_HTYP_WSID(htyp)
#define DLT_COMMON_ASCII_CHAR_TILDE
DltReturnValue dlt_message_payload(DltMessage *msg, char *text, int textlength, int type, int verbose)
char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]
DltReturnValue dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose)
#define _DLT_PACKAGE_REVISION
void dlt_print_id(char *text, const char *id)
#define DLT_MSG_IS_CONTROL(MSG)
#define DLT_MSG_IS_CONTROL_TIME(MSG)
DltReturnValue dlt_check_storageheader(DltStorageHeader *storageheader)
char dltFifoBaseDir[PATH_MAX+1]
DltReturnValue dlt_file_free(DltFile *file, int verbose)
DltReturnValue dlt_setup_serial(int fd, speed_t speed)
static FILE * logging_handle
DltReturnValue dlt_vnlog(int prio, size_t size, const char *format,...)
DltStandardHeader * standardheader
DltReturnValue dlt_message_free(DltMessage *msg, int verbose)
#define DLT_HEADER_SHOW_NOARG
speed_t dlt_convert_serial_speed(int baudrate)
char dltSerialHeaderChar[DLT_ID_SIZE]
int dlt_buffer_increase_size(DltBuffer *buf)
#define DLT_TYPE_INFO_BOOL
void dlt_print_hex(uint8_t *ptr, int size)
#define DLT_OUTPUT_MIXED_FOR_PLAIN
#define DLT_COMMON_BUFFER_LENGTH
#define DLT_TYPE_INFO_FIXP
#define DLT_HEADER_SHOW_APID
#define DLT_TYPE_INFO_RAWD
int dlt_buffer_push3(DltBuffer *buf, const unsigned char *data1, unsigned int size1, const unsigned char *data2, unsigned int size2, const unsigned char *data3, unsigned int size3)
void dlt_get_version(char *buf, size_t size)
void dlt_log_set_level(int level)
int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete)
DltReturnValue dlt_message_header(DltMessage *msg, char *text, int textlength, int verbose)
#define DLT_TYPE_INFO_VARI
#define DLT_TYPE_INFO_UINT
int dlt_buffer_pull(DltBuffer *buf, unsigned char *data, int max_size)
#define DLT_MESSAGE_ERROR_SIZE
#define DLT_TYPE_INFO_TRAI
DltReturnValue dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose)
#define DLT_TYPE_INFO_TYLE
#define DLT_IS_HTYP_WTMS(htyp)
DltReturnValue dlt_message_get_extraparameters(DltMessage *msg, int verbose)
DltReturnValue dlt_file_close(DltFile *file, int verbose)
#define DLT_SERVICE_ID_LAST_ENTRY
DltReturnValue dlt_vlog(int prio, const char *format,...)
DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, int textlength, int flags, int verbose)
void dlt_get_major_version(char *buf, size_t size)
#define DLT_COMMON_HEX_CHARS
#define DLT_HEADER_SHOW_ALL
#define DLT_COMMON_ASCII_CHAR_SPACE
void dlt_log_set_fifo_basedir(const char *env_pipe_dir)
#define DLT_COMMON_INDEX_ALLOC
DltReturnValue dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose)
void dlt_log_init(int mode)
#define DLT_TYPE_INFO_SCOD
#define DLT_MSG_READ_STRING(dst, src, maxlength, length)
DltReturnValue dlt_receiver_free(DltReceiver *receiver)