OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Duet Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Duet.hpp>

Inheritance diagram for Slic3r::Duet:
Collaboration diagram for Slic3r::Duet:

Public Types

typedef Http::ProgressFn ProgressFn
typedef std::function< void(wxString)> ErrorFn
typedef std::function< void(wxString, wxString)> InfoFn

Public Member Functions

 Duet (DynamicPrintConfig *config)
 ~Duet () override=default
const char * get_name () const override
bool test (wxString &curl_msg) const override
wxString get_test_ok_msg () const override
wxString get_test_failed_msg (wxString &msg) const override
bool upload (PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const override
bool has_auto_discovery () const override
bool can_test () const override
PrintHostPostUploadActions get_post_upload_actions () const override
std::string get_host () const override
virtual bool supports_multiple_printers () const
virtual std::string get_sn () const
virtual bool get_groups (wxArrayString &) const
virtual bool get_printers (wxArrayString &) const
virtual bool get_storage (wxArrayString &, wxArrayString &) const
virtual bool is_cloud () const
virtual bool is_logged_in () const
virtual void log_out () const
virtual bool get_login_url (wxString &auth_url) const

Static Public Member Functions

static PrintHost * get_print_host (DynamicPrintConfig *config)
static std::string get_print_host_webui (DynamicPrintConfig *config)
static int get_err_code_from_body (const std::string &body)

Protected Member Functions

virtual wxString format_error (const std::string &body, const std::string &error, unsigned status) const

Static Protected Member Functions

static wxString timed_out_message ()

Private Types

enum class  ConnectionType { rrf , dsf , error }

Private Member Functions

std::string get_upload_url (const std::string &filename, ConnectionType connectionType) const
std::string get_connect_url (const bool dsfUrl) const
std::string get_base_url () const
std::string timestamp_str () const
ConnectionType connect (wxString &msg) const
void disconnect (ConnectionType connectionType) const
bool start_print (wxString &msg, const std::string &filename, ConnectionType connectionType, bool simulationMode) const

Private Attributes

std::string host
std::string password

Detailed Description

Member Typedef Documentation

◆ ErrorFn

typedef std::function<void(wxString )> Slic3r::PrintHost::ErrorFn
inherited

◆ InfoFn

typedef std::function<void(wxString , wxString )> Slic3r::PrintHost::InfoFn
inherited

◆ ProgressFn

Member Enumeration Documentation

◆ ConnectionType

enum class Slic3r::Duet::ConnectionType
strongprivate
Enumerator
rrf 
dsf 
error 
33{ rrf, dsf, error };

Constructor & Destructor Documentation

◆ Duet()

Slic3r::Duet::Duet ( DynamicPrintConfig * config)
explicit
27 :
28 host(config->opt_string("print_host")),
29 password(config->opt_string("printhost_apikey"))
30{}
std::string host
Definition Duet.hpp:34
std::string password
Definition Duet.hpp:35

References host, and password.

◆ ~Duet()

Slic3r::Duet::~Duet ( )
overridedefault

Member Function Documentation

◆ can_test()

bool Slic3r::Duet::can_test ( ) const
inlineoverridevirtual

Implements Slic3r::PrintHost.

28{ return true; }

◆ connect()

Duet::ConnectionType Slic3r::Duet::connect ( wxString & msg) const
private
122{
123 auto res = ConnectionType::error;
124 auto url = get_connect_url(false);
125
126 auto http = Http::get(std::move(url));
127 http.on_error([&](std::string body, std::string error, unsigned status) {
128 auto dsfUrl = get_connect_url(true);
129 auto dsfHttp = Http::get(std::move(dsfUrl));
130 dsfHttp.on_error([&](std::string body, std::string error, unsigned status) {
131 BOOST_LOG_TRIVIAL(error) << boost::format("Duet: Error connecting: %1%, HTTP %2%, body: `%3%`") % error % status % body;
132 msg = format_error(body, error, status);
133 })
134 .on_complete([&](std::string body, unsigned) {
136 })
137 .perform_sync();
138 })
139 .on_complete([&](std::string body, unsigned) {
140 BOOST_LOG_TRIVIAL(debug) << boost::format("Duet: Got: %1%") % body;
141
142 int err_code = get_err_code_from_body(body);
143 switch (err_code) {
144 case 0:
146 break;
147 case 1:
148 msg = format_error(body, _u8L("Wrong password"), 0);
149 break;
150 case 2:
151 msg = format_error(body, _u8L("Could not get resources to create a new connection"), 0);
152 break;
153 default:
154 msg = format_error(body, _u8L("Unknown error occurred"), 0);
155 break;
156 }
157
158 })
159 .perform_sync();
160
161 return res;
162}
@ rrf
Definition Duet.hpp:33
@ error
Definition Duet.hpp:33
@ dsf
Definition Duet.hpp:33
std::string get_connect_url(const bool dsfUrl) const
Definition Duet.cpp:197
static Http get(std::string url)
Definition Http.cpp:886
virtual wxString format_error(const std::string &body, const std::string &error, unsigned status) const
Definition PrintHost.cpp:202
static int get_err_code_from_body(const std::string &body)
Definition PrintHost.cpp:188
@ http
Definition IPrinterAgent.hpp:64
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, dsf, error, Slic3r::PrintHost::format_error(), Slic3r::Http::get(), get_connect_url(), Slic3r::PrintHost::get_err_code_from_body(), Slic3r::http, and rrf.

Referenced by test(), and upload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect()

void Slic3r::Duet::disconnect ( ConnectionType connectionType) const
private
165{
166 // we don't need to disconnect from DSF or if it failed anyway
167 if (connectionType != ConnectionType::rrf) {
168 return;
169 }
170 auto url = (boost::format("%1%rr_disconnect")
171 % get_base_url()).str();
172
173 auto http = Http::get(std::move(url));
174 http.on_error([&](std::string body, std::string error, unsigned status) {
175 // we don't care about it, if disconnect is not working Duet will disconnect automatically after some time
176 BOOST_LOG_TRIVIAL(error) << boost::format("Duet: Error disconnecting: %1%, HTTP %2%, body: `%3%`") % error % status % body;
177 })
178 .perform_sync();
179}
std::string get_base_url() const
Definition Duet.cpp:210

References error, Slic3r::Http::get(), get_base_url(), Slic3r::http, and rrf.

Referenced by test(), and upload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format_error()

wxString Slic3r::PrintHost::format_error ( const std::string & body,
const std::string & error,
unsigned status ) const
protectedvirtualinherited
203{
204 if (status != 0) {
205 const std::string reason = moonraker_error_reason(body);
206 auto wxbody = wxString::FromUTF8(reason.empty() ? body : reason);
207 return wxString::Format("HTTP %u: %s", status, wxbody);
208 } else {
209 if (error.find("curl:Timeout was reached") != std::string::npos) {
210 return timed_out_message();
211 }else if(error.find("curl:Couldn't resolve host name")!= std::string::npos){
212 return _L("The Hostname/IP/URL could not be parsed, please check it and try again.");
213 } else if (error.find("Connection was reset") != std::string::npos){
214 return _L("File/data transfer interrupted. Please check the printer and network, then try it again.");
215 }
216 else {
217 return wxString::FromUTF8(error.data());
218 }
219 }
220}
#define _L(s)
Definition OBJ.cpp:34
static wxString timed_out_message()
Definition PrintHost.cpp:222
std::string moonraker_error_reason(const std::string &body)
Definition PrintHost.cpp:137

References _L, and timed_out_message().

Referenced by Slic3r::Duet::connect(), Slic3r::UltiMaker::connect(), Slic3r::SimplyPrint::do_chunk_upload(), Slic3r::SimplyPrint::do_temp_upload(), Slic3r::ElegooLink::elegoo_cc2_test(), Slic3r::ElegooLink::elegoo_test(), Slic3r::PrusaLink::post_inner(), Slic3r::PrusaLink::put_inner(), Slic3r::Flashforge::request_local_api_json(), Slic3r::Duet::start_print(), Slic3r::Moonraker::start_print(), Slic3r::UltiMaker::start_print(), Slic3r::AstroBox::test(), Slic3r::CrealityPrint::test(), Slic3r::ESP3D::test(), Slic3r::FlashAir::test(), Slic3r::Moonraker::test(), Slic3r::Obico::test(), Slic3r::OctoPrint::test(), Slic3r::PrusaLink::test(), Slic3r::Repetier::test(), Slic3r::UltiMaker::test(), Slic3r::PrusaLink::test_with_method_check(), Slic3r::AstroBox::upload(), Slic3r::C3DPrinterOS::upload(), Slic3r::CrealityPrint::upload(), Slic3r::Duet::upload(), Slic3r::ESP3D::upload(), Slic3r::FlashAir::upload(), Slic3r::MKS::upload(), Slic3r::Moonraker::upload(), Slic3r::Obico::upload(), Slic3r::Repetier::upload(), Slic3r::UltiMaker::upload(), Slic3r::OctoPrint::upload_inner_with_host(), Slic3r::Flashforge::upload_local_api(), Slic3r::ElegooLink::uploadPart(), and Slic3r::ElegooLink::uploadPartCC2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_base_url()

std::string Slic3r::Duet::get_base_url ( ) const
private
211{
212 if (host.find("http://") == 0 || host.find("https://") == 0) {
213 if (host.back() == '/') {
214 return host;
215 } else {
216 return (boost::format("%1%/") % host).str();
217 }
218 } else {
219 return (boost::format("http://%1%/") % host).str();
220 }
221}

References host.

Referenced by disconnect(), get_connect_url(), get_upload_url(), and start_print().

Here is the caller graph for this function:

◆ get_connect_url()

std::string Slic3r::Duet::get_connect_url ( const bool dsfUrl) const
private
198{
199 if (dsfUrl) {
200 return (boost::format("%1%machine/status")
201 % get_base_url()).str();
202 } else {
203 return (boost::format("%1%rr_connect?password=%2%&%3%")
204 % get_base_url()
205 % Http::url_encode(password.empty() ? "reprap" : password) // url_encode is needed because password can contain special characters like `&`, "#", etc.
206 % timestamp_str()).str();
207 }
208}
std::string timestamp_str() const
Definition Duet.cpp:223
static std::string url_encode(const std::string &str)
Definition Http.cpp:969

References get_base_url(), password, timestamp_str(), and Slic3r::Http::url_encode().

Referenced by connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_err_code_from_body()

int Slic3r::PrintHost::get_err_code_from_body ( const std::string & body)
staticinherited
189{
190 boost::property_tree::ptree root;
191 std::istringstream iss(body);
192 try {
193 boost::property_tree::read_json(iss, root);
194 } catch (const std::exception &ex) {
195 BOOST_LOG_TRIVIAL(error) << "PrintHost: response is not valid JSON: " << ex.what();
196 return -1;
197 }
198
199 return root.get<int>("err", 0);
200}

Referenced by Slic3r::Duet::connect(), Slic3r::UltiMaker::connect(), Slic3r::Duet::upload(), Slic3r::MKS::upload(), and Slic3r::UltiMaker::upload().

Here is the caller graph for this function:

◆ get_groups()

virtual bool Slic3r::PrintHost::get_groups ( wxArrayString & ) const
inlinevirtualinherited

Reimplemented in Slic3r::Repetier.

84{ return false; }

◆ get_host()

std::string Slic3r::Duet::get_host ( ) const
inlineoverridevirtual

Implements Slic3r::PrintHost.

30{ return host; }

References host.

◆ get_login_url()

virtual bool Slic3r::PrintHost::get_login_url ( wxString & auth_url) const
inlinevirtualinherited

Reimplemented in Slic3r::Obico.

99{ return false; }

Referenced by Slic3r::GUI::PrinterCloudAuthDialog::PrinterCloudAuthDialog().

Here is the caller graph for this function:

◆ get_name()

const char * Slic3r::Duet::get_name ( ) const
overridevirtual

Implements Slic3r::PrintHost.

32{ return "Duet"; }

◆ get_post_upload_actions()

PrintHostPostUploadActions Slic3r::Duet::get_post_upload_actions ( ) const
inlineoverridevirtual

◆ get_print_host()

PrintHost * Slic3r::PrintHost::get_print_host ( DynamicPrintConfig * config)
staticinherited
59{
61
62 {
63 const auto opt = config->option<ConfigOptionEnum<PrinterTechnology>>("printer_technology");
64 if (opt != nullptr) {
65 tech = opt->value;
66 }
67 }
68
69 if (tech == ptFFF) {
70 const auto opt = config->option<ConfigOptionEnum<PrintHostType>>("host_type");
71 const auto host_type = opt != nullptr ? opt->value : htOctoPrint;
72
73 switch (host_type) {
74 case htOctoPrint: return new OctoPrint(config);
75 case htDuet: return new Duet(config);
76 case htUltiMaker: return new UltiMaker(config);
77 case htFlashAir: return new FlashAir(config);
78 case htAstroBox: return new AstroBox(config);
79 case htRepetier: return new Repetier(config);
80 case htPrusaLink: return new PrusaLink(config);
81 case htPrusaConnect: return new PrusaConnect(config);
82 case htMKS: return new MKS(config);
83 case htESP3D: return new ESP3D(config);
84 case htCrealityPrint: return new CrealityPrint(config);
85 case htObico: return new Obico(config);
86 case htFlashforge: return new Flashforge(config);
87 case htSimplyPrint: return new SimplyPrint(config);
88 case htElegooLink: return new ElegooLink(config);
89 case ht3DPrinterOS: return new C3DPrinterOS(config);
90 case htMoonraker: return new Moonraker(config);
91 default: return nullptr;
92 }
93 } else {
94 return new SL1Host(config);
95 }
96}
PrinterTechnology
Definition Config.hpp:229
@ ptFFF
Definition Config.hpp:231
@ htSimplyPrint
Definition PrintConfig.hpp:119
@ htMoonraker
Definition PrintConfig.hpp:119
@ htElegooLink
Definition PrintConfig.hpp:119
@ htCrealityPrint
Definition PrintConfig.hpp:119
@ ht3DPrinterOS
Definition PrintConfig.hpp:119
@ htPrusaLink
Definition PrintConfig.hpp:119
@ htRepetier
Definition PrintConfig.hpp:119
@ htMKS
Definition PrintConfig.hpp:119
@ htPrusaConnect
Definition PrintConfig.hpp:119
@ htDuet
Definition PrintConfig.hpp:119
@ htUltiMaker
Definition PrintConfig.hpp:119
@ htObico
Definition PrintConfig.hpp:119
@ htOctoPrint
Definition PrintConfig.hpp:119
@ htFlashforge
Definition PrintConfig.hpp:119
@ htFlashAir
Definition PrintConfig.hpp:119
@ htAstroBox
Definition PrintConfig.hpp:119
@ htESP3D
Definition PrintConfig.hpp:119
ConfigOptionEnum< PrinterTechnology >
Definition PrintConfig.hpp:2358

References Slic3r::ht3DPrinterOS, Slic3r::htAstroBox, Slic3r::htCrealityPrint, Slic3r::htDuet, Slic3r::htElegooLink, Slic3r::htESP3D, Slic3r::htFlashAir, Slic3r::htFlashforge, Slic3r::htMKS, Slic3r::htMoonraker, Slic3r::htObico, Slic3r::htOctoPrint, Slic3r::htPrusaConnect, Slic3r::htPrusaLink, Slic3r::htRepetier, Slic3r::htSimplyPrint, Slic3r::htUltiMaker, Slic3r::ConfigBase::option(), and Slic3r::ptFFF.

Referenced by Slic3r::GUI::PhysicalPrinterDialog::build_printhost_settings(), Slic3r::GUI::anonymous_namespace{PrinterWebViewHandler.cpp}::ElegooPrinterWebViewHandler::handle_get_sn_request(), Slic3r::GUI::anonymous_namespace{PrinterWebViewHandler.cpp}::ElegooPrinterWebViewHandler::handle_upload_request(), Slic3r::GUI::PhysicalPrinterDialog::update_printers(), and Slic3r::GUI::PhysicalPrinterDialog::update_printhost_buttons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_print_host_webui()

std::string Slic3r::PrintHost::get_print_host_webui ( DynamicPrintConfig * config)
staticinherited
99{
100 if (config == nullptr)
101 return {};
102
103 std::string webui_url;
104 const auto* host_type_opt = config->option<ConfigOptionEnum<PrintHostType>>("host_type");
105 const auto host_type = host_type_opt != nullptr ? host_type_opt->value : htOctoPrint;
106
107 switch (host_type) {
108 case htElegooLink: {
109 webui_url = ElegooLink::get_print_host_webui(config);
110 break;
111 }
112 default: break;
113 }
114
115 if (webui_url.empty()) {
116 webui_url = config->opt_string("print_host_webui");
117 if (webui_url.empty())
118 webui_url = config->opt_string("print_host");
119 if (webui_url.empty())
120 return webui_url;
121 }
122
123 const bool has_http_scheme = boost::algorithm::istarts_with(webui_url, "http");
124 const bool has_file_scheme = boost::algorithm::istarts_with(webui_url, "file:");
125
126 if (!has_http_scheme && !has_file_scheme)
127 webui_url = "http://" + webui_url;
128
129 return webui_url;
130}

References Slic3r::ElegooLink::get_print_host_webui(), Slic3r::htElegooLink, Slic3r::htOctoPrint, Slic3r::DynamicConfig::opt_string(), Slic3r::ConfigBase::option(), and Slic3r::ConfigOptionSingle< T >::value.

Referenced by Slic3r::GUI::MainFrame::load_printer_url(), Slic3r::GUI::Plater::priv::on_tab_selection_changing(), and Slic3r::GUI::Sidebar::update_all_preset_comboboxes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_printers()

virtual bool Slic3r::PrintHost::get_printers ( wxArrayString & ) const
inlinevirtualinherited

Reimplemented in Slic3r::Obico, and Slic3r::Repetier.

85{ return false; }

◆ get_sn()

virtual std::string Slic3r::PrintHost::get_sn ( ) const
inlinevirtualinherited

Get the serial number for connecting to the printer. For Elegoo CC2, the device details connection to the printer requires the serial number. Other print hosts do not need to implement this interface, and it returns an empty string by default.

Reimplemented in Slic3r::ElegooLink.

80{ return ""; }

◆ get_storage()

virtual bool Slic3r::PrintHost::get_storage ( wxArrayString & ,
wxArrayString &  ) const
inlinevirtualinherited

Reimplemented in Slic3r::Moonraker, Slic3r::PrusaConnect, and Slic3r::PrusaLink.

88{ return false; }

◆ get_test_failed_msg()

wxString Slic3r::Duet::get_test_failed_msg ( wxString & msg) const
overridevirtual

Implements Slic3r::PrintHost.

48{
49 return GUI::from_u8((boost::format("%s: %s")
50 % _utf8(L("Could not connect to Duet"))
51 % std::string(msg.ToUTF8())).str());
52}
#define L(s)
Definition ExtrusionEntity.cpp:25
wxString from_u8(const std::string &str)
Definition GUI.cpp:544
#define _utf8(s)
Definition I18N.hpp:10

References _utf8, Slic3r::GUI::from_u8(), and L.

Here is the call graph for this function:

◆ get_test_ok_msg()

wxString Slic3r::Duet::get_test_ok_msg ( ) const
overridevirtual

Implements Slic3r::PrintHost.

43{
44 return _(L("Connection to Duet is working correctly."));
45}
#define _(s)
Definition 3mf.cpp:306

References _, and L.

◆ get_upload_url()

std::string Slic3r::Duet::get_upload_url ( const std::string & filename,
ConnectionType connectionType ) const
private
182{
183 assert(connectionType != ConnectionType::error);
184
185 if (connectionType == ConnectionType::dsf) {
186 return (boost::format("%1%machine/file/gcodes/%2%")
187 % get_base_url()
188 % Http::url_encode(filename)).str();
189 } else {
190 return (boost::format("%1%rr_upload?name=0:/gcodes/%2%&%3%")
191 % get_base_url()
192 % Http::url_encode(filename)
193 % timestamp_str()).str();
194 }
195}

References dsf, error, get_base_url(), timestamp_str(), and Slic3r::Http::url_encode().

Referenced by upload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_auto_discovery()

bool Slic3r::Duet::has_auto_discovery ( ) const
inlineoverridevirtual

Implements Slic3r::PrintHost.

27{ return false; }

◆ is_cloud()

virtual bool Slic3r::PrintHost::is_cloud ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::C3DPrinterOS, Slic3r::Obico, and Slic3r::SimplyPrint.

96{ return false; }

◆ is_logged_in()

virtual bool Slic3r::PrintHost::is_logged_in ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::C3DPrinterOS, and Slic3r::SimplyPrint.

97{ return false; }

◆ log_out()

virtual void Slic3r::PrintHost::log_out ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::C3DPrinterOS, and Slic3r::SimplyPrint.

98{}

◆ start_print()

bool Slic3r::Duet::start_print ( wxString & msg,
const std::string & filename,
ConnectionType connectionType,
bool simulationMode ) const
private
237{
238 assert(connectionType != ConnectionType::error);
239
240 bool res = false;
241 bool dsf = (connectionType == ConnectionType::dsf);
242
243 auto url = dsf
244 ? (boost::format("%1%machine/code")
245 % get_base_url()).str()
246 : (boost::format(simulationMode
247 ? "%1%rr_gcode?gcode=M37%%20P\"0:/gcodes/%2%\""
248 : "%1%rr_gcode?gcode=M32%%20\"0:/gcodes/%2%\"")
249 % get_base_url()
250 % Http::url_encode(filename)).str();
251
252 auto http = (dsf ? Http::post(std::move(url)) : Http::get(std::move(url)));
253 if (dsf) {
254 http.set_post_body(
255 (boost::format(simulationMode
256 ? "M37 P\"0:/gcodes/%1%\""
257 : "M32 \"0:/gcodes/%1%\"")
258 % filename).str()
259 );
260 }
261 http.on_error([&](std::string body, std::string error, unsigned status) {
262 BOOST_LOG_TRIVIAL(error) << boost::format("Duet: Error starting print: %1%, HTTP %2%, body: `%3%`") % error % status % body;
263 msg = format_error(body, error, status);
264 })
265 .on_complete([&](std::string body, unsigned) {
266 BOOST_LOG_TRIVIAL(debug) << boost::format("Duet: Got: %1%") % body;
267 res = true;
268 })
269 .perform_sync();
270
271 return res;
272}
static Http post(std::string url)
Definition Http.cpp:891
static std::string url_encode(const std::vector< std::pair< std::string, std::string > > query)
Definition SimplyPrint.cpp:99
@ Http
Definition PluginAuditManager.hpp:49
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:45
id get(id object, const void *key)
Definition MacIME.mm:22

References dsf, error, Slic3r::PrintHost::format_error(), Slic3r::Http::get(), get_base_url(), Slic3r::http, Slic3r::Http::post(), and Slic3r::Http::url_encode().

Referenced by upload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ supports_multiple_printers()

virtual bool Slic3r::PrintHost::supports_multiple_printers ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::Repetier.

73{ return false; }

◆ test()

bool Slic3r::Duet::test ( wxString & curl_msg) const
overridevirtual

Implements Slic3r::PrintHost.

35{
36 auto connectionType = connect(msg);
37 disconnect(connectionType);
38
39 return connectionType != ConnectionType::error;
40}
void disconnect(ConnectionType connectionType) const
Definition Duet.cpp:164
ConnectionType connect(wxString &msg) const
Definition Duet.cpp:121

References connect(), disconnect(), and error.

Here is the call graph for this function:

◆ timed_out_message()

wxString Slic3r::PrintHost::timed_out_message ( )
staticprotectedinherited
223{
224 return _L("Connection timed out. Please check if the printer and computer network are functioning properly, and confirm that they are on the same network.");
225}

References _L.

Referenced by format_error(), and Slic3r::CrealityPrint::start_print().

Here is the caller graph for this function:

◆ timestamp_str()

std::string Slic3r::Duet::timestamp_str ( ) const
private
224{
225 enum { BUFFER_SIZE = 32 };
226
227 auto t = std::time(nullptr);
228 auto tm = *std::localtime(&t);
229
230 char buffer[BUFFER_SIZE];
231 std::strftime(buffer, BUFFER_SIZE, "time=%Y-%m-%dT%H:%M:%S", &tm);
232
233 return std::string(buffer);
234}

Referenced by get_connect_url(), and get_upload_url().

Here is the caller graph for this function:

◆ upload()

bool Slic3r::Duet::upload ( PrintHostUpload upload_data,
ProgressFn prorgess_fn,
ErrorFn error_fn,
InfoFn info_fn ) const
overridevirtual

Implements Slic3r::PrintHost.

55{
56 wxString connect_msg;
57 auto connectionType = connect(connect_msg);
58 if (connectionType == ConnectionType::error) {
59 error_fn(std::move(connect_msg));
60 return false;
61 }
62
63 bool res = true;
64 bool dsf = (connectionType == ConnectionType::dsf);
65
66 auto upload_cmd = get_upload_url(upload_data.upload_path.string(), connectionType);
67 BOOST_LOG_TRIVIAL(info) << boost::format("Duet: Uploading file %1%, filepath: %2%, post_action: %3%, command: %4%")
68 % upload_data.source_path
69 % upload_data.upload_path
70 % int(upload_data.post_action)
71 % upload_cmd;
72
73 auto http = (dsf ? Http::put(std::move(upload_cmd)) : Http::post(std::move(upload_cmd)));
74 if (dsf) {
75 http.set_put_body(upload_data.source_path);
76 } else {
77 http.set_post_body(upload_data.source_path);
78 }
79 http.on_complete([&](std::string body, unsigned status) {
80 BOOST_LOG_TRIVIAL(debug) << boost::format("Duet: File uploaded: HTTP %1%: %2%") % status % body;
81
82 int err_code = dsf ? (status == 201 ? 0 : 1) : get_err_code_from_body(body);
83 if (err_code != 0) {
84 BOOST_LOG_TRIVIAL(error) << boost::format("Duet: Request completed but error code was received: %1%") % err_code;
85 error_fn(format_error(body, _u8L("Unknown error occurred"), 0));
86 res = false;
87 } else if (upload_data.post_action == PrintHostPostUploadAction::StartPrint) {
88 wxString errormsg;
89 res = start_print(errormsg, upload_data.upload_path.string(), connectionType, false);
90 if (! res) {
91 error_fn(std::move(errormsg));
92 }
93 } else if (upload_data.post_action == PrintHostPostUploadAction::StartSimulation) {
94 wxString errormsg;
95 res = start_print(errormsg, upload_data.upload_path.string(), connectionType, true);
96 if (! res) {
97 error_fn(std::move(errormsg));
98 }
99 }
100 })
101 .on_error([&](std::string body, std::string error, unsigned status) {
102 BOOST_LOG_TRIVIAL(error) << boost::format("Duet: Error uploading file: %1%, HTTP %2%, body: `%3%`") % error % status % body;
103 error_fn(format_error(body, error, status));
104 res = false;
105 })
106 .on_progress([&](Http::Progress progress, bool &cancel) {
107 prorgess_fn(std::move(progress), cancel);
108 if (cancel) {
109 // Upload was canceled
110 BOOST_LOG_TRIVIAL(info) << "Duet: Upload canceled";
111 res = false;
112 }
113 })
114 .perform_sync();
115
116 disconnect(connectionType);
117
118 return res;
119}
std::string get_upload_url(const std::string &filename, ConnectionType connectionType) const
Definition Duet.cpp:181
static Http put(std::string url)
Definition Http.cpp:899

References _u8L, connect(), disconnect(), dsf, error, Slic3r::PrintHost::format_error(), Slic3r::PrintHost::get_err_code_from_body(), get_upload_url(), Slic3r::http, Slic3r::Http::post(), Slic3r::PrintHostUpload::post_action, Slic3r::Http::put(), Slic3r::PrintHostUpload::source_path, start_print(), Slic3r::StartPrint, Slic3r::StartSimulation, and Slic3r::PrintHostUpload::upload_path.

Here is the call graph for this function:

Member Data Documentation

◆ host

std::string Slic3r::Duet::host
private

Referenced by Duet(), get_base_url(), and get_host().

◆ password

std::string Slic3r::Duet::password
private

Referenced by Duet(), and get_connect_url().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Duet.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Duet.cpp