ENH:add network verification process for LAN printing

Change-Id: I0a9e9fa5e9746f5ceb989b00c6b44e812d071132
This commit is contained in:
tao wang 2023-02-07 10:42:30 +08:00 committed by Lane.Wei
parent 088668994c
commit a94b78d296
5 changed files with 71 additions and 14 deletions

View File

@ -34,6 +34,12 @@ PrintJob::PrintJob(std::shared_ptr<ProgressIndicator> pri, Plater* plater, std::
void PrintJob::prepare()
{
m_plater->get_print_job_data(&job_data);
if (&job_data) {
std::string temp_file = Slic3r::resources_dir() + "/check_access_code.txt";
auto check_access_code_path = temp_file.c_str();
BOOST_LOG_TRIVIAL(trace) << "sned_job: check_access_code_path = " << check_access_code_path;
job_data._temp_path = fs::path(check_access_code_path);
}
}
void PrintJob::on_exception(const std::exception_ptr &eptr)
@ -144,7 +150,32 @@ void PrintJob::process()
else
curr_plate_idx = m_plater->get_partplate_list().get_curr_plate_index() + 1;
BBL::PrintParams params;
// local print access
params.dev_ip = m_dev_ip;
params.use_ssl = m_local_use_ssl;
params.username = "bblp";
params.password = m_access_code;
// check access code and ip address
if (this->connection_type == "lan") {
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);
if (result != 0) {
BOOST_LOG_TRIVIAL(error) << "access code is invalid";
m_enter_ip_address_fun_fail();
m_job_finished = true;
return;
}
}
params.dev_id = m_dev_id;
//params.project_name = project_name;
params.project_name = m_project_name;
@ -179,11 +210,6 @@ void PrintJob::process()
}
}
// local print access
params.dev_ip = m_dev_ip;
params.use_ssl = m_local_use_ssl;
params.username = "bblp";
params.password = m_access_code;
wxString error_text;
wxString msg_text;
@ -385,4 +411,14 @@ void PrintJob::set_project_name(std::string name)
m_project_name = name;
}
void PrintJob::on_check_ip_address_fail(std::function<void()> func)
{
m_enter_ip_address_fun_fail = func;
}
void PrintJob::on_check_ip_address_success(std::function<void()> func)
{
m_enter_ip_address_fun_success = func;
}
}} // namespace Slic3r::GUI

View File

@ -29,6 +29,8 @@ class PrintJob : public PlaterJob
std::string m_dev_id;
bool m_job_finished{ false };
int m_print_job_completed_id = 0;
std::function<void()> m_enter_ip_address_fun_fail{ nullptr };
std::function<void()> m_enter_ip_address_fun_success{ nullptr };
protected:
@ -78,6 +80,8 @@ public:
void process() override;
void finalize() override;
void set_project_name(std::string name);
void on_check_ip_address_fail(std::function<void()> func);
void on_check_ip_address_success(std::function<void()> func);
};
}} // namespace Slic3r::GUI

View File

@ -40,7 +40,6 @@ void SendJob::prepare()
BOOST_LOG_TRIVIAL(trace) << "sned_job: check_access_code_path = " << check_access_code_path;
job_data._temp_path = fs::path(check_access_code_path);
}
}
void SendJob::on_exception(const std::exception_ptr &eptr)

View File

@ -33,6 +33,7 @@ wxDEFINE_EVENT(EVT_UNBIND_MACHINE, wxCommandEvent);
wxDEFINE_EVENT(EVT_DISSMISS_MACHINE_LIST, wxCommandEvent);
wxDEFINE_EVENT(EVT_CONNECT_LAN_PRINT, wxCommandEvent);
wxDEFINE_EVENT(EVT_EDIT_PRINT_NAME, wxCommandEvent);
wxDEFINE_EVENT(EVT_CLEAR_IPADDRESS, wxCommandEvent);
#define INITIAL_NUMBER_OF_MACHINES 0
#define LIST_REFRESH_INTERVAL 200
@ -1248,7 +1249,9 @@ SelectMachineDialog::SelectMachineDialog(Plater *plater)
if (e.GetInt() == 1) {
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
m_comboBox_printer->SetValue(dev->get_selected_machine()->dev_name + "(LAN)");
if (dev->get_selected_machine()) {
m_comboBox_printer->SetValue(dev->get_selected_machine()->dev_name + "(LAN)");
}
}
});
@ -1919,6 +1922,7 @@ void SelectMachineDialog::init_model()
void SelectMachineDialog::init_bind()
{
Bind(wxEVT_TIMER, &SelectMachineDialog::on_timer, this);
Bind(EVT_CLEAR_IPADDRESS, &SelectMachineDialog::clear_ip_address_config, this);
}
void SelectMachineDialog::init_timer()
@ -1948,6 +1952,7 @@ bool SelectMachineDialog::is_same_printer_model()
if (!dev) return result;
MachineObject* obj_ = dev->get_selected_machine();
assert(obj_->dev_id == m_printer_last_select);
if (obj_ == nullptr) {
return result;
@ -1972,6 +1977,12 @@ void SelectMachineDialog::show_errors(wxString &info)
void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
{
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
MachineObject* obj_ = dev->get_selected_machine();
if (!obj_) return;
std::vector<wxString> confirm_text;
confirm_text.push_back(_L("Please check the following infomation and click Confirm to continue sending print:") + "\n");
@ -1987,11 +1998,7 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
//Check slice warnings
bool has_slice_warnings = false;
PartPlate* plate = m_plater->get_partplate_list().get_curr_plate();
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if(!dev) return;
MachineObject* obj_ = dev->get_selected_machine();
for (auto warning : plate->get_slice_result()->warnings) {
if (warning.msg == BED_TEMP_TOO_HIGH_THAN_FILAMENT) {
if ((obj_->printer_type == "BL-P001" || obj_->printer_type == "BL-P002")) {
@ -2210,11 +2217,21 @@ void SelectMachineDialog::on_ok()
m_print_job->on_success([this]() { finish_mode(); });
wxCommandEvent evt(m_plater->get_print_finished_event());
m_print_job->on_check_ip_address_fail([this]() {
wxCommandEvent* evt = new wxCommandEvent(EVT_CLEAR_IPADDRESS);
wxQueueEvent(this, evt);
wxGetApp().show_ip_address_enter_dialog();
});
m_print_job->start();
BOOST_LOG_TRIVIAL(info) << "print_job: start print job";
}
void SelectMachineDialog::clear_ip_address_config(wxCommandEvent& e)
{
prepare_mode();
}
void SelectMachineDialog::update_user_machine_list()
{
NetworkAgent* m_agent = wxGetApp().getAgent();

View File

@ -425,7 +425,8 @@ protected:
void show_errors(wxString &info);
void on_ok_btn(wxCommandEvent &event);
void on_ok();
void on_refresh(wxCommandEvent &event);
void clear_ip_address_config(wxCommandEvent& e);
void on_refresh(wxCommandEvent& event);
void on_set_finish_mapping(wxCommandEvent &evt);
void on_print_job_cancel(wxCommandEvent &evt);
void set_default();