mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 15:37:30 -06:00
ENH: add retry for get version cmd
1. ota and xm does not have SN 2. retry for 10 times Change-Id: Id158021435df76817262896d79bdd7d07af8db94 Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
parent
a481e91105
commit
cc32ecdbd4
2 changed files with 38 additions and 2 deletions
|
@ -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<std::string>();
|
||||
module_vers.emplace(ver_info.name, ver_info);
|
||||
}
|
||||
bool get_version_result = true;
|
||||
if (j["info"].contains("result"))
|
||||
if (j["info"]["result"].get<std::string>() == "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 (...) {}
|
||||
|
|
|
@ -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<std::string, ModuleVersionInfo> module_vers;
|
||||
std::map<std::string, ModuleVersionInfo> 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<int, ModuleVersionInfo> 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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue