refactor: abstract bambu specific protocol to printer agent

This commit is contained in:
Ian Chua
2026-08-11 15:00:34 +08:00
parent 58be7f4861
commit 742cb712d8
8 changed files with 68 additions and 49 deletions
+20 -44
View File
@@ -12,9 +12,6 @@
#include "slic3r/GUI/DeviceCore/DevManager.h"
#include "slic3r/GUI/DeviceCore/DevUtil.h"
#include "slic3r/Utils/FileTransferUtils.hpp"
#include "slic3r/Utils/BBLNetworkPlugin.hpp"
namespace Slic3r {
namespace GUI {
@@ -204,45 +201,35 @@ void PrintJob::process(Ctl &ctl)
params.dev_ip = m_dev_ip;
params.use_ssl_for_ftp = m_local_use_ssl_for_ftp;
params.use_ssl_for_mqtt = m_local_use_ssl;
params.username = "bblp";
params.username = m_agent->default_lan_username();
params.password = m_access_code;
// Allow disabling the eMMC print path via AppConfig. Plugin 02.03.00.62's
// eMMC tunnel code hangs indefinitely at the upload phase with some
// printers (e.g., Bambu H2D), so we default to disabled. Users with
// working eMMC support can opt-in by setting disable_emmc_print = 0.
bool disable_emmc = true;
if (wxGetApp().app_config) {
auto v = wxGetApp().app_config->get("disable_emmc_print");
if (v == "0" || v == "false")
disable_emmc = false;
}
params.try_emmc_print = this->could_emmc_print && !disable_emmc;
// check access code and ip address
if (this->connection_type == "lan" && m_print_type == "from_normal") {
bool emmc_ok = false;
bool ftp_ok = false;
if (could_emmc_print) {
std::string devIP = m_dev_ip;
std::string accessCode = m_access_code;
std::string url = "bambu:///local/" + devIP + "?port=6000&user=" + "bblp" + "&passwd=" + accessCode;
try {
std::unique_ptr<FileTransferTunnel> tunnel = std::make_unique<FileTransferTunnel>(module(), url);
emmc_ok = tunnel->sync_start_connect();
} catch (const std::exception &e) {
BOOST_LOG_TRIVIAL(warning) << "eMMC tunnel unavailable, falling back to FTP: " << e.what();
emmc_ok = false;
}
}
{
params.dev_id = m_dev_id;
params.project_name = "verify_job";
params.filename = job_data._temp_path.string();
params.connection_type = this->connection_type;
params.dev_id = m_dev_id;
params.project_name = "verify_job";
params.filename = job_data._temp_path.string();
params.connection_type = this->connection_type;
result = m_agent->start_send_gcode_to_sdcard(params, nullptr, nullptr, nullptr);
result = m_agent->start_send_gcode_to_sdcard(params, nullptr, nullptr, nullptr);
ftp_ok = result == 0;
}
if (!emmc_ok && !ftp_ok) {
bool legacy_mode = BBLNetworkPlugin::instance().use_legacy_network();
if (result != 0) {
BOOST_LOG_TRIVIAL(error) << "LAN connection verification failed:"
<< " emmc_ok=" << emmc_ok
<< ", ftp_ok=" << ftp_ok
<< ", ftp_result=" << result
<< " result=" << result
<< ", dev_ip=" << m_dev_ip
<< ", dev_id=" << m_dev_id
<< ", password_length=" << m_access_code.size()
<< ", legacy_mode=" << (legacy_mode ? "true" : "false");
<< ", password_length=" << m_access_code.size();
m_enter_ip_address_fun_fail();
m_job_finished = true;
return;
@@ -277,17 +264,6 @@ void PrintJob::process(Ctl &ctl)
params.auto_offset_cali = this->auto_offset_cali;
params.extruder_cali_manual_mode = this->extruder_cali_manual_mode;
params.task_ext_change_assist = this->task_ext_change_assist;
// Allow disabling the eMMC print path via AppConfig. Plugin 02.03.00.62's
// eMMC tunnel code hangs indefinitely at the upload phase with some
// printers (e.g., Bambu H2D), so we default to disabled. Users with
// working eMMC support can opt-in by setting disable_emmc_print = 0.
bool disable_emmc = true;
if (wxGetApp().app_config) {
auto v = wxGetApp().app_config->get("disable_emmc_print");
if (v == "0" || v == "false")
disable_emmc = false;
}
params.try_emmc_print = this->could_emmc_print && !disable_emmc;
if (m_print_type == "from_sdcard_view") {
params.dst_file = m_dst_path;