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
 			break;
210
 			break;
211
 		case PARSE_ROUTE:
211
 		case PARSE_ROUTE:
212
 			dest_port_num = strtoul(port_data, NULL, 10);
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
 			if (dest_port_num + 1 > d_port->num) {
222
 			if (dest_port_num + 1 > d_port->num) {
214
 				q("WARNING: %s: invalid %s port %u (valid 0..%u)\n", cmd_txt,
223
 				q("WARNING: %s: invalid %s port %u (valid 0..%u)\n", cmd_txt,
215
 				  v->port_id2, dest_port_num, d_port->num - 1);
224
 				  v->port_id2, dest_port_num, d_port->num - 1);
216
 				continue;
225
 				continue;
217
 			}
226
 			}
218
 			s_port->port[port_num].routed_to = dest_port_num;
227
 			s_port->port[port_num].routed_to = dest_port_num;
219
-			s_port->port[port_num].routed_to_set = true;
220
 			break;
228
 			break;
221
 		case PARSE_LOCK:
229
 		case PARSE_LOCK:
222
 			switch (port_data[0]) {
230
 			switch (port_data[0]) {

+ 1
- 1
data.h View File

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

+ 8
- 10
display.c View File

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

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

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

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

79
 10 10
79
 10 10
80
 11 12
80
 11 12
81
 12 11
81
 12 11
82
-13 13
83
-14 14
82
+13 -1
83
+14 -1
84
 15 15
84
 15 15
85
 
85
 

+ 7
- 0
videohubctrl.c View File

275
 			p->num, ARRAY_SIZE(p->port));
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
 static void print_device_full(struct videohub_data *d) {
284
 static void print_device_full(struct videohub_data *d) {
279
 	print_device_info(d);
285
 	print_device_info(d);
280
 	print_device_video_inputs(d);
286
 	print_device_video_inputs(d);
316
 			exit(EXIT_FAILURE);
322
 			exit(EXIT_FAILURE);
317
 	}
323
 	}
318
 
324
 
325
+	reset_routed_to(&data->serial);
319
 	read_device_command_stream(data);
326
 	read_device_command_stream(data);
320
 
327
 
321
 	if (test_data)
328
 	if (test_data)

Loading…
Cancel
Save