mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 12:41:20 -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 ""; |     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) | wxString MachineObject::get_upgrade_result_str(int err_code) | ||||||
| { | { | ||||||
|     switch(err_code) { |     switch(err_code) { | ||||||
|  | @ -1217,12 +1232,14 @@ bool MachineObject::is_recording() | ||||||
|     return camera_recording; |     return camera_recording; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int MachineObject::command_get_version() | int MachineObject::command_get_version(bool with_retry) | ||||||
| { | { | ||||||
|     BOOST_LOG_TRIVIAL(info) << "command_get_version"; |     BOOST_LOG_TRIVIAL(info) << "command_get_version"; | ||||||
|     json j; |     json j; | ||||||
|     j["info"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); |     j["info"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); | ||||||
|     j["info"]["command"] = "get_version"; |     j["info"]["command"] = "get_version"; | ||||||
|  |     if (with_retry) | ||||||
|  |         get_version_retry = GET_VERSION_RETRYS; | ||||||
|     return this->publish_json(j.dump()); |     return this->publish_json(j.dump()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -1790,6 +1807,7 @@ void MachineObject::reset() | ||||||
|     last_update_time = std::chrono::system_clock::now(); |     last_update_time = std::chrono::system_clock::now(); | ||||||
|     m_push_count = 0; |     m_push_count = 0; | ||||||
|     is_220V_voltage = false; |     is_220V_voltage = false; | ||||||
|  |     get_version_retry = 0; | ||||||
|     camera_recording = false; |     camera_recording = false; | ||||||
|     camera_recording_when_printing = false; |     camera_recording_when_printing = false; | ||||||
|     camera_timelapse = 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>(); |                             ver_info.hw_ver = (*it)["hw_ver"].get<std::string>(); | ||||||
|                         module_vers.emplace(ver_info.name, ver_info); |                         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 (...) {} |         } catch (...) {} | ||||||
|  |  | ||||||
|  | @ -25,6 +25,8 @@ | ||||||
| #define BED_TEMP_LIMIT          120 | #define BED_TEMP_LIMIT          120 | ||||||
| 
 | 
 | ||||||
| #define HOLD_COUNT_MAX          3 | #define HOLD_COUNT_MAX          3 | ||||||
|  | #define GET_VERSION_RETRYS      10 | ||||||
|  | #define RETRY_INTERNAL          2000 | ||||||
| 
 | 
 | ||||||
| inline int correct_filament_temperature(int filament_temp) | inline int correct_filament_temperature(int filament_temp) | ||||||
| { | { | ||||||
|  | @ -483,6 +485,7 @@ public: | ||||||
|     std::string ams_new_version_number; |     std::string ams_new_version_number; | ||||||
|     std::string ota_new_version_number; |     std::string ota_new_version_number; | ||||||
|     std::string ahb_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> module_vers; | ||||||
|     std::map<std::string, ModuleVersionInfo> new_ver_list; |     std::map<std::string, ModuleVersionInfo> new_ver_list; | ||||||
|     bool    m_new_ver_list_exist = false; |     bool    m_new_ver_list_exist = false; | ||||||
|  | @ -494,6 +497,7 @@ public: | ||||||
|     bool is_upgrading_avalable(); |     bool is_upgrading_avalable(); | ||||||
|     int get_upgrade_percent(); |     int get_upgrade_percent(); | ||||||
|     std::string get_ota_version(); |     std::string get_ota_version(); | ||||||
|  |     bool check_version_valid(); | ||||||
|     wxString get_upgrade_result_str(int upgrade_err_code); |     wxString get_upgrade_result_str(int upgrade_err_code); | ||||||
|     // key: ams_id start as 0,1,2,3
 |     // key: ams_id start as 0,1,2,3
 | ||||||
|     std::map<int, ModuleVersionInfo> get_ams_version(); |     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(NetworkAgent* agent, std::string name, std::string id, std::string ip); | ||||||
|     ~MachineObject(); |     ~MachineObject(); | ||||||
|     /* command commands */ |     /* command commands */ | ||||||
|     int command_get_version(); |     int command_get_version(bool with_retry = true); | ||||||
|     int command_request_push_all(); |     int command_request_push_all(); | ||||||
| 
 | 
 | ||||||
|     /* command upgrade */ |     /* command upgrade */ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Stone Li
						Stone Li