|
@@ -12,6 +12,7 @@
|
12
|
12
|
#include <stdlib.h>
|
13
|
13
|
#include <string.h>
|
14
|
14
|
#include <getopt.h>
|
|
15
|
+#include <unistd.h>
|
15
|
16
|
|
16
|
17
|
#include "data.h"
|
17
|
18
|
#include "cmd.h"
|
|
@@ -26,10 +27,11 @@ int quiet;
|
26
|
27
|
|
27
|
28
|
static struct videohub_data maindata;
|
28
|
29
|
static int show_info = 1;
|
|
30
|
+static int show_monitor = 0;
|
29
|
31
|
|
30
|
32
|
static const char *program_id = PROGRAM_NAME " Version: " VERSION " Git: " GIT_VER;
|
31
|
33
|
|
32
|
|
-static const char short_options[] = "s:p:qvhVi";
|
|
34
|
+static const char short_options[] = "s:p:qvhVim";
|
33
|
35
|
|
34
|
36
|
static const struct option long_options[] = {
|
35
|
37
|
{ "host", required_argument, NULL, 's' },
|
|
@@ -39,6 +41,7 @@ static const struct option long_options[] = {
|
39
|
41
|
{ "help", no_argument, NULL, 'h' },
|
40
|
42
|
{ "version", no_argument, NULL, 'V' },
|
41
|
43
|
{ "info", no_argument, NULL, 'i' },
|
|
44
|
+ { "monitor", no_argument, NULL, 'm' },
|
42
|
45
|
{ 0, 0, 0, 0 }
|
43
|
46
|
};
|
44
|
47
|
|
|
@@ -58,6 +61,7 @@ static void show_help(struct videohub_data *data) {
|
58
|
61
|
printf("\n");
|
59
|
62
|
printf("Commands:\n");
|
60
|
63
|
printf(" -i --info | Show device info (default command).\n");
|
|
64
|
+ printf(" -m --monitor | Show real time monitor for config changes.\n");
|
61
|
65
|
printf("\n");
|
62
|
66
|
}
|
63
|
67
|
|
|
@@ -84,6 +88,9 @@ static void parse_options(struct videohub_data *data, int argc, char **argv) {
|
84
|
88
|
case 'i': // --info
|
85
|
89
|
show_info = 1;
|
86
|
90
|
break;
|
|
91
|
+ case 'm': // --monitor
|
|
92
|
+ show_monitor = 1;
|
|
93
|
+ break;
|
87
|
94
|
case 'h': // --help
|
88
|
95
|
show_help(data);
|
89
|
96
|
exit(EXIT_SUCCESS);
|
|
@@ -144,6 +151,18 @@ static void print_device_settings(struct videohub_data *d) {
|
144
|
151
|
printf_line(70);
|
145
|
152
|
}
|
146
|
153
|
|
|
154
|
+static int read_device_command_stream(struct videohub_data *d) {
|
|
155
|
+ int ret, ncommands = 0;
|
|
156
|
+ char buf[8192 + 1];
|
|
157
|
+ memset(buf, 0, sizeof(buf));
|
|
158
|
+ while ((ret = fdread_ex(d->dev_fd, buf, sizeof(buf) - 1, 5, 0, 0)) >= 0) {
|
|
159
|
+ if (parse_command(d, buf))
|
|
160
|
+ ncommands++;
|
|
161
|
+ memset(buf, 0, sizeof(buf));
|
|
162
|
+ }
|
|
163
|
+ return ncommands;
|
|
164
|
+}
|
|
165
|
+
|
147
|
166
|
int main(int argc, char **argv) {
|
148
|
167
|
struct videohub_data *data = &maindata;
|
149
|
168
|
|
|
@@ -156,20 +175,25 @@ int main(int argc, char **argv) {
|
156
|
175
|
if (data->dev_fd < 0)
|
157
|
176
|
exit(EXIT_FAILURE);
|
158
|
177
|
|
159
|
|
- int ret;
|
160
|
|
- char buf[8192 + 1];
|
161
|
|
- memset(buf, 0, sizeof(buf));
|
162
|
|
- while ((ret = fdread_ex(data->dev_fd, buf, sizeof(buf) - 1, 5, 0, 0)) >= 0) {
|
163
|
|
- parse_command(data, buf);
|
164
|
|
- memset(buf, 0, sizeof(buf));
|
165
|
|
- }
|
166
|
|
- shutdown_fd(&data->dev_fd);
|
167
|
|
-
|
168
|
|
- if (show_info) {
|
|
178
|
+ read_device_command_stream(data);
|
|
179
|
+ if (show_monitor) {
|
|
180
|
+ while (1) {
|
|
181
|
+ printf("\e[2J\e[H"); // Clear screen
|
|
182
|
+ printf("%s\n", program_id);
|
|
183
|
+ print_device_desc(&data->device);
|
|
184
|
+ print_device_settings(data);
|
|
185
|
+ fflush(stdout);
|
|
186
|
+ do {
|
|
187
|
+ sleep(1);
|
|
188
|
+ } while (read_device_command_stream(data) == 0);
|
|
189
|
+ }
|
|
190
|
+ } else if (show_info) {
|
169
|
191
|
print_device_desc(&data->device);
|
170
|
192
|
print_device_settings(data);
|
171
|
193
|
fflush(stdout);
|
172
|
194
|
}
|
173
|
195
|
|
|
196
|
+ shutdown_fd(&data->dev_fd);
|
|
197
|
+
|
174
|
198
|
return 0;
|
175
|
199
|
}
|