From b8dde8ae7f4f5883fc163c57bb607a08ecdabf2b Mon Sep 17 00:00:00 2001 From: Kunlong Ma Date: Tue, 1 Apr 2025 14:40:07 +0800 Subject: [PATCH] FIX: fix some issue in sending files to external storage through cloud JIRA: STUDIO-9372 STUDIO-9374 STUDIO-9368 If the printer version does not support uploading, the original protocol will be used Change-Id: I3d47ac2567c2c6709a5b983ff1ad552d9a8606d4 --- src/slic3r/GUI/DeviceManager.cpp | 1 + src/slic3r/GUI/DeviceManager.hpp | 1 + src/slic3r/GUI/Printer/PrinterFileSystem.cpp | 1 + src/slic3r/GUI/SendToPrinter.cpp | 79 +++++++++++--------- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 7f61ec08d..315c1fc75 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -6219,6 +6219,7 @@ void MachineObject::parse_new_info(json print) is_support_upgrade_kit = get_flag_bits(fun, 14); is_support_internal_timelapse = get_flag_bits(fun, 28); is_support_command_homing = get_flag_bits(fun, 32); + is_support_brtc = get_flag_bits(fun, 31); } /*aux*/ diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index acf5e8c38..54578ad23 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -1081,6 +1081,7 @@ public: bool is_support_filament_setting_inprinting{false}; bool is_support_internal_timelapse { false };// fun[28], support timelapse without SD card bool is_support_command_homing { false };// fun[32] + bool is_support_brtc { false }; // fun[31], support tcp and upload protocol bool installed_upgrade_kit{false}; int bed_temperature_limit = -1; diff --git a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp index 9862786a1..b00c4e3a6 100644 --- a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp +++ b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp @@ -560,6 +560,7 @@ void PrinterFileSystem::Stop(bool quit) void PrinterFileSystem::SetUploadFile(const std::string &path, const std::string &name, const std::string &select_storage) { + boost::unique_lock l(m_mutex); if (!m_upload_file) { m_upload_file = std::make_unique(); } diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index 9b7b7fdc1..2ba9240b2 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -857,7 +857,7 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) file_name = default_output_file_path.filename().string(); }*/ #if !BBL_RELEASE_TO_PUBLIC - if (!obj_->is_lan_mode_printer()) { + if (!obj_->is_lan_mode_printer() && obj_->is_support_brtc) { update_print_status_msg(wxEmptyString, false, false); if (m_file_sys) { PrintPrepareData print_data; @@ -865,37 +865,38 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) std::string project_name = m_current_project_name.utf8_string() + ".3mf"; std::string _3mf_path = print_data._3mf_path.string(); - std::string storage; auto it = std::find_if(m_ability_list.begin(), m_ability_list.end(), [](const std::string& s) { return s != EMMC_STORAGE; }); - if (it != m_ability_list.end()) + if (it != m_ability_list.end()) { m_file_sys->SetUploadFile(_3mf_path, project_name, *it); - else { - BOOST_LOG_TRIVIAL(info) << "SendToPrinter::send job: The printer media capability set is incorrect."; + m_file_sys->RequestUploadFile(); + + // time out + if (m_task_timer && m_task_timer->IsRunning()) m_task_timer->Stop(); + + m_task_timer.reset(new wxTimer()); + m_task_timer->SetOwner(this); + + this->Bind( + wxEVT_TIMER, + [this, wfs = boost::weak_ptr(m_file_sys)](auto e) { + show_status(PrintDialogStatus::PrintStatusPublicUploadFiled); + + boost::shared_ptr fs(wfs.lock()); + if (!fs) return; + fs->CancelUploadTask(false); + update_print_status_msg(_L("Upload file timeout, please check if the firmware version supports it."), false, true); + }, + m_task_timer->GetId()); + m_task_timer->StartOnce(timeout_period); + } + else { + BOOST_LOG_TRIVIAL(error) << "SendToPrinter::send job: The printer media capability set is incorrect."; + show_status(PrintDialogStatus::PrintStatusPublicUploadFiled); + update_print_status_msg(_L("No available external storage was obtained. Please confirm and try again."), true, true); } - m_file_sys->RequestUploadFile(); - - // time out - if (m_task_timer && m_task_timer->IsRunning()) - m_task_timer->Stop(); - - m_task_timer.reset(new wxTimer()); - m_task_timer->SetOwner(this); - - this->Bind( - wxEVT_TIMER, - [this, wfs = boost::weak_ptr(m_file_sys)](auto e) { - show_status(PrintDialogStatus::PrintStatusPublicUploadFiled); - - boost::shared_ptr fs(wfs.lock()); - if (!fs) return; - fs->CancelUploadTask(false); - update_print_status_msg(_L("Upload file timeout, please check if the firmware version supports it."), false, true); - }, - m_task_timer->GetId()); - m_task_timer->StartOnce(timeout_period); } } else { #endif @@ -993,7 +994,10 @@ void SendToPrinterDialog::on_refresh(wxCommandEvent &event) show_status(PrintDialogStatus::PrintStatusRefreshingMachineList); update_user_machine_list(); /*todo refresh*/ - /*if (m_file_sys) { m_file_sys->Retry(); }*/ + if (m_file_sys) { + m_file_sys->Stop(true); + m_file_sys.reset(); + } } void SendToPrinterDialog::on_print_job_cancel(wxCommandEvent &evt) @@ -1233,11 +1237,16 @@ void SendToPrinterDialog::update_show_status() return; } #else - if (obj_->connection_type() == "lan") { + if (obj_->connection_type() == "lan" || !obj_->is_support_brtc) { + if (m_file_sys) { + m_device_select.clear(); + m_file_sys->Stop(true); + m_file_sys.reset(); + } show_status(PrintDialogStatus::PrintStatusReadingFinished); return; } else if (obj_->connection_type() == "cloud") { - Enable(obj_ && obj_->is_connected() && obj_->m_push_count > 0); + Enable(obj_ && obj_->is_connected()); std::string dev_id = obj_->dev_ip; if (m_file_sys) { if (dev_id == m_device_select) { @@ -1275,11 +1284,8 @@ void SendToPrinterDialog::update_show_status() m_task_timer->SetOwner(this); this->Bind(wxEVT_TIMER, [this, wfs_1 = boost::weak_ptr(fs), seq](auto e) { - show_status(PrintDialogStatus::PrintStatusPublicUploadFiled); - boost::shared_ptr fs_1(wfs_1.lock()); - if (!fs_1) return; - fs_1->CancelUploadTask(false); - update_print_status_msg(_L("Media capability acquisition timeout, please check if the firmware version supports it."), false, true); + show_status(PrintDialogStatus::PrintStatusPublicInitFailed); + update_print_status_msg(_L("Media capability acquisition timeout, please check if the firmware version supports it."), true, true); }, m_task_timer->GetId()); m_task_timer->StartOnce(timeout_period); @@ -1680,11 +1686,10 @@ bool SendToPrinterDialog::Show(bool show) if (show) { CenterOnParent(); } #if !BBL_RELEASE_TO_PUBLIC - if (m_file_sys && !show) { - m_file_sys->Stop(true); + if (m_file_sys) { m_waiting_enable = false; m_waiting_support = false; - m_file_sys.reset(); + show ? m_file_sys->Start() : m_file_sys->Stop(); } #endif