Skip to content

Commit 8c2d4a8

Browse files
duvanan13maiananthanandv
authored and
LUU QUANG MINH
committed
dlt-receive: rework reconnect option for PR620 (#640)
* dlt-receive: add reconnect option with milli seconds as value * dlt-receive: rework reconnect option for PR620 + Correct the waiting loop + Replace poll(NULL) with sleep() + Correct mispelling Signed-off-by: andv <fixed-term.An.DuVan@vn.bosch.com> --------- Signed-off-by: andv <fixed-term.An.DuVan@vn.bosch.com> Co-authored-by: Maiananthan <46962558+maiananthan@users.noreply.github.com> Co-authored-by: andv <fixed-term.An.DuVan@vn.bosch.com>
1 parent da3bde3 commit 8c2d4a8

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/console/dlt-receive.c

+32-12
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#define DLT_RECEIVE_ECU_ID "RECV"
9292

9393
DltClient dltclient;
94+
static bool sig_close_recv = false;
9495

9596
void signal_handler(int signal)
9697
{
@@ -100,6 +101,7 @@ void signal_handler(int signal)
100101
case SIGINT:
101102
case SIGQUIT:
102103
/* stop main loop */
104+
sig_close_recv = true;
103105
shutdown(dltclient.receiver.fd, SHUT_RD);
104106
break;
105107
default:
@@ -120,12 +122,14 @@ typedef struct {
120122
int vflag;
121123
int yflag;
122124
int uflag;
125+
int rflag;
123126
char *ovalue;
124127
char *ovaluebase; /* ovalue without ".dlt" */
125128
char *fvalue; /* filename for space separated filter file (<AppID> <ContextID>) */
126129
char *jvalue; /* filename for json filter file */
127130
char *evalue;
128131
int bvalue;
132+
int rvalue;
129133
int sendSerialHeaderFlag;
130134
int resyncSerialHeaderFlag;
131135
int64_t climit;
@@ -163,6 +167,7 @@ void usage()
163167
printf(" -R Enable resync serial header\n");
164168
printf(" -y Serial device mode\n");
165169
printf(" -u UDP multicast mode\n");
170+
printf(" -r msecs Reconnect to server with milli seconds specified\n");
166171
printf(" -i addr Host interface address\n");
167172
printf(" -b baudrate Serial device baudrate (Default: 115200)\n");
168173
printf(" -e ecuid Set ECU ID (Default: RECV)\n");
@@ -345,7 +350,7 @@ int main(int argc, char *argv[])
345350
/* Fetch command line arguments */
346351
opterr = 0;
347352

348-
while ((c = getopt (argc, argv, "vashSRyuxmf:j:o:e:b:c:p:i:")) != -1)
353+
while ((c = getopt(argc, argv, "vashSRyuxmf:j:o:e:b:c:p:i:r:")) != -1)
349354
switch (c) {
350355
case 'v':
351356
{
@@ -418,6 +423,11 @@ int main(int argc, char *argv[])
418423
return -1;
419424
#endif
420425
}
426+
case 'r': {
427+
dltdata.rflag = 1;
428+
dltdata.rvalue = atoi(optarg);
429+
break;
430+
}
421431
case 'o':
422432
{
423433
dltdata.ovalue = optarg;
@@ -612,17 +622,27 @@ int main(int argc, char *argv[])
612622

613623
if (dltdata.evalue)
614624
dlt_set_id(dltdata.ecuid, dltdata.evalue);
615-
else
616-
dlt_set_id(dltdata.ecuid, DLT_RECEIVE_ECU_ID);
617-
618-
/* Connect to TCP socket or open serial device */
619-
if (dlt_client_connect(&dltclient, dltdata.vflag) != DLT_RETURN_ERROR) {
620-
621-
/* Dlt Client Main Loop */
622-
dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag);
623-
624-
/* Dlt Client Cleanup */
625-
dlt_client_cleanup(&dltclient, dltdata.vflag);
625+
else{
626+
dlt_set_id(dltdata.ecuid, DLT_RECEIVE_ECU_ID);}
627+
628+
while (true) {
629+
/* Attempt to connect to TCP socket or open serial device */
630+
if (dlt_client_connect(&dltclient, dltdata.vflag) != DLT_RETURN_ERROR) {
631+
632+
/* Dlt Client Main Loop */
633+
dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag);
634+
635+
if (dltdata.rflag == 1 && sig_close_recv == false) {
636+
dlt_vlog(LOG_INFO, "Reconnect to server with %d milli seconds specified\n", dltdata.rvalue);
637+
sleep(dltdata.rvalue / 1000);
638+
} else {
639+
/* Dlt Client Cleanup */
640+
dlt_client_cleanup(&dltclient, dltdata.vflag);
641+
break;
642+
}
643+
} else {
644+
break;
645+
}
626646
}
627647

628648
/* dlt-receive cleanup */

0 commit comments

Comments
 (0)