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.

videohubctrl.c 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. /*
  2. * Blackmagic Design Videohub control application
  3. * Copyright (C) 2014 Unix Solutions Ltd.
  4. * Written by Georgi Chorbadzhiyski
  5. *
  6. * Released under MIT license.
  7. * See LICENSE-MIT.txt for license terms.
  8. *
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <getopt.h>
  14. #include <unistd.h>
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17. #include <unistd.h>
  18. #include <errno.h>
  19. #include "data.h"
  20. #include "cmd.h"
  21. #include "net.h"
  22. #include "util.h"
  23. #include "display.h"
  24. #include "version.h"
  25. #include "libfuncs/libfuncs.h"
  26. int debug;
  27. int quiet;
  28. static struct videohub_data maindata;
  29. static int show_info = 1;
  30. static int show_monitor = 0;
  31. static int show_backup = 0;
  32. static int show_list = 0;
  33. static char *test_data;
  34. enum list_actions {
  35. action_list_device = (1 << 0),
  36. action_list_vinputs = (1 << 1),
  37. action_list_voutputs = (1 << 2),
  38. action_list_moutputs = (1 << 3),
  39. action_list_serial = (1 << 4),
  40. action_list_proc_units = (1 << 5),
  41. action_list_frames = (1 << 6),
  42. };
  43. static const char *program_id = PROGRAM_NAME " Version: " VERSION " Git: " GIT_VER;
  44. static const char short_options[] = "h:p:T:qdHVimb";
  45. static const struct option long_options[] = {
  46. { "host", required_argument, NULL, 'h' },
  47. { "port", required_argument, NULL, 'p' },
  48. { "test-input", required_argument, NULL, 'T' },
  49. { "quiet", no_argument, NULL, 'q' },
  50. { "debug", no_argument, NULL, 'd' },
  51. { "help", no_argument, NULL, 'H' },
  52. { "version", no_argument, NULL, 'V' },
  53. { "info", no_argument, NULL, 'i' },
  54. { "monitor", no_argument, NULL, 'm' },
  55. { "backup", no_argument, NULL, 'b' },
  56. { "list-device", no_argument, NULL, 901 },
  57. { "list-vinputs", no_argument, NULL, 902 },
  58. { "list-voutputs", no_argument, NULL, 903 },
  59. { "list-moutputs", no_argument, NULL, 904 },
  60. { "list-serial", no_argument, NULL, 905 },
  61. { "list-proc-units", no_argument, NULL, 906 },
  62. { "list-frames", no_argument, NULL, 907 },
  63. { "set-name", required_argument, NULL, 950 },
  64. { "vi-name", required_argument, NULL, 1001 },
  65. { "vi-output", required_argument, NULL, 1002 },
  66. { "vi-monitor", required_argument, NULL, 1003 },
  67. { "vo-name", required_argument, NULL, 2001 },
  68. { "vo-input", required_argument, NULL, 2002 },
  69. { "vo-route", required_argument, NULL, 2002 }, // Alias of --vo-input
  70. { "vo-lock", required_argument, NULL, 2003 },
  71. { "vo-unlock", required_argument, NULL, 2004 },
  72. { "mo-name", required_argument, NULL, 3001 },
  73. { "mo-input", required_argument, NULL, 3002 },
  74. { "mo-route", required_argument, NULL, 3002 }, // Alias of --mo-input
  75. { "mo-lock", required_argument, NULL, 3003 },
  76. { "mo-unlock", required_argument, NULL, 3004 },
  77. { "se-name", required_argument, NULL, 4001 },
  78. { "se-input", required_argument, NULL, 4002 },
  79. { "se-connect", required_argument, NULL, 4002 }, // Alias of --se-input
  80. { "se-route", required_argument, NULL, 4002 }, // Alias of --se-input
  81. { "se-lock", required_argument, NULL, 4003 },
  82. { "se-unlock", required_argument, NULL, 4004 },
  83. { "se-dir", required_argument, NULL, 4005 },
  84. { "se-clear", required_argument, NULL, 4006 },
  85. { "pu-input", required_argument, NULL, 5001 },
  86. { "pu-connect", required_argument, NULL, 5001 }, // Alias of --pu-input
  87. { "pu-route", required_argument, NULL, 5001 }, // Alias of --pu-input
  88. { "pu-lock", required_argument, NULL, 5002 },
  89. { "pu-unlock", required_argument, NULL, 5003 },
  90. { "pu-clear", required_argument, NULL, 5004 },
  91. { "fr-name", required_argument, NULL, 6001 },
  92. { "fr-output", required_argument, NULL, 6002 },
  93. { "fr-connect", required_argument, NULL, 6002 }, // Alias of --fr-output
  94. { "fr-input", required_argument, NULL, 6002 }, // Alias of --fr-output
  95. { "fr-route", required_argument, NULL, 6002 }, // Alias of --fr-output
  96. { "fr-lock", required_argument, NULL, 6003 },
  97. { "fr-unlock", required_argument, NULL, 6004 },
  98. { "fr-clear", required_argument, NULL, 6006 },
  99. { 0, 0, 0, 0 }
  100. };
  101. static void show_help(struct videohub_data *data) {
  102. printf("%s\n", program_id);
  103. printf("\n");
  104. printf(" Usage: " PROGRAM_NAME " --host <host> [..commands..]\n");
  105. printf("\n");
  106. printf("Main options:\n");
  107. printf(" -h --host <host> | Set device host name.\n");
  108. printf(" -p --port <port_number> | Set device port (default: 9990).\n");
  109. printf("\n");
  110. printf("Commands:\n");
  111. printf(" -i --info | Show full device info (default command).\n");
  112. printf(" . This command is shows the equivalent of\n");
  113. printf(" . running all --list-XXX commands.\n");
  114. printf(" -m --monitor | Display real-time config changes monitor.\n");
  115. printf(" -b --backup | Show the command line that will restore\n");
  116. printf(" . the device to the current configuration.\n");
  117. printf("\n");
  118. printf(" --list-device | Display device info.\n");
  119. printf(" --list-vinputs | List device video inputs.\n");
  120. printf(" --list-voutputs | List device video outputs.\n");
  121. printf(" --list-moutputs | List device monitoring outputs.\n");
  122. printf(" --list-serial | List device serial ports.\n");
  123. printf(" --list-proc-units | List device processing units.\n");
  124. printf(" --list-frames | List device frame buffers.\n");
  125. printf("\n");
  126. printf(" --set-name <name> | Set the device \"friendly name\".\n");
  127. printf("\n");
  128. printf("Video inputs configuration:\n");
  129. printf(" --vi-name <in_X> <name> | Set video input port X name.\n");
  130. printf(" --vi-output <in_X> <out_Y> | Route video input X to output Y.\n");
  131. printf(" --vi-monitor <in_X> <mout_Y> | Route video input X to mon port Y.\n");
  132. printf("\n");
  133. printf("Video outputs configuration:\n");
  134. printf(" --vo-name <out_X> <name> | Set video output port X name.\n");
  135. printf(" --vo-input <out_X> <in_Y> | Connect video output X to input Y.\n");
  136. printf(" --vo-lock <out_X> | Lock output port X.\n");
  137. printf(" --vo-unlock <out_X> | Unlock output port X.\n");
  138. printf("\n");
  139. printf("Monitoring outputs configuration:\n");
  140. printf(" --mo-name <mout_X> <name> | Set monitoring port X name.\n");
  141. printf(" --mo-input <mout_X> <in_Y> | Connect monitoring X to input Y.\n");
  142. printf(" --mo-lock <mout_X> | Lock monitoring port X.\n");
  143. printf(" --mo-unlock <mout_X> | Unlock monitoring port X.\n");
  144. printf("\n");
  145. printf("Serial ports configuration:\n");
  146. printf(" --se-name <ser_X> <name> | Set serial port X name.\n");
  147. printf(" --se-connect <ser_X> <ser_Y> | Connect serial X to serial Y.\n");
  148. printf(" --se-clear <ser_X> | Disconnect serial port X from serial Y.\n");
  149. printf(" --se-lock <ser_X> | Lock serial port X.\n");
  150. printf(" --se-unlock <ser_X> | Unlock serial port X.\n");
  151. printf(" --se-dir <ser_X> <dir> | Set serial port X direction.\n");
  152. printf(" . <dir> can be 'auto', 'in' or 'out'.\n");
  153. printf("\n");
  154. printf("Processing units configuration:\n");
  155. printf(" --pu-input <pu_X> <in_Y> | Connect processing unit X to input Y.\n");
  156. printf(" --pu-clear <pu_X> | Disconnect unit X from input Y.\n");
  157. printf(" --pu-lock <pu_X> | Lock processing unit X.\n");
  158. printf(" --pu-unlock <pu_X> | Unlock processing unit X.\n");
  159. printf("\n");
  160. printf("Frames configuration:\n");
  161. printf(" --fr-name <fr_X> <name> | Set frame X name.\n");
  162. printf(" --fr-output <fr_X> <out_Y> | Output frame X to output Y.\n");
  163. printf(" --fr-clear <fr_X> | Stop outputing frame X to the output.\n");
  164. printf(" --fr-lock <fr_X> | Lock frame X.\n");
  165. printf(" --fr-unlock <rf_X> | Unlock frame X.\n");
  166. printf("\n");
  167. printf("Misc options:\n");
  168. printf(" -T --test-input <file> | Read commands from <file>.\n");
  169. printf(" -d --debug | Increase logging verbosity.\n");
  170. printf(" -q --quiet | Suppress warnings.\n");
  171. printf(" -H --help | Show help screen.\n");
  172. printf(" -V --version | Show program version.\n");
  173. printf("\n");
  174. }
  175. static int num_parsed_cmds = 0;
  176. static struct run_cmds {
  177. struct vcmd_entry entry[MAX_RUN_CMDS];
  178. } parsed_cmds;
  179. static void check_num_parsed_cmds(void) {
  180. if (num_parsed_cmds == ARRAY_SIZE(parsed_cmds.entry))
  181. die("No more than %u commands are supported.", num_parsed_cmds);
  182. }
  183. static void parse_cmd2(int argc, char **argv, enum vcmd vcmd) {
  184. check_num_parsed_cmds();
  185. struct vcmd_entry *c = &parsed_cmds.entry[num_parsed_cmds];
  186. if (optind == argc || argv[optind - 1][0] == '-' || argv[optind][0] == '-') {
  187. fprintf(stderr, "%s: option '%s' requires two arguments\n", argv[0], argv[optind - 2]);
  188. exit(EXIT_FAILURE);
  189. }
  190. c->cmd = &videohub_commands[vcmd];
  191. c->p1.param = argv[optind - 1];
  192. c->p2.param = argv[optind];
  193. if (vcmd == CMD_SERIAL_PORT_DIRECTIONS) {
  194. if (strcasecmp("in", c->p2.param) == 0) c->direction = DIR_CONTROL;
  195. else if (strcasecmp("out", c->p2.param) == 0) c->direction = DIR_SLAVE;
  196. else if (strcasecmp("auto", c->p2.param) == 0) c->direction = DIR_AUTO;
  197. else die("Invalid serial port direction '%s'. Allowed are: in, out, auto.", c->p2.param);
  198. }
  199. num_parsed_cmds++;
  200. }
  201. static void parse_cmd2s(int argc, char **argv, enum vcmd vcmd) {
  202. check_num_parsed_cmds();
  203. struct vcmd_entry *c = &parsed_cmds.entry[num_parsed_cmds];
  204. c->cmd = &videohub_commands[vcmd];
  205. c->p1.param = optarg;
  206. c->p2.param = "1"; // Fake
  207. c->clear_port = true;
  208. num_parsed_cmds++;
  209. }
  210. static void parse_cmd1(int argc, char **argv, enum vcmd vcmd, bool do_lock) {
  211. check_num_parsed_cmds();
  212. struct vcmd_entry *c = &parsed_cmds.entry[num_parsed_cmds];
  213. c->cmd = &videohub_commands[vcmd];
  214. c->p1.param = argv[optind - 1];
  215. c->do_lock = do_lock;
  216. num_parsed_cmds++;
  217. }
  218. static void set_device_option(char *setting, char *value) {
  219. check_num_parsed_cmds();
  220. struct vcmd_entry *c = &parsed_cmds.entry[num_parsed_cmds];
  221. c->cmd = &videohub_commands[CMD_VIDEOHUB_DEVICE];
  222. c->p1.param = setting;
  223. c->p2.param = value;
  224. num_parsed_cmds++;
  225. }
  226. static void switch_cmd_args(void) {
  227. char *p1, *p2;
  228. parsed_cmds.entry[num_parsed_cmds-1].reversed_args = 1;
  229. p1 = parsed_cmds.entry[num_parsed_cmds-1].p1.param;
  230. p2 = parsed_cmds.entry[num_parsed_cmds-1].p2.param;
  231. parsed_cmds.entry[num_parsed_cmds-1].p1.param = p2;
  232. parsed_cmds.entry[num_parsed_cmds-1].p2.param = p1;
  233. }
  234. static void parse_options(struct videohub_data *data, int argc, char **argv) {
  235. int j, err = 0;
  236. // Check environment
  237. data->dev_host = getenv("VIDEOHUB_HOST");
  238. data->dev_port = getenv("VIDEOHUB_PORT");
  239. // Set defaults
  240. if (!data->dev_port)
  241. data->dev_port = "9990";
  242. while ((j = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
  243. if (j == '?') // Invalid parameter
  244. exit(EXIT_FAILURE);
  245. switch (j) {
  246. case 'h': // --host
  247. data->dev_host = optarg;
  248. break;
  249. case 'p': // --port
  250. data->dev_port = optarg;
  251. break;
  252. case 'T': { // --test-input
  253. struct stat st;
  254. FILE *f;
  255. if (stat(optarg, &st) != 0)
  256. die("Can't stat %s: %s", optarg, strerror(errno));
  257. f = fopen(optarg, "r");
  258. if (!f)
  259. die("Can't open %s: %s", optarg, strerror(errno));
  260. test_data = xzalloc(st.st_size + 1);
  261. if (fread(test_data, st.st_size, 1, f) < 1)
  262. die("Can't read from %s: %s", optarg, strerror(errno));
  263. fclose(f);
  264. data->dev_host = "sdi-matrix";
  265. break;
  266. }
  267. case 'd': // --debug
  268. debug++;
  269. if (debug)
  270. quiet = 0; // Disable quiet
  271. break;
  272. case 'q': // --quiet
  273. quiet = !quiet;
  274. break;
  275. case 'i': // --info
  276. show_info = 1;
  277. break;
  278. case 'm': // --monitor
  279. show_monitor = 1;
  280. break;
  281. case 'b': // --backup
  282. show_backup = 1;
  283. break;
  284. case 901: show_list |= action_list_device; break; // --list-device
  285. case 902: show_list |= action_list_vinputs; break; // --list-vinputs
  286. case 903: show_list |= action_list_voutputs; break; // --list-voutputs
  287. case 904: show_list |= action_list_moutputs; break; // --list-moutputs
  288. case 905: show_list |= action_list_serial; break; // --list-serial
  289. case 906: show_list |= action_list_proc_units; break; // --list-proc-units
  290. case 907: show_list |= action_list_frames; break; // --list-frames
  291. case 950: set_device_option("Friendly name", optarg); break; // --set-name
  292. case 1001: parse_cmd2(argc, argv, CMD_INPUT_LABELS); break; // --vi-name
  293. case 1002: parse_cmd2(argc, argv, CMD_VIDEO_OUTPUT_ROUTING); switch_cmd_args(); break; // --vi-output
  294. case 1003: parse_cmd2(argc, argv, CMD_MONITORING_OUTPUT_ROUTING); switch_cmd_args(); break; // --vi-monitor
  295. case 2001: parse_cmd2(argc, argv, CMD_OUTPUT_LABELS); break; // --vo-name
  296. case 2002: parse_cmd2(argc, argv, CMD_VIDEO_OUTPUT_ROUTING); break; // --vo-input
  297. case 2003: parse_cmd1(argc, argv, CMD_VIDEO_OUTPUT_LOCKS, true); break; // --vo-lock
  298. case 2004: parse_cmd1(argc, argv, CMD_VIDEO_OUTPUT_LOCKS, false); break; // --vo-unlock
  299. case 3001: parse_cmd2(argc, argv, CMD_MONITORING_OUTPUT_LABELS); break; // --mo-name
  300. case 3002: parse_cmd2(argc, argv, CMD_MONITORING_OUTPUT_ROUTING); break; // --mo-input
  301. case 3003: parse_cmd1(argc, argv, CMD_MONITORING_OUTPUT_LOCKS, true); break; // --mo-lock
  302. case 3004: parse_cmd1(argc, argv, CMD_MONITORING_OUTPUT_LOCKS, false); break; // --mo-unlock
  303. case 4001: parse_cmd2(argc, argv, CMD_SERIAL_PORT_LABELS); break; // --se-name
  304. case 4002: parse_cmd2(argc, argv, CMD_SERIAL_PORT_ROUTING); break; // --se-input
  305. case 4003: parse_cmd1(argc, argv, CMD_SERIAL_PORT_LOCKS, true); break; // --se-lock
  306. case 4004: parse_cmd1(argc, argv, CMD_SERIAL_PORT_LOCKS, false); break; // --se-unlock
  307. case 4005: parse_cmd2(argc, argv, CMD_SERIAL_PORT_DIRECTIONS); break; // --se-dir
  308. case 4006: parse_cmd2s(argc, argv, CMD_SERIAL_PORT_ROUTING); break; // --se-clear
  309. case 5001: parse_cmd2(argc, argv, CMD_PROCESSING_UNIT_ROUTING); break; // --pu-input
  310. case 5002: parse_cmd1(argc, argv, CMD_PROCESSING_UNIT_LOCKS, true); break; // --pu-lock
  311. case 5003: parse_cmd1(argc, argv, CMD_PROCESSING_UNIT_LOCKS, false); break; // --pu-unlock
  312. case 5004: parse_cmd2s(argc, argv, CMD_PROCESSING_UNIT_ROUTING); break; // --pu-clear
  313. case 6001: parse_cmd2(argc, argv, CMD_FRAME_LABELS); break; // --fr-name
  314. case 6002: parse_cmd2(argc, argv, CMD_FRAME_BUFFER_ROUTING); break; // --fr-input
  315. case 6003: parse_cmd1(argc, argv, CMD_FRAME_BUFFER_LOCKS, true); break; // --fr-lock
  316. case 6004: parse_cmd1(argc, argv, CMD_FRAME_BUFFER_LOCKS, false); break; // --fr-unlock
  317. case 6005: parse_cmd2s(argc, argv, CMD_FRAME_BUFFER_ROUTING); break; // --fr-clear
  318. case 'H': // --help
  319. show_help(data);
  320. exit(EXIT_SUCCESS);
  321. case 'V': // --version
  322. printf("%s\n", program_id);
  323. exit(EXIT_SUCCESS);
  324. }
  325. }
  326. if (!data->dev_host || !strtoul(data->dev_port, NULL, 10))
  327. err = 1;
  328. if (err) {
  329. show_help(data);
  330. if (!data->dev_host)
  331. fprintf(stderr, "ERROR: host is not set. Use --host option.\n");
  332. exit(EXIT_FAILURE);
  333. }
  334. d("Device address: %s:%s\n", data->dev_host, data->dev_port);
  335. }
  336. static void check_number_of_ports(struct port_set *p) {
  337. if (p->num > ARRAY_SIZE(p->port))
  338. die("The device supports %d ports. Increase MAX_PORTS (%lu) and recompile the program.",
  339. p->num, ARRAY_SIZE(p->port));
  340. }
  341. static void reset_routed_to(struct port_set *p) {
  342. unsigned int i;
  343. for (i = 0; i < ARRAY_SIZE(p->port); i++)
  344. p->port[i].routed_to = NO_PORT;
  345. }
  346. static void print_device_full(struct videohub_data *d) {
  347. print_device_info(d);
  348. print_device_video_inputs(d);
  349. print_device_video_outputs(d);
  350. print_device_monitoring_outputs(d);
  351. print_device_serial_ports(d);
  352. print_device_processing_units(d);
  353. print_device_frame_buffers(d);
  354. fflush(stdout);
  355. }
  356. static int read_device_command_stream(struct videohub_data *d) {
  357. int ret, ncommands = 0;
  358. char buf[8192 + 1];
  359. if (test_data)
  360. return 0;
  361. memset(buf, 0, sizeof(buf));
  362. while ((ret = fdread_ex(d->dev_fd, buf, sizeof(buf) - 1, 5, 0, 0)) >= 0) {
  363. ncommands += parse_text_buffer(d, buf);
  364. memset(buf, 0, sizeof(buf));
  365. }
  366. return ncommands;
  367. }
  368. static void send_device_command(struct videohub_data *d, char *cmd_buffer) {
  369. if (!test_data)
  370. fdwrite(d->dev_fd, cmd_buffer, strlen(cmd_buffer));
  371. else
  372. parse_text_buffer(d, cmd_buffer);
  373. }
  374. int main(int argc, char **argv) {
  375. struct videohub_data *data = &maindata;
  376. parse_options(data, argc, argv);
  377. set_log_io_errors(0);
  378. if (!test_data) {
  379. data->dev_fd = connect_client(SOCK_STREAM, data->dev_host, data->dev_port);
  380. if (data->dev_fd < 0)
  381. exit(EXIT_FAILURE);
  382. }
  383. reset_routed_to(&data->inputs);
  384. reset_routed_to(&data->outputs);
  385. reset_routed_to(&data->serial);
  386. reset_routed_to(&data->proc_units);
  387. reset_routed_to(&data->frames);
  388. read_device_command_stream(data);
  389. if (test_data)
  390. parse_text_buffer(data, test_data);
  391. if (!strlen(data->device.protocol_ver) || !strlen(data->device.model_name))
  392. die("The device does not respond correctly. Is it Videohub?");
  393. if (strstr(data->device.protocol_ver, "2.") != data->device.protocol_ver)
  394. q("WARNING: Device protocol is %s but this program is tested with 2.x only.\n",
  395. data->device.protocol_ver);
  396. if (!data->device.dev_present) {
  397. if (data->device.needs_fw_update) {
  398. die("Device reports that it needs firmware update.");
  399. }
  400. die("Device reports that it is not present.");
  401. }
  402. check_number_of_ports(&data->inputs);
  403. check_number_of_ports(&data->outputs);
  404. check_number_of_ports(&data->mon_outputs);
  405. check_number_of_ports(&data->serial);
  406. check_number_of_ports(&data->proc_units);
  407. check_number_of_ports(&data->frames);
  408. if (num_parsed_cmds) {
  409. unsigned int i;
  410. for (i = 0; i < ARRAY_SIZE(parsed_cmds.entry); i++) {
  411. struct vcmd_entry *ve = &parsed_cmds.entry[i];
  412. if (!ve->p1.param)
  413. continue;
  414. prepare_cmd_entry(data, &parsed_cmds.entry[i]);
  415. }
  416. for (i = 0; i < ARRAY_SIZE(parsed_cmds.entry); i++) {
  417. char cmd_buffer[1024];
  418. struct vcmd_entry *ve = &parsed_cmds.entry[i];
  419. if (!ve->p1.param)
  420. continue;
  421. format_cmd_text(ve, cmd_buffer, sizeof(cmd_buffer));
  422. if (strlen(cmd_buffer)) {
  423. show_cmd(data, ve);
  424. send_device_command(data, cmd_buffer);
  425. read_device_command_stream(data);
  426. }
  427. }
  428. // Show the result after commands
  429. if (test_data)
  430. print_device_full(data);
  431. } else if (show_monitor) {
  432. while (1) {
  433. int sleeps = 0;
  434. printf("\e[2J\e[H"); // Clear screen
  435. time_t now = time(NULL);
  436. struct tm *tm = localtime(&now);
  437. printf("Last update: %s\n", asctime(tm));
  438. print_device_info(data);
  439. print_device_video_inputs(data);
  440. print_device_video_outputs(data);
  441. fflush(stdout);
  442. do {
  443. usleep(500000);
  444. if (++sleeps >= 20)
  445. send_device_command(data, "PING:\n\n");
  446. } while (read_device_command_stream(data) == 0);
  447. }
  448. } else if (show_list) {
  449. if (show_list & action_list_device) print_device_info(data);
  450. if (show_list & action_list_vinputs) print_device_video_inputs(data);
  451. if (show_list & action_list_voutputs) print_device_video_outputs(data);
  452. if (show_list & action_list_moutputs) print_device_monitoring_outputs(data);
  453. if (show_list & action_list_serial) print_device_serial_ports(data);
  454. if (show_list & action_list_proc_units) print_device_processing_units(data);
  455. if (show_list & action_list_frames) print_device_frame_buffers(data);
  456. fflush(stdout);
  457. } else if (show_backup) {
  458. print_device_backup(data);
  459. } else if (show_info) {
  460. print_device_full(data);
  461. }
  462. shutdown_fd(&data->dev_fd);
  463. free(test_data);
  464. return 0;
  465. }