Skip to content

Commit 80d3593

Browse files
committed
UNDO getMxId() and extra debug
1 parent d2ddf25 commit 80d3593

5 files changed

Lines changed: 26 additions & 11 deletions

File tree

include/depthai/xlink/XLinkConnection.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ class XLinkConnection {
153153
constexpr static std::chrono::milliseconds WAIT_FOR_BOOTUP_TIMEOUT{15000};
154154
constexpr static std::chrono::milliseconds WAIT_FOR_CONNECT_TIMEOUT{5000};
155155
constexpr static std::chrono::milliseconds POLLING_DELAY_TIME{10};
156+
157+
public:
158+
std::string getMxId() const {
159+
return deviceInfo.getMxId();
160+
}
156161
};
157162

158163
} // namespace dai

include/depthai/xlink/XLinkStream.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class XLinkStream {
7777
[[deprecated]] void readRawRelease();
7878

7979
streamId_t getStreamId() const;
80+
std::string getMxId() const {
81+
return connection->getMxId();
82+
}
8083
};
8184

8285
struct XLinkError : public std::runtime_error {

src/device/DeviceBase.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void DeviceBase::close() {
487487
void DeviceBase::closeImpl() {
488488
using namespace std::chrono;
489489
auto t1 = steady_clock::now();
490-
pimpl->logger.debug("Device about to be closed...");
490+
pimpl->logger.warn("Device mxid({}) about to be closed...", deviceInfo.getMxId());
491491

492492
// Close connection first; causes Xlink internal calls to unblock semaphore waits and
493493
// return error codes, which then allows queues to unblock
@@ -513,7 +513,7 @@ void DeviceBase::closeImpl() {
513513
// At the end stop the monitor thread
514514
if(monitorThread.joinable()) monitorThread.join();
515515

516-
pimpl->logger.debug("Device closed, {}", duration_cast<milliseconds>(steady_clock::now() - t1).count());
516+
pimpl->logger.warn("Device mxid({}) closed, {}", deviceInfo.getMxId(), duration_cast<milliseconds>(steady_clock::now() - t1).count());
517517
}
518518

519519
// This function is thread-unsafe. The idea of "isClosed" is ephemerial and
@@ -608,7 +608,7 @@ void DeviceBase::init2(Config cfg, const dai::Path& pathToMvcmd, tl::optional<co
608608
pimpl->logger.debug("Found an actual device by given DeviceInfo: {}", deviceInfo.toString());
609609
} else {
610610
deviceInfo.state = X_LINK_ANY_STATE;
611-
pimpl->logger.debug("Searched, but no actual device found by given DeviceInfo");
611+
pimpl->logger.warn("Searched, but no actual device found by given DeviceInfo");
612612
}
613613
}
614614

@@ -693,14 +693,14 @@ void DeviceBase::init2(Config cfg, const dai::Path& pathToMvcmd, tl::optional<co
693693
auto t1 = steady_clock::now();
694694
bl.bootMemory(fwWithConfig);
695695
auto t2 = steady_clock::now();
696-
pimpl->logger.debug("Booting FW with Bootloader. Version {}, Time taken: {}", version.toString(), duration_cast<milliseconds>(t2 - t1));
696+
pimpl->logger.warn("Booting FW with Bootloader. Version {}, Time taken: {}", version.toString(), duration_cast<milliseconds>(t2 - t1));
697697

698698
// After that the state will be expectedBootState
699699
deviceInfo.state = expectedBootState;
700700
} else {
701701
// Boot into USB ROM BOOTLOADER
702702
bl.bootUsbRomBootloader();
703-
pimpl->logger.debug("Booting FW by jumping to USB ROM Bootloader first. Bootloader Version {}", version.toString());
703+
pimpl->logger.warn("Booting FW by jumping to USB ROM Bootloader first. Bootloader Version {}", version.toString());
704704

705705
// After that the state will be UNBOOTED
706706
deviceInfo.state = X_LINK_UNBOOTED;
@@ -742,7 +742,7 @@ void DeviceBase::init2(Config cfg, const dai::Path& pathToMvcmd, tl::optional<co
742742
return rpcStream->read();
743743
} catch(const std::exception& e) {
744744
// If any exception is thrown, log it and rethrow
745-
implLogger.debug("RPC error: {}", e.what());
745+
implLogger.warn("RPC mxid({}) error: {}", rpcStream->getMxId(), e.what());
746746
throw std::system_error(std::make_error_code(std::errc::io_error), "Device already closed or disconnected");
747747
}
748748
});

src/xlink/XLinkConnection.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void XLinkConnection::close() {
311311

312312
const auto ret = XLinkResetRemoteTimeout(deviceLinkId, static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(RESET_TIMEOUT).count()));
313313
if(ret != X_LINK_SUCCESS) {
314-
logger::debug("XLinkResetRemoteTimeout({}) returned: {}", previousLinkId, XLinkErrorToStr(ret));
314+
logger::warn("XLinkResetRemoteTimeout({}) mxid({}) returned: {}", previousLinkId, deviceInfo.getMxId(), XLinkErrorToStr(ret));
315315
}
316316

317317
deviceLinkId = -1;
@@ -331,20 +331,24 @@ void XLinkConnection::close() {
331331
}
332332
if(steady_clock::now() - t1 >= BOOTUP_SEARCH) {
333333
if(found) {
334-
logger::debug("XLinkResetRemoteTimeout({}) post-reboot({}s) unusable state {}",
334+
logger::warn("XLinkResetRemoteTimeout({}) mxid({}) post-reboot({}s) unusable state {}",
335335
previousLinkId,
336+
deviceInfo.getMxId(),
336337
BOOTUP_SEARCH.count(),
337338
rebootingDeviceInfo.toString());
338339
} else {
339-
logger::debug("XLinkResetRemoteTimeout({}) post-reboot({}s) can't find device", previousLinkId, BOOTUP_SEARCH.count());
340+
logger::warn("XLinkResetRemoteTimeout({}) mxid({}) post-reboot({}s) can't find device",
341+
previousLinkId,
342+
deviceInfo.getMxId(),
343+
BOOTUP_SEARCH.count());
340344
}
341345
break;
342346
}
343347
std::this_thread::sleep_for(POLLING_DELAY_TIME);
344348
};
345349
}
346350

347-
logger::debug("XLinkResetRemoteTimeout({})", previousLinkId);
351+
logger::debug("XLinkResetRemoteTimeout({}) mxid({})", previousLinkId, deviceInfo.getMxId());
348352
}
349353
}
350354

tests/src/multiple_devices_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ TEST_CASE("Multiple devices with 50 messages each") {
101101
}
102102

103103
REQUIRE(finished);
104-
}
104+
} // the first device in vector cleanly destructs, but the 2nd and 3rd always post-reboot 5s can't find device
105+
// curious as sometimes the found devices are in a different order but on destruct its always the 2nd and 3rd
106+
// c++ std has no rule or guarantee for the order of vector element destruction -- fact that it differs in std lib implementations
107+
// http://www7.open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0752r0.md
105108

106109
TEST_CASE("Multiple devices created and destroyed in parallel") {
107110
constexpr auto TEST_TIMEOUT = 30s;

0 commit comments

Comments
 (0)