Browse Source

Create struct port_set which contains a set of ports.

Georgi Chorbadzhiyski 9 years ago
parent
commit
ebdf864c80
4 changed files with 72 additions and 70 deletions
  1. 26
    26
      cmd.c
  2. 10
    9
      data.h
  3. 28
    28
      display.c
  4. 8
    7
      videohubctrl.c

+ 26
- 26
cmd.c View File

@@ -105,7 +105,7 @@ bool parse_command(struct videohub_data *data, char *cmd) {
105 105
 			slot_data[0] = '\0'; // Separate slot_pos from slot_data
106 106
 			slot_data++;
107 107
 			slot_pos = strtoul(line, NULL, 10);
108
-			if (slot_pos + 1 > data->device.num_video_outputs) {
108
+			if (slot_pos + 1 > data->outputs.num) {
109 109
 				q("WARNING: %s - invalid slot %u\n", v->txt, slot_pos);
110 110
 				continue;
111 111
 			}
@@ -113,7 +113,7 @@ bool parse_command(struct videohub_data *data, char *cmd) {
113 113
 
114 114
 		if (v->flags & PARSE_SLOT_DEST) {
115 115
 			dest_pos = strtoul(slot_data, NULL, 10);
116
-			if (dest_pos + 1 > data->device.num_video_inputs) {
116
+			if (dest_pos + 1 > data->inputs.num) {
117 117
 				q("WARNING: %s - invalid dest %u\n", v->txt, dest_pos);
118 118
 				continue;
119 119
 			}
@@ -139,13 +139,13 @@ bool parse_command(struct videohub_data *data, char *cmd) {
139 139
 				snprintf(data->device.unique_id, sizeof(data->device.unique_id) , "%s", p);
140 140
 
141 141
 			if ((p = parse_text(line, "Video inputs: ")))
142
-				data->device.num_video_inputs = strtoul(p, NULL, 10);
142
+				data->inputs.num = strtoul(p, NULL, 10);
143 143
 
144 144
 			if ((p = parse_text(line, "Video processing units: ")))
145 145
 				data->device.num_video_processing_units = strtoul(p, NULL, 10);
146 146
 
147 147
 			if ((p = parse_text(line, "Video outputs: ")))
148
-				data->device.num_video_outputs = strtoul(p, NULL, 10);
148
+				data->outputs.num = strtoul(p, NULL, 10);
149 149
 
150 150
 			if ((p = parse_text(line, "Video monitoring output: ")))
151 151
 				data->device.num_video_monitoring_outputs = strtoul(p, NULL, 10);
@@ -155,31 +155,31 @@ bool parse_command(struct videohub_data *data, char *cmd) {
155 155
 			break;
156 156
 
157 157
 		case CMD_INPUT_LABELS:
158
-			snprintf(data->inputs[slot_pos].name, sizeof(data->inputs[slot_pos].name), "%s", slot_data);
158
+			snprintf(data->inputs.port[slot_pos].name, sizeof(data->inputs.port[slot_pos].name), "%s", slot_data);
159 159
 			break;
160 160
 
161 161
 		case CMD_OUTPUT_LABELS:
162
-			snprintf(data->outputs[slot_pos].name, sizeof(data->outputs[slot_pos].name), "%s", slot_data);
162
+			snprintf(data->outputs.port[slot_pos].name, sizeof(data->outputs.port[slot_pos].name), "%s", slot_data);
163 163
 			break;
164 164
 
165 165
 		case CMD_VIDEO_INPUT_STATUS:
166
-			snprintf(data->inputs[slot_pos].status, sizeof(data->inputs[slot_pos].status), "%s", slot_data);
166
+			snprintf(data->inputs.port[slot_pos].status, sizeof(data->inputs.port[slot_pos].status), "%s", slot_data);
167 167
 			break;
168 168
 
169 169
 		case CMD_VIDEO_OUTPUT_STATUS:
170
-			snprintf(data->outputs[slot_pos].status, sizeof(data->outputs[slot_pos].status), "%s", slot_data);
170
+			snprintf(data->outputs.port[slot_pos].status, sizeof(data->outputs.port[slot_pos].status), "%s", slot_data);
171 171
 			break;
172 172
 
173 173
 		case CMD_VIDEO_OUTPUT_LOCKS:
174 174
 			switch (slot_data[0]) {
175
-			case 'O': data->outputs[slot_pos].lock = PORT_LOCKED; break;
176
-			case 'L': data->outputs[slot_pos].lock = PORT_LOCKED_OTHER; break;
177
-			default : data->outputs[slot_pos].lock = PORT_UNLOCKED; break;
175
+			case 'O': data->outputs.port[slot_pos].lock = PORT_LOCKED; break;
176
+			case 'L': data->outputs.port[slot_pos].lock = PORT_LOCKED_OTHER; break;
177
+			default : data->outputs.port[slot_pos].lock = PORT_UNLOCKED; break;
178 178
 			}
179 179
 			break;
180 180
 
181 181
 		case CMD_VIDEO_OUTPUT_ROUTING:
182
-			data->outputs[slot_pos].routed_to = dest_pos;
182
+			data->outputs.port[slot_pos].routed_to = dest_pos;
183 183
 
184 184
 		case CMD_PING:
185 185
 		case CMD_ACK:
@@ -221,8 +221,8 @@ int parse_text_buffer(struct videohub_data *data, char *cmd_buffer) {
221 221
 // Try to find input/output with certain name, return 0 on not found, pos + 1 is found
222 222
 static int search_video_output_name(struct videohub_data *d, char *name) {
223 223
 	unsigned int i;
224
-	for(i = 0; i < d->device.num_video_outputs; i++) {
225
-		if (streq(name, d->outputs[i].name)) {
224
+	for(i = 0; i < d->outputs.num; i++) {
225
+		if (streq(name, d->outputs.port[i].name)) {
226 226
 			return i + 1;
227 227
 		}
228 228
 	}
@@ -231,8 +231,8 @@ static int search_video_output_name(struct videohub_data *d, char *name) {
231 231
 
232 232
 static int search_video_input_name(struct videohub_data *d, char *name) {
233 233
 	unsigned int i;
234
-	for(i = 0; i < d->device.num_video_inputs; i++) {
235
-		if (streq(name, d->inputs[i].name)) {
234
+	for(i = 0; i < d->inputs.num; i++) {
235
+		if (streq(name, d->inputs.port[i].name)) {
236 236
 			return i + 1;
237 237
 		}
238 238
 	}
@@ -255,7 +255,7 @@ void prepare_cmd_entry(struct videohub_data *d, struct vcmd_entry *e) {
255 255
 	e->port_no2 = my_atoi(e->param2);
256 256
 	switch (e->cmd) {
257 257
 	case CMD_INPUT_LABELS:
258
-		if (e->port_no1 == 0 || e->port_no1 > d->device.num_video_inputs) {
258
+		if (e->port_no1 == 0 || e->port_no1 > d->inputs.num) {
259 259
 			e->port_no1 = search_video_input_name(d, e->param1);
260 260
 			if (!e->port_no1)
261 261
 				die("Unknown input port number/name: %s", e->param1);
@@ -263,20 +263,20 @@ void prepare_cmd_entry(struct videohub_data *d, struct vcmd_entry *e) {
263 263
 		break;
264 264
 	case CMD_OUTPUT_LABELS:
265 265
 	case CMD_VIDEO_OUTPUT_LOCKS:
266
-		if (e->port_no1 == 0 || e->port_no1 > d->device.num_video_outputs) {
266
+		if (e->port_no1 == 0 || e->port_no1 > d->outputs.num) {
267 267
 			e->port_no1 = search_video_output_name(d, e->param1);
268 268
 			if (!e->port_no1)
269 269
 				die("Unknown output port number/name: %s", e->param1);
270 270
 		}
271
-		e->lock = d->outputs[e->port_no1 - 1].lock;
271
+		e->lock = d->outputs.port[e->port_no1 - 1].lock;
272 272
 		break;
273 273
 	case CMD_VIDEO_OUTPUT_ROUTING:
274
-		if (e->port_no1 == 0 || e->port_no1 > d->device.num_video_outputs) {
274
+		if (e->port_no1 == 0 || e->port_no1 > d->outputs.num) {
275 275
 			e->port_no1 = search_video_output_name(d, e->param1);
276 276
 			if (!e->port_no1)
277 277
 				die("Unknown output port number/name: %s", e->param1);
278 278
 		}
279
-		if (e->port_no2 == 0 || e->port_no2 > d->device.num_video_inputs) {
279
+		if (e->port_no2 == 0 || e->port_no2 > d->inputs.num) {
280 280
 			e->port_no2 = search_video_input_name(d, e->param2);
281 281
 			if (!e->port_no2)
282 282
 				die("Unknown input port number/name: %s", e->param2);
@@ -328,14 +328,14 @@ void show_cmd(struct videohub_data *d, struct vcmd_entry *e) {
328 328
 	case CMD_INPUT_LABELS:
329 329
 		printf("%srename video input %d - \"%s\" to \"%s\"\n",
330 330
 			prefix,
331
-			e->port_no1, d->inputs[e->port_no1 - 1].name,
331
+			e->port_no1, d->inputs.port[e->port_no1 - 1].name,
332 332
 			e->param2
333 333
 		);
334 334
 		break;
335 335
 	case CMD_OUTPUT_LABELS:
336 336
 		printf("%srename video output %d - \"%s\" to \"%s\"\n",
337 337
 			prefix,
338
-			e->port_no1, d->outputs[e->port_no1 - 1].name,
338
+			e->port_no1, d->outputs.port[e->port_no1 - 1].name,
339 339
 			e->param2
340 340
 		);
341 341
 		break;
@@ -343,14 +343,14 @@ void show_cmd(struct videohub_data *d, struct vcmd_entry *e) {
343 343
 		printf("%s%s video output %d - \"%s\"\n",
344 344
 			prefix,
345 345
 			e->do_lock ? "lock" : (e->lock == PORT_LOCKED_OTHER ? "force unlock" : "unlock"),
346
-			e->port_no1, d->outputs[e->port_no1 - 1].name
346
+			e->port_no1, d->outputs.port[e->port_no1 - 1].name
347 347
 		);
348 348
 		break;
349 349
 	case CMD_VIDEO_OUTPUT_ROUTING:
350 350
 		printf("%sset video output %d \"%s\" to read from input %d \"%s\"\n",
351 351
 			prefix,
352
-			e->port_no1, d->outputs[e->port_no1 - 1].name,
353
-			e->port_no2, d->inputs [e->port_no2 - 1].name
352
+			e->port_no1, d->outputs.port[e->port_no1 - 1].name,
353
+			e->port_no2, d->inputs.port [e->port_no2 - 1].name
354 354
 		);
355 355
 		break;
356 356
 	case CMD_VIDEO_INPUT_STATUS:

+ 10
- 9
data.h View File

@@ -15,11 +15,9 @@
15 15
 
16 16
 #include <stdbool.h>
17 17
 
18
-#define MAX_INPUTS 288
19
-#define MAX_OUTPUTS 288
20
-#define MAX_NAME_LEN 64
21
-
22
-#define MAX_RUN_CMDS (MAX_INPUTS + (MAX_OUTPUTS * 2))
18
+#define MAX_PORTS 288
19
+#define MAX_NAME_LEN 32
20
+#define MAX_RUN_CMDS (288 * 5)
23 21
 
24 22
 struct device_desc {
25 23
 	bool			dev_present;
@@ -27,9 +25,7 @@ struct device_desc {
27 25
 	char			protocol_ver[16];
28 26
 	char			model_name[MAX_NAME_LEN];
29 27
 	char			unique_id[MAX_NAME_LEN];
30
-	unsigned int	num_video_inputs;
31 28
 	unsigned int	num_video_processing_units;
32
-	unsigned int	num_video_outputs;
33 29
 	unsigned int	num_video_monitoring_outputs;
34 30
 	unsigned int	num_serial_ports;
35 31
 };
@@ -50,13 +46,18 @@ struct port {
50 46
 	enum port_lock	lock;
51 47
 };
52 48
 
49
+struct port_set {
50
+	unsigned int	num;
51
+	struct port		port[MAX_PORTS];
52
+};
53
+
53 54
 struct videohub_data {
54 55
 	char					*dev_host;
55 56
 	char					*dev_port;
56 57
 	int						dev_fd;
57 58
 	struct device_desc		device;
58
-	struct port				inputs[MAX_INPUTS];
59
-	struct port				outputs[MAX_OUTPUTS];
59
+	struct port_set			inputs;
60
+	struct port_set			outputs;
60 61
 };
61 62
 
62 63
 extern int debug;

+ 28
- 28
display.c View File

@@ -42,8 +42,8 @@ void print_device_info(struct videohub_data *d) {
42 42
 	printf("  | %-26s | %-26s |\n", "Model name", d->device.model_name);
43 43
 	printf("  | %-26s | %-26s |\n", "Unique ID", d->device.unique_id);
44 44
 	printf("  | %-26s | %-26s |\n", "Protocol", d->device.protocol_ver);
45
-	printf("  | %-26s | %-26u |\n", "Video inputs", d->device.num_video_inputs);
46
-	printf("  | %-26s | %-26u |\n", "Video outputs", d->device.num_video_outputs);
45
+	printf("  | %-26s | %-26u |\n", "Video inputs", d->inputs.num);
46
+	printf("  | %-26s | %-26u |\n", "Video outputs", d->outputs.num);
47 47
 	if (d->device.num_serial_ports)
48 48
 		printf("  | %-26s | %-26u |\n", "Serial ports", d->device.num_serial_ports);
49 49
 	if (d->device.num_video_processing_units)
@@ -56,36 +56,36 @@ void print_device_info(struct videohub_data *d) {
56 56
 
57 57
 void print_device_video_inputs(struct videohub_data *d) {
58 58
 	unsigned int i, r, len = 68;
59
-	if (!d->device.num_video_inputs)
59
+	if (!d->inputs.num)
60 60
 		return;
61 61
 	printf("Video inputs\n");
62 62
 	printf_line(len);
63 63
 	printf("  | ## | %-24s | n | %-24s | s |\n", "Video input name", "Routed to output");
64 64
 	printf_line(len);
65
-	for(i = 0; i < d->device.num_video_inputs; i++) {
65
+	for(i = 0; i < d->inputs.num; i++) {
66 66
 		unsigned int num_outputs = 0, routed_to = 0;
67
-		for(r = 0; r < d->device.num_video_outputs; r++) {
68
-			if (d->outputs[r].routed_to == i) {
67
+		for(r = 0; r < d->outputs.num; r++) {
68
+			if (d->outputs.port[r].routed_to == i) {
69 69
 				num_outputs++;
70 70
 				if (num_outputs == 1)
71 71
 					routed_to = r; // The first output
72 72
 			}
73 73
 		}
74
-		printf("  | %2d | %-24s | %d | ", i + 1, d->inputs[i].name,
74
+		printf("  | %2d | %-24s | %d | ", i + 1, d->inputs.port[i].name,
75 75
 			 num_outputs);
76 76
 		if (num_outputs == 0) {
77
-			printf("%-24s | %c |\n", "-", format_status(d->inputs[i].status));
77
+			printf("%-24s | %c |\n", "-", format_status(d->inputs.port[i].status));
78 78
 		} else {
79
-			printf("%-24s | %c |\n", d->outputs[routed_to].name, format_status(d->inputs[i].status));
79
+			printf("%-24s | %c |\n", d->outputs.port[routed_to].name, format_status(d->inputs.port[i].status));
80 80
 			bool first_skipped = false;
81
-			for(r = 0; r < d->device.num_video_outputs; r++) {
82
-				if (d->outputs[r].routed_to == i) {
81
+			for(r = 0; r < d->outputs.num; r++) {
82
+				if (d->outputs.port[r].routed_to == i) {
83 83
 					if (!first_skipped) {
84 84
 						first_skipped = true;
85 85
 						continue;
86 86
 					}
87 87
 					printf("  | %2s | %-24s | %s | %-24s | %c |\n",
88
-						" ", " ", " ", d->outputs[r].name, ' ');
88
+						" ", " ", " ", d->outputs.port[r].name, ' ');
89 89
 				}
90 90
 			}
91 91
 		}
@@ -105,19 +105,19 @@ static char port_lock_symbol(enum port_lock p) {
105 105
 
106 106
 void print_device_video_outputs(struct videohub_data *d) {
107 107
 	unsigned int i, len = 68;
108
-	if (!d->device.num_video_outputs)
108
+	if (!d->outputs.num)
109 109
 		return;
110 110
 	printf("Video outputs\n");
111 111
 	printf_line(len);
112 112
 	printf("  | ## | x | %-24s | %-24s | s |\n", "Video output name", "Connected video input");
113 113
 	printf_line(len);
114
-	for(i = 0; i < d->device.num_video_outputs; i++) {
114
+	for(i = 0; i < d->outputs.num; i++) {
115 115
 		printf("  | %2d | %c | %-24s | %-24s | %c |\n",
116 116
 			i + 1,
117
-			port_lock_symbol(d->outputs[i].lock),
118
-			d->outputs[i].name,
119
-			d->inputs[d->outputs[i].routed_to].name,
120
-			format_status(d->outputs[i].status)
117
+			port_lock_symbol(d->outputs.port[i].lock),
118
+			d->outputs.port[i].name,
119
+			d->inputs.port[d->outputs.port[i].routed_to].name,
120
+			format_status(d->outputs.port[i].status)
121 121
 		);
122 122
 	}
123 123
 	printf_line(len);
@@ -127,19 +127,19 @@ void print_device_video_outputs(struct videohub_data *d) {
127 127
 void print_device_backup(struct videohub_data *d) {
128 128
 	unsigned int i;
129 129
 	printf("videohubctrl \\\n");
130
-	for(i = 0; i < d->device.num_video_inputs; i++)
131
-		printf("  --vi-name %2d \"%s\" \\\n", i + 1, d->inputs[i].name);
132
-	for(i = 0; i < d->device.num_video_outputs; i++)
133
-		printf("  --vo-name %2d \"%s\" \\\n", i + 1, d->outputs[i].name);
134
-	for(i = 0; i < d->device.num_video_outputs; i++)
135
-		printf("  --vo-route %2d %2d \\\n", i + 1, d->outputs[i].routed_to + 1);
136
-	for(i = 0; i < d->device.num_video_outputs; i++) {
137
-		if (d->outputs[i].lock != PORT_UNLOCKED) {
130
+	for(i = 0; i < d->inputs.num; i++)
131
+		printf("  --vi-name %2d \"%s\" \\\n", i + 1, d->inputs.port[i].name);
132
+	for(i = 0; i < d->outputs.num; i++)
133
+		printf("  --vo-name %2d \"%s\" \\\n", i + 1, d->outputs.port[i].name);
134
+	for(i = 0; i < d->outputs.num; i++)
135
+		printf("  --vo-route %2d %2d \\\n", i + 1, d->outputs.port[i].routed_to + 1);
136
+	for(i = 0; i < d->outputs.num; i++) {
137
+		if (d->outputs.port[i].lock != PORT_UNLOCKED) {
138 138
 			printf("  --vo-unlock %2d --vo-lock %2d%s\n", i + 1, i + 1,
139
-				i + 1 < d->device.num_video_outputs ? " \\" : "");
139
+				i + 1 < d->outputs.num ? " \\" : "");
140 140
 		} else {
141 141
 			printf("  --vo-unlock %2d%s\n", i + 1,
142
-				i + 1 < d->device.num_video_outputs ? " \\" : "");
142
+				i + 1 < d->outputs.num ? " \\" : "");
143 143
 		}
144 144
 	}
145 145
 	printf("\n");

+ 8
- 7
videohubctrl.c View File

@@ -221,6 +221,12 @@ static void parse_options(struct videohub_data *data, int argc, char **argv) {
221 221
 	d("Device address: %s:%s\n", data->dev_host, data->dev_port);
222 222
 }
223 223
 
224
+static void check_number_of_ports(struct port_set *p) {
225
+	if (p->num > ARRAY_SIZE(p->port))
226
+		die("The device supports %d ports. Increase MAX_PORTS (%lu) and recompile the program.",
227
+			p->num, ARRAY_SIZE(p->port));
228
+}
229
+
224 230
 static int read_device_command_stream(struct videohub_data *d) {
225 231
 	int ret, ncommands = 0;
226 232
 	char buf[8192 + 1];
@@ -270,13 +276,8 @@ int main(int argc, char **argv) {
270 276
 		die("Device reports that it is not present.");
271 277
 	}
272 278
 
273
-	if (data->device.num_video_inputs > ARRAY_SIZE(data->inputs))
274
-		die("Device supports %d inputs. Recompile the program with more MAX_INPUTS (currently %d)",
275
-			data->device.num_video_inputs, MAX_INPUTS);
276
-
277
-	if (data->device.num_video_outputs > ARRAY_SIZE(data->outputs))
278
-		die("Device supports %d outputs. Recompile the program with more MAX_OUTPUTS (currently %d)\n",
279
-			data->device.num_video_outputs, MAX_OUTPUTS);
279
+	check_number_of_ports(&data->inputs);
280
+	check_number_of_ports(&data->outputs);
280 281
 
281 282
 	if (num_parsed_cmds) {
282 283
 		unsigned int i;

Loading…
Cancel
Save