Skip to content

Commit beab851

Browse files
committed
Add RPC wait for device
Signed-off-by: stas.bucik <[email protected]>
1 parent 95e6eed commit beab851

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/device/DeviceBase.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "XLink/XLinkTime.h"
4343
#include "nanorpc/core/client.h"
4444
#include "nanorpc/packer/nlohmann_msgpack.h"
45+
#include "nanorpc/core/hash.h"
4546
#include "spdlog/details/os.h"
4647
#include "spdlog/fmt/bin_to_hex.h"
4748
#include "spdlog/fmt/chrono.h"
@@ -60,6 +61,9 @@ constexpr int DEVICE_SEARCH_FIRST_TIMEOUT_MS = 30;
6061

6162
const unsigned int DEFAULT_CRASHDUMP_TIMEOUT_MS = 9000;
6263
const unsigned int RPC_READ_TIMEOUT = 10000;
64+
const unsigned int WAIT_FOR_DEVICE_READY_RPC_READ_TIMEOUT = 60000;
65+
66+
std::string const WAIT_FOR_DEVICE_READY_RPC_NAME = "waitForDeviceReady";
6367

6468
// local static function
6569
static void getFlashingPermissions(bool& factoryPermissions, bool& protectedPermissions) {
@@ -762,10 +766,18 @@ void DeviceBase::init2(Config cfg, const std::filesystem::path& pathToMvcmd, boo
762766
try {
763767
// Send request to device
764768
rpcStream->write(std::move(request));
769+
770+
auto id = nlohmann::json::from_msgpack(request).at(2).get<nanorpc::core::type::id>();
771+
772+
unsigned int timeout = RPC_READ_TIMEOUT;
773+
774+
if (id == nanorpc::core::hash_id(WAIT_FOR_DEVICE_READY_RPC_NAME)) {
775+
timeout = WAIT_FOR_DEVICE_READY_RPC_READ_TIMEOUT;
776+
}
765777

766778
// Receive response back
767779
// Send to nanorpc to parse
768-
return rpcStream->read(std::chrono::milliseconds(RPC_READ_TIMEOUT));
780+
return rpcStream->read(std::chrono::milliseconds(timeout));
769781
} catch(const std::exception& e) {
770782
// If any exception is thrown, log it and rethrow
771783
pimpl->logger.debug("RPC error: {}", e.what());
@@ -1619,10 +1631,18 @@ bool DeviceBase::startPipelineImpl(const Pipeline& pipeline) {
16191631
logCollection::logPipeline(schema, deviceInfo);
16201632
this->pipelineSchema = schema; // Save the schema so it can be saved alongside the crashdump
16211633

1622-
// Build and start the pipeline
16231634
bool success = false;
16241635
std::string errorMsg;
1636+
1637+
std::tie(success, errorMsg) = pimpl->rpcClient->call(WAIT_FOR_DEVICE_READY_RPC_NAME).as<std::tuple<bool, std::string>>();
1638+
1639+
if (!success) {
1640+
throw std::runtime_error("Device not ready: " + errorMsg);
1641+
}
1642+
1643+
// Build and start the pipeline
16251644
std::tie(success, errorMsg) = pimpl->rpcClient->call("buildPipeline").as<std::tuple<bool, std::string>>();
1645+
16261646
if(success) {
16271647
pimpl->rpcClient->call("startPipeline");
16281648
} else {

0 commit comments

Comments
 (0)