ENH: waiting for printer ack in printing job

JIRA: STUDIO-4175

Change-Id: I94c26497979d7ffecebf378a4c4bc244914491fd
Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
Stone Li
2023-09-11 15:55:00 +08:00
committed by Lane.Wei
parent 38b86616ce
commit 2ff4173db3
9 changed files with 101 additions and 25 deletions

View File

@@ -209,7 +209,7 @@ void PrintJob::process()
params.filename = job_data._temp_path.string();
params.connection_type = this->connection_type;
result = m_agent->start_send_gcode_to_sdcard(params, nullptr, nullptr);
result = m_agent->start_send_gcode_to_sdcard(params, nullptr, nullptr, nullptr);
if (result != 0) {
BOOST_LOG_TRIVIAL(error) << "access code is invalid";
m_enter_ip_address_fun_fail();
@@ -391,6 +391,51 @@ void PrintJob::process()
return was_canceled();
};
DeviceManager* dev = wxGetApp().getDeviceManager();
MachineObject* obj = dev->get_selected_machine();
auto wait_fn = [this, curr_percent, &obj](int state, std::string job_info) {
BOOST_LOG_TRIVIAL(info) << "print_job: get_job_info = " << job_info;
std::string curr_job_id;
json job_info_j;
try {
job_info_j.parse(job_info);
if (job_info_j.contains("job_id")) {
curr_job_id = job_info_j["job_id"].get<std::string>();
}
BOOST_LOG_TRIVIAL(trace) << "print_job: curr_obj_id=" << curr_job_id;
} catch(...) {
;
}
if (obj) {
int time_out = 0;
while (time_out < PRINT_JOB_SENDING_TIMEOUT) {
BOOST_LOG_TRIVIAL(trace) << "print_job: obj job_id = " << obj->job_id_;
if (!obj->job_id_.empty() && obj->job_id_.compare(curr_job_id) == 0) {
BOOST_LOG_TRIVIAL(info) << "print_job: got job_id = " << obj->job_id_ << ", time_out=" << time_out;
return true;
}
if (obj->is_in_printing_status(obj->print_status)) {
BOOST_LOG_TRIVIAL(info) << "print_job: printer has enter printing status, s = " << obj->print_status;
return true;
}
time_out++;
boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
}
this->update_status(curr_percent, _L("Print task sending times out."));
BOOST_LOG_TRIVIAL(info) << "print_job: timeout, cancel the job" << obj->job_id_;
/* handle tiemout */
obj->command_task_cancel(curr_job_id);
return false;
}
BOOST_LOG_TRIVIAL(info) << "print_job: obj is null";
return true;
};
if (params.connection_type != "lan") {
if (params.dev_ip.empty())
params.comments = "no_ip";
@@ -413,7 +458,7 @@ void PrintJob::process()
BOOST_LOG_TRIVIAL(info) << "print_job: use ftp send print only";
this->update_status(curr_percent, _L("Sending print job over LAN"));
is_try_lan_mode = true;
result = m_agent->start_local_print_with_record(params, update_fn, cancel_fn);
result = m_agent->start_local_print_with_record(params, update_fn, cancel_fn, wait_fn);
if (result < 0) {
error_text = wxString::Format("Access code:%s Ip address:%s", params.password, params.dev_ip);
// try to send with cloud
@@ -429,7 +474,7 @@ void PrintJob::process()
// try to send local with record
BOOST_LOG_TRIVIAL(info) << "print_job: try to start local print with record";
this->update_status(curr_percent, _L("Sending print job over LAN"));
result = m_agent->start_local_print_with_record(params, update_fn, cancel_fn);
result = m_agent->start_local_print_with_record(params, update_fn, cancel_fn, wait_fn);
if (result == 0) {
params.comments = "";
}
@@ -444,13 +489,13 @@ void PrintJob::process()
// try to send with cloud
BOOST_LOG_TRIVIAL(warning) << "print_job: try to send with cloud";
this->update_status(curr_percent, _L("Sending print job through cloud service"));
result = m_agent->start_print(params, update_fn, cancel_fn);
result = m_agent->start_print(params, update_fn, cancel_fn, wait_fn);
}
}
else {
BOOST_LOG_TRIVIAL(info) << "print_job: send with cloud";
this->update_status(curr_percent, _L("Sending print job through cloud service"));
result = m_agent->start_print(params, update_fn, cancel_fn);
result = m_agent->start_print(params, update_fn, cancel_fn, wait_fn);
}
}
} else {
@@ -489,6 +534,8 @@ void PrintJob::process()
BOOST_LOG_TRIVIAL(error) << "print_job: failed, result = " << result;
} else {
// wait for printer mqtt ready the same job id
wxGetApp().plater()->record_slice_preset("print");
BOOST_LOG_TRIVIAL(error) << "print_job: send ok.";

View File

@@ -10,6 +10,8 @@ namespace fs = boost::filesystem;
namespace Slic3r {
namespace GUI {
#define PRINT_JOB_SENDING_TIMEOUT 10
class PrintPrepareData
{
public:

View File

@@ -139,7 +139,7 @@ void SendJob::process()
params.filename = job_data._temp_path.string();
params.connection_type = this->connection_type;
result = m_agent->start_send_gcode_to_sdcard(params, nullptr, nullptr);
result = m_agent->start_send_gcode_to_sdcard(params, nullptr, nullptr, nullptr);
if (result != 0) {
BOOST_LOG_TRIVIAL(error) << "access code is invalid";
m_enter_ip_address_fun_fail(result);
@@ -317,7 +317,7 @@ void SendJob::process()
// try to send local with record
BOOST_LOG_TRIVIAL(info) << "send_job: try to send gcode to printer";
this->update_status(curr_percent, _L("Sending gcode file over LAN"));
result = m_agent->start_send_gcode_to_sdcard(params, update_fn, cancel_fn);
result = m_agent->start_send_gcode_to_sdcard(params, update_fn, cancel_fn, nullptr);
if (result == BAMBU_NETWORK_ERR_FTP_UPLOAD_FAILED) {
params.comments = "upload_failed";
} else {
@@ -335,7 +335,7 @@ void SendJob::process()
} else {
if (this->has_sdcard) {
this->update_status(curr_percent, _L("Sending gcode file over LAN"));
result = m_agent->start_send_gcode_to_sdcard(params, update_fn, cancel_fn);
result = m_agent->start_send_gcode_to_sdcard(params, update_fn, cancel_fn, nullptr);
} else {
this->update_status(curr_percent, _L("An SD card needs to be inserted before sending to printer."));
return;