videohubctrl can be used to control Blackmagic Design Videohub SDI router device over the network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmd.c 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /*
  2. * === Commands processing ===
  3. *
  4. * Blackmagic Design Videohub control application
  5. * Copyright (C) 2014 Unix Solutions Ltd.
  6. * Written by Georgi Chorbadzhiyski
  7. *
  8. * Released under MIT license.
  9. * See LICENSE-MIT.txt for license terms.
  10. *
  11. */
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <stddef.h>
  15. #include <string.h>
  16. #include "data.h"
  17. #include "cmd.h"
  18. #include "util.h"
  19. const char *videohub_commands_text[NUM_COMMANDS] = {
  20. [CMD_PROTOCOL_PREAMBLE] = "PROTOCOL PREAMBLE",
  21. [CMD_VIDEOHUB_DEVICE] = "VIDEOHUB DEVICE",
  22. [CMD_CONFIGURATION] = "CONFIGURATION",
  23. [CMD_INPUT_LABELS] = "INPUT LABELS",
  24. [CMD_OUTPUT_LABELS] = "OUTPUT LABELS",
  25. [CMD_VIDEO_OUTPUT_LOCKS] = "VIDEO OUTPUT LOCKS",
  26. [CMD_VIDEO_OUTPUT_ROUTING] = "VIDEO OUTPUT ROUTING",
  27. [CMD_VIDEO_INPUT_STATUS] = "VIDEO INPUT STATUS",
  28. [CMD_VIDEO_OUTPUT_STATUS] = "VIDEO OUTPUT STATUS",
  29. [CMD_MONITORING_OUTPUT_LABELS] = "MONITORING OUTPUT LABELS",
  30. [CMD_MONITORING_OUTPUT_LOCKS] = "MONITORING OUTPUT LOCKS",
  31. [CMD_MONITORING_OUTPUT_ROUTING] = "VIDEO MONITORING OUTPUT ROUTING",
  32. [CMD_SERIAL_PORT_LABELS] = "SERIAL PORT LABELS",
  33. [CMD_SERIAL_PORT_ROUTING] = "SERIAL PORT ROUTING",
  34. [CMD_SERIAL_PORT_LOCKS] = "SERIAL PORT LOCKS",
  35. [CMD_SERIAL_PORT_STATUS] = "SERIAL PORT STATUS",
  36. [CMD_SERIAL_PORT_DIRECTIONS] = "SERIAL PORT DIRECTIONS",
  37. [CMD_PROCESSING_UNIT_ROUTING]= "PROCESSING UNIT ROUTING",
  38. [CMD_PROCESSING_UNIT_LOCKS] = "PROCESSING UNIT LOCKS",
  39. [CMD_FRAME_LABELS] = "FRAME LABELS",
  40. [CMD_FRAME_BUFFER_ROUTING] = "FRAME BUFFER ROUTING",
  41. [CMD_FRAME_BUFFER_LOCKS] = "FRAME BUFFER LOCKS",
  42. [CMD_PING] = "PING",
  43. [CMD_ACK] = "ACK",
  44. [CMD_NAK] = "NAK",
  45. };
  46. #define OFS(X) offsetof(struct videohub_data, X)
  47. struct videohub_commands videohub_commands[NUM_COMMANDS] = {
  48. [CMD_PROTOCOL_PREAMBLE] = { .cmd = CMD_PROTOCOL_PREAMBLE , .type = PARSE_CUSTOM },
  49. [CMD_VIDEOHUB_DEVICE] = { .cmd = CMD_VIDEOHUB_DEVICE , .type = PARSE_CUSTOM },
  50. [CMD_CONFIGURATION] = { .cmd = CMD_CONFIGURATION , .type = PARSE_CUSTOM },
  51. [CMD_INPUT_LABELS] = { .cmd = CMD_INPUT_LABELS , .type = PARSE_LABEL,
  52. .ports1 = OFS(inputs),
  53. .port_id1 = "video input",
  54. .opt_prefix = "in",
  55. },
  56. [CMD_OUTPUT_LABELS] = { .cmd = CMD_OUTPUT_LABELS , .type = PARSE_LABEL,
  57. .ports1 = OFS(outputs),
  58. .port_id1 = "video output",
  59. .opt_prefix = "out",
  60. },
  61. [CMD_VIDEO_OUTPUT_LOCKS] = { .cmd = CMD_VIDEO_OUTPUT_LOCKS , .type = PARSE_LOCK,
  62. .ports1 = OFS(outputs),
  63. .port_id1 = "video output",
  64. .opt_prefix = "out",
  65. },
  66. [CMD_VIDEO_OUTPUT_ROUTING] = { .cmd = CMD_VIDEO_OUTPUT_ROUTING, .type = PARSE_ROUTE,
  67. .ports1 = OFS(outputs),
  68. .ports2 = OFS(inputs),
  69. .port_id1 = "video output",
  70. .port_id2 = "video input",
  71. .opt_prefix = "out",
  72. },
  73. [CMD_VIDEO_INPUT_STATUS] = { .cmd = CMD_VIDEO_INPUT_STATUS , .type = PARSE_STATUS,
  74. .ports1 = OFS(inputs),
  75. .port_id1 = "video input",
  76. .opt_prefix = "in",
  77. },
  78. [CMD_VIDEO_OUTPUT_STATUS] = { .cmd = CMD_VIDEO_OUTPUT_STATUS , .type = PARSE_STATUS,
  79. .ports1 = OFS(outputs),
  80. .port_id1 = "video output",
  81. .opt_prefix = "out",
  82. },
  83. [CMD_MONITORING_OUTPUT_LABELS] = { .cmd = CMD_MONITORING_OUTPUT_LABELS , .type = PARSE_LABEL,
  84. .ports1 = OFS(mon_outputs),
  85. .port_id1 = "monitoring output",
  86. .opt_prefix = "mon",
  87. },
  88. [CMD_MONITORING_OUTPUT_LOCKS] = { .cmd = CMD_MONITORING_OUTPUT_LOCKS , .type = PARSE_LOCK,
  89. .ports1 = OFS(mon_outputs),
  90. .port_id1 = "monitoring output",
  91. .opt_prefix = "mon",
  92. },
  93. [CMD_MONITORING_OUTPUT_ROUTING] = { .cmd = CMD_MONITORING_OUTPUT_ROUTING, .type = PARSE_ROUTE,
  94. .ports1 = OFS(mon_outputs),
  95. .ports2 = OFS(inputs),
  96. .port_id1 = "monitoring output",
  97. .port_id2 = "video input",
  98. .opt_prefix = "mon",
  99. },
  100. [CMD_SERIAL_PORT_LABELS] = { .cmd = CMD_SERIAL_PORT_LABELS, .type = PARSE_LABEL,
  101. .ports1 = OFS(serial),
  102. .port_id1 = "serial",
  103. .opt_prefix = "ser",
  104. },
  105. [CMD_SERIAL_PORT_LOCKS] = { .cmd = CMD_SERIAL_PORT_LOCKS , .type = PARSE_LOCK,
  106. .ports1 = OFS(serial),
  107. .port_id1 = "serial",
  108. .opt_prefix = "ser",
  109. },
  110. [CMD_SERIAL_PORT_ROUTING] = { .cmd = CMD_SERIAL_PORT_ROUTING, .type = PARSE_ROUTE,
  111. .ports1 = OFS(serial),
  112. .ports2 = OFS(serial),
  113. .port_id1 = "serial",
  114. .port_id2 = "serial",
  115. .opt_prefix = "ser",
  116. .allow_disconnect = true,
  117. },
  118. [CMD_SERIAL_PORT_STATUS] = { .cmd = CMD_SERIAL_PORT_STATUS , .type = PARSE_STATUS,
  119. .ports1 = OFS(serial),
  120. .port_id1 = "serial",
  121. .opt_prefix = "ser",
  122. },
  123. [CMD_SERIAL_PORT_DIRECTIONS] = { .cmd = CMD_SERIAL_PORT_DIRECTIONS, .type = PARSE_DIR,
  124. .ports1 = OFS(serial),
  125. .port_id1 = "serial",
  126. .opt_prefix = "ser",
  127. },
  128. [CMD_PROCESSING_UNIT_ROUTING] = { .cmd = CMD_PROCESSING_UNIT_ROUTING, .type = PARSE_ROUTE,
  129. .ports1 = OFS(proc_units),
  130. .ports2 = OFS(inputs),
  131. .port_id1 = "proc unit",
  132. .port_id2 = "input",
  133. .opt_prefix = "pu",
  134. .allow_disconnect = true,
  135. },
  136. [CMD_PROCESSING_UNIT_LOCKS] = { .cmd = CMD_PROCESSING_UNIT_LOCKS, .type = PARSE_LOCK,
  137. .ports1 = OFS(proc_units),
  138. .port_id1 = "proc unit",
  139. .opt_prefix = "pu",
  140. },
  141. [CMD_FRAME_LABELS] = { .cmd = CMD_FRAME_LABELS, .type = PARSE_LABEL,
  142. .ports1 = OFS(frames),
  143. .port_id1 = "frame",
  144. .opt_prefix = "fr",
  145. },
  146. [CMD_FRAME_BUFFER_ROUTING] = { .cmd = CMD_FRAME_BUFFER_ROUTING, .type = PARSE_ROUTE,
  147. .ports1 = OFS(frames),
  148. .ports2 = OFS(outputs),
  149. .port_id1 = "frame",
  150. .port_id2 = "output",
  151. .opt_prefix = "fr",
  152. .allow_disconnect = true,
  153. },
  154. [CMD_FRAME_BUFFER_LOCKS] = { .cmd = CMD_FRAME_BUFFER_LOCKS, .type = PARSE_LOCK,
  155. .ports1 = OFS(frames),
  156. .port_id1 = "frame",
  157. .opt_prefix = "fr",
  158. },
  159. [CMD_PING] = { .cmd = CMD_PING , .type = PARSE_NONE },
  160. [CMD_ACK] = { .cmd = CMD_ACK , .type = PARSE_NONE },
  161. [CMD_NAK] = { .cmd = CMD_NAK , .type = PARSE_NONE },
  162. };
  163. static char *parse_text(char *line, char *cmd) {
  164. char *parsed_text = strstr(line, cmd);
  165. if (parsed_text == line) {
  166. return parsed_text + strlen(cmd);
  167. }
  168. return NULL;
  169. }
  170. bool parse_command(struct videohub_data *d, char *cmd) {
  171. unsigned int i;
  172. bool ret = true;
  173. if (!strlen(cmd))
  174. return false;
  175. struct videohub_commands *v = NULL;
  176. const char *cmd_txt = NULL;
  177. for (i = 0; i < NUM_COMMANDS; i++) {
  178. const char *cmd_text = videohub_commands_text[i];
  179. if (strstr(cmd, cmd_text) == cmd) {
  180. v = &videohub_commands[i];
  181. cmd_txt = videohub_commands_text[i];
  182. break;
  183. }
  184. }
  185. if (!v) {
  186. q("WARNING: Videohub sent unknown command!\n");
  187. q(" Please report this command to author's email: georgi@unixsol.org\n");
  188. q(" You may use -q or --quiet to suppress the message.\n");
  189. q("---------8<-----------8<----------- cut here ---------8<------------8<---------\n");
  190. q("%s\n", cmd);
  191. q("---------8<-----------8<----------- cut here ---------8<------------8<---------\n");
  192. return false;
  193. }
  194. d("debug: Got '%s' command.\n", cmd_txt);
  195. if (debug > 1)
  196. d("----\n%s\n----\n", cmd);
  197. struct port_set *s_port = !v->ports1 ? NULL : (void *)d + v->ports1;
  198. struct port_set *d_port = !v->ports2 ? NULL : (void *)d + v->ports2;
  199. char *p, *cmd_data = xstrdup( cmd + strlen(cmd_txt) + 2 ); // +2 to compensate for :\n at the end of the command
  200. // Split line by line
  201. char *line, *saveptr = NULL;
  202. for(i = 0, line = strtok_r(cmd_data, "\n", &saveptr); line; line = strtok_r(NULL, "\n", &saveptr), i++) {
  203. // Parse command data response
  204. unsigned int port_num = 0;
  205. unsigned int dest_port_num = 0;
  206. char *port_data = NULL;
  207. if (v->type != PARSE_NONE && v->type != PARSE_CUSTOM) {
  208. port_data = strchr(line, ' ');
  209. if (!port_data)
  210. continue;
  211. port_data[0] = '\0'; // Separate port_num from port_data
  212. port_data++;
  213. port_num = strtoul(line, NULL, 10);
  214. if (port_num + 1 > s_port->num) {
  215. q("WARNING: %s: invalid %s port %u (valid 0..%u)\n", cmd_txt,
  216. v->port_id1, port_num, s_port->num - 1);
  217. continue;
  218. }
  219. }
  220. switch (v->type) {
  221. case PARSE_LABEL:
  222. snprintf(s_port->port[port_num].name, sizeof(s_port->port[port_num].name), "%s", port_data);
  223. break;
  224. case PARSE_STATUS:
  225. s_port->port[port_num].status = S_UNKNOWN;
  226. bool invalid_status = false;
  227. if (v->cmd == CMD_SERIAL_PORT_STATUS) {
  228. if (streq("RS422", port_data)) s_port->port[port_num].status = S_RS422;
  229. else if (streq("None", port_data)) s_port->port[port_num].status = S_NONE;
  230. else invalid_status = true;
  231. } else {
  232. if (streq("BNC", port_data)) s_port->port[port_num].status = S_BNC;
  233. else if (streq("Optical", port_data)) s_port->port[port_num].status = S_OPTICAL;
  234. else if (streq("None", port_data)) s_port->port[port_num].status = S_NONE;
  235. else if (streq("Thunderbolt", port_data)) s_port->port[port_num].status = S_THUNDERBOLT;
  236. else invalid_status = true;
  237. }
  238. if (invalid_status) {
  239. q("WARNING: %s command returned unknown status: '%s'\n", cmd_txt, port_data);
  240. q("Please report this line to author's email: georgi@unixsol.org\n");
  241. }
  242. break;
  243. case PARSE_DIR:
  244. s_port->port[port_num].direction = DIR_AUTO;
  245. if (streq("control", port_data)) s_port->port[port_num].direction = DIR_CONTROL;
  246. else if (streq("slave", port_data)) s_port->port[port_num].direction = DIR_SLAVE;
  247. else if (streq("auto", port_data)) s_port->port[port_num].direction = DIR_AUTO;
  248. else {
  249. q("WARNING: %s command returned unknown direction: '%s'\n", cmd_txt, port_data);
  250. q("Please report this line to author's email: georgi@unixsol.org\n");
  251. }
  252. break;
  253. case PARSE_ROUTE:
  254. dest_port_num = strtoul(port_data, NULL, 10);
  255. if (dest_port_num == NO_PORT) {
  256. if (v->allow_disconnect) {
  257. s_port->port[port_num].routed_to = dest_port_num;
  258. continue;
  259. } else {
  260. dest_port_num = port_num;
  261. }
  262. }
  263. if (dest_port_num + 1 > d_port->num) {
  264. q("WARNING: %s: invalid %s port %u (valid 0..%u)\n", cmd_txt,
  265. v->port_id2, dest_port_num, d_port->num - 1);
  266. continue;
  267. }
  268. s_port->port[port_num].routed_to = dest_port_num;
  269. break;
  270. case PARSE_LOCK:
  271. switch (port_data[0]) {
  272. case 'O': s_port->port[port_num].lock = PORT_LOCKED; break;
  273. case 'L': s_port->port[port_num].lock = PORT_LOCKED_OTHER; break;
  274. default : s_port->port[port_num].lock = PORT_UNLOCKED; break;
  275. }
  276. break;
  277. default: break;
  278. }
  279. // Parse custom commands
  280. switch (v->cmd) {
  281. case CMD_PROTOCOL_PREAMBLE:
  282. if ((p = parse_text(line, "Version: ")))
  283. snprintf(d->device.protocol_ver, sizeof(d->device.protocol_ver), "%s", p);
  284. break;
  285. case CMD_VIDEOHUB_DEVICE:
  286. if ((p = parse_text(line, "Device present: "))) {
  287. d->device.dev_present = streq(p, "true");
  288. d->device.needs_fw_update = streq(p, "needs_update");
  289. }
  290. else if ((p = parse_text(line, "Model name: ")))
  291. snprintf(d->device.model_name, sizeof(d->device.model_name), "%s", p);
  292. else if ((p = parse_text(line, "Friendly name: ")))
  293. snprintf(d->device.friendly_name, sizeof(d->device.friendly_name), "%s", p);
  294. else if ((p = parse_text(line, "Unique ID: ")))
  295. snprintf(d->device.unique_id, sizeof(d->device.unique_id) , "%s", p);
  296. else if ((p = parse_text(line, "Video inputs: ")))
  297. d->inputs.num = strtoul(p, NULL, 10);
  298. else if ((p = parse_text(line, "Video processing units: ")))
  299. d->proc_units.num = strtoul(p, NULL, 10);
  300. else if ((p = parse_text(line, "Video outputs: ")))
  301. d->outputs.num = strtoul(p, NULL, 10);
  302. else if ((p = parse_text(line, "Video monitoring outputs: ")))
  303. d->mon_outputs.num = strtoul(p, NULL, 10);
  304. else if ((p = parse_text(line, "Serial ports: "))) {
  305. d->serial.num = strtoul(p, NULL, 10);
  306. d->frames.num = d->serial.num;
  307. } else {
  308. q("WARNING: VIDEOHUB DEVICE command sent unknown line: '%s'\n", line);
  309. q("Please report this line to author's email: georgi@unixsol.org\n");
  310. }
  311. break;
  312. case CMD_CONFIGURATION:
  313. if ((p = parse_text(line, "Take Mode: "))) {
  314. d->device.conf_take_mode = streq(p, "true");
  315. }
  316. case CMD_NAK:
  317. ret = false;
  318. break;
  319. default: break;
  320. }
  321. }
  322. free(cmd_data);
  323. return ret;
  324. }
  325. int parse_text_buffer(struct videohub_data *d, char *cmd_buffer) {
  326. // The buffer contains only one command, no splitting is needed
  327. if (!strstr(cmd_buffer, "\n\n"))
  328. return parse_command(d, cmd_buffer);
  329. // Split commands and parse them one by one
  330. int ok_commands = 0;
  331. char *buf_copy = xstrdup(cmd_buffer);
  332. char *newcmd, *cmd = buf_copy;
  333. while(1) {
  334. newcmd = strstr(cmd, "\n\n"); // Find next command
  335. if (!newcmd) {
  336. if (parse_command(d, cmd)) // Parse current command
  337. ok_commands++;
  338. break;
  339. }
  340. newcmd[0] = '\0'; // Terminate previous command
  341. if (parse_command(d, cmd)) // Parse previous command
  342. ok_commands++;
  343. cmd = newcmd + 2; // Advance cmd to the next command
  344. }
  345. free(buf_copy);
  346. return ok_commands;
  347. }
  348. // Try to find port with certain name, return 0 on not found, pos + 1 is found
  349. static int get_port_by_name(struct port_set *p, char *name) {
  350. unsigned int i;
  351. for(i = 0; i < p->num; i++) {
  352. if (streq(name, p->port[i].name)) {
  353. return i + 1;
  354. }
  355. }
  356. return 0;
  357. }
  358. // Return 0 on error, number otherwise if it can parse the whole input
  359. static unsigned int my_atoi(char *txt) {
  360. char *endptr = NULL;
  361. if (!txt)
  362. return 0;
  363. unsigned int ret = strtoul(txt, &endptr, 10);
  364. if (endptr == txt || *endptr)
  365. return 0;
  366. return ret;
  367. }
  368. static void init_port_number(struct vcmd_param *p, struct port_set *port, const char *port_id) {
  369. p->port_no = my_atoi(p->param);
  370. if (!port) {
  371. die("impossible! port == NULL");
  372. return;
  373. }
  374. if (p->port_no == 0 || p->port_no > port->num) {
  375. p->port_no = get_port_by_name(port, p->param);
  376. if (!p->port_no)
  377. die("Unknown %s port number/name: %s", port_id, p->param);
  378. }
  379. }
  380. void prepare_cmd_entry(struct videohub_data *d, struct vcmd_entry *e) {
  381. struct port_set *s_port = !e->cmd->ports1 ? NULL : (void *)d + e->cmd->ports1;
  382. struct port_set *d_port = !e->cmd->ports2 ? NULL : (void *)d + e->cmd->ports2;
  383. if (e->cmd->type == PARSE_CUSTOM)
  384. return;
  385. // All command types needs parsing of the "source port"
  386. init_port_number(&e->p1, s_port, e->cmd->port_id1);
  387. // ROUTE type needs parsing of the "destination port"
  388. if (e->cmd->type == PARSE_ROUTE) {
  389. init_port_number(&e->p2, d_port, e->cmd->port_id2);
  390. }
  391. // Allow port_noX to be used as index into ->port[]
  392. e->p1.port_no -= 1;
  393. e->p2.port_no -= 1;
  394. if (e->clear_port)
  395. e->p2.port_no = NO_PORT;
  396. if (e->cmd->type == PARSE_LOCK) {
  397. e->lock = s_port->port[e->p1.port_no].lock;
  398. }
  399. }
  400. static char *dir2cmd(enum serial_dir dir) {
  401. switch (dir) {
  402. case DIR_CONTROL: return "control";
  403. case DIR_SLAVE : return "slave";
  404. case DIR_AUTO : return "auto";
  405. }
  406. return "auto";
  407. }
  408. static char *dir2txt(enum serial_dir dir) {
  409. switch (dir) {
  410. case DIR_CONTROL: return "IN (Workstation)";
  411. case DIR_SLAVE : return "OUT (Deck)";
  412. case DIR_AUTO : return "AUTO";
  413. }
  414. return "AUTO";
  415. }
  416. void format_cmd_text(struct vcmd_entry *e, char *buf, unsigned int bufsz) {
  417. if (e->cmd->cmd == CMD_VIDEOHUB_DEVICE) {
  418. snprintf(buf, bufsz, "%s:\n%s: %s\n\n", videohub_commands_text[e->cmd->cmd],
  419. e->p1.param, e->p2.param);
  420. return;
  421. }
  422. switch (e->cmd->type) {
  423. case PARSE_LABEL:
  424. snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
  425. e->p1.port_no, e->p2.param);
  426. break;
  427. case PARSE_LOCK:
  428. snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
  429. e->p1.port_no, e->do_lock ? "O" : (e->lock == PORT_LOCKED_OTHER ? "F" : "U"));
  430. break;
  431. case PARSE_ROUTE:
  432. snprintf(buf, bufsz, "%s:\n%u %d\n\n", videohub_commands_text[e->cmd->cmd],
  433. e->p1.port_no, (e->p2.port_no == NO_PORT ? -1 : (int)e->p2.port_no));
  434. break;
  435. case PARSE_DIR:
  436. snprintf(buf, bufsz, "%s:\n%u %s\n\n", videohub_commands_text[e->cmd->cmd],
  437. e->p1.port_no, dir2cmd(e->direction));
  438. break;
  439. default: break;
  440. }
  441. }
  442. void show_cmd(struct videohub_data *d, struct vcmd_entry *e) {
  443. struct port_set *s_port = !e->cmd->ports1 ? NULL : (void *)d + e->cmd->ports1;
  444. struct port_set *d_port = !e->cmd->ports2 ? NULL : (void *)d + e->cmd->ports2;
  445. const char *prefix = "videohub: ";
  446. if (e->cmd->cmd == CMD_VIDEOHUB_DEVICE) {
  447. printf("%sset device \"%s\" to \"%s\"\n",
  448. prefix,
  449. e->p1.param,
  450. e->p2.param
  451. );
  452. return;
  453. }
  454. switch (e->cmd->type) {
  455. case PARSE_LABEL:
  456. printf("%srename %s %d \"%s\" to \"%s\"\n",
  457. prefix,
  458. e->cmd->port_id1,
  459. e->p1.port_no + 1, s_port->port[e->p1.port_no].name,
  460. e->p2.param
  461. );
  462. break;
  463. case PARSE_LOCK:
  464. printf("%s%s %s %d \"%s\"\n",
  465. prefix,
  466. e->do_lock ? "lock" : (e->lock == PORT_LOCKED_OTHER ? "force unlock" : "unlock"),
  467. e->cmd->port_id1,
  468. e->p1.port_no + 1, s_port->port[e->p1.port_no].name
  469. );
  470. break;
  471. case PARSE_ROUTE:
  472. if (e->p2.port_no == NO_PORT) {
  473. printf("%sdisconnect %s %d \"%s\"\n",
  474. prefix,
  475. e->cmd->port_id1,
  476. e->p1.port_no + 1, s_port->port[e->p1.port_no].name
  477. );
  478. break;
  479. }
  480. if (e->cmd->allow_disconnect) {
  481. printf("%sconnect %s %d \"%s\" to %s %d \"%s\"\n",
  482. prefix,
  483. e->cmd->port_id1,
  484. e->p1.port_no + 1, s_port->port[e->p1.port_no].name,
  485. e->cmd->port_id2,
  486. e->p2.port_no + 1, d_port->port [e->p2.port_no].name
  487. );
  488. break;
  489. }
  490. if (e->reversed_args) {
  491. printf("%sset %s %d \"%s\" to go out of %s %d \"%s\"\n",
  492. prefix,
  493. e->cmd->port_id2,
  494. e->p2.port_no + 1, d_port->port[e->p2.port_no].name,
  495. e->cmd->port_id1,
  496. e->p1.port_no + 1, s_port->port [e->p1.port_no].name
  497. );
  498. break;
  499. }
  500. printf("%sset %s %d \"%s\" to read from %s %d \"%s\"\n",
  501. prefix,
  502. e->cmd->port_id1,
  503. e->p1.port_no + 1, s_port->port[e->p1.port_no].name,
  504. e->cmd->port_id2,
  505. e->p2.port_no + 1, d_port->port [e->p2.port_no].name
  506. );
  507. break;
  508. case PARSE_DIR:
  509. printf("%sset %s %d \"%s\" direction to %s\n",
  510. prefix,
  511. e->cmd->port_id1,
  512. e->p1.port_no + 1, s_port->port[e->p1.port_no].name,
  513. dir2txt(e->direction)
  514. );
  515. break;
  516. default: break;
  517. }
  518. }