|
@@ -29,6 +29,7 @@
|
29
|
29
|
|
30
|
30
|
int debug;
|
31
|
31
|
int quiet;
|
|
32
|
+int timeout = 15;
|
32
|
33
|
|
33
|
34
|
static struct videohub_data maindata;
|
34
|
35
|
static int show_info = 1;
|
|
@@ -49,7 +50,7 @@ enum list_actions {
|
49
|
50
|
|
50
|
51
|
static const char *program_id = PROGRAM_NAME " Version: " VERSION " Git: " GIT_VER;
|
51
|
52
|
|
52
|
|
-static const char short_options[] = "h:p:T:qdHVimb";
|
|
53
|
+static const char short_options[] = "h:p:T:qdHVimbt:";
|
53
|
54
|
|
54
|
55
|
static const struct option long_options[] = {
|
55
|
56
|
{ "host", required_argument, NULL, 'h' },
|
|
@@ -62,6 +63,7 @@ static const struct option long_options[] = {
|
62
|
63
|
{ "info", no_argument, NULL, 'i' },
|
63
|
64
|
{ "monitor", no_argument, NULL, 'm' },
|
64
|
65
|
{ "backup", no_argument, NULL, 'b' },
|
|
66
|
+ { "timeout", required_argument, NULL, 't' },
|
65
|
67
|
|
66
|
68
|
{ "list-device", no_argument, NULL, 901 },
|
67
|
69
|
{ "list-inputs", no_argument, NULL, 902 },
|
|
@@ -148,6 +150,7 @@ static void show_help(struct videohub_data *data) {
|
148
|
150
|
printf("Main options:\n");
|
149
|
151
|
printf(" -h --host <host> | Set device host name.\n");
|
150
|
152
|
printf(" -p --port <port_number> | Set device port (default: 9990).\n");
|
|
153
|
+ printf(" -t --timeout <secs> | Set connect/read timeout. Default: %d\n", timeout);
|
151
|
154
|
printf("\n");
|
152
|
155
|
printf("Commands:\n");
|
153
|
156
|
printf(" -i --info | Show full device info (default command).\n");
|
|
@@ -299,6 +302,9 @@ static void parse_options(struct videohub_data *data, int argc, char **argv) {
|
299
|
302
|
case 'p': // --port
|
300
|
303
|
data->dev_port = optarg;
|
301
|
304
|
break;
|
|
305
|
+ case 't': // --timeout
|
|
306
|
+ timeout = strtoimax(optarg, NULL, 0);
|
|
307
|
+ break;
|
302
|
308
|
case 'T': { // --test-input
|
303
|
309
|
struct stat st;
|
304
|
310
|
FILE *f;
|
|
@@ -374,13 +380,15 @@ static void parse_options(struct videohub_data *data, int argc, char **argv) {
|
374
|
380
|
}
|
375
|
381
|
}
|
376
|
382
|
|
377
|
|
- if (!data->dev_host || !strtoul(data->dev_port, NULL, 10))
|
|
383
|
+ if (!data->dev_host || !strtoul(data->dev_port, NULL, 10) || !timeout || timeout > 60)
|
378
|
384
|
err = 1;
|
379
|
385
|
|
380
|
386
|
if (err) {
|
381
|
387
|
show_help(data);
|
382
|
388
|
if (!data->dev_host)
|
383
|
389
|
fprintf(stderr, "ERROR: host is not set. Use --host option.\n");
|
|
390
|
+ if (!timeout || timeout > 60)
|
|
391
|
+ fprintf(stderr, "ERROR: invalid timeout value, must be between 1 and 60\n");
|
384
|
392
|
exit(EXIT_FAILURE);
|
385
|
393
|
}
|
386
|
394
|
|
|
@@ -416,7 +424,7 @@ static int read_device_command_stream(struct videohub_data *d) {
|
416
|
424
|
if (test_data)
|
417
|
425
|
return 0;
|
418
|
426
|
memset(buf, 0, sizeof(buf));
|
419
|
|
- while ((ret = fdread_ex(d->dev_fd, buf, sizeof(buf) - 1, 5, 0, 1)) >= 0) {
|
|
427
|
+ while ((ret = fdread_ex(d->dev_fd, buf, sizeof(buf) - 1, timeout, 0, 1)) >= 0) {
|
420
|
428
|
ncommands += parse_text_buffer(d, buf);
|
421
|
429
|
memset(buf, 0, sizeof(buf));
|
422
|
430
|
}
|