Browse Source

Allow port routing to be canceled. It is needed for serial ports.

Georgi Chorbadzhiyski 9 years ago
parent
commit
6004840714
6 changed files with 31 additions and 14 deletions
  1. 9
    1
      cmd.c
  2. 1
    1
      data.h
  3. 8
    10
      display.c
  4. 4
    0
      test/input-00.txt
  5. 2
    2
      test/input-14.txt
  6. 7
    0
      videohubctrl.c

+ 9
- 1
cmd.c View File

@@ -210,13 +210,21 @@ bool parse_command(struct videohub_data *d, char *cmd) {
210 210
 			break;
211 211
 		case PARSE_ROUTE:
212 212
 			dest_port_num = strtoul(port_data, NULL, 10);
213
+			if (dest_port_num == NO_PORT) {
214
+				// Only serial port routing can be disabled with -1
215
+				if (v->cmd == CMD_SERIAL_PORT_ROUTING) {
216
+					s_port->port[port_num].routed_to = dest_port_num;
217
+					continue;
218
+				} else {
219
+					dest_port_num = port_num;
220
+				}
221
+			}
213 222
 			if (dest_port_num + 1 > d_port->num) {
214 223
 				q("WARNING: %s: invalid %s port %u (valid 0..%u)\n", cmd_txt,
215 224
 				  v->port_id2, dest_port_num, d_port->num - 1);
216 225
 				continue;
217 226
 			}
218 227
 			s_port->port[port_num].routed_to = dest_port_num;
219
-			s_port->port[port_num].routed_to_set = true;
220 228
 			break;
221 229
 		case PARSE_LOCK:
222 230
 			switch (port_data[0]) {

+ 1
- 1
data.h View File

@@ -18,6 +18,7 @@
18 18
 #define MAX_PORTS 288
19 19
 #define MAX_NAME_LEN 32
20 20
 #define MAX_RUN_CMDS (288 * 5)
21
+#define NO_PORT ((unsigned int) -1)
21 22
 
22 23
 struct device_desc {
23 24
 	bool			dev_present;
@@ -62,7 +63,6 @@ struct port {
62 63
 	//       auto - Automatic
63 64
 	enum serial_dir	direction;
64 65
 	unsigned int	routed_to;
65
-	bool			routed_to_set; // For serial ports
66 66
 	enum port_lock	lock;
67 67
 };
68 68
 

+ 8
- 10
display.c View File

@@ -80,7 +80,10 @@ void print_device_video_inputs(struct videohub_data *d) {
80 80
 		if (num_outputs == 0) {
81 81
 			printf("%-24s | %c |\n", "-", format_status(d->inputs.port[i].status));
82 82
 		} else {
83
-			printf("%-24s | %c |\n", d->outputs.port[routed_to].name, format_status(d->inputs.port[i].status));
83
+			printf("%-24s | %c |\n",
84
+				routed_to == NO_PORT ? "" : d->outputs.port[routed_to].name,
85
+				format_status(d->inputs.port[i].status)
86
+			);
84 87
 			bool first_skipped = false;
85 88
 			for(r = 0; r < d->outputs.num; r++) {
86 89
 				if (d->outputs.port[r].routed_to == i) {
@@ -120,7 +123,7 @@ void print_device_video_outputs(struct videohub_data *d) {
120 123
 			i + 1,
121 124
 			port_lock_symbol(d->outputs.port[i].lock),
122 125
 			d->outputs.port[i].name,
123
-			d->inputs.port[d->outputs.port[i].routed_to].name,
126
+			d->outputs.port[i].routed_to == NO_PORT ? "" : d->inputs.port[d->outputs.port[i].routed_to].name,
124 127
 			format_status(d->outputs.port[i].status)
125 128
 		);
126 129
 	}
@@ -141,7 +144,7 @@ void print_device_monitoring_outputs(struct videohub_data *d) {
141 144
 			i + 1,
142 145
 			port_lock_symbol(d->mon_outputs.port[i].lock),
143 146
 			d->mon_outputs.port[i].name,
144
-			d->inputs.port[d->mon_outputs.port[i].routed_to].name
147
+			d->mon_outputs.port[i].routed_to == NO_PORT ? "" : d->inputs.port[d->mon_outputs.port[i].routed_to].name
145 148
 		);
146 149
 	}
147 150
 	printf_line(len);
@@ -158,11 +161,9 @@ static char *dir2opt(enum serial_dir dir) {
158 161
 }
159 162
 
160 163
 void print_device_serial_ports(struct videohub_data *d) {
161
-	unsigned char port_seen[MAX_PORTS];
162 164
 	unsigned int i, len = 63;
163 165
 	if (!d->serial.num)
164 166
 		return;
165
-	memset(port_seen, 0, sizeof(port_seen));
166 167
 	printf("Serial ports\n");
167 168
 	printf_line(len);
168 169
 	printf("  | ## | x | Dir  | %-18s | %-18s | s |\n", "Serial port", "Connected serial");
@@ -173,12 +174,9 @@ void print_device_serial_ports(struct videohub_data *d) {
173 174
 			port_lock_symbol(d->serial.port[i].lock),
174 175
 			dir2opt(d->serial.port[i].direction),
175 176
 			d->serial.port[i].name,
176
-			(d->serial.port[i].routed_to_set && !port_seen[d->serial.port[i].routed_to]
177
-				? d->serial.port[d->serial.port[i].routed_to].name
178
-				: ""),
177
+			d->serial.port[i].routed_to == NO_PORT ? "" : d->serial.port[d->serial.port[i].routed_to].name,
179 178
 			format_status(d->serial.port[i].status)
180 179
 		);
181
-		port_seen[d->serial.port[i].routed_to]++;
182 180
 	}
183 181
 	printf_line(len);
184 182
 	printf("\n");
@@ -195,7 +193,7 @@ static void __print_opt(struct videohub_data *d, enum vcmd vcmd) {
195 193
 			printf("  --%s-name %2d \"%s\" \\\n", p, i + 1, s_port->port[i].name);
196 194
 			break;
197 195
 		case PARSE_ROUTE:
198
-			if (v->cmd == CMD_SERIAL_PORT_ROUTING && !s_port->port[i].routed_to_set)
196
+			if (s_port->port[i].routed_to == NO_PORT)
199 197
 				continue;
200 198
 			printf("  --%s-input %2d %2d \\\n", p, i + 1, s_port->port[i].routed_to + 1);
201 199
 			break;

+ 4
- 0
test/input-00.txt View File

@@ -139,6 +139,9 @@ SERIAL PORT LABELS:
139 139
 SERIAL PORT ROUTING:
140 140
 0 2
141 141
 1 3
142
+2 5
143
+3 -1
144
+2 -1
142 145
 
143 146
 SERIAL PORT LOCKS:
144 147
 0 O
@@ -163,3 +166,4 @@ SERIAL PORT DIRECTIONS:
163 166
 5 auto
164 167
 6 control
165 168
 7 slave
169
+

+ 2
- 2
test/input-14.txt View File

@@ -79,7 +79,7 @@ VIDEO OUTPUT ROUTING:
79 79
 10 10
80 80
 11 12
81 81
 12 11
82
-13 13
83
-14 14
82
+13 -1
83
+14 -1
84 84
 15 15
85 85
 

+ 7
- 0
videohubctrl.c View File

@@ -275,6 +275,12 @@ static void check_number_of_ports(struct port_set *p) {
275 275
 			p->num, ARRAY_SIZE(p->port));
276 276
 }
277 277
 
278
+static void reset_routed_to(struct port_set *p) {
279
+	unsigned int i;
280
+	for (i = 0; i < ARRAY_SIZE(p->port); i++)
281
+		p->port[i].routed_to = NO_PORT;
282
+}
283
+
278 284
 static void print_device_full(struct videohub_data *d) {
279 285
 	print_device_info(d);
280 286
 	print_device_video_inputs(d);
@@ -316,6 +322,7 @@ int main(int argc, char **argv) {
316 322
 			exit(EXIT_FAILURE);
317 323
 	}
318 324
 
325
+	reset_routed_to(&data->serial);
319 326
 	read_device_command_stream(data);
320 327
 
321 328
 	if (test_data)

Loading…
Cancel
Save