Browse Source

Add -m / --monitor parameter for live configuration monitoring.

Georgi Chorbadzhiyski 9 years ago
parent
commit
80a15bb523
4 changed files with 37 additions and 12 deletions
  1. 1
    0
      ChangeLog
  2. 1
    0
      README
  3. 0
    1
      TODO
  4. 35
    11
      videohubctrl.c

+ 1
- 0
ChangeLog View File

1
 |-----------------------------------------------------------------------|
1
 |-----------------------------------------------------------------------|
2
 xxxx-xx-xx : Version 0.2 - dev
2
 xxxx-xx-xx : Version 0.2 - dev
3
  * Fix port routing. Previously it was reversed and incorrect.
3
  * Fix port routing. Previously it was reversed and incorrect.
4
+ * Add -m / --monitor parameter for live configuration monitoring.
4
 
5
 
5
 2014-11-26 : Version 0.1
6
 2014-11-26 : Version 0.1
6
  * Initial vesion with support for showing Videohub configuration
7
  * Initial vesion with support for showing Videohub configuration

+ 1
- 0
README View File

88
 
88
 
89
 Commands:
89
 Commands:
90
  -i --info                  | Show device info (default command).
90
  -i --info                  | Show device info (default command).
91
+ -m --monitor               | Show real time monitor for config changes.
91
 
92
 
92
 
93
 
93
 Example usage
94
 Example usage

+ 0
- 1
TODO View File

1
-- Add --monitor option to continually display configuration and changes to it.
2
 - Add --save-config and --restore-config.
1
 - Add --save-config and --restore-config.
3
 - Add commands to set labels, routing and locking.
2
 - Add commands to set labels, routing and locking.
4
 - Create man page.
3
 - Create man page.

+ 35
- 11
videohubctrl.c View File

12
 #include <stdlib.h>
12
 #include <stdlib.h>
13
 #include <string.h>
13
 #include <string.h>
14
 #include <getopt.h>
14
 #include <getopt.h>
15
+#include <unistd.h>
15
 
16
 
16
 #include "data.h"
17
 #include "data.h"
17
 #include "cmd.h"
18
 #include "cmd.h"
26
 
27
 
27
 static struct videohub_data maindata;
28
 static struct videohub_data maindata;
28
 static int show_info = 1;
29
 static int show_info = 1;
30
+static int show_monitor = 0;
29
 
31
 
30
 static const char *program_id = PROGRAM_NAME " Version: " VERSION " Git: " GIT_VER;
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
 static const struct option long_options[] = {
36
 static const struct option long_options[] = {
35
 	{ "host",				required_argument, NULL, 's' },
37
 	{ "host",				required_argument, NULL, 's' },
39
 	{ "help",				no_argument,       NULL, 'h' },
41
 	{ "help",				no_argument,       NULL, 'h' },
40
 	{ "version",			no_argument,       NULL, 'V' },
42
 	{ "version",			no_argument,       NULL, 'V' },
41
 	{ "info",				no_argument,       NULL, 'i' },
43
 	{ "info",				no_argument,       NULL, 'i' },
44
+	{ "monitor",			no_argument,       NULL, 'm' },
42
 	{ 0, 0, 0, 0 }
45
 	{ 0, 0, 0, 0 }
43
 };
46
 };
44
 
47
 
58
 	printf("\n");
61
 	printf("\n");
59
 	printf("Commands:\n");
62
 	printf("Commands:\n");
60
 	printf(" -i --info                  | Show device info (default command).\n");
63
 	printf(" -i --info                  | Show device info (default command).\n");
64
+	printf(" -m --monitor               | Show real time monitor for config changes.\n");
61
 	printf("\n");
65
 	printf("\n");
62
 }
66
 }
63
 
67
 
84
 			case 'i': // --info
88
 			case 'i': // --info
85
 				show_info = 1;
89
 				show_info = 1;
86
 				break;
90
 				break;
91
+			case 'm': // --monitor
92
+				show_monitor = 1;
93
+				break;
87
 			case 'h': // --help
94
 			case 'h': // --help
88
 				show_help(data);
95
 				show_help(data);
89
 				exit(EXIT_SUCCESS);
96
 				exit(EXIT_SUCCESS);
144
 	printf_line(70);
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
 int main(int argc, char **argv) {
166
 int main(int argc, char **argv) {
148
 	struct videohub_data *data = &maindata;
167
 	struct videohub_data *data = &maindata;
149
 
168
 
156
 	if (data->dev_fd < 0)
175
 	if (data->dev_fd < 0)
157
 		exit(EXIT_FAILURE);
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
 		print_device_desc(&data->device);
191
 		print_device_desc(&data->device);
170
 		print_device_settings(data);
192
 		print_device_settings(data);
171
 		fflush(stdout);
193
 		fflush(stdout);
172
 	}
194
 	}
173
 
195
 
196
+	shutdown_fd(&data->dev_fd);
197
+
174
 	return 0;
198
 	return 0;
175
 }
199
 }

Loading…
Cancel
Save