80 #include <linux/limits.h> 85 #define DLT_RECEIVE_TEXTBUFSIZE 10024 87 #define DLT_RECEIVE_ECU_ID "RECV" 122 printf(
"Usage: dlt-receive [options] hostname/serial_device_name\n");
123 printf(
"Receive DLT messages from DLT daemon and print or store the messages.\n");
124 printf(
"Use filters to filter received messages.\n");
125 printf(
"%s \n", version);
126 printf(
"Options:\n");
127 printf(
" -a Print DLT messages; payload as ASCII\n");
128 printf(
" -x Print DLT messages; payload as hex\n");
129 printf(
" -m Print DLT messages; payload as hex and ASCII\n");
130 printf(
" -s Print DLT messages; only headers\n");
131 printf(
" -v Verbose mode\n");
132 printf(
" -h Usage\n");
133 printf(
" -y Serial device mode\n");
134 printf(
" -b baudrate Serial device baudrate (Default: 115200)\n");
135 printf(
" -e ecuid Set ECU ID (Default: RECV)\n");
136 printf(
" -o filename Output messages in new DLT file\n");
137 printf(
" -c limit Restrict file size to <limit> bytes when output to file\n");
138 printf(
" When limit is reached, a new file is opened. Use K,M,G as\n");
139 printf(
" suffix to specify kilo-, mega-, giga-bytes respectively\n");
140 printf(
" -f filename Enable filtering of messages\n");
150 for (i = 0; i<strlen(arg)-1; ++i)
152 if (!isdigit(arg[i]))
160 if ((arg[strlen(arg)-1] ==
'K') || (arg[strlen(arg)-1] ==
'k'))
164 else if ((arg[strlen(arg)-1] ==
'M') || (arg[strlen(arg)-1] ==
'm'))
166 factor = 1024 * 1024;
168 else if ((arg[strlen(arg)-1] ==
'G') || (arg[strlen(arg)-1] ==
'g'))
170 factor = 1024 * 1024 * 1024;
174 if (!isdigit(arg[strlen(arg)-1]))
181 int64_t
const mult = atoll(arg);
182 if (((INT64_MAX)/factor) < mult)
188 result = factor * mult;
197 if (min_size > result)
200 snprintf(tmp, 256,
"ERROR: Specified limit: %" PRId64
"is smaller than a the size of a single message: %" PRId64
"!\n", result, min_size);
216 if (glob(dltdata->
ovalue, GLOB_TILDE_CHECK | GLOB_NOSORT,
NULL, &outer) == 0)
221 snprintf(tmp, 256,
"File %s already exists, need to rename first\n", dltdata->
ovalue);
227 char pattern[PATH_MAX+1];
228 pattern[PATH_MAX] = 0;
229 snprintf(pattern, PATH_MAX,
"%s.*.dlt", dltdata->
ovaluebase);
239 if (glob(pattern, GLOB_TILDE_CHECK | GLOB_NOSORT,
NULL, &inner) == 0)
243 for (i= 0; i<inner.gl_pathc; ++i)
248 int cur = atoi(&inner.gl_pathv[i][strlen(dltdata->
ovaluebase)+1]);
261 char filename[PATH_MAX+1];
262 filename[PATH_MAX] = 0;
265 if (rename(dltdata->
ovalue, filename) != 0)
268 snprintf(tmp, 256,
"ERROR: rename %s to %s failed with error %s\n", dltdata->
ovalue, filename, strerror(errno));
276 snprintf(tmp, 256,
"Renaming existing file from %s to %s\n", dltdata->
ovalue, filename);
284 dltdata->
ohandle = open(dltdata->
ovalue, O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
302 int main(
int argc,
char* argv[])
329 while ((c = getopt (argc, argv,
"vashyxmf:o:e:b:c:")) != -1)
375 size_t to_copy = strlen(dltdata.
ovalue);
376 if (strcmp(&dltdata.
ovalue[to_copy-4],
".dlt") == 0)
378 to_copy = to_copy - 4;
391 dltdata.
bvalue = atoi(optarg);
400 fprintf (stderr,
"Invalid argument for option -c.\n");
409 if (optopt ==
'o' || optopt ==
'f' || optopt ==
'c')
411 fprintf (stderr,
"Option -%c requires an argument.\n", optopt);
413 else if (isprint (optopt))
415 fprintf (stderr,
"Unknown option `-%c'.\n", optopt);
419 fprintf (stderr,
"Unknown option character `\\x%x'.\n",optopt);
443 for (index = optind; index < argc; index++)
447 fprintf(stderr,
"set server ip didn't succeed\n");
452 if (dltclient.
servIP == 0)
455 fprintf(stderr,
"ERROR: No hostname selected\n");
463 for (index = optind; index < argc; index++)
467 fprintf(stderr,
"set serial device didn't succeed\n");
475 fprintf(stderr,
"ERROR: No serial device name specified\n");
506 snprintf(tmp, 256,
"Using file size limit of %" PRId64
"bytes\n", dltdata.
climit);
512 dltdata.
ohandle = open(dltdata.
ovalue, O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
518 fprintf(stderr,
"ERROR: Output file %s cannot be opened!\n",dltdata.
ovalue);
566 if ((message==0) || (data==0))
583 if ((dltdata->
fvalue==0) ||
591 else if (dltdata->
aflag)
600 printf(
"[%s]\n",text);
602 else if (dltdata->
mflag)
606 else if (dltdata->
sflag)
611 printf(
"%s \n",text);
632 printf(
"ERROR: dlt_receive_message_callback: Unable to open log when maximum filesize was reached!\n");
640 bytes_written = writev(dltdata->
ohandle, iov, 2);
644 if (0 > bytes_written){
645 printf(
"dlt_receive_message_callback: writev(dltdata->ohandle, iov, 2); returned an error!" );
DltStorageHeader * storageheader
void dlt_set_id(char *id, const char *text)
void dlt_client_register_message_callback(int(*registerd_callback)(DltMessage *message, void *data))
DltReturnValue dlt_file_set_filter(DltFile *file, DltFilter *filter, int verbose)
#define DLT_RECEIVE_ECU_ID
DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose)
int dlt_client_set_server_ip(DltClient *client, char *ipaddr)
int main(int argc, char *argv[])
DltReturnValue dlt_message_filter_check(DltMessage *msg, DltFilter *filter, int verbose)
int dlt_receive_message_callback(DltMessage *message, void *data)
DltReturnValue dlt_log(int prio, char *s)
DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate)
DltReturnValue dlt_filter_init(DltFilter *filter, int verbose)
int dlt_client_set_serial_device(DltClient *client, char *serial_device)
static char data[kDataSize]
DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
DltReturnValue dlt_client_init(DltClient *client, int verbose)
DltReturnValue dlt_filter_free(DltFilter *filter, int verbose)
DltReturnValue dlt_client_cleanup(DltClient *client, int verbose)
DltReturnValue dlt_client_connect(DltClient *client, int verbose)
DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verbose)
uint8_t headerbuffer[sizeof(DltStorageHeader)+sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]
#define DLT_RECEIVE_TEXTBUFSIZE
#define DLT_IS_HTYP_WEID(htyp)
DltStandardHeaderExtra headerextra
DltReturnValue dlt_file_init(DltFile *file, int verbose)
DltReturnValue dlt_message_payload(DltMessage *msg, char *text, int textlength, int type, int verbose)
int dlt_receive_open_output_file(DltReceiveData *dltdata)
DltReturnValue dlt_file_free(DltFile *file, int verbose)
DltStandardHeader * standardheader
void dlt_get_version(char *buf, size_t size)
DltReturnValue dlt_message_header(DltMessage *msg, char *text, int textlength, int verbose)
int64_t convert_arg_to_byte_size(char *arg)
DltReturnValue dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose)
void dlt_receive_close_output_file(DltReceiveData *dltdata)
DltReturnValue dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose)