mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-25 18:00:57 +00:00
Merge branch 'feat/printer-agent-infra' into feat/printer-agent-impl
This commit is contained in:
@@ -673,12 +673,7 @@ namespace Slic3r
|
||||
m_agent->disconnect_printer();
|
||||
it->second->reset();
|
||||
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
AppConfig* config = get_app_config();
|
||||
it->second->connect(config && config->get("enable_ssl_for_mqtt") == "true");
|
||||
#else
|
||||
it->second->connect(it->second->local_use_ssl);
|
||||
#endif
|
||||
it->second->connect();
|
||||
it->second->set_lan_mode_connection_state(true);
|
||||
}
|
||||
}
|
||||
@@ -700,12 +695,7 @@ namespace Slic3r
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << "set_selected_machine: select new lan machine, dev_id =" << dev_id;
|
||||
it->second->reset();
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
AppConfig* config = get_app_config();
|
||||
it->second->connect(config && config->get("enable_ssl_for_mqtt") == "true");
|
||||
#else
|
||||
it->second->connect(it->second->local_use_ssl);
|
||||
#endif
|
||||
it->second->connect();
|
||||
it->second->set_lan_mode_connection_state(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1774,20 +1774,10 @@ int MachineObject::command_ams_filament_settings(int ams_id, int slot_id, std::s
|
||||
return this->publish_json(j);
|
||||
}
|
||||
|
||||
int MachineObject::command_ams_refresh_rfid(std::string tray_id)
|
||||
int MachineObject::command_ams_refresh_rfid(int ams_id, int slot_id)
|
||||
{
|
||||
if (!m_agent) return -1;
|
||||
return command_with_dialog(m_agent->command_ams_refresh_rfid(get_dev_id(), tray_id, MachineObject::m_sequence_id++, is_lan_mode_printer()));
|
||||
}
|
||||
|
||||
int MachineObject::command_ams_refresh_rfid2(int ams_id, int slot_id)
|
||||
{
|
||||
json j;
|
||||
j["print"]["command"] = "ams_get_rfid";
|
||||
j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
|
||||
j["print"]["ams_id"] = ams_id;
|
||||
j["print"]["slot_id"] = slot_id;
|
||||
return this->publish_json(j);
|
||||
return command_with_dialog(m_agent->command_ams_refresh_rfid(get_dev_id(), ams_id, slot_id, MachineObject::m_sequence_id++, is_lan_mode_printer()));
|
||||
}
|
||||
|
||||
int MachineObject::command_start_camera()
|
||||
@@ -2629,14 +2619,19 @@ void MachineObject::update_print_progress(const json& value)
|
||||
curr_task->task_progress = mc_print_percent;
|
||||
}
|
||||
|
||||
int MachineObject::connect(bool use_openssl)
|
||||
int MachineObject::connect()
|
||||
{
|
||||
if (get_dev_ip().empty()) return -1;
|
||||
std::string username = m_agent ? m_agent->default_lan_username() : std::string();
|
||||
std::string password = get_access_code();
|
||||
|
||||
std::string port;
|
||||
std::string host = Http::get_host_from_url(get_dev_ip(), &port);
|
||||
std::string input = get_dev_ip();
|
||||
|
||||
const bool use_ssl = input.rfind("https", 0) == 0;
|
||||
|
||||
// This strips out the http/https prefix
|
||||
std::string host = Http::get_host_from_url(input, &port);
|
||||
std::string ca_file;
|
||||
|
||||
if (GUI::wxGetApp().preset_bundle) {
|
||||
@@ -2649,6 +2644,7 @@ int MachineObject::connect(bool use_openssl)
|
||||
if (host.empty())
|
||||
host = get_dev_ip();
|
||||
|
||||
|
||||
if (m_agent) {
|
||||
try {
|
||||
PrinterConnectionParams params{
|
||||
@@ -2657,7 +2653,7 @@ int MachineObject::connect(bool use_openssl)
|
||||
port,
|
||||
username,
|
||||
password,
|
||||
use_openssl,
|
||||
use_ssl,
|
||||
ca_file
|
||||
};
|
||||
return m_agent->connect_printer(params);
|
||||
|
||||
@@ -678,7 +678,7 @@ public:
|
||||
|
||||
|
||||
/* machine mqtt apis */
|
||||
int connect(bool use_openssl = true);
|
||||
int connect();
|
||||
int disconnect();
|
||||
|
||||
json_diff print_json;
|
||||
@@ -796,8 +796,7 @@ public:
|
||||
int command_ams_calibrate(int ams_id);
|
||||
int command_ams_filament_settings(int ams_id, int slot_id, std::string filament_id, std::string setting_id, std::string tray_color, std::string tray_type, int nozzle_temp_min, int nozzle_temp_max);
|
||||
int command_ams_select_tray(std::string tray_id);
|
||||
int command_ams_refresh_rfid(std::string tray_id);
|
||||
int command_ams_refresh_rfid2(int ams_id, int slot_id);
|
||||
int command_ams_refresh_rfid(int ams_id, int slot_id);
|
||||
int command_ams_control(std::string action);
|
||||
int command_ams_drying_stop();
|
||||
int command_start_extrusion_cali(int tray_index, int nozzle_temp, int bed_temp, float max_volumetric_speed, std::string setting_id = "");
|
||||
|
||||
@@ -1866,6 +1866,11 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt)
|
||||
|
||||
if (wxGetApp().preset_bundle) {
|
||||
auto& config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
||||
std::string port;
|
||||
Http::get_host_from_url(str_ip, &port);
|
||||
config.opt_string("print_host") = str_ip;
|
||||
if (!port.empty())
|
||||
config.opt_string("printhost_port") = port;
|
||||
if (Http::ca_file_supported())
|
||||
config.opt_string("printhost_cafile") = m_input_cafile->GetValue().ToStdString();
|
||||
}
|
||||
|
||||
@@ -4734,11 +4734,11 @@ void StatusPanel::on_ams_refresh_rfid(wxCommandEvent &event)
|
||||
try {
|
||||
if (!use_new_command) {
|
||||
int tray_index = atoi(curr_ams_id.c_str()) * 4 + atoi(slot_it->second->id.c_str());
|
||||
obj->command_ams_refresh_rfid(std::to_string(tray_index));
|
||||
obj->command_ams_refresh_rfid(-1, tray_index);
|
||||
}
|
||||
|
||||
if (use_new_command) {
|
||||
obj->command_ams_refresh_rfid2(stoi(curr_ams_id), stoi(curr_can_id));
|
||||
obj->command_ams_refresh_rfid(stoi(curr_ams_id), stoi(curr_can_id));
|
||||
}
|
||||
|
||||
} catch (...) {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "NetworkAgentFactory.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "NetworkAgent.hpp"
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/DeviceCore/DevManager.h"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
@@ -148,36 +150,27 @@ void BBLPrinterAgent::set_cloud_agent(std::shared_ptr<ICloudServiceAgent> cloud)
|
||||
// Communication
|
||||
// ============================================================================
|
||||
|
||||
std::string BBLPrinterAgent::ams_refresh_rfid_gcode(const std::string& tray_id)
|
||||
int BBLPrinterAgent::command_ams_refresh_rfid(std::string dev_id, int ams_id, int slot_id, int sequence_id, bool lan_mode)
|
||||
{
|
||||
return (boost::format("M620 R%1% \n") % tray_id).str();
|
||||
}
|
||||
|
||||
std::string BBLPrinterAgent::ams_calibrate_gcode(int ams_id)
|
||||
{
|
||||
return (boost::format("M620 C%1% \n") % ams_id).str();
|
||||
}
|
||||
|
||||
std::string BBLPrinterAgent::ams_select_tray_gcode(const std::string& tray_id)
|
||||
{
|
||||
return (boost::format("M620 P%1% \n") % tray_id).str();
|
||||
}
|
||||
|
||||
int BBLPrinterAgent::command_ams_refresh_rfid(std::string dev_id, std::string tray_id, int sequence_id, bool lan_mode)
|
||||
{
|
||||
const std::string gcode = ams_refresh_rfid_gcode(tray_id);
|
||||
BOOST_LOG_TRIVIAL(trace) << "ams_debug: gcode_cmd" << gcode;
|
||||
nlohmann::json j;
|
||||
j["print"]["command"] = "gcode_line";
|
||||
j["print"]["param"] = gcode;
|
||||
j["print"]["sequence_id"] = std::to_string(sequence_id);
|
||||
if (ams_id == -1) {
|
||||
const std::string gcode = (boost::format("M620 R%1% \n") % slot_id).str();
|
||||
j["print"]["command"] = "gcode_line";
|
||||
j["print"]["param"] = gcode;
|
||||
j["print"]["sequence_id"] = std::to_string(sequence_id);
|
||||
return publish(dev_id, j, lan_mode);
|
||||
}
|
||||
|
||||
j["print"]["command"] = "ams_get_rfid";
|
||||
j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
|
||||
j["print"]["ams_id"] = ams_id;
|
||||
j["print"]["slot_id"] = slot_id;
|
||||
return publish(dev_id, j, lan_mode);
|
||||
}
|
||||
|
||||
int BBLPrinterAgent::command_ams_calibrate(std::string dev_id, int ams_id, int sequence_id, bool lan_mode)
|
||||
{
|
||||
const std::string gcode = ams_calibrate_gcode(ams_id);
|
||||
BOOST_LOG_TRIVIAL(trace) << "ams_debug: gcode_cmd" << gcode;
|
||||
const std::string gcode = (boost::format("M620 C%1% \n") % ams_id).str();
|
||||
nlohmann::json j;
|
||||
j["print"]["command"] = "gcode_line";
|
||||
j["print"]["param"] = gcode;
|
||||
@@ -187,8 +180,7 @@ int BBLPrinterAgent::command_ams_calibrate(std::string dev_id, int ams_id, int s
|
||||
|
||||
int BBLPrinterAgent::command_ams_select_tray(std::string dev_id, std::string tray_id, int sequence_id, bool lan_mode)
|
||||
{
|
||||
const std::string gcode = ams_select_tray_gcode(tray_id);
|
||||
BOOST_LOG_TRIVIAL(trace) << "ams_debug: gcode_cmd" << gcode;
|
||||
const std::string gcode = (boost::format("M620 P%1% \n") % tray_id).str();
|
||||
nlohmann::json j;
|
||||
j["print"]["command"] = "gcode_line";
|
||||
j["print"]["param"] = gcode;
|
||||
@@ -278,8 +270,18 @@ int BBLPrinterAgent::connect_printer(const PrinterConnectionParams& params)
|
||||
auto& plugin = BBLNetworkPlugin::instance();
|
||||
auto agent = plugin.get_agent();
|
||||
auto func = plugin.get_connect_printer();
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
const bool use_ssl_for_mqtt = GUI::wxGetApp().app_config &&
|
||||
GUI::wxGetApp().app_config->get_bool("enable_ssl_for_mqtt");
|
||||
#else
|
||||
bool use_ssl_for_mqtt = true;
|
||||
if (auto* dev_manager = GUI::wxGetApp().getDeviceManager()) {
|
||||
if (auto* machine = dev_manager->get_my_machine(params.dev_id))
|
||||
use_ssl_for_mqtt = machine->local_use_ssl;
|
||||
}
|
||||
#endif
|
||||
if (func && agent) {
|
||||
return func(agent, params.dev_id, params.host, params.username, params.password, params.use_ssl);
|
||||
return func(agent, params.dev_id, params.host, params.username, params.password, use_ssl_for_mqtt);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -29,10 +29,7 @@ public:
|
||||
|
||||
// Communication
|
||||
int send_message(std::string dev_id, std::string json_str, int qos, int flag) override;
|
||||
static std::string ams_refresh_rfid_gcode(const std::string& tray_id);
|
||||
static std::string ams_calibrate_gcode(int ams_id);
|
||||
static std::string ams_select_tray_gcode(const std::string& tray_id);
|
||||
int command_ams_refresh_rfid(std::string dev_id, std::string tray_id, int sequence_id, bool lan_mode) override;
|
||||
int command_ams_refresh_rfid(std::string dev_id, int ams_id, int slot_id, int sequence_id, bool lan_mode) override;
|
||||
int command_ams_calibrate(std::string dev_id, int ams_id, int sequence_id, bool lan_mode) override;
|
||||
int command_ams_select_tray(std::string dev_id, std::string tray_id, int sequence_id, bool lan_mode) override;
|
||||
int command_axis_control(std::string dev_id, std::string axis, double unit, double input_val, int speed,
|
||||
|
||||
@@ -34,13 +34,14 @@ struct AgentInfo {
|
||||
std::string description; ///< Brief description of the agent's capabilities, e.g. "Orca printer agent"
|
||||
};
|
||||
|
||||
struct PrinterConnectionParams {
|
||||
struct PrinterConnectionParams
|
||||
{
|
||||
std::string dev_id;
|
||||
std::string host;
|
||||
std::string port;
|
||||
std::string host; // host address, usually the IP address without the http/https protocol
|
||||
std::string port; // optional
|
||||
std::string username;
|
||||
std::string password;
|
||||
bool use_ssl = false;
|
||||
bool use_ssl = false; // indicates if http or https
|
||||
std::string ca_file;
|
||||
};
|
||||
|
||||
@@ -111,7 +112,7 @@ public:
|
||||
// why: gcode is firmware dialect, not a waist concept - commands whose body is Bambu-dialect
|
||||
// gcode live on the agent that speaks it; the default is an honest refusal that MachineObject's
|
||||
// publish funnel turns into a dialog.
|
||||
virtual int command_ams_refresh_rfid(std::string, std::string, int, bool)
|
||||
virtual int command_ams_refresh_rfid(std::string, int, int, int, bool)
|
||||
{ return ORCA_NETWORK_ERR_CMD_NOT_SUPPORTED; }
|
||||
virtual int command_ams_calibrate(std::string, int, int, bool)
|
||||
{ return ORCA_NETWORK_ERR_CMD_NOT_SUPPORTED; }
|
||||
|
||||
@@ -379,7 +379,7 @@ int MoonrakerPrinterAgent::connect_printer(const PrinterConnectionParams& params
|
||||
// Launch connection in background thread (capture by value to avoid data races)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(connect_mutex);
|
||||
connect_thread = std::thread([this, params, base_url, api_key, gen]() { perform_connection_async(params.dev_id, base_url, api_key, gen); });
|
||||
connect_thread = std::thread([this, dev_id = params.dev_id, base_url, api_key, gen]() { perform_connection_async(dev_id, base_url, api_key, gen); });
|
||||
}
|
||||
|
||||
return BAMBU_NETWORK_SUCCESS;
|
||||
@@ -575,12 +575,11 @@ int MoonrakerPrinterAgent::start_local_print(PrintParams params, OnUpdateStatusF
|
||||
return BAMBU_NETWORK_ERR_CANCELED;
|
||||
}
|
||||
|
||||
// Start print via Moonraker's print API, referencing the file we just uploaded.
|
||||
// Start print via Moonraker's G-code script endpoint, referencing the file we just uploaded.
|
||||
if (update_fn)
|
||||
update_fn(PrintingStageSending, 0, "Starting print...");
|
||||
|
||||
std::string start_error;
|
||||
if (!start_print_file(device_info.base_url, device_info.api_key, upload_filename, start_error)) {
|
||||
std::string gcode = "SDCARD_PRINT_FILE FILENAME=" + upload_filename;
|
||||
if (!send_gcode_sync(device_info.dev_id, gcode)) {
|
||||
return BAMBU_NETWORK_ERR_PRINT_LP_PUBLISH_MSG_FAILED;
|
||||
}
|
||||
|
||||
@@ -1385,12 +1384,8 @@ int MoonrakerPrinterAgent::handle_request(const std::string& dev_id, const std::
|
||||
}
|
||||
response["print"]["param"] = gcode;
|
||||
|
||||
auto [base_url, api_key] = connection_snapshot();
|
||||
enqueue_command([this, dev_id, response = std::move(response), base_url = std::move(base_url),
|
||||
api_key = std::move(api_key)]() mutable {
|
||||
response["print"]["result"] = send_gcode(dev_id, response["print"]["param"].get<std::string>(), base_url, api_key)
|
||||
? "success"
|
||||
: "failed";
|
||||
send_gcode_async(dev_id, gcode, [this, dev_id, response](bool success) mutable {
|
||||
response["print"]["result"] = success ? "success" : "failed";
|
||||
dispatch_message(dev_id, response.dump());
|
||||
});
|
||||
return BAMBU_NETWORK_SUCCESS;
|
||||
@@ -1424,11 +1419,7 @@ int MoonrakerPrinterAgent::handle_request(const std::string& dev_id, const std::
|
||||
if (json["print"].contains("temp") && json["print"]["temp"].is_number()) {
|
||||
int temp = json["print"]["temp"].get<int>();
|
||||
std::string gcode = "SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET=" + std::to_string(temp);
|
||||
auto [base_url, api_key] = connection_snapshot();
|
||||
enqueue_command([this, dev_id, gcode = std::move(gcode), base_url = std::move(base_url),
|
||||
api_key = std::move(api_key)] {
|
||||
send_gcode(dev_id, gcode, base_url, api_key);
|
||||
});
|
||||
send_gcode_async(dev_id, gcode);
|
||||
return BAMBU_NETWORK_SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -1443,11 +1434,7 @@ int MoonrakerPrinterAgent::handle_request(const std::string& dev_id, const std::
|
||||
}
|
||||
std::string heater = (extruder_idx == 0) ? "extruder" : "extruder" + std::to_string(extruder_idx);
|
||||
std::string gcode = "SET_HEATER_TEMPERATURE HEATER=" + heater + " TARGET=" + std::to_string(temp);
|
||||
auto [base_url, api_key] = connection_snapshot();
|
||||
enqueue_command([this, dev_id, gcode = std::move(gcode), base_url = std::move(base_url),
|
||||
api_key = std::move(api_key)] {
|
||||
send_gcode(dev_id, gcode, base_url, api_key);
|
||||
});
|
||||
send_gcode_async(dev_id, gcode);
|
||||
return BAMBU_NETWORK_SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -1455,10 +1442,7 @@ int MoonrakerPrinterAgent::handle_request(const std::string& dev_id, const std::
|
||||
// why: no current OrcaSlicer sender emits the "home" discriminator;
|
||||
// GUI homing uses gcode_line with G28 instead.
|
||||
if (cmd == "home") {
|
||||
auto [base_url, api_key] = connection_snapshot();
|
||||
enqueue_command([this, dev_id, base_url = std::move(base_url), api_key = std::move(api_key)] {
|
||||
send_gcode(dev_id, "G28", base_url, api_key);
|
||||
});
|
||||
send_gcode_async(dev_id, "G28");
|
||||
return BAMBU_NETWORK_SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -1504,9 +1488,7 @@ bool MoonrakerPrinterAgent::init_device_info(const std::string& dev_id, const st
|
||||
device_info.use_ssl = use_ssl;
|
||||
device_info.model_name = printer_cfg.opt_string("printer_model");
|
||||
device_info.model_id = preset.get_printer_type(preset_bundle);
|
||||
device_info.base_url = normalize_base_url(dev_ip, port);
|
||||
if (use_ssl && boost::istarts_with(device_info.base_url, "http://"))
|
||||
device_info.base_url.replace(0, 7, "https://");
|
||||
device_info.base_url = normalize_base_url(use_ssl, dev_ip, port);
|
||||
device_info.dev_id = dev_id;
|
||||
device_info.version = "";
|
||||
device_info.dev_name = device_info.dev_id;
|
||||
@@ -1913,7 +1895,56 @@ bool MoonrakerPrinterAgent::post_print_action(const std::string& action,
|
||||
return true;
|
||||
}
|
||||
|
||||
void MoonrakerPrinterAgent::send_gcode_async(const std::string& dev_id, const std::string& gcode,
|
||||
std::function<void(bool)> on_result) const
|
||||
{
|
||||
(void) dev_id;
|
||||
std::string base_url;
|
||||
std::string api_key;
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(connect_mutex);
|
||||
base_url = device_info.base_url;
|
||||
api_key = device_info.api_key;
|
||||
}
|
||||
|
||||
auto http = Http::post(join_url(base_url, "/printer/gcode/script"));
|
||||
if (!api_key.empty()) {
|
||||
http.header("X-Api-Key", api_key);
|
||||
}
|
||||
http.header("Content-Type", "application/json")
|
||||
.set_post_body(nlohmann::json{{"script", gcode}}.dump())
|
||||
.timeout_connect(5)
|
||||
.timeout_max(10)
|
||||
.on_complete([on_result](std::string body, unsigned status_code) {
|
||||
(void) body;
|
||||
const bool success = status_code == 200;
|
||||
if (!success) {
|
||||
BOOST_LOG_TRIVIAL(error) << "MoonrakerPrinterAgent: send_gcode failed: HTTP error " << status_code;
|
||||
}
|
||||
if (on_result) {
|
||||
on_result(success);
|
||||
}
|
||||
})
|
||||
.on_error([on_result](std::string body, std::string err, unsigned status_code) {
|
||||
(void) body;
|
||||
std::string error = err;
|
||||
if (status_code > 0) {
|
||||
error += " (HTTP " + std::to_string(status_code) + ")";
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(error) << "MoonrakerPrinterAgent: send_gcode failed: " << error;
|
||||
if (on_result) {
|
||||
on_result(false);
|
||||
}
|
||||
})
|
||||
.perform();
|
||||
}
|
||||
|
||||
bool MoonrakerPrinterAgent::send_gcode(const std::string& dev_id, const std::string& gcode) const
|
||||
{
|
||||
return send_gcode_sync(dev_id, gcode);
|
||||
}
|
||||
|
||||
bool MoonrakerPrinterAgent::send_gcode_sync(const std::string& dev_id, const std::string& gcode) const
|
||||
{
|
||||
// why: snapshot then release - see post_print_action.
|
||||
std::string base_url, api_key;
|
||||
@@ -3018,7 +3049,7 @@ void MoonrakerPrinterAgent::perform_connection_async(const std::string& dev_id,
|
||||
if (is_stale()) {
|
||||
return;
|
||||
}
|
||||
device_info.dev_name = fetched_info.dev_name;
|
||||
device_info.dev_name = fetched_info.dev_name.empty() ? dev_id : fetched_info.dev_name;
|
||||
device_info.version = fetched_info.version;
|
||||
device_info.klippy_state = fetched_info.klippy_state;
|
||||
device_info.nozzle_diameter = fetched_info.nozzle_diameter;
|
||||
@@ -3066,26 +3097,11 @@ bool MoonrakerPrinterAgent::is_numeric(const std::string& value)
|
||||
return !value.empty() && std::all_of(value.begin(), value.end(), [](unsigned char c) { return std::isdigit(c) != 0; });
|
||||
}
|
||||
|
||||
std::string MoonrakerPrinterAgent::normalize_base_url(std::string host, const std::string& port)
|
||||
std::string MoonrakerPrinterAgent::normalize_base_url(bool use_ssl, const std::string& host, const std::string& port)
|
||||
{
|
||||
boost::trim(host);
|
||||
if (host.empty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string value = host;
|
||||
if (is_numeric(port) && value.find("://") == std::string::npos && value.find(':') == std::string::npos) {
|
||||
value += ":" + port;
|
||||
}
|
||||
|
||||
if (!boost::istarts_with(value, "http://") && !boost::istarts_with(value, "https://")) {
|
||||
value = "http://" + value;
|
||||
}
|
||||
|
||||
if (value.size() > 1 && value.back() == '/') {
|
||||
value.pop_back();
|
||||
}
|
||||
|
||||
std::string value = use_ssl ? "https://" : "http://";
|
||||
value += host;
|
||||
value += port.empty() ? "" : (":" + port);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ protected:
|
||||
|
||||
// Helpers
|
||||
bool is_numeric(const std::string& value);
|
||||
std::string normalize_base_url(std::string host, const std::string& port);
|
||||
std::string normalize_base_url(bool use_ssl, const std::string& host, const std::string& port);
|
||||
std::string sanitize_filename(const std::string& filename);
|
||||
std::string join_url(const std::string& base_url, const std::string& path) const;
|
||||
|
||||
@@ -177,6 +177,9 @@ private:
|
||||
|
||||
bool fetch_object_list(const std::string& base_url, const std::string& api_key, std::set<std::string>& objects, std::string& error) const;
|
||||
bool query_printer_status(const std::string& base_url, const std::string& api_key, nlohmann::json& status, std::string& error) const;
|
||||
bool send_gcode_sync(const std::string& dev_id, const std::string& gcode) const;
|
||||
void send_gcode_async(const std::string& dev_id, const std::string& gcode,
|
||||
std::function<void(bool)> on_result = {}) const;
|
||||
|
||||
void announce_printhost_device();
|
||||
void dispatch_local_connect(int state, const std::string& dev_id, const std::string& msg);
|
||||
|
||||
@@ -793,10 +793,10 @@ int NetworkAgent::send_message(std::string dev_id, std::string json_str, int qos
|
||||
return -1;
|
||||
}
|
||||
|
||||
int NetworkAgent::command_ams_refresh_rfid(std::string dev_id, std::string tray_id, int sequence_id, bool lan_mode)
|
||||
int NetworkAgent::command_ams_refresh_rfid(std::string dev_id, int ams_id, int slot_id, int sequence_id, bool lan_mode)
|
||||
{
|
||||
if (m_printer_agent)
|
||||
return m_printer_agent->command_ams_refresh_rfid(dev_id, tray_id, sequence_id, lan_mode);
|
||||
return m_printer_agent->command_ams_refresh_rfid(dev_id, ams_id, slot_id, sequence_id, lan_mode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
int set_on_local_message_fn(OnMessageFn fn);
|
||||
int set_server_callback(OnServerErrFn fn);
|
||||
int send_message(std::string dev_id, std::string json_str, int qos, int flag);
|
||||
int command_ams_refresh_rfid(std::string dev_id, std::string tray_id, int sequence_id, bool lan_mode);
|
||||
int command_ams_refresh_rfid(std::string dev_id, int ams_id, int slot_id, int sequence_id, bool lan_mode);
|
||||
int command_ams_calibrate(std::string dev_id, int ams_id, int sequence_id, bool lan_mode);
|
||||
int command_ams_select_tray(std::string dev_id, std::string tray_id, int sequence_id, bool lan_mode);
|
||||
int command_start_camera(std::string dev_id);
|
||||
|
||||
+2
-2
@@ -71,9 +71,9 @@ public:
|
||||
ORCA_PY_AGENT_OVERRIDE(int, send_message_to_printer, dev_id, json_str, qos, flag);
|
||||
}
|
||||
|
||||
int command_ams_refresh_rfid(std::string dev_id, std::string tray_id, int sequence_id, bool lan_mode) override
|
||||
int command_ams_refresh_rfid(std::string dev_id, int ams_id,int slot_id, int sequence_id, bool lan_mode) override
|
||||
{
|
||||
ORCA_PY_AGENT_OVERRIDE_DEFAULT(int, command_ams_refresh_rfid, dev_id, tray_id, sequence_id, lan_mode);
|
||||
ORCA_PY_AGENT_OVERRIDE_DEFAULT(int, command_ams_refresh_rfid, dev_id, ams_id, slot_id, sequence_id, lan_mode);
|
||||
}
|
||||
|
||||
int command_ams_calibrate(std::string dev_id, int ams_id, int sequence_id, bool lan_mode) override
|
||||
|
||||
@@ -128,7 +128,7 @@ TEST_CASE("A printer agent uses IPrinterAgent defaults for omitted commands", "[
|
||||
|
||||
CHECK(agent->command_xyz_abs("dev", 1, false) == 7);
|
||||
CHECK(agent->command_set_nozzle("dev", 200, 2, true) == 8);
|
||||
CHECK(agent->command_ams_refresh_rfid("dev", "tray", 3, false) == ORCA_NETWORK_ERR_CMD_NOT_SUPPORTED);
|
||||
CHECK(agent->command_ams_refresh_rfid("dev", -1, 0, 3, false) == ORCA_NETWORK_ERR_CMD_NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
TEST_CASE("A printer agent operation returning the wrong type answers like a missing agent", "[PluginPrinterAgent][Python]")
|
||||
|
||||
Reference in New Issue
Block a user