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
32 changes: 25 additions & 7 deletions host/py_module/py_bindings.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ std::shared_ptr<CNNHostPipeline> gl_result = nullptr;

static volatile std::atomic<int> wdog_keep;

bool deinit_device();
bool soft_deinit_device();
bool init_device(
const std::string &device_cmd_file,
const std::string &usb_device
Expand All@@ -55,14 +55,23 @@ static int wdog_thread_alive = 1;
void wdog_thread(int& wd_timeout_ms)
{
std::cout << "watchdog started " << wd_timeout_ms << std::endl;
const int sleep_chunk = 100;
const int sleep_nr = wd_timeout_ms / sleep_chunk;
while(wdog_thread_alive)
{
wdog_keep = 0;
std::this_thread::sleep_for(std::chrono::milliseconds(wd_timeout_ms));
for(int i = 0; i < sleep_nr; i++)
{
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_chunk));
if(wdog_thread_alive == 0)
{
break;
}
}
if(wdog_keep == 0 && wdog_thread_alive == 1)
{
std::cout << "watchdog triggered " << std::endl;
deinit_device();
soft_deinit_device();
bool init;
for(int retry = 0; retry < 1; retry++)
{
Expand DownExpand Up@@ -175,7 +184,7 @@ bool init_device(
&g_xlink_device_handler,
device_cmd_file,
usb_device,
false)
true)
)
{
std::cout << "depthai: Error initializing xlink\n";
Expand DownExpand Up@@ -278,12 +287,23 @@ bool init_device(
return result;
}

bool soft_deinit_device()
{
g_xlink = nullptr;
g_disparity_post_proc = nullptr;
g_device_support_listener = nullptr;
g_host_caputure_command = nullptr;
return true;
}

bool deinit_device()
{
wdog_stop();
g_xlink = nullptr;
g_disparity_post_proc = nullptr;
g_device_support_listener = nullptr;
g_host_caputure_command = nullptr;
gl_result = nullptr;
return true;
}

Expand DownExpand Up@@ -859,17 +879,15 @@ PYBIND11_MODULE(depthai, m)
.def("get_available_data_packets", &HostPipeline::getAvailableDataPackets, py::return_value_policy::copy)
;

py::class_<CNNHostPipeline>(m, "CNNPipeline")
py::class_<CNNHostPipeline, std::shared_ptr<CNNHostPipeline>>(m, "CNNPipeline")
.def("get_available_data_packets", &CNNHostPipeline::getAvailableDataPackets, py::return_value_policy::copy)
.def("get_available_nnet_and_data_packets", &CNNHostPipeline::getAvailableNNetAndDataPackets, py::return_value_policy::copy)
;


// module destructor
auto cleanup_callback = []() {
wdog_stop();
deinit_device();
gl_result = nullptr;
};

m.add_object("_cleanup", py::capsule(cleanup_callback));
Expand Down
2 changes: 1 addition & 1 deletion shared/version.hpp
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
#pragma once

const char *c_depthai_dev_version = "c722ebde932d6627463321816a5654b5be6069e1";
const char *c_depthai_dev_version = "30295b558351cd030408e12a220cdd55b5fb450e";
const char *c_depthai_version = "0.0.10a";
16 changes: 14 additions & 2 deletions shared/xlink/xlink_wrapper.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,9 +25,19 @@ XLinkWrapper::~XLinkWrapper()
{
if (_device_link_id != -1)
{
if (_be_verbose) { printf("Stopping threads: ...\n"); }
std::chrono::steady_clock::time_point tstart;
std::chrono::duration<double> tdiff;
if (_be_verbose)
{
printf("Stopping threads: ...\n");
tstart = std::chrono::steady_clock::now();
}
stopThreads();
if (_be_verbose) { printf("Stopping threads: DONE.\n"); }
if (_be_verbose)
{
tdiff = std::chrono::steady_clock::now() - tstart;
printf("Stopping threads: DONE %.3fs.\n",tdiff.count());
}

if (_be_verbose) { printf("Closing all observer streams: ...\n"); }
closeAllObserverStreams();
Expand All@@ -39,6 +49,7 @@ XLinkWrapper::~XLinkWrapper()
XLinkWrapper::rebootDevice(_device_link_id);
}
#endif
_device_link_id = -1;
}
}

Expand DownExpand Up@@ -662,6 +673,7 @@ void XLinkWrapper::openAndReadDataThreadFunc(
else
{
printf("Device get data failed: %x\n", status);
break;
}

std::this_thread::sleep_for(std::chrono::milliseconds(c_stream_read_thread_wait_ms));
Expand Down