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
6162const unsigned int DEFAULT_CRASHDUMP_TIMEOUT_MS = 9000 ;
6263const 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
6569static 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 ());
@@ -1623,10 +1635,18 @@ bool DeviceBase::startPipelineImpl(const Pipeline& pipeline) {
16231635 logCollection::logPipeline (schema, deviceInfo);
16241636 this ->pipelineSchema = schema; // Save the schema so it can be saved alongside the crashdump
16251637
1626- // Build and start the pipeline
16271638 bool success = false ;
16281639 std::string errorMsg;
1640+
1641+ std::tie (success, errorMsg) = pimpl->rpcClient ->call (WAIT_FOR_DEVICE_READY_RPC_NAME).as <std::tuple<bool , std::string>>();
1642+
1643+ if (!success) {
1644+ throw std::runtime_error (" Device not ready: " + errorMsg);
1645+ }
1646+
1647+ // Build and start the pipeline
16291648 std::tie (success, errorMsg) = pimpl->rpcClient ->call (" buildPipeline" ).as <std::tuple<bool , std::string>>();
1649+
16301650 if (success) {
16311651 pimpl->rpcClient ->call (" startPipeline" );
16321652 } else {
0 commit comments