Browse Source

Add support for clearing serial port connections.

Georgi Chorbadzhiyski 9 years ago
parent
commit
6176fb9bfe
9 changed files with 72 additions and 19 deletions
  1. 2
    1
      ChangeLog
  2. 2
    1
      README
  3. 35
    11
      cmd.c
  4. 1
    0
      cmd.h
  5. 4
    0
      test/run
  6. 2
    2
      test/test-03.ok
  7. 5
    1
      test/test-04.ok
  8. 6
    2
      videohubctrl.1
  9. 15
    1
      videohubctrl.c

+ 2
- 1
ChangeLog View File

@@ -2,7 +2,8 @@
2 2
 xxxx-xx-xx : Version 0.5-dev
3 3
  * Add missing documentation for --list-moutputs parameter.
4 4
  * Add support for serial ports (names, routing, locks and directions),
5
-    --se-name, --se-input, --se-lock, --se-unlock and --se-dir.
5
+    --se-name, --se-connect, --se-clear, --se-lock, --se-unlock,
6
+    --se-dir and --list-serial.
6 7
 
7 8
 2014-11-30 : Version 0.4
8 9
  * Add videohubctrl(1) man page.

+ 2
- 1
README View File

@@ -71,7 +71,8 @@ Monitoring outputs configuration:
71 71
 
72 72
 Serial ports configuration:
73 73
  --se-name <ser_X> <name>   | Set serial port X name.
74
- --se-input <ser_X> <ser_Y> | Connect serial X to serial Y.
74
+ --se-connect <ser_X> <ser_Y> | Connect serial X to serial Y.
75
+ --se-clear <ser_X>         | Disconnect serial port X from serial Y.
75 76
  --se-lock <ser_X>          | Lock serial port X.
76 77
  --se-unlock <ser_X>        | Unlock serial port X.
77 78
  --se-dir <ser_X> <dir>     | Set serial port X direction.

+ 35
- 11
cmd.c View File

@@ -344,8 +344,14 @@ void prepare_cmd_entry(struct videohub_data *d, struct vcmd_entry *e) {
344 344
 		}
345 345
 	}
346 346
 
347
+	// Allow port_noX to be used as index into ->port[]
348
+	e->port_no1 -= 1;
349
+	e->port_no2 -= 1;
350
+	if (e->clear_port)
351
+		e->port_no2 = NO_PORT;
352
+
347 353
 	if (e->cmd->type == PARSE_LOCK) {
348
-		e->lock = s_port->port[e->port_no1 - 1].lock;
354
+		e->lock = s_port->port[e->port_no1].lock;
349 355
 	}
350 356
 }
351 357
 
@@ -371,19 +377,19 @@ void format_cmd_text(struct vcmd_entry *e, char *buf, unsigned int bufsz) {
371 377
 	switch (e->cmd->type) {
372 378
 	case PARSE_LABEL:
373 379
 		snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
374
-			e->port_no1 - 1, e->param2);
380
+			e->port_no1, e->param2);
375 381
 		break;
376 382
 	case PARSE_LOCK:
377 383
 		snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
378
-			e->port_no1 - 1, e->do_lock ? "O" : (e->lock == PORT_LOCKED_OTHER ? "F" : "U"));
384
+			e->port_no1, e->do_lock ? "O" : (e->lock == PORT_LOCKED_OTHER ? "F" : "U"));
379 385
 		break;
380 386
 	case PARSE_ROUTE:
381
-		snprintf(buf, bufsz, "%s:\n%u %u\n\n", videohub_commands_text[e->cmd->cmd],
382
-			e->port_no1 - 1, e->port_no2 - 1);
387
+		snprintf(buf, bufsz, "%s:\n%u %d\n\n", videohub_commands_text[e->cmd->cmd],
388
+			e->port_no1, (e->port_no2 == NO_PORT ? -1 : (int)e->port_no2));
383 389
 		break;
384 390
 	case PARSE_DIR:
385 391
 		snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
386
-			e->port_no1 - 1, dir2cmd(e->direction));
392
+			e->port_no1, dir2cmd(e->direction));
387 393
 		break;
388 394
 	default: break;
389 395
 	}
@@ -398,7 +404,7 @@ void show_cmd(struct videohub_data *d, struct vcmd_entry *e) {
398 404
 		printf("%srename %s %d \"%s\" to \"%s\"\n",
399 405
 			prefix,
400 406
 			e->cmd->port_id1,
401
-			e->port_no1, s_port->port[e->port_no1 - 1].name,
407
+			e->port_no1 + 1, s_port->port[e->port_no1].name,
402 408
 			e->param2
403 409
 		);
404 410
 		break;
@@ -407,23 +413,41 @@ void show_cmd(struct videohub_data *d, struct vcmd_entry *e) {
407 413
 			prefix,
408 414
 			e->do_lock ? "lock" : (e->lock == PORT_LOCKED_OTHER ? "force unlock" : "unlock"),
409 415
 			e->cmd->port_id1,
410
-			e->port_no1, s_port->port[e->port_no1 - 1].name
416
+			e->port_no1 + 1, s_port->port[e->port_no1].name
411 417
 		);
412 418
 		break;
413 419
 	case PARSE_ROUTE:
420
+		if (e->port_no2 == NO_PORT) {
421
+			printf("%sdisconnect %s %d \"%s\"\n",
422
+				prefix,
423
+				e->cmd->port_id1,
424
+				e->port_no1 + 1, s_port->port[e->port_no1].name
425
+			);
426
+			break;
427
+		}
428
+		if (e->cmd->cmd == CMD_SERIAL_PORT_ROUTING) {
429
+			printf("%sconnect %s %d \"%s\" to %s %d \"%s\"\n",
430
+				prefix,
431
+				e->cmd->port_id1,
432
+				e->port_no1 + 1, s_port->port[e->port_no1].name,
433
+				e->cmd->port_id2,
434
+				e->port_no2 + 1, d_port->port [e->port_no2].name
435
+			);
436
+			break;
437
+		}
414 438
 		printf("%sset %s %d \"%s\" to read from %s %d \"%s\"\n",
415 439
 			prefix,
416 440
 			e->cmd->port_id1,
417
-			e->port_no1, s_port->port[e->port_no1 - 1].name,
441
+			e->port_no1 + 1, s_port->port[e->port_no1].name,
418 442
 			e->cmd->port_id2,
419
-			e->port_no2, d_port->port [e->port_no2 - 1].name
443
+			e->port_no2 + 1, d_port->port [e->port_no2].name
420 444
 		);
421 445
 		break;
422 446
 	case PARSE_DIR:
423 447
 		printf("%sset %s %d \"%s\" direction to %s\n",
424 448
 			prefix,
425 449
 			e->cmd->port_id1,
426
-			e->port_no1, s_port->port[e->port_no1 - 1].name,
450
+			e->port_no1 + 1, s_port->port[e->port_no1].name,
427 451
 			dir2txt(e->direction)
428 452
 		);
429 453
 		break;

+ 1
- 0
cmd.h View File

@@ -73,6 +73,7 @@ struct vcmd_entry {
73 73
 	bool			do_lock;
74 74
 	enum port_lock	lock;
75 75
 	enum serial_dir	direction;
76
+	bool			clear_port;
76 77
 };
77 78
 
78 79
 void prepare_cmd_entry(struct videohub_data *d, struct vcmd_entry *e);

+ 4
- 0
test/run View File

@@ -58,6 +58,10 @@ videohubctrl --test-input test/input-00.txt \
58 58
 	--se-dir 6 in \
59 59
 	--se-dir 7 out \
60 60
 	--se-dir 8 out --se-dir 8 auto \
61
+	--se-input 4 5 \
62
+	--se-input 6 7 \
63
+	--se-clear 4 \
64
+	--se-clear "Serial 6" \
61 65
 $@ &> test/test-04.out
62 66
 check test/test-04 "Test multiple configuration commands"
63 67
 

+ 2
- 2
test/test-03.ok View File

@@ -62,8 +62,8 @@ videohub: set monitoring output 1 "Monitor 1" to read from video input 1 "Window
62 62
 videohub: set monitoring output 2 "Monitor 2" to read from video input 2 "Windows 2"
63 63
 videohub: set monitoring output 3 "Monitor 3" to read from video input 3 "Windows 3"
64 64
 videohub: set monitoring output 4 "Monitor 4" to read from video input 4 "Windows 4 HD"
65
-videohub: set serial 1 "Serial Ctrl 1" to read from serial 3 "Deck 3"
66
-videohub: set serial 2 "Serial Ctrl 2" to read from serial 4 "Deck 4"
65
+videohub: connect serial 1 "Serial Ctrl 1" to serial 3 "Deck 3"
66
+videohub: connect serial 2 "Serial Ctrl 2" to serial 4 "Deck 4"
67 67
 videohub: set serial 1 "Serial Ctrl 1" direction to IN (Workstation)
68 68
 videohub: set serial 2 "Serial Ctrl 2" direction to AUTO
69 69
 videohub: set serial 3 "Deck 3" direction to OUT (Deck)

+ 5
- 1
test/test-04.ok View File

@@ -20,11 +20,15 @@ videohub: rename serial 1 "Serial Ctrl 1" to "Ren Ctrl 1"
20 20
 videohub: rename serial 3 "Deck 3" to "Ren Deck 3"
21 21
 videohub: unlock serial 1 "Ren Ctrl 1"
22 22
 videohub: lock serial 2 "Serial Ctrl 2"
23
-videohub: set serial 2 "Serial Ctrl 2" to read from serial 1 "Ren Ctrl 1"
23
+videohub: connect serial 2 "Serial Ctrl 2" to serial 1 "Ren Ctrl 1"
24 24
 videohub: set serial 6 "Serial 6" direction to IN (Workstation)
25 25
 videohub: set serial 7 "Serial 7" direction to OUT (Deck)
26 26
 videohub: set serial 8 "Serial 8" direction to OUT (Deck)
27 27
 videohub: set serial 8 "Serial 8" direction to AUTO
28
+videohub: connect serial 4 "Deck 4" to serial 5 "Serial 5"
29
+videohub: connect serial 6 "Serial 6" to serial 7 "Serial 7"
30
+videohub: disconnect serial 4 "Deck 4"
31
+videohub: disconnect serial 6 "Serial 6"
28 32
 Device info
29 33
   -----------------------------------------------------------
30 34
   | Device address             | sdi-matrix                 |

+ 6
- 2
videohubctrl.1 View File

@@ -129,8 +129,12 @@ else the port would be forcefully unlocked.
129 129
 \fB\-\-se\-name\fR <ser_X> <name>
130 130
 Set serial port X name.
131 131
 .TP
132
-\fB\-\-se\-input\fR <ser_X> <ser_Y>
133
-Connect serial port X to serial port Y.
132
+\fB\-\-se\-connect\fR <ser_X> <ser_Y>
133
+Connect serial port X to serial port Y. This option have two aliases \fB\-\-se\-input\fR
134
+and \fB\-\-se\-route\fR.
135
+.TP
136
+\fB\-\-se\-clear\fR <ser_X>
137
+Disconnect serial port X from serial port Y.
134 138
 .TP
135 139
 \fB\-\-se\-lock\fR <ser_X>
136 140
 Lock serial port X.

+ 15
- 1
videohubctrl.c View File

@@ -78,10 +78,12 @@ static const struct option long_options[] = {
78 78
 	{ "mo-unlock",			required_argument, NULL, 3004 },
79 79
 	{ "se-name",			required_argument, NULL, 4001 },
80 80
 	{ "se-input",			required_argument, NULL, 4002 },
81
+	{ "se-connect",			required_argument, NULL, 4002 }, // Alias of --se-input
81 82
 	{ "se-route",			required_argument, NULL, 4002 }, // Alias of --se-input
82 83
 	{ "se-lock",			required_argument, NULL, 4003 },
83 84
 	{ "se-unlock",			required_argument, NULL, 4004 },
84 85
 	{ "se-dir",				required_argument, NULL, 4005 },
86
+	{ "se-clear",			required_argument, NULL, 4006 },
85 87
 	{ 0, 0, 0, 0 }
86 88
 };
87 89
 
@@ -125,7 +127,8 @@ static void show_help(struct videohub_data *data) {
125 127
 	printf("\n");
126 128
 	printf("Serial ports configuration:\n");
127 129
 	printf(" --se-name <ser_X> <name>   | Set serial port X name.\n");
128
-	printf(" --se-input <ser_X> <ser_Y> | Connect serial X to serial Y.\n");
130
+	printf(" --se-connect <ser_X> <ser_Y> | Connect serial X to serial Y.\n");
131
+	printf(" --se-clear <ser_X>         | Disconnect serial port X from serial Y.\n");
129 132
 	printf(" --se-lock <ser_X>          | Lock serial port X.\n");
130 133
 	printf(" --se-unlock <ser_X>        | Unlock serial port X.\n");
131 134
 	printf(" --se-dir <ser_X> <dir>     | Set serial port X direction.\n");
@@ -169,6 +172,16 @@ static void parse_cmd2(int argc, char **argv, enum vcmd vcmd) {
169 172
 	num_parsed_cmds++;
170 173
 }
171 174
 
175
+static void parse_cmd2s(int argc, char **argv, enum vcmd vcmd) {
176
+	check_num_parsed_cmds();
177
+	struct vcmd_entry *c = &parsed_cmds.entry[num_parsed_cmds];
178
+	c->cmd = &videohub_commands[vcmd];
179
+	c->param1 = optarg;
180
+	c->param2 = "1"; // Fake
181
+	c->clear_port = true;
182
+	num_parsed_cmds++;
183
+}
184
+
172 185
 static void parse_cmd1(int argc, char **argv, enum vcmd vcmd, bool do_lock) {
173 186
 	check_num_parsed_cmds();
174 187
 	struct vcmd_entry *c = &parsed_cmds.entry[num_parsed_cmds];
@@ -247,6 +260,7 @@ static void parse_options(struct videohub_data *data, int argc, char **argv) {
247 260
 			case 4003: parse_cmd1(argc, argv, CMD_SERIAL_PORT_LOCKS, true); break; // --se-lock
248 261
 			case 4004: parse_cmd1(argc, argv, CMD_SERIAL_PORT_LOCKS, false); break; // --se-unlock
249 262
 			case 4005: parse_cmd2(argc, argv, CMD_SERIAL_PORT_DIRECTIONS); break; // --se-dir
263
+			case 4006: parse_cmd2s(argc, argv, CMD_SERIAL_PORT_ROUTING); break; // --se-clear
250 264
 			case 'H': // --help
251 265
 				show_help(data);
252 266
 				exit(EXIT_SUCCESS);

Loading…
Cancel
Save