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
 xxxx-xx-xx : Version 0.5-dev
2
 xxxx-xx-xx : Version 0.5-dev
3
  * Add missing documentation for --list-moutputs parameter.
3
  * Add missing documentation for --list-moutputs parameter.
4
  * Add support for serial ports (names, routing, locks and directions),
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
 2014-11-30 : Version 0.4
8
 2014-11-30 : Version 0.4
8
  * Add videohubctrl(1) man page.
9
  * Add videohubctrl(1) man page.

+ 2
- 1
README View File

71
 
71
 
72
 Serial ports configuration:
72
 Serial ports configuration:
73
  --se-name <ser_X> <name>   | Set serial port X name.
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
  --se-lock <ser_X>          | Lock serial port X.
76
  --se-lock <ser_X>          | Lock serial port X.
76
  --se-unlock <ser_X>        | Unlock serial port X.
77
  --se-unlock <ser_X>        | Unlock serial port X.
77
  --se-dir <ser_X> <dir>     | Set serial port X direction.
78
  --se-dir <ser_X> <dir>     | Set serial port X direction.

+ 35
- 11
cmd.c View File

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
 	if (e->cmd->type == PARSE_LOCK) {
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
 	switch (e->cmd->type) {
377
 	switch (e->cmd->type) {
372
 	case PARSE_LABEL:
378
 	case PARSE_LABEL:
373
 		snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
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
 		break;
381
 		break;
376
 	case PARSE_LOCK:
382
 	case PARSE_LOCK:
377
 		snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
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
 		break;
385
 		break;
380
 	case PARSE_ROUTE:
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
 		break;
389
 		break;
384
 	case PARSE_DIR:
390
 	case PARSE_DIR:
385
 		snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
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
 		break;
393
 		break;
388
 	default: break;
394
 	default: break;
389
 	}
395
 	}
398
 		printf("%srename %s %d \"%s\" to \"%s\"\n",
404
 		printf("%srename %s %d \"%s\" to \"%s\"\n",
399
 			prefix,
405
 			prefix,
400
 			e->cmd->port_id1,
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
 			e->param2
408
 			e->param2
403
 		);
409
 		);
404
 		break;
410
 		break;
407
 			prefix,
413
 			prefix,
408
 			e->do_lock ? "lock" : (e->lock == PORT_LOCKED_OTHER ? "force unlock" : "unlock"),
414
 			e->do_lock ? "lock" : (e->lock == PORT_LOCKED_OTHER ? "force unlock" : "unlock"),
409
 			e->cmd->port_id1,
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
 		break;
418
 		break;
413
 	case PARSE_ROUTE:
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
 		printf("%sset %s %d \"%s\" to read from %s %d \"%s\"\n",
438
 		printf("%sset %s %d \"%s\" to read from %s %d \"%s\"\n",
415
 			prefix,
439
 			prefix,
416
 			e->cmd->port_id1,
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
 			e->cmd->port_id2,
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
 		break;
445
 		break;
422
 	case PARSE_DIR:
446
 	case PARSE_DIR:
423
 		printf("%sset %s %d \"%s\" direction to %s\n",
447
 		printf("%sset %s %d \"%s\" direction to %s\n",
424
 			prefix,
448
 			prefix,
425
 			e->cmd->port_id1,
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
 			dir2txt(e->direction)
451
 			dir2txt(e->direction)
428
 		);
452
 		);
429
 		break;
453
 		break;

+ 1
- 0
cmd.h View File

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

+ 4
- 0
test/run View File

58
 	--se-dir 6 in \
58
 	--se-dir 6 in \
59
 	--se-dir 7 out \
59
 	--se-dir 7 out \
60
 	--se-dir 8 out --se-dir 8 auto \
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
 $@ &> test/test-04.out
65
 $@ &> test/test-04.out
62
 check test/test-04 "Test multiple configuration commands"
66
 check test/test-04 "Test multiple configuration commands"
63
 
67
 

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

62
 videohub: set monitoring output 2 "Monitor 2" to read from video input 2 "Windows 2"
62
 videohub: set monitoring output 2 "Monitor 2" to read from video input 2 "Windows 2"
63
 videohub: set monitoring output 3 "Monitor 3" to read from video input 3 "Windows 3"
63
 videohub: set monitoring output 3 "Monitor 3" to read from video input 3 "Windows 3"
64
 videohub: set monitoring output 4 "Monitor 4" to read from video input 4 "Windows 4 HD"
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
 videohub: set serial 1 "Serial Ctrl 1" direction to IN (Workstation)
67
 videohub: set serial 1 "Serial Ctrl 1" direction to IN (Workstation)
68
 videohub: set serial 2 "Serial Ctrl 2" direction to AUTO
68
 videohub: set serial 2 "Serial Ctrl 2" direction to AUTO
69
 videohub: set serial 3 "Deck 3" direction to OUT (Deck)
69
 videohub: set serial 3 "Deck 3" direction to OUT (Deck)

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

20
 videohub: rename serial 3 "Deck 3" to "Ren Deck 3"
20
 videohub: rename serial 3 "Deck 3" to "Ren Deck 3"
21
 videohub: unlock serial 1 "Ren Ctrl 1"
21
 videohub: unlock serial 1 "Ren Ctrl 1"
22
 videohub: lock serial 2 "Serial Ctrl 2"
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
 videohub: set serial 6 "Serial 6" direction to IN (Workstation)
24
 videohub: set serial 6 "Serial 6" direction to IN (Workstation)
25
 videohub: set serial 7 "Serial 7" direction to OUT (Deck)
25
 videohub: set serial 7 "Serial 7" direction to OUT (Deck)
26
 videohub: set serial 8 "Serial 8" direction to OUT (Deck)
26
 videohub: set serial 8 "Serial 8" direction to OUT (Deck)
27
 videohub: set serial 8 "Serial 8" direction to AUTO
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
 Device info
32
 Device info
29
   -----------------------------------------------------------
33
   -----------------------------------------------------------
30
   | Device address             | sdi-matrix                 |
34
   | Device address             | sdi-matrix                 |

+ 6
- 2
videohubctrl.1 View File

129
 \fB\-\-se\-name\fR <ser_X> <name>
129
 \fB\-\-se\-name\fR <ser_X> <name>
130
 Set serial port X name.
130
 Set serial port X name.
131
 .TP
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
 .TP
138
 .TP
135
 \fB\-\-se\-lock\fR <ser_X>
139
 \fB\-\-se\-lock\fR <ser_X>
136
 Lock serial port X.
140
 Lock serial port X.

+ 15
- 1
videohubctrl.c View File

78
 	{ "mo-unlock",			required_argument, NULL, 3004 },
78
 	{ "mo-unlock",			required_argument, NULL, 3004 },
79
 	{ "se-name",			required_argument, NULL, 4001 },
79
 	{ "se-name",			required_argument, NULL, 4001 },
80
 	{ "se-input",			required_argument, NULL, 4002 },
80
 	{ "se-input",			required_argument, NULL, 4002 },
81
+	{ "se-connect",			required_argument, NULL, 4002 }, // Alias of --se-input
81
 	{ "se-route",			required_argument, NULL, 4002 }, // Alias of --se-input
82
 	{ "se-route",			required_argument, NULL, 4002 }, // Alias of --se-input
82
 	{ "se-lock",			required_argument, NULL, 4003 },
83
 	{ "se-lock",			required_argument, NULL, 4003 },
83
 	{ "se-unlock",			required_argument, NULL, 4004 },
84
 	{ "se-unlock",			required_argument, NULL, 4004 },
84
 	{ "se-dir",				required_argument, NULL, 4005 },
85
 	{ "se-dir",				required_argument, NULL, 4005 },
86
+	{ "se-clear",			required_argument, NULL, 4006 },
85
 	{ 0, 0, 0, 0 }
87
 	{ 0, 0, 0, 0 }
86
 };
88
 };
87
 
89
 
125
 	printf("\n");
127
 	printf("\n");
126
 	printf("Serial ports configuration:\n");
128
 	printf("Serial ports configuration:\n");
127
 	printf(" --se-name <ser_X> <name>   | Set serial port X name.\n");
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
 	printf(" --se-lock <ser_X>          | Lock serial port X.\n");
132
 	printf(" --se-lock <ser_X>          | Lock serial port X.\n");
130
 	printf(" --se-unlock <ser_X>        | Unlock serial port X.\n");
133
 	printf(" --se-unlock <ser_X>        | Unlock serial port X.\n");
131
 	printf(" --se-dir <ser_X> <dir>     | Set serial port X direction.\n");
134
 	printf(" --se-dir <ser_X> <dir>     | Set serial port X direction.\n");
169
 	num_parsed_cmds++;
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
 static void parse_cmd1(int argc, char **argv, enum vcmd vcmd, bool do_lock) {
185
 static void parse_cmd1(int argc, char **argv, enum vcmd vcmd, bool do_lock) {
173
 	check_num_parsed_cmds();
186
 	check_num_parsed_cmds();
174
 	struct vcmd_entry *c = &parsed_cmds.entry[num_parsed_cmds];
187
 	struct vcmd_entry *c = &parsed_cmds.entry[num_parsed_cmds];
247
 			case 4003: parse_cmd1(argc, argv, CMD_SERIAL_PORT_LOCKS, true); break; // --se-lock
260
 			case 4003: parse_cmd1(argc, argv, CMD_SERIAL_PORT_LOCKS, true); break; // --se-lock
248
 			case 4004: parse_cmd1(argc, argv, CMD_SERIAL_PORT_LOCKS, false); break; // --se-unlock
261
 			case 4004: parse_cmd1(argc, argv, CMD_SERIAL_PORT_LOCKS, false); break; // --se-unlock
249
 			case 4005: parse_cmd2(argc, argv, CMD_SERIAL_PORT_DIRECTIONS); break; // --se-dir
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
 			case 'H': // --help
264
 			case 'H': // --help
251
 				show_help(data);
265
 				show_help(data);
252
 				exit(EXIT_SUCCESS);
266
 				exit(EXIT_SUCCESS);

Loading…
Cancel
Save