mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-27 11:59:27 +00:00
refactor: abstract bambu specific protocol to printer agent
This commit is contained in:
@@ -12,9 +12,6 @@
|
|||||||
#include "slic3r/GUI/DeviceCore/DevManager.h"
|
#include "slic3r/GUI/DeviceCore/DevManager.h"
|
||||||
#include "slic3r/GUI/DeviceCore/DevUtil.h"
|
#include "slic3r/GUI/DeviceCore/DevUtil.h"
|
||||||
|
|
||||||
#include "slic3r/Utils/FileTransferUtils.hpp"
|
|
||||||
#include "slic3r/Utils/BBLNetworkPlugin.hpp"
|
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
@@ -204,45 +201,35 @@ void PrintJob::process(Ctl &ctl)
|
|||||||
params.dev_ip = m_dev_ip;
|
params.dev_ip = m_dev_ip;
|
||||||
params.use_ssl_for_ftp = m_local_use_ssl_for_ftp;
|
params.use_ssl_for_ftp = m_local_use_ssl_for_ftp;
|
||||||
params.use_ssl_for_mqtt = m_local_use_ssl;
|
params.use_ssl_for_mqtt = m_local_use_ssl;
|
||||||
params.username = "bblp";
|
params.username = m_agent->default_lan_username();
|
||||||
params.password = m_access_code;
|
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
|
// check access code and ip address
|
||||||
if (this->connection_type == "lan" && m_print_type == "from_normal") {
|
if (this->connection_type == "lan" && m_print_type == "from_normal") {
|
||||||
bool emmc_ok = false;
|
params.dev_id = m_dev_id;
|
||||||
bool ftp_ok = false;
|
params.project_name = "verify_job";
|
||||||
if (could_emmc_print) {
|
params.filename = job_data._temp_path.string();
|
||||||
std::string devIP = m_dev_ip;
|
params.connection_type = this->connection_type;
|
||||||
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;
|
|
||||||
|
|
||||||
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 (result != 0) {
|
||||||
}
|
|
||||||
if (!emmc_ok && !ftp_ok) {
|
|
||||||
bool legacy_mode = BBLNetworkPlugin::instance().use_legacy_network();
|
|
||||||
BOOST_LOG_TRIVIAL(error) << "LAN connection verification failed:"
|
BOOST_LOG_TRIVIAL(error) << "LAN connection verification failed:"
|
||||||
<< " emmc_ok=" << emmc_ok
|
<< " result=" << result
|
||||||
<< ", ftp_ok=" << ftp_ok
|
|
||||||
<< ", ftp_result=" << result
|
|
||||||
<< ", dev_ip=" << m_dev_ip
|
<< ", dev_ip=" << m_dev_ip
|
||||||
<< ", dev_id=" << m_dev_id
|
<< ", dev_id=" << m_dev_id
|
||||||
<< ", password_length=" << m_access_code.size()
|
<< ", password_length=" << m_access_code.size();
|
||||||
<< ", legacy_mode=" << (legacy_mode ? "true" : "false");
|
|
||||||
m_enter_ip_address_fun_fail();
|
m_enter_ip_address_fun_fail();
|
||||||
m_job_finished = true;
|
m_job_finished = true;
|
||||||
return;
|
return;
|
||||||
@@ -277,17 +264,6 @@ void PrintJob::process(Ctl &ctl)
|
|||||||
params.auto_offset_cali = this->auto_offset_cali;
|
params.auto_offset_cali = this->auto_offset_cali;
|
||||||
params.extruder_cali_manual_mode = this->extruder_cali_manual_mode;
|
params.extruder_cali_manual_mode = this->extruder_cali_manual_mode;
|
||||||
params.task_ext_change_assist = this->task_ext_change_assist;
|
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") {
|
if (m_print_type == "from_sdcard_view") {
|
||||||
params.dst_file = m_dst_path;
|
params.dst_file = m_dst_path;
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ void SendJob::process(Ctl &ctl)
|
|||||||
if (m_is_check_mode) {
|
if (m_is_check_mode) {
|
||||||
PrintParams verify_params;
|
PrintParams verify_params;
|
||||||
verify_params.dev_ip = m_dev_ip;
|
verify_params.dev_ip = m_dev_ip;
|
||||||
verify_params.username = "bblp";
|
verify_params.username = agent->default_lan_username();
|
||||||
verify_params.password = m_access_code;
|
verify_params.password = m_access_code;
|
||||||
verify_params.use_ssl_for_ftp = m_local_use_ssl_for_ftp;
|
verify_params.use_ssl_for_ftp = m_local_use_ssl_for_ftp;
|
||||||
verify_params.use_ssl_for_mqtt = m_local_use_ssl;
|
verify_params.use_ssl_for_mqtt = m_local_use_ssl;
|
||||||
@@ -209,7 +209,7 @@ void SendJob::process(Ctl &ctl)
|
|||||||
|
|
||||||
// local print access
|
// local print access
|
||||||
params.dev_ip = m_dev_ip;
|
params.dev_ip = m_dev_ip;
|
||||||
params.username = "bblp";
|
params.username = agent->default_lan_username();
|
||||||
params.password = m_access_code;
|
params.password = m_access_code;
|
||||||
params.use_ssl_for_ftp = m_local_use_ssl_for_ftp;
|
params.use_ssl_for_ftp = m_local_use_ssl_for_ftp;
|
||||||
params.use_ssl_for_mqtt = m_local_use_ssl;
|
params.use_ssl_for_mqtt = m_local_use_ssl;
|
||||||
|
|||||||
@@ -466,8 +466,8 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr<PrinterFileSystem> wfs)
|
|||||||
m_waiting_support = false;
|
m_waiting_support = false;
|
||||||
NetworkAgent *agent = wxGetApp().getAgent();
|
NetworkAgent *agent = wxGetApp().getAgent();
|
||||||
std::string agent_version = agent ? agent->get_version() : "";
|
std::string agent_version = agent ? agent->get_version() : "";
|
||||||
if ((m_lan_mode || !m_remote_proto) && m_local_proto && !m_lan_ip.empty()) {
|
if (agent && (m_lan_mode || !m_remote_proto) && m_local_proto && !m_lan_ip.empty()) {
|
||||||
std::string url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd;
|
std::string url = agent->get_local_camera_url(m_lan_ip, m_lan_user, m_lan_passwd);
|
||||||
url += "&device=" + m_machine;
|
url += "&device=" + m_machine;
|
||||||
url += "&net_ver=" + agent_version;
|
url += "&net_ver=" + agent_version;
|
||||||
url += "&dev_ver=" + m_dev_ver;
|
url += "&dev_ver=" + m_dev_ver;
|
||||||
|
|||||||
@@ -246,6 +246,11 @@ int BBLPrinterAgent::send_message_to_printer(std::string dev_id, std::string jso
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string BBLPrinterAgent::get_local_camera_url(std::string dev_ip, std::string username, std::string password)
|
||||||
|
{
|
||||||
|
return "bambu:///local/" + dev_ip + ".?port=6000&user=" + username + "&passwd=" + password;
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Certificates
|
// Certificates
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -509,8 +514,15 @@ int BBLPrinterAgent::start_local_print_with_record(PrintParams params, OnUpdateS
|
|||||||
|
|
||||||
int BBLPrinterAgent::start_send_gcode_to_sdcard(PrintParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn, OnWaitFn wait_fn)
|
int BBLPrinterAgent::start_send_gcode_to_sdcard(PrintParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn, OnWaitFn wait_fn)
|
||||||
{
|
{
|
||||||
return dispatch_start<func_start_send_gcode_to_sdcard_legacy, func_start_send_gcode_to_sdcard_0203>(
|
int result = dispatch_start<func_start_send_gcode_to_sdcard_legacy, func_start_send_gcode_to_sdcard_0203>(
|
||||||
BBLNetworkPlugin::instance().get_start_send_gcode_to_sdcard(), params, update_fn, cancel_fn, wait_fn);
|
BBLNetworkPlugin::instance().get_start_send_gcode_to_sdcard(), params, update_fn, cancel_fn, wait_fn);
|
||||||
|
if (result != 0) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "start_send_gcode_to_sdcard failed: result=" << result
|
||||||
|
<< ", try_emmc_print=" << params.try_emmc_print
|
||||||
|
<< ", legacy_mode=" << BBLNetworkPlugin::instance().use_legacy_network()
|
||||||
|
<< ", dev_ip=" << params.dev_ip << ", dev_id=" << params.dev_id;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BBLPrinterAgent::start_local_print(PrintParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn)
|
int BBLPrinterAgent::start_local_print(PrintParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn)
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ public:
|
|||||||
int connect_printer(std::string dev_id, std::string dev_ip, std::string username, std::string password, bool use_ssl) override;
|
int connect_printer(std::string dev_id, std::string dev_ip, std::string username, std::string password, bool use_ssl) override;
|
||||||
int disconnect_printer() override;
|
int disconnect_printer() override;
|
||||||
int send_message_to_printer(std::string dev_id, std::string json_str, int qos, int flag) override;
|
int send_message_to_printer(std::string dev_id, std::string json_str, int qos, int flag) override;
|
||||||
|
std::string get_local_camera_url(std::string dev_ip, std::string username, std::string password) override;
|
||||||
|
std::string default_lan_username() const override { return "bblp"; }
|
||||||
|
|
||||||
// Certificates
|
// Certificates
|
||||||
int check_cert() override;
|
int check_cert() override;
|
||||||
|
|||||||
@@ -107,6 +107,19 @@ public:
|
|||||||
bool is_core_xy, bool supports_mqtt_axis_control, int sequence_id, bool lan_mode)
|
bool is_core_xy, bool supports_mqtt_axis_control, int sequence_id, bool lan_mode)
|
||||||
{ return ORCA_NETWORK_ERR_CMD_NOT_SUPPORTED; }
|
{ return ORCA_NETWORK_ERR_CMD_NOT_SUPPORTED; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a ready-to-use local (LAN) camera stream URL for this agent's protocol.
|
||||||
|
* Returns an empty string if the agent has no local camera stream support.
|
||||||
|
*/
|
||||||
|
virtual std::string get_local_camera_url(std::string dev_ip, std::string username, std::string password)
|
||||||
|
{ return {}; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default LAN account username for this agent's protocol, if it has a fixed one.
|
||||||
|
* Returns an empty string if the agent has no fixed default (e.g. caller must supply one).
|
||||||
|
*/
|
||||||
|
virtual std::string default_lan_username() const { return {}; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Establish a direct LAN connection to a printer.
|
* Establish a direct LAN connection to a printer.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -852,6 +852,20 @@ int NetworkAgent::send_message_to_printer(std::string dev_id, std::string json_s
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string NetworkAgent::get_local_camera_url(std::string dev_ip, std::string username, std::string password)
|
||||||
|
{
|
||||||
|
if (m_printer_agent)
|
||||||
|
return m_printer_agent->get_local_camera_url(dev_ip, username, password);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string NetworkAgent::default_lan_username() const
|
||||||
|
{
|
||||||
|
if (m_printer_agent)
|
||||||
|
return m_printer_agent->default_lan_username();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
int NetworkAgent::check_cert()
|
int NetworkAgent::check_cert()
|
||||||
{
|
{
|
||||||
if (m_printer_agent)
|
if (m_printer_agent)
|
||||||
|
|||||||
@@ -155,6 +155,8 @@ public:
|
|||||||
int connect_printer(std::string dev_id, std::string dev_ip, std::string username, std::string password, bool use_ssl);
|
int connect_printer(std::string dev_id, std::string dev_ip, std::string username, std::string password, bool use_ssl);
|
||||||
int disconnect_printer();
|
int disconnect_printer();
|
||||||
int send_message_to_printer(std::string dev_id, std::string json_str, int qos, int flag);
|
int send_message_to_printer(std::string dev_id, std::string json_str, int qos, int flag);
|
||||||
|
std::string get_local_camera_url(std::string dev_ip, std::string username, std::string password);
|
||||||
|
std::string default_lan_username() const;
|
||||||
int check_cert();
|
int check_cert();
|
||||||
void install_device_cert(std::string dev_id, bool lan_only);
|
void install_device_cert(std::string dev_id, bool lan_only);
|
||||||
bool start_discovery(bool start, bool sending);
|
bool start_discovery(bool start, bool sending);
|
||||||
|
|||||||
Reference in New Issue
Block a user