From a2a9b2ce94cc67a865ca8f44c876b635c440c750 Mon Sep 17 00:00:00 2001 From: Ian Chua Date: Wed, 23 Sep 2026 18:30:05 +0800 Subject: [PATCH] refactor: collapse command_ams_refresh_rfid and command_ams_refresh_rfid2 --- src/slic3r/GUI/DeviceManager.cpp | 14 ++----------- src/slic3r/GUI/DeviceManager.hpp | 3 +-- src/slic3r/GUI/StatusPanel.cpp | 4 ++-- src/slic3r/Utils/BBLPrinterAgent.cpp | 21 ++++++++++++------- src/slic3r/Utils/BBLPrinterAgent.hpp | 2 +- src/slic3r/Utils/IPrinterAgent.hpp | 2 +- src/slic3r/Utils/NetworkAgent.cpp | 4 ++-- src/slic3r/Utils/NetworkAgent.hpp | 2 +- ...PrinterAgentPluginCapabilityTrampoline.hpp | 4 ++-- .../slic3rutils/test_plugin_printer_agent.cpp | 2 +- 10 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 3645bbd0a2..06cf365752 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -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() diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index d67a3f8c29..2182c2a645 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -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 = ""); diff --git a/src/slic3r/GUI/StatusPanel.cpp b/src/slic3r/GUI/StatusPanel.cpp index 39b7c43de2..da852fe535 100644 --- a/src/slic3r/GUI/StatusPanel.cpp +++ b/src/slic3r/GUI/StatusPanel.cpp @@ -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 (...) { diff --git a/src/slic3r/Utils/BBLPrinterAgent.cpp b/src/slic3r/Utils/BBLPrinterAgent.cpp index f1a335b8c8..613df8834f 100644 --- a/src/slic3r/Utils/BBLPrinterAgent.cpp +++ b/src/slic3r/Utils/BBLPrinterAgent.cpp @@ -147,21 +147,27 @@ void BBLPrinterAgent::set_cloud_agent(std::shared_ptr cloud) // Communication // ============================================================================ -int BBLPrinterAgent::command_ams_refresh_rfid(std::string dev_id, std::string tray_id, int sequence_id, bool lan_mode) +int BBLPrinterAgent::command_ams_refresh_rfid(std::string dev_id, int ams_id, int slot_id, int sequence_id, bool lan_mode) { - const std::string gcode = (boost::format("M620 R%1% \n") % tray_id).str(); - 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 = (boost::format("M620 C%1% \n") % ams_id).str(); - BOOST_LOG_TRIVIAL(trace) << "ams_debug: gcode_cmd" << gcode; nlohmann::json j; j["print"]["command"] = "gcode_line"; j["print"]["param"] = gcode; @@ -172,7 +178,6 @@ 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 = (boost::format("M620 P%1% \n") % tray_id).str(); - BOOST_LOG_TRIVIAL(trace) << "ams_debug: gcode_cmd" << gcode; nlohmann::json j; j["print"]["command"] = "gcode_line"; j["print"]["param"] = gcode; diff --git a/src/slic3r/Utils/BBLPrinterAgent.hpp b/src/slic3r/Utils/BBLPrinterAgent.hpp index 62f25f6927..4398602976 100644 --- a/src/slic3r/Utils/BBLPrinterAgent.hpp +++ b/src/slic3r/Utils/BBLPrinterAgent.hpp @@ -29,7 +29,7 @@ public: // Communication int send_message(std::string dev_id, std::string json_str, int qos, int flag) override; - 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, diff --git a/src/slic3r/Utils/IPrinterAgent.hpp b/src/slic3r/Utils/IPrinterAgent.hpp index 5ce6daa123..ad018d466e 100644 --- a/src/slic3r/Utils/IPrinterAgent.hpp +++ b/src/slic3r/Utils/IPrinterAgent.hpp @@ -111,7 +111,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; } diff --git a/src/slic3r/Utils/NetworkAgent.cpp b/src/slic3r/Utils/NetworkAgent.cpp index 51bc38b87f..1f7705658e 100644 --- a/src/slic3r/Utils/NetworkAgent.cpp +++ b/src/slic3r/Utils/NetworkAgent.cpp @@ -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; } diff --git a/src/slic3r/Utils/NetworkAgent.hpp b/src/slic3r/Utils/NetworkAgent.hpp index dcbdb1bea6..f93178db8b 100644 --- a/src/slic3r/Utils/NetworkAgent.hpp +++ b/src/slic3r/Utils/NetworkAgent.hpp @@ -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); diff --git a/src/slic3r/plugin/pluginTypes/printerAgent/PrinterAgentPluginCapabilityTrampoline.hpp b/src/slic3r/plugin/pluginTypes/printerAgent/PrinterAgentPluginCapabilityTrampoline.hpp index 05b9e79cdd..2e15523430 100644 --- a/src/slic3r/plugin/pluginTypes/printerAgent/PrinterAgentPluginCapabilityTrampoline.hpp +++ b/src/slic3r/plugin/pluginTypes/printerAgent/PrinterAgentPluginCapabilityTrampoline.hpp @@ -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 diff --git a/tests/slic3rutils/test_plugin_printer_agent.cpp b/tests/slic3rutils/test_plugin_printer_agent.cpp index e61248309c..fc85363a39 100644 --- a/tests/slic3rutils/test_plugin_printer_agent.cpp +++ b/tests/slic3rutils/test_plugin_printer_agent.cpp @@ -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]")