|
@@ -378,6 +378,15 @@ static unsigned int my_atoi(char *txt) {
|
378
|
378
|
return ret;
|
379
|
379
|
}
|
380
|
380
|
|
|
381
|
+static void init_port_number(struct vcmd_param *p, struct port_set *port, const char *port_id) {
|
|
382
|
+ p->port_no = my_atoi(p->param);
|
|
383
|
+ if (p->port_no == 0 || p->port_no > port->num) {
|
|
384
|
+ p->port_no = get_port_by_name(port, p->param);
|
|
385
|
+ if (!p->port_no)
|
|
386
|
+ die("Unknown %s port number/name: %s", port_id, p->param);
|
|
387
|
+ }
|
|
388
|
+}
|
|
389
|
+
|
381
|
390
|
void prepare_cmd_entry(struct videohub_data *d, struct vcmd_entry *e) {
|
382
|
391
|
struct port_set *s_port = !e->cmd->ports1 ? NULL : (void *)d + e->cmd->ports1;
|
383
|
392
|
struct port_set *d_port = !e->cmd->ports2 ? NULL : (void *)d + e->cmd->ports2;
|
|
@@ -386,31 +395,21 @@ void prepare_cmd_entry(struct videohub_data *d, struct vcmd_entry *e) {
|
386
|
395
|
return;
|
387
|
396
|
|
388
|
397
|
// All command types needs parsing of the "source port"
|
389
|
|
- e->port_no1 = my_atoi(e->param1);
|
390
|
|
- if (e->port_no1 == 0 || e->port_no1 > s_port->num) {
|
391
|
|
- e->port_no1 = get_port_by_name(s_port, e->param1);
|
392
|
|
- if (!e->port_no1)
|
393
|
|
- die("Unknown %s port number/name: %s", e->cmd->port_id1, e->param1);
|
394
|
|
- }
|
|
398
|
+ init_port_number(&e->p1, s_port, e->cmd->port_id1);
|
395
|
399
|
|
396
|
400
|
// ROUTE type needs parsing of the "destination port"
|
397
|
401
|
if (e->cmd->type == PARSE_ROUTE) {
|
398
|
|
- e->port_no2 = my_atoi(e->param2);
|
399
|
|
- if (e->port_no2 == 0 || e->port_no2 > d_port->num) {
|
400
|
|
- e->port_no2 = get_port_by_name(d_port, e->param2);
|
401
|
|
- if (!e->port_no2)
|
402
|
|
- die("Unknown %s port number/name: %s", e->cmd->port_id2, e->param2);
|
403
|
|
- }
|
|
402
|
+ init_port_number(&e->p2, d_port, e->cmd->port_id2);
|
404
|
403
|
}
|
405
|
404
|
|
406
|
405
|
// Allow port_noX to be used as index into ->port[]
|
407
|
|
- e->port_no1 -= 1;
|
408
|
|
- e->port_no2 -= 1;
|
|
406
|
+ e->p1.port_no -= 1;
|
|
407
|
+ e->p2.port_no -= 1;
|
409
|
408
|
if (e->clear_port)
|
410
|
|
- e->port_no2 = NO_PORT;
|
|
409
|
+ e->p2.port_no = NO_PORT;
|
411
|
410
|
|
412
|
411
|
if (e->cmd->type == PARSE_LOCK) {
|
413
|
|
- e->lock = s_port->port[e->port_no1].lock;
|
|
412
|
+ e->lock = s_port->port[e->p1.port_no].lock;
|
414
|
413
|
}
|
415
|
414
|
}
|
416
|
415
|
|
|
@@ -435,25 +434,25 @@ static char *dir2txt(enum serial_dir dir) {
|
435
|
434
|
void format_cmd_text(struct vcmd_entry *e, char *buf, unsigned int bufsz) {
|
436
|
435
|
if (e->cmd->cmd == CMD_VIDEOHUB_DEVICE) {
|
437
|
436
|
snprintf(buf, bufsz, "%s:\n%s: %s\n\n", videohub_commands_text[e->cmd->cmd],
|
438
|
|
- e->param1, e->param2);
|
|
437
|
+ e->p1.param, e->p2.param);
|
439
|
438
|
return;
|
440
|
439
|
}
|
441
|
440
|
switch (e->cmd->type) {
|
442
|
441
|
case PARSE_LABEL:
|
443
|
442
|
snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
|
444
|
|
- e->port_no1, e->param2);
|
|
443
|
+ e->p1.port_no, e->p2.param);
|
445
|
444
|
break;
|
446
|
445
|
case PARSE_LOCK:
|
447
|
446
|
snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
|
448
|
|
- e->port_no1, e->do_lock ? "O" : (e->lock == PORT_LOCKED_OTHER ? "F" : "U"));
|
|
447
|
+ e->p1.port_no, e->do_lock ? "O" : (e->lock == PORT_LOCKED_OTHER ? "F" : "U"));
|
449
|
448
|
break;
|
450
|
449
|
case PARSE_ROUTE:
|
451
|
450
|
snprintf(buf, bufsz, "%s:\n%u %d\n\n", videohub_commands_text[e->cmd->cmd],
|
452
|
|
- e->port_no1, (e->port_no2 == NO_PORT ? -1 : (int)e->port_no2));
|
|
451
|
+ e->p1.port_no, (e->p2.port_no == NO_PORT ? -1 : (int)e->p2.port_no));
|
453
|
452
|
break;
|
454
|
453
|
case PARSE_DIR:
|
455
|
454
|
snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
|
456
|
|
- e->port_no1, dir2cmd(e->direction));
|
|
455
|
+ e->p1.port_no, dir2cmd(e->direction));
|
457
|
456
|
break;
|
458
|
457
|
default: break;
|
459
|
458
|
}
|
|
@@ -466,8 +465,8 @@ void show_cmd(struct videohub_data *d, struct vcmd_entry *e) {
|
466
|
465
|
if (e->cmd->cmd == CMD_VIDEOHUB_DEVICE) {
|
467
|
466
|
printf("%sset device \"%s\" to \"%s\"\n",
|
468
|
467
|
prefix,
|
469
|
|
- e->param1,
|
470
|
|
- e->param2
|
|
468
|
+ e->p1.param,
|
|
469
|
+ e->p2.param
|
471
|
470
|
);
|
472
|
471
|
return;
|
473
|
472
|
}
|
|
@@ -476,8 +475,8 @@ void show_cmd(struct videohub_data *d, struct vcmd_entry *e) {
|
476
|
475
|
printf("%srename %s %d \"%s\" to \"%s\"\n",
|
477
|
476
|
prefix,
|
478
|
477
|
e->cmd->port_id1,
|
479
|
|
- e->port_no1 + 1, s_port->port[e->port_no1].name,
|
480
|
|
- e->param2
|
|
478
|
+ e->p1.port_no + 1, s_port->port[e->p1.port_no].name,
|
|
479
|
+ e->p2.param
|
481
|
480
|
);
|
482
|
481
|
break;
|
483
|
482
|
case PARSE_LOCK:
|
|
@@ -485,15 +484,15 @@ void show_cmd(struct videohub_data *d, struct vcmd_entry *e) {
|
485
|
484
|
prefix,
|
486
|
485
|
e->do_lock ? "lock" : (e->lock == PORT_LOCKED_OTHER ? "force unlock" : "unlock"),
|
487
|
486
|
e->cmd->port_id1,
|
488
|
|
- e->port_no1 + 1, s_port->port[e->port_no1].name
|
|
487
|
+ e->p1.port_no + 1, s_port->port[e->p1.port_no].name
|
489
|
488
|
);
|
490
|
489
|
break;
|
491
|
490
|
case PARSE_ROUTE:
|
492
|
|
- if (e->port_no2 == NO_PORT) {
|
|
491
|
+ if (e->p2.port_no == NO_PORT) {
|
493
|
492
|
printf("%sdisconnect %s %d \"%s\"\n",
|
494
|
493
|
prefix,
|
495
|
494
|
e->cmd->port_id1,
|
496
|
|
- e->port_no1 + 1, s_port->port[e->port_no1].name
|
|
495
|
+ e->p1.port_no + 1, s_port->port[e->p1.port_no].name
|
497
|
496
|
);
|
498
|
497
|
break;
|
499
|
498
|
}
|
|
@@ -501,25 +500,25 @@ void show_cmd(struct videohub_data *d, struct vcmd_entry *e) {
|
501
|
500
|
printf("%sconnect %s %d \"%s\" to %s %d \"%s\"\n",
|
502
|
501
|
prefix,
|
503
|
502
|
e->cmd->port_id1,
|
504
|
|
- e->port_no1 + 1, s_port->port[e->port_no1].name,
|
|
503
|
+ e->p1.port_no + 1, s_port->port[e->p1.port_no].name,
|
505
|
504
|
e->cmd->port_id2,
|
506
|
|
- e->port_no2 + 1, d_port->port [e->port_no2].name
|
|
505
|
+ e->p2.port_no + 1, d_port->port [e->p2.port_no].name
|
507
|
506
|
);
|
508
|
507
|
break;
|
509
|
508
|
}
|
510
|
509
|
printf("%sset %s %d \"%s\" to read from %s %d \"%s\"\n",
|
511
|
510
|
prefix,
|
512
|
511
|
e->cmd->port_id1,
|
513
|
|
- e->port_no1 + 1, s_port->port[e->port_no1].name,
|
|
512
|
+ e->p1.port_no + 1, s_port->port[e->p1.port_no].name,
|
514
|
513
|
e->cmd->port_id2,
|
515
|
|
- e->port_no2 + 1, d_port->port [e->port_no2].name
|
|
514
|
+ e->p2.port_no + 1, d_port->port [e->p2.port_no].name
|
516
|
515
|
);
|
517
|
516
|
break;
|
518
|
517
|
case PARSE_DIR:
|
519
|
518
|
printf("%sset %s %d \"%s\" direction to %s\n",
|
520
|
519
|
prefix,
|
521
|
520
|
e->cmd->port_id1,
|
522
|
|
- e->port_no1 + 1, s_port->port[e->port_no1].name,
|
|
521
|
+ e->p1.port_no + 1, s_port->port[e->p1.port_no].name,
|
523
|
522
|
dir2txt(e->direction)
|
524
|
523
|
);
|
525
|
524
|
break;
|