diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 513dcb854..4bd4f81c7 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -2468,6 +2468,7 @@ void MachineObject::reset_update_time() { BOOST_LOG_TRIVIAL(trace) << "reset reset_update_time, dev_id =" << dev_id; last_update_time = std::chrono::system_clock::now(); + subscribe_counter = 3; } void MachineObject::reset() @@ -2491,6 +2492,7 @@ void MachineObject::reset() nozzle_diameter = 0.0f; network_wired = false; dev_connection_name = ""; + subscribe_counter = 3; job_id_ = ""; // reset print_json @@ -5201,6 +5203,10 @@ bool DeviceManager::set_selected_machine(std::string dev_id, bool need_disconnec if (it->second->connection_type() != "lan") { // only reset update time it->second->reset_update_time(); + + // check subscribe state + Slic3r::GUI::wxGetApp().on_start_subscribe_again(dev_id); + return true; } else { // lan mode printer reconnect printer diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index 44e1ed4e1..9ef546dbe 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -405,6 +405,7 @@ public: bool local_use_ssl_for_mqtt { true }; bool local_use_ssl_for_ftp { true }; float nozzle_diameter { 0.0f }; + int subscribe_counter{3}; std::string nozzle_type; std::string dev_connection_type; /* lan | cloud */ std::string connection_type() { return dev_connection_type; } diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index cb3c1031c..288553e9b 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1884,6 +1884,12 @@ void GUI_App::init_networking_callbacks() } ); + m_agent->set_on_subscribe_failure_fn([this](std::string dev_id) { + CallAfter([this, dev_id] { + on_start_subscribe_again(dev_id); + }); + }); + m_agent->set_on_local_connect_fn( [this](int state, std::string dev_id, std::string msg) { if (m_is_closing) { @@ -2230,7 +2236,8 @@ void GUI_App::on_start_subscribe_again(std::string dev_id) MachineObject* obj = dev->get_selected_machine(); if (!obj) return; - if ( (dev_id == obj->dev_id) && obj->is_connecting() ) { + if ( (dev_id == obj->dev_id) && obj->is_connecting() && obj->subscribe_counter > 0) { + obj->subscribe_counter--; if(wxGetApp().getAgent()) wxGetApp().getAgent()->set_user_selected_machine(dev_id); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": dev_id=" << obj->dev_id; } diff --git a/src/slic3r/Utils/NetworkAgent.cpp b/src/slic3r/Utils/NetworkAgent.cpp index fe79bd51b..764d2c1fa 100644 --- a/src/slic3r/Utils/NetworkAgent.cpp +++ b/src/slic3r/Utils/NetworkAgent.cpp @@ -42,6 +42,7 @@ func_set_on_printer_connected_fn NetworkAgent::set_on_printer_connected_fn_pt func_set_on_server_connected_fn NetworkAgent::set_on_server_connected_fn_ptr = nullptr; func_set_on_http_error_fn NetworkAgent::set_on_http_error_fn_ptr = nullptr; func_set_get_country_code_fn NetworkAgent::set_get_country_code_fn_ptr = nullptr; +func_set_on_subscribe_failure_fn NetworkAgent::set_on_subscribe_failure_fn_ptr = nullptr; func_set_on_message_fn NetworkAgent::set_on_message_fn_ptr = nullptr; func_set_on_local_connect_fn NetworkAgent::set_on_local_connect_fn_ptr = nullptr; func_set_on_local_message_fn NetworkAgent::set_on_local_message_fn_ptr = nullptr; @@ -200,6 +201,7 @@ int NetworkAgent::initialize_network_module(bool using_backup) set_on_server_connected_fn_ptr = reinterpret_cast(get_network_function("bambu_network_set_on_server_connected_fn")); set_on_http_error_fn_ptr = reinterpret_cast(get_network_function("bambu_network_set_on_http_error_fn")); set_get_country_code_fn_ptr = reinterpret_cast(get_network_function("bambu_network_set_get_country_code_fn")); + set_on_subscribe_failure_fn_ptr = reinterpret_cast(get_network_function("bambu_network_set_on_subscribe_failure_fn")); set_on_message_fn_ptr = reinterpret_cast(get_network_function("bambu_network_set_on_message_fn")); set_on_local_connect_fn_ptr = reinterpret_cast(get_network_function("bambu_network_set_on_local_connect_fn")); set_on_local_message_fn_ptr = reinterpret_cast(get_network_function("bambu_network_set_on_local_message_fn")); @@ -312,6 +314,7 @@ int NetworkAgent::unload_network_module() set_on_server_connected_fn_ptr = nullptr; set_on_http_error_fn_ptr = nullptr; set_get_country_code_fn_ptr = nullptr; + set_on_subscribe_failure_fn_ptr = nullptr; set_on_message_fn_ptr = nullptr; set_on_local_connect_fn_ptr = nullptr; set_on_local_message_fn_ptr = nullptr; @@ -595,6 +598,17 @@ int NetworkAgent::set_get_country_code_fn(GetCountryCodeFn fn) return ret; } +int NetworkAgent::set_on_subscribe_failure_fn(GetSubscribeFailureFn fn) +{ + int ret = 0; + if (network_agent && set_on_subscribe_failure_fn_ptr) { + ret = set_on_subscribe_failure_fn_ptr(network_agent, fn); + if (ret) + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" error: network_agent=%1%, ret=%2%") % network_agent % ret; + } + return ret; +} + int NetworkAgent::set_on_message_fn(OnMessageFn fn) { int ret = 0; diff --git a/src/slic3r/Utils/NetworkAgent.hpp b/src/slic3r/Utils/NetworkAgent.hpp index 49651fcf4..60998c773 100644 --- a/src/slic3r/Utils/NetworkAgent.hpp +++ b/src/slic3r/Utils/NetworkAgent.hpp @@ -22,6 +22,7 @@ typedef int (*func_set_on_printer_connected_fn)(void *agent, OnPrinterConnectedF typedef int (*func_set_on_server_connected_fn)(void *agent, OnServerConnectedFn fn); typedef int (*func_set_on_http_error_fn)(void *agent, OnHttpErrorFn fn); typedef int (*func_set_get_country_code_fn)(void *agent, GetCountryCodeFn fn); +typedef int (*func_set_on_subscribe_failure_fn)(void *agent, GetSubscribeFailureFn fn); typedef int (*func_set_on_message_fn)(void *agent, OnMessageFn fn); typedef int (*func_set_on_local_connect_fn)(void *agent, OnLocalConnectedFn fn); typedef int (*func_set_on_local_message_fn)(void *agent, OnMessageFn fn); @@ -124,6 +125,7 @@ public: int set_on_server_connected_fn(OnServerConnectedFn fn); int set_on_http_error_fn(OnHttpErrorFn fn); int set_get_country_code_fn(GetCountryCodeFn fn); + int set_on_subscribe_failure_fn(GetSubscribeFailureFn fn); int set_on_message_fn(OnMessageFn fn); int set_on_local_connect_fn(OnLocalConnectedFn fn); int set_on_local_message_fn(OnMessageFn fn); @@ -214,6 +216,7 @@ private: static func_set_on_server_connected_fn set_on_server_connected_fn_ptr; static func_set_on_http_error_fn set_on_http_error_fn_ptr; static func_set_get_country_code_fn set_get_country_code_fn_ptr; + static func_set_on_subscribe_failure_fn set_on_subscribe_failure_fn_ptr; static func_set_on_message_fn set_on_message_fn_ptr; static func_set_on_local_connect_fn set_on_local_connect_fn_ptr; static func_set_on_local_message_fn set_on_local_message_fn_ptr; diff --git a/src/slic3r/Utils/bambu_networking.hpp b/src/slic3r/Utils/bambu_networking.hpp index c4aa1613a..e87540ec4 100644 --- a/src/slic3r/Utils/bambu_networking.hpp +++ b/src/slic3r/Utils/bambu_networking.hpp @@ -135,6 +135,7 @@ typedef std::function OnMessageFn; // http callbacks typedef std::function OnHttpErrorFn; typedef std::function GetCountryCodeFn; +typedef std::function GetSubscribeFailureFn; // print callbacks typedef std::function OnUpdateStatusFn; typedef std::function WasCancelledFn;