Skip to content

Commit 68a402b

Browse files
author
Matevz Morato
committed
Backport RPC timeouts from v3
1 parent 582aec1 commit 68a402b

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

include/depthai/xlink/XLinkStream.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class XLinkStream {
5656
void write(const std::uint8_t* data, std::size_t size);
5757
void write(const std::vector<std::uint8_t>& data);
5858
std::vector<std::uint8_t> read();
59+
std::vector<std::uint8_t> read(std::chrono::milliseconds timeout);
5960
std::vector<std::uint8_t> read(XLinkTimespec& timestampReceived);
6061
void read(std::vector<std::uint8_t>& data);
6162
void read(std::vector<std::uint8_t>& data, XLinkTimespec& timestampReceived);

src/device/DeviceBase.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const std::string MAGIC_FACTORY_FLASHING_VALUE = "413424129";
4949
const std::string MAGIC_FACTORY_PROTECTED_FLASHING_VALUE = "868632271";
5050

5151
const unsigned int DEFAULT_CRASHDUMP_TIMEOUT = 9000;
52+
const unsigned int RPC_READ_TIMEOUT = 30000;
5253

5354
// local static function
5455
static void getFlashingPermissions(bool& factoryPermissions, bool& protectedPermissions) {
@@ -830,7 +831,7 @@ void DeviceBase::init2(Config cfg, const dai::Path& pathToMvcmd, tl::optional<co
830831

831832
// Receive response back
832833
// Send to nanorpc to parse
833-
return rpcStream->read();
834+
return rpcStream->read(std::chrono::milliseconds(RPC_READ_TIMEOUT));
834835
} catch(const std::exception& e) {
835836
// If any exception is thrown, log it and rethrow
836837
pimpl->logger.debug("RPC error: {}", e.what());

src/xlink/XLinkStream.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ bool XLinkStream::write(const std::vector<std::uint8_t>& data, std::chrono::mill
192192
return write(data.data(), data.size(), timeout);
193193
}
194194

195+
std::vector<std::uint8_t> XLinkStream::read(std::chrono::milliseconds timeout) {
196+
std::vector<std::uint8_t> data;
197+
if(!read(data, timeout)) {
198+
throw XLinkReadError(X_LINK_TIMEOUT, streamName);
199+
}
200+
return data;
201+
}
202+
195203
bool XLinkStream::read(std::vector<std::uint8_t>& data, std::chrono::milliseconds timeout) {
196204
StreamPacketDesc packet;
197205
const auto status = XLinkReadMoveDataWithTimeout(streamId, &packet, static_cast<unsigned int>(timeout.count()));

0 commit comments

Comments
 (0)