diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 14fd23c405..ddb0a9fcbd 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -1007,6 +1007,21 @@ std::string MachineObject::get_ota_version() return ""; } +bool MachineObject::check_version_valid() +{ + bool valid = true; + for (auto module : module_vers) { + if (module.second.sn.empty() + && module.first != "ota" + && module.first != "xm") + return false; + if (module.second.sw_ver.empty()) + return false; + } + get_version_retry = 0; + return valid; +} + wxString MachineObject::get_upgrade_result_str(int err_code) { switch(err_code) { @@ -1217,12 +1232,14 @@ bool MachineObject::is_recording() return camera_recording; } -int MachineObject::command_get_version() +int MachineObject::command_get_version(bool with_retry) { BOOST_LOG_TRIVIAL(info) << "command_get_version"; json j; j["info"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); j["info"]["command"] = "get_version"; + if (with_retry) + get_version_retry = GET_VERSION_RETRYS; return this->publish_json(j.dump()); } @@ -1790,6 +1807,7 @@ void MachineObject::reset() last_update_time = std::chrono::system_clock::now(); m_push_count = 0; is_220V_voltage = false; + get_version_retry = 0; camera_recording = false; camera_recording_when_printing = false; camera_timelapse = false; @@ -2882,6 +2900,20 @@ int MachineObject::parse_json(std::string payload) ver_info.hw_ver = (*it)["hw_ver"].get(); module_vers.emplace(ver_info.name, ver_info); } + bool get_version_result = true; + if (j["info"].contains("result")) + if (j["info"]["result"].get() == "fail") + get_version_result = false; + if ((!check_version_valid() && get_version_retry-- >= 0) + && get_version_result) { + BOOST_LOG_TRIVIAL(info) << "get_version_retry = " << get_version_retry; + boost::thread retry = boost::thread([this] { + boost::this_thread::sleep_for(boost::chrono::milliseconds(RETRY_INTERNAL)); + GUI::wxGetApp().CallAfter([this] { + this->command_get_version(false); + }); + }); + } } } } catch (...) {} diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index d1398724af..835d78f53f 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -25,6 +25,8 @@ #define BED_TEMP_LIMIT 120 #define HOLD_COUNT_MAX 3 +#define GET_VERSION_RETRYS 10 +#define RETRY_INTERNAL 2000 inline int correct_filament_temperature(int filament_temp) { @@ -483,6 +485,7 @@ public: std::string ams_new_version_number; std::string ota_new_version_number; std::string ahb_new_version_number; + int get_version_retry = 0; std::map module_vers; std::map new_ver_list; bool m_new_ver_list_exist = false; @@ -494,6 +497,7 @@ public: bool is_upgrading_avalable(); int get_upgrade_percent(); std::string get_ota_version(); + bool check_version_valid(); wxString get_upgrade_result_str(int upgrade_err_code); // key: ams_id start as 0,1,2,3 std::map get_ams_version(); @@ -601,7 +605,7 @@ public: MachineObject(NetworkAgent* agent, std::string name, std::string id, std::string ip); ~MachineObject(); /* command commands */ - int command_get_version(); + int command_get_version(bool with_retry = true); int command_request_push_all(); /* command upgrade */