Skip to content

Commit

Permalink
dlt-receive: rework reconnect option for PR620 (#640)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Signed-off-by: andv <[email protected]>
Co-authored-by: Maiananthan <[email protected]>
Co-authored-by: andv <[email protected]>
  • Loading branch information
3 people authored and LUU QUANG MINH committed Jul 2, 2024
1 parent da3bde3 commit 8c2d4a8
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/console/dlt-receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#define DLT_RECEIVE_ECU_ID "RECV"

DltClient dltclient;
static bool sig_close_recv = false;

void signal_handler(int signal)
{
Expand All @@ -100,6 +101,7 @@ void signal_handler(int signal)
case SIGINT:
case SIGQUIT:
/* stop main loop */
sig_close_recv = true;
shutdown(dltclient.receiver.fd, SHUT_RD);
break;
default:
Expand All @@ -120,12 +122,14 @@ typedef struct {
int vflag;
int yflag;
int uflag;
int rflag;
char *ovalue;
char *ovaluebase; /* ovalue without ".dlt" */
char *fvalue; /* filename for space separated filter file (<AppID> <ContextID>) */
char *jvalue; /* filename for json filter file */
char *evalue;
int bvalue;
int rvalue;
int sendSerialHeaderFlag;
int resyncSerialHeaderFlag;
int64_t climit;
Expand Down Expand Up @@ -163,6 +167,7 @@ void usage()
printf(" -R Enable resync serial header\n");
printf(" -y Serial device mode\n");
printf(" -u UDP multicast mode\n");
printf(" -r msecs Reconnect to server with milli seconds specified\n");
printf(" -i addr Host interface address\n");
printf(" -b baudrate Serial device baudrate (Default: 115200)\n");
printf(" -e ecuid Set ECU ID (Default: RECV)\n");
Expand Down Expand Up @@ -345,7 +350,7 @@ int main(int argc, char *argv[])
/* Fetch command line arguments */
opterr = 0;

while ((c = getopt (argc, argv, "vashSRyuxmf:j:o:e:b:c:p:i:")) != -1)
while ((c = getopt(argc, argv, "vashSRyuxmf:j:o:e:b:c:p:i:r:")) != -1)
switch (c) {
case 'v':
{
Expand Down Expand Up @@ -418,6 +423,11 @@ int main(int argc, char *argv[])
return -1;
#endif
}
case 'r': {
dltdata.rflag = 1;
dltdata.rvalue = atoi(optarg);
break;
}
case 'o':
{
dltdata.ovalue = optarg;
Expand Down Expand Up @@ -612,17 +622,27 @@ int main(int argc, char *argv[])

if (dltdata.evalue)
dlt_set_id(dltdata.ecuid, dltdata.evalue);
else
dlt_set_id(dltdata.ecuid, DLT_RECEIVE_ECU_ID);

/* Connect to TCP socket or open serial device */
if (dlt_client_connect(&dltclient, dltdata.vflag) != DLT_RETURN_ERROR) {

/* Dlt Client Main Loop */
dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag);

/* Dlt Client Cleanup */
dlt_client_cleanup(&dltclient, dltdata.vflag);
else{
dlt_set_id(dltdata.ecuid, DLT_RECEIVE_ECU_ID);}

while (true) {
/* Attempt to connect to TCP socket or open serial device */
if (dlt_client_connect(&dltclient, dltdata.vflag) != DLT_RETURN_ERROR) {

/* Dlt Client Main Loop */
dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag);

if (dltdata.rflag == 1 && sig_close_recv == false) {
dlt_vlog(LOG_INFO, "Reconnect to server with %d milli seconds specified\n", dltdata.rvalue);
sleep(dltdata.rvalue / 1000);
} else {
/* Dlt Client Cleanup */
dlt_client_cleanup(&dltclient, dltdata.vflag);
break;
}
} else {
break;
}
}

/* dlt-receive cleanup */
Expand Down

0 comments on commit 8c2d4a8

Please sign in to comment.