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 18KB

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