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

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