FIX: [STUDIO-2767] retry with remote tunnel when local failed

Change-Id: Id0172239d752508227729e81bee6c1a6ff4d3e9d
This commit is contained in:
chunmao.guo 2023-05-06 13:54:14 +08:00 committed by Lane.Wei
parent c142c8a31e
commit d8517991e4
6 changed files with 38 additions and 16 deletions

View file

@ -2325,6 +2325,13 @@ bool MachineObject::is_support_print_with_timelapse()
return true;
}
bool MachineObject::is_camera_busy_off()
{
if (printer_type == "C11")
return is_in_prepare() || is_in_upgrading();
return false;
}
int MachineObject::publish_json(std::string json_str, int qos)
{
if (is_lan_mode_printer()) {

View file

@ -784,7 +784,7 @@ public:
bool is_function_supported(PrinterFunction func);
std::vector<std::string> get_resolution_supported();
bool is_support_print_with_timelapse();
bool is_camera_busy_off();
/* Msg for display MsgFn */
typedef std::function<void(std::string topic, std::string payload)> MsgFn;

View file

@ -82,14 +82,14 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj)
m_lan_mode = obj->is_lan_mode_printer();
m_lan_ip = obj->is_function_supported(PrinterFunction::FUNC_LOCAL_TUNNEL) ? obj->dev_ip : "";
m_lan_passwd = obj->is_function_supported(PrinterFunction::FUNC_LOCAL_TUNNEL) ? obj->get_access_code() : "";
m_tutk_support = obj->is_function_supported(PrinterFunction::FUNC_REMOTE_TUNNEL);
m_device_busy = obj->is_in_prepare() || obj->is_in_upgrading();
m_remote_support = obj->is_function_supported(PrinterFunction::FUNC_REMOTE_TUNNEL);
m_device_busy = obj->is_camera_busy_off();
} else {
m_camera_exists = false;
m_lan_mode = false;
m_lan_ip.clear();
m_lan_passwd.clear();
m_tutk_support = true;
m_remote_support = true;
m_device_busy = false;
}
if (machine == m_machine) {
@ -99,6 +99,7 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj)
}
m_machine = machine;
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl switch machine: " << m_machine;
m_disable_lan = false;
m_failed_retry = 0;
m_last_failed_codes.clear();
std::string stream_url;
@ -129,10 +130,19 @@ void MediaPlayCtrl::Play()
Stop(_L("Initialize failed (No Device)!"));
return;
}
if (!IsEnabled()) {
Stop(_L("Initialize failed (Device connection not ready)!"));
return;
}
if (!m_camera_exists) {
Stop(_L("Initialize failed (No Camera Device)!"));
return;
}
if (m_device_busy) {
Stop(_L("Printer is busy downloading, Please wait for the downloading to finish."));
m_failed_retry = 0;
return;
}
m_last_state = MEDIASTATE_INITIALIZING;
m_button_play->SetIcon("media_stop");
@ -140,7 +150,8 @@ void MediaPlayCtrl::Play()
NetworkAgent *agent = wxGetApp().getAgent();
std::string agent_version = agent ? agent->get_version() : "";
if (!m_lan_ip.empty() && (!m_lan_mode || !m_lan_passwd.empty()) && !m_device_busy) {
if (!m_disable_lan && !m_lan_ip.empty() && (!m_lan_mode || !m_lan_passwd.empty())) {
m_disable_lan = m_remote_support && !m_lan_mode; // try remote next time
m_url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd + "&device=" + m_machine + "&version=" + agent_version;
m_last_state = MEDIASTATE_LOADING;
SetStatus(_L("Loading..."));
@ -160,21 +171,18 @@ void MediaPlayCtrl::Play()
return;
}
if (m_lan_mode) {
m_disable_lan = false;
if (m_lan_ip.empty())
m_failed_code = 1;
if (m_lan_mode) {
Stop(m_lan_passwd.empty()
? _L("Initialize failed (Not supported with LAN-only mode)!")
: _L("Initialize failed (Not accessible in LAN-only mode)!"));
return;
}
if (!m_tutk_support) { // not support tutk
if (m_device_busy) {
Stop(_L("Printer is busy downloading, Please wait for the downloading to finish."));
m_failed_retry = 0;
return;
}
m_failed_code = 1;
if (!m_remote_support) { // not support tutk
Stop(m_lan_ip.empty()
? _L("Initialize failed (Missing LAN ip of printer)!")
: _L("Initialize failed (Not supported by printer)!"));
@ -248,6 +256,7 @@ void MediaPlayCtrl::Stop(wxString const &msg)
j["dev_ip"] = m_lan_ip;
j["result"] = "failed";
j["user_triggered"] = m_user_triggered;
j["tunnel"] = m_url.find("/local/") == std::string::npos ? "remote" : "local";
j["code"] = m_failed_code;
j["msg"] = into_u8(msg);
NetworkAgent *agent = wxGetApp().getAgent();
@ -257,7 +266,7 @@ void MediaPlayCtrl::Stop(wxString const &msg)
}
++m_failed_retry;
if (m_failed_code != 0 && !m_tutk_support && (m_failed_retry > 1 || m_user_triggered)) {
if (m_failed_code != 0 && (!m_remote_support || m_lan_mode) && (m_failed_retry > 1 || m_user_triggered)) {
m_next_retry = wxDateTime(); // stop retry
if (wxGetApp().show_modal_ip_address_enter_dialog(_L("LAN Connection Failed (Failed to start liveview)"))) {
m_failed_retry = 0;

View file

@ -74,8 +74,9 @@ private:
std::string m_lan_passwd;
bool m_camera_exists = false;
bool m_lan_mode = false;
bool m_tutk_support = false;
bool m_remote_support = false;
bool m_device_busy = false;
bool m_disable_lan = false;
wxString m_url;
std::deque<wxString> m_tasks;

View file

@ -573,6 +573,7 @@ void MonitorPanel::show_status(int status)
m_status_info_panel->show_status(status);
m_hms_panel->show_status(status);
m_upgrade_panel->show_status(status);
m_media_file_panel->Enable(status == MonitorStatus::MONITOR_NORMAL);
if ((status & (int)MonitorStatus::MONITOR_NO_PRINTER) != 0) {
set_default();

View file

@ -3488,10 +3488,14 @@ void StatusPanel::show_status(int status)
show_printing_status(false, false);
m_calibration_btn->Disable();
m_options_btn->Disable();
m_panel_monitoring_title->Disable();
m_media_play_ctrl->Disable();
} else if ((status & (int) MonitorStatus::MONITOR_NORMAL) != 0) {
show_printing_status(true, true);
m_calibration_btn->Disable();
m_options_btn->Enable();
m_panel_monitoring_title->Enable();
m_media_play_ctrl->Enable();
}
}