mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-08-05 19:46:43 +08:00
ENH:Add logging to the send function and optimize the connection process
jira: [STUDIO-11777] Change-Id: Idac7b7835f13ec1805442a8c8aefbb35786c36ef
This commit is contained in:
parent
2a7da8456c
commit
6c07f1b9a2
@ -1537,6 +1537,8 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
|
||||
m_messages.clear();
|
||||
if (result)
|
||||
m_cond.timed_wait(l, boost::posix_time::seconds(10));
|
||||
|
||||
|
||||
while (true) {
|
||||
while (m_stopped) {
|
||||
if (m_session.owner == nullptr)
|
||||
@ -1573,14 +1575,24 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
|
||||
Bambu_SetLogger(tunnel, DumpLog, this);
|
||||
ret = Bambu_Open(tunnel);
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
do {
|
||||
ret = Bambu_StartStreamEx
|
||||
? Bambu_StartStreamEx(tunnel, CTRL_TYPE)
|
||||
: Bambu_StartStream(tunnel, false);
|
||||
if (ret == Bambu_would_block) {}
|
||||
{
|
||||
auto start_time = boost::posix_time::microsec_clock::universal_time();
|
||||
boost::posix_time::time_duration timeout = boost::posix_time::seconds(3);
|
||||
do{
|
||||
ret = Bambu_StartStreamEx ? Bambu_StartStreamEx(tunnel, CTRL_TYPE) : Bambu_StartStream(tunnel, false);
|
||||
if (ret == Bambu_would_block)
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(100));
|
||||
|
||||
auto now = boost::posix_time::microsec_clock::universal_time();
|
||||
if (now - start_time > timeout) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "StartStream timeout after 5 seconds.";
|
||||
break;
|
||||
}
|
||||
|
||||
} while (ret == Bambu_would_block && !m_stopped);
|
||||
}
|
||||
l.lock();
|
||||
if (ret == 0) {
|
||||
m_session.tunnel = tunnel;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <algorithm>
|
||||
#include "BitmapCache.hpp"
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
@ -779,12 +780,13 @@ void SendToPrinterDialog::on_cancel(wxCloseEvent &event)
|
||||
m_tutk_try_connect = false;
|
||||
m_ftp_try_connect = false;
|
||||
m_connect_try_times = 0;
|
||||
|
||||
this->EndModal(wxID_CANCEL);
|
||||
}
|
||||
|
||||
void SendToPrinterDialog::on_ok(wxCommandEvent &event)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << "print_job: on_ok to send";
|
||||
BOOST_LOG_TRIVIAL(info) << "print_job: on_ok to send !";
|
||||
m_is_canceled = false;
|
||||
Enable_Send_Button(false);
|
||||
if (m_is_in_sending_mode)
|
||||
@ -891,7 +893,7 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
|
||||
file_name = default_output_file_path.filename().string();
|
||||
}*/
|
||||
|
||||
if (!obj_->is_lan_mode_printer() && obj_->is_support_brtc) {
|
||||
if ((!obj_->is_lan_mode_printer() && obj_->is_support_brtc) || m_tcp_try_connect) {
|
||||
update_print_status_msg(wxEmptyString, false, false);
|
||||
if (m_file_sys) {
|
||||
PrintPrepareData print_data;
|
||||
@ -920,13 +922,36 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
|
||||
|
||||
this->Bind(
|
||||
wxEVT_TIMER,
|
||||
[this, wfs = boost::weak_ptr(m_file_sys)](auto e) {
|
||||
[this, wfs = boost::weak_ptr(m_file_sys), obj_](auto e) {
|
||||
show_status(PrintDialogStatus::PrintStatusPublicUploadFiled);
|
||||
|
||||
boost::shared_ptr fs(wfs.lock());
|
||||
if (!fs) return;
|
||||
fs->CancelUploadTask(false);
|
||||
update_print_status_msg(_L("Upload file timeout, please check if the firmware version supports it."), false, true);
|
||||
|
||||
//first time use tcp, second time use tutk , secnod time use ftp
|
||||
if (m_connect_try_times < 2) {
|
||||
bool is_lan = (obj_->connection_type() == "lan");
|
||||
m_tcp_try_connect = false;
|
||||
|
||||
if (is_lan) {
|
||||
m_ftp_try_connect = true;
|
||||
m_tutk_try_connect = false;
|
||||
} else {
|
||||
if (m_connect_try_times == 0) {
|
||||
m_ftp_try_connect = false;
|
||||
m_tutk_try_connect = true;
|
||||
} else {
|
||||
m_ftp_try_connect = true;
|
||||
m_tutk_try_connect = false;
|
||||
}
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << "send failed";
|
||||
BOOST_LOG_TRIVIAL(info) << "m_ftp_try_connect is " << m_ftp_try_connect ;
|
||||
BOOST_LOG_TRIVIAL(info) << "m_tutk_try_connect is " << m_tutk_try_connect ;
|
||||
BOOST_LOG_TRIVIAL(info) << "m_tcp_try_connect is " << m_tcp_try_connect ;
|
||||
} else
|
||||
update_print_status_msg(_L("Upload file timeout, please check if the firmware version supports it."), false, true);
|
||||
m_connect_try_times++;
|
||||
},
|
||||
m_task_timer->GetId());
|
||||
m_task_timer->StartOnce(timeout_period);
|
||||
@ -944,14 +969,19 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
|
||||
m_send_job->m_access_code = obj_->get_access_code();
|
||||
|
||||
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "send_job: use ftp send job";
|
||||
|
||||
|
||||
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
m_send_job->m_local_use_ssl_for_ftp = wxGetApp().app_config->get("enable_ssl_for_ftp") == "true" ? true : false;
|
||||
m_send_job->m_local_use_ssl_for_mqtt = wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false;
|
||||
#else
|
||||
m_send_job->m_local_use_ssl_for_ftp = obj_->local_use_ssl_for_ftp;
|
||||
m_send_job->m_local_use_ssl_for_mqtt = obj_->local_use_ssl_for_mqtt;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
m_send_job->connection_type = obj_->connection_type();
|
||||
m_send_job->cloud_print_only = true;
|
||||
m_send_job->has_sdcard = obj_->get_sdcard_state() == MachineObject::SdcardState::HAS_SDCARD_NORMAL;
|
||||
@ -985,6 +1015,7 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
|
||||
} else {
|
||||
m_send_job->start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1169,7 +1200,9 @@ void SendToPrinterDialog::on_selection_changed(wxCommandEvent &event)
|
||||
m_tcp_try_connect = true;
|
||||
m_tutk_try_connect = false;
|
||||
m_ftp_try_connect = false;
|
||||
|
||||
m_connect_try_times = 0;
|
||||
|
||||
MachineObject* obj = nullptr;
|
||||
for (int i = 0; i < m_list.size(); i++) {
|
||||
if (i == selection) {
|
||||
@ -1269,6 +1302,8 @@ void SendToPrinterDialog::update_show_status()
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!m_is_in_sending_mode) {
|
||||
if (!obj_->is_support_brtc || m_ftp_try_connect) {
|
||||
if (m_file_sys) {
|
||||
@ -1276,6 +1311,9 @@ void SendToPrinterDialog::update_show_status()
|
||||
m_file_sys->Stop(true);
|
||||
m_file_sys.reset();
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << "m_ftp_try_connect is " << m_ftp_try_connect;
|
||||
|
||||
// add log
|
||||
show_status(PrintDialogStatus::PrintStatusReadingFinished);
|
||||
return;
|
||||
} else/* if (obj_->connection_type() == "cloud")*/ {
|
||||
@ -1284,7 +1322,10 @@ void SendToPrinterDialog::update_show_status()
|
||||
if (m_file_sys) {
|
||||
if (dev_id == m_device_select) {
|
||||
if ((m_waiting_enable && IsEnabled()) || (m_waiting_support && obj_->get_file_remote()))
|
||||
{
|
||||
m_file_sys->Retry();
|
||||
BOOST_LOG_TRIVIAL(info) << "m_file_sys Retry success!" ;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
m_file_sys->Stop(true);
|
||||
@ -1327,17 +1368,34 @@ void SendToPrinterDialog::update_show_status()
|
||||
break;
|
||||
}
|
||||
case PrinterFileSystem::Failed: {
|
||||
if (m_connect_try_times < 3) {
|
||||
if (m_connect_try_times < 2) {
|
||||
bool is_lan = (obj_->connection_type() == "lan");
|
||||
|
||||
m_ftp_try_connect = is_lan || m_tutk_try_connect;
|
||||
m_tutk_try_connect = !is_lan || m_tutk_try_connect;
|
||||
m_tcp_try_connect = false;
|
||||
m_tcp_try_connect = false;
|
||||
|
||||
if (is_lan) {
|
||||
m_ftp_try_connect = true;
|
||||
m_tutk_try_connect = false;
|
||||
} else {
|
||||
if (m_connect_try_times == 0) {
|
||||
m_ftp_try_connect = false;
|
||||
m_tutk_try_connect = true;
|
||||
} else {
|
||||
m_ftp_try_connect = true;
|
||||
m_tutk_try_connect = false;
|
||||
}
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << "connect failed" ;
|
||||
BOOST_LOG_TRIVIAL(info) << "m_ftp_try_connect is " << m_ftp_try_connect;
|
||||
BOOST_LOG_TRIVIAL(info) << "m_tutk_try_connect is " << m_tutk_try_connect ;
|
||||
BOOST_LOG_TRIVIAL(info) << "m_tcp_try_connect is " << m_tcp_try_connect;
|
||||
}
|
||||
else
|
||||
msg = _L("Please check the network and try again, You can restart or update the printer if the issue persists.");
|
||||
fs->Stop();
|
||||
m_connect_try_times++;
|
||||
BOOST_LOG_TRIVIAL(info) << "m_connect_try_times is " << m_connect_try_times;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1764,6 +1822,7 @@ bool SendToPrinterDialog::Show(bool show)
|
||||
m_tcp_try_connect = true;
|
||||
m_ftp_try_connect = false;
|
||||
m_tutk_try_connect = false;
|
||||
//BOOST_LOG_TRIVIAL(info) << "m_ftp_try_connect is " << m_ftp_try_connect << boost::stacktrace::stacktrace();
|
||||
m_connect_try_times = 0;
|
||||
} else {
|
||||
m_refresh_timer->Stop();
|
||||
@ -1817,6 +1876,8 @@ void SendToPrinterDialog::fetchUrl(boost::weak_ptr<PrinterFileSystem> wfs)
|
||||
NetworkAgent *agent = wxGetApp().getAgent();
|
||||
std::string agent_version = agent ? agent->get_version() : "";
|
||||
|
||||
|
||||
|
||||
if (agent) {
|
||||
if (m_tcp_try_connect) {
|
||||
std::string devIP = obj->dev_ip;
|
||||
|
Loading…
x
Reference in New Issue
Block a user