summaryrefslogtreecommitdiff
path: root/src/console/dlt-receive.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/console/dlt-receive.c')
-rw-r--r--src/console/dlt-receive.c73
1 files changed, 44 insertions, 29 deletions
diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c
index a302dd7..62cc18f 100644
--- a/src/console/dlt-receive.c
+++ b/src/console/dlt-receive.c
@@ -104,6 +104,7 @@ void signal_handler(int signal)
/* This case should never happen! */
break;
} /* switch */
+
}
/* Function prototypes */
@@ -119,7 +120,8 @@ typedef struct {
int uflag;
char *ovalue;
char *ovaluebase; /* ovalue without ".dlt" */
- char *fvalue;
+ char *fvalue; /* filename for space separated filter file (<AppID> <ContextID>) */
+ char *jvalue; /* filename for json filter file */
char *evalue;
int bvalue;
int64_t climit;
@@ -160,7 +162,8 @@ void usage()
printf(" -c limit Restrict file size to <limit> bytes when output to file\n");
printf(" When limit is reached, a new file is opened. Use K,M,G as\n");
printf(" suffix to specify kilo-, mega-, giga-bytes respectively\n");
- printf(" -f filename Enable filtering of messages\n");
+ printf(" -f filename Enable filtering of messages with space separated list (<AppID> <ContextID>)\n");
+ printf(" -j filename Enable filtering of messages with filter defined in json file\n");
printf(" -p port Use the given port instead the default port\n");
printf(" Cannot be used with serial devices\n");
}
@@ -180,17 +183,12 @@ int64_t convert_arg_to_byte_size(char *arg)
/* last character */
factor = 1;
- if ((arg[strlen(arg) - 1] == 'K') || (arg[strlen(arg) - 1] == 'k')) {
+ if ((arg[strlen(arg) - 1] == 'K') || (arg[strlen(arg) - 1] == 'k'))
factor = 1024;
- }
else if ((arg[strlen(arg) - 1] == 'M') || (arg[strlen(arg) - 1] == 'm'))
- {
factor = 1024 * 1024;
- }
else if ((arg[strlen(arg) - 1] == 'G') || (arg[strlen(arg) - 1] == 'g'))
- {
factor = 1024 * 1024 * 1024;
- }
else if (!isdigit(arg[strlen(arg) - 1]))
return -2;
@@ -232,12 +230,11 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata)
if (glob(dltdata->ovalue,
#ifndef __ANDROID_API__
- GLOB_TILDE |
+ GLOB_TILDE |
#endif
- GLOB_NOSORT, NULL, &outer) == 0) {
- if (dltdata->vflag) {
+ GLOB_NOSORT, NULL, &outer) == 0) {
+ if (dltdata->vflag)
dlt_vlog(LOG_INFO, "File %s already exists, need to rename first\n", dltdata->ovalue);
- }
if (dltdata->part_num < 0) {
char pattern[PATH_MAX + 1];
@@ -254,9 +251,9 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata)
*/
if (glob(pattern,
#ifndef __ANDROID_API__
- GLOB_TILDE |
+ GLOB_TILDE |
#endif
- GLOB_NOSORT, NULL, &inner) == 0) {
+ GLOB_NOSORT, NULL, &inner) == 0) {
/* search for the highest number used */
size_t i;
@@ -282,14 +279,12 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata)
snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase, dltdata->part_num++);
- if (rename(dltdata->ovalue, filename) != 0) {
+ if (rename(dltdata->ovalue, filename) != 0)
dlt_vlog(LOG_ERR, "ERROR: rename %s to %s failed with error %s\n",
dltdata->ovalue, filename, strerror(errno));
- }
- else if (dltdata->vflag) {
+ else if (dltdata->vflag)
dlt_vlog(LOG_INFO, "Renaming existing file from %s to %s\n",
dltdata->ovalue, filename);
- }
} /* if (file_already_exists) */
globfree(&outer);
@@ -328,6 +323,7 @@ int main(int argc, char *argv[])
dltdata.ovalue = 0;
dltdata.ovaluebase = 0;
dltdata.fvalue = 0;
+ dltdata.jvalue = 0;
dltdata.evalue = 0;
dltdata.bvalue = 0;
dltdata.climit = -1; /* default: -1 = unlimited */
@@ -351,7 +347,7 @@ int main(int argc, char *argv[])
/* Fetch command line arguments */
opterr = 0;
- while ((c = getopt (argc, argv, "vashyuxmf:o:e:b:c:p:")) != -1)
+ while ((c = getopt (argc, argv, "vashyuxmf:j:o:e:b:c:p:")) != -1)
switch (c) {
case 'v':
{
@@ -398,6 +394,17 @@ int main(int argc, char *argv[])
dltdata.fvalue = optarg;
break;
}
+ case 'j':
+ {
+ #ifdef EXTENDED_FILTERING
+ dltdata.jvalue = optarg;
+ break;
+ #else
+ fprintf (stderr,
+ "Extended filtering is not supported. Please build with the corresponding cmake option to use it.\n");
+ return -1;
+ #endif
+ }
case 'o':
{
dltdata.ovalue = optarg;
@@ -488,8 +495,6 @@ int main(int argc, char *argv[])
return -1;
}
-
-
if (dltclient.servIP == 0) {
/* no hostname selected, show usage and terminate */
fprintf(stderr, "ERROR: No hostname selected\n");
@@ -505,8 +510,6 @@ int main(int argc, char *argv[])
return -1;
}
-
-
if (dltclient.serialDevice == 0) {
/* no serial device name selected, show usage and terminate */
fprintf(stderr, "ERROR: No serial device name specified\n");
@@ -532,6 +535,19 @@ int main(int argc, char *argv[])
dlt_file_set_filter(&(dltdata.file), &(dltdata.filter), dltdata.vflag);
}
+ #ifdef EXTENDED_FILTERING
+
+ if (dltdata.jvalue) {
+ if (dlt_json_filter_load(&(dltdata.filter), dltdata.jvalue, dltdata.vflag) < DLT_RETURN_OK) {
+ dlt_file_free(&(dltdata.file), dltdata.vflag);
+ return -1;
+ }
+
+ dlt_file_set_filter(&(dltdata.file), &(dltdata.filter), dltdata.vflag);
+ }
+
+ #endif
+
/* open DLT output file */
if (dltdata.ovalue) {
if (dltdata.climit > -1) {
@@ -597,9 +613,8 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
else
dlt_set_storageheader(message->storageheader, dltdata->ecuid);
- if ((dltdata->fvalue == 0) ||
- (dltdata->fvalue &&
- (dlt_message_filter_check(message, &(dltdata->filter), dltdata->vflag) == DLT_RETURN_TRUE))) {
+ if (((dltdata->fvalue || dltdata->jvalue) == 0) ||
+ (dlt_message_filter_check(message, &(dltdata->filter), dltdata->vflag) == DLT_RETURN_TRUE)) {
/* if no filter set or filter is matching display message */
if (dltdata->xflag) {
dlt_message_print_hex(message, text, DLT_RECEIVE_BUFSIZE, dltdata->vflag);
@@ -630,9 +645,9 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
/* if file output enabled write message */
if (dltdata->ovalue) {
iov[0].iov_base = message->headerbuffer;
- iov[0].iov_len = (uint32_t) message->headersize;
+ iov[0].iov_len = (uint32_t)message->headersize;
iov[1].iov_base = message->databuffer;
- iov[1].iov_len = (uint32_t) message->datasize;
+ iov[1].iov_len = (uint32_t)message->datasize;
if (dltdata->climit > -1) {
uint32_t bytes_to_write = message->headersize + message->datasize;
@@ -650,7 +665,7 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
}
}
- bytes_written = (int) writev(dltdata->ohandle, iov, 2);
+ bytes_written = (int)writev(dltdata->ohandle, iov, 2);
dltdata->totalbytes += bytes_written;