Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions host/py_module/py_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ std::vector<std::unique_ptr<TestDataSubject>> g_test_data_subjects;


bool init_device(
const std::string &device_cmd_file
const std::string &device_cmd_file,
const std::string &usb_device
)
{
bool result = false;
Expand All @@ -94,6 +95,7 @@ bool init_device(
&g_xlink_global_handler,
&g_xlink_device_handler,
device_cmd_file,
usb_device,
true)
)
{
Expand Down Expand Up @@ -604,11 +606,13 @@ PYBIND11_MODULE(depthai, m)

// init device
std::string device_cmd_file = "./depthai.cmd";
std::string usb_device = "";
m.def(
"init_device",
&init_device,
"Function that establishes the connection with device and gets configurations from it.",
py::arg("cmd_file") = device_cmd_file
py::arg("cmd_file") = device_cmd_file,
py::arg("usb_device") = usb_device
);

// reboot
Expand Down
32 changes: 30 additions & 2 deletions shared/xlink/xlink_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bool XLinkWrapper::initFromHostSide(
XLinkGlobalHandler_t* global_handler,
XLinkHandler_t* device_handler,
const std::string &device_cmd_file,
const std::string &usb_device,
bool reboot_device_on_destructor
)
{
Expand Down Expand Up @@ -80,17 +81,40 @@ bool XLinkWrapper::initFromHostSide(
break;
}

if (usb_device == "list") {
const int MAX_DEVICES = 32;
unsigned int numdev = 0;
deviceDesc_t deviceDescAll[MAX_DEVICES] = {};
rc = XLinkFindAllSuitableDevices(X_LINK_ANY_STATE, in_deviceDesc,
deviceDescAll, MAX_DEVICES, &numdev);
printf("Detected %d device(s):\n", numdev);
for (int i = 0; i < numdev; i++) {
char *port = strdup(deviceDescAll[i].name);
strtok(port, "-");
printf(" %-12s on USB port: %s\n", deviceDescAll[i].name, port);
free(port);
}
exit(0);
}

if (!usb_device.empty())
snprintf(in_deviceDesc.name, sizeof in_deviceDesc.name,
"%s-ma2480", usb_device.c_str());

// boot device
if (!device_cmd_file.empty()) {
// Find un-booted device
static bool print_found = false;
bool print_found = false;
tstart = std::chrono::steady_clock::now();
do {
rc = XLinkFindFirstSuitableDevice(X_LINK_UNBOOTED, in_deviceDesc, &deviceDesc);
tdiff = std::chrono::steady_clock::now() - tstart;
if (rc != X_LINK_SUCCESS) {
print_found = true;
printf("\rNo USB device [03e7:2485], still looking... %.3fs ", tdiff.count());
printf("\rNo USB device [03e7:2485], still looking");
if (!usb_device.empty())
printf(" on port %s", usb_device.c_str());
printf("... %.3fs ", tdiff.count());
fflush(stdout);
} else {
if (print_found)
Expand All @@ -115,6 +139,10 @@ bool XLinkWrapper::initFromHostSide(
printf("Device boot is skipped. (\"cmd_file\" NOT SPECIFIED !)\n");
}

if (!usb_device.empty())
snprintf(in_deviceDesc.name, sizeof in_deviceDesc.name,
"%s-", usb_device.c_str());

// Search for booted device
tstart = std::chrono::steady_clock::now();
do {
Expand Down
1 change: 1 addition & 0 deletions shared/xlink/xlink_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class XLinkWrapper
XLinkGlobalHandler_t* global_handler,
XLinkHandler_t* device_handler,
const std::string &path_to_mvcmd = "",
const std::string &usb_device = "",
bool reboot_device_on_destructor = true
);
#endif // __PC__
Expand Down