t/cli: Add a just probe command

This commit is contained in:
Jakob Bornecrantz 2019-10-25 18:34:18 +01:00
parent 56f61412f5
commit 5f4ddcc414
5 changed files with 78 additions and 1 deletions

View file

@ -13,6 +13,7 @@ include_directories(
set(SOURCE_FILES
cli_cmd_calibrate.c
cli_cmd_probe.c
cli_cmd_test.c
cli_common.h
cli_main.c

View file

@ -0,0 +1,67 @@
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Just does a probe.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#include <string.h>
#include <stdio.h>
#include "xrt/xrt_prober.h"
#include "cli_common.h"
static int
do_exit(struct xrt_prober **xp_ptr, int ret)
{
xrt_prober_destroy(xp_ptr);
printf(" :: Exiting '%i'\n", ret);
return ret;
}
#define NUM_XDEVS 32
int
cli_cmd_probe(int argc, const char **argv)
{
struct xrt_device *xdevs[NUM_XDEVS] = {0};
struct xrt_prober *xp = NULL;
int ret = 0;
// Initialize the prober.
printf(" :: Creating prober!\n");
ret = xrt_prober_create(&xp);
if (ret != 0) {
return do_exit(&xp, 0);
}
// Need to prime the prober with devices before dumping and listing.
printf(" :: Probing!\n");
ret = xrt_prober_probe(xp);
if (ret != 0) {
return do_exit(&xp, ret);
}
// End of program
printf(" :: All ok, shutting down.\n");
for (size_t i = 0; i < NUM_XDEVS; i++) {
if (xdevs[i] == NULL) {
continue;
}
printf("\tDestroying '%s'\n", xdevs[i]->str);
xdevs[i]->destroy(xdevs[i]);
xdevs[i] = NULL;
}
// Finally done
return do_exit(&xp, 0);
}

View file

@ -12,5 +12,8 @@
int
cli_cmd_calibrate(int argc, const char **argv);
int
cli_cmd_probe(int argc, const char **argv);
int
cli_cmd_test(int argc, const char **argv);

View file

@ -26,7 +26,9 @@ cli_print_help(int argc, const char **argv)
P("\n");
P("Commands:\n");
P(" test - List found devices, for prober testing.\n");
P(" calibrate - Calibrate a camera and save config.\n");
P(" probe - Just probe and then exit.\n");
P(" calibrate - Calibrate a camera and save config (not implemented "
"yet).\n");
return 1;
}
@ -41,6 +43,9 @@ main(int argc, const char **argv)
if (strcmp(argv[1], "test") == 0) {
return cli_cmd_test(argc, argv);
}
if (strcmp(argv[1], "probe") == 0) {
return cli_cmd_probe(argc, argv);
}
if (strcmp(argv[1], "calibrate") == 0) {
return cli_cmd_calibrate(argc, argv);
}

View file

@ -5,6 +5,7 @@ cli = executable(
'monado-cli',
files(
'cli_cmd_calibrate.c',
'cli_cmd_probe.c',
'cli_cmd_test.c',
'cli_common.h',
'cli_main.c',