Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::FlashAir Class Reference

#include <src/slic3r/Utils/FlashAir.hpp>

+ Inheritance diagram for Slic3r::FlashAir:
+ Collaboration diagram for Slic3r::FlashAir:

Public Types

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

Public Member Functions

 FlashAir (DynamicPrintConfig *config)
 
 ~FlashAir () 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 bool get_groups (wxArrayString &) const
 
virtual bool get_printers (wxArrayString &) const
 
virtual bool get_storage (wxArrayString &, wxArrayString &) const
 

Static Public Member Functions

static PrintHostget_print_host (DynamicPrintConfig *config)
 

Protected Member Functions

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

Private Member Functions

std::string timestamp_str () const
 
std::string make_url (const std::string &path) const
 
std::string make_url (const std::string &path, const std::string &arg, const std::string &val) const
 

Private Attributes

std::string host
 

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

Constructor & Destructor Documentation

◆ FlashAir()

Slic3r::FlashAir::FlashAir ( DynamicPrintConfig config)
30 :
31 host(config->opt_string("print_host"))
32{}
std::string host
Definition FlashAir.hpp:33

◆ ~FlashAir()

Slic3r::FlashAir::~FlashAir ( )
overridedefault

Member Function Documentation

◆ can_test()

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

Implements Slic3r::PrintHost.

28{ return true; }

◆ format_error()

wxString Slic3r::PrintHost::format_error ( const std::string &  body,
const std::string &  error,
unsigned  status 
) const
protectedvirtualinherited
67{
68 if (status != 0) {
69 auto wxbody = wxString::FromUTF8(body.data());
70 return wxString::Format("HTTP %u: %s", status, wxbody);
71 } else {
72 return wxString::FromUTF8(error.data());
73 }
74}
static char error[256]
Definition tga.cpp:50

References error.

Referenced by Slic3r::Duet::connect(), Slic3r::PrusaLink::post_inner(), Slic3r::PrusaLink::put_inner(), Slic3r::Duet::start_print(), Slic3r::AstroBox::test(), test(), Slic3r::Moonraker::test(), Slic3r::OctoPrint::test(), Slic3r::PrusaLink::test(), Slic3r::Repetier::test(), Slic3r::PrusaLink::test_with_method_check(), Slic3r::AstroBox::upload(), Slic3r::Duet::upload(), upload(), Slic3r::MKS::upload(), Slic3r::Moonraker::upload(), Slic3r::Repetier::upload(), and Slic3r::OctoPrint::upload_inner_with_host().

+ Here is the caller graph for this function:

◆ get_groups()

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

Reimplemented in Slic3r::Repetier.

65{ return false; }

◆ get_host()

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

Implements Slic3r::PrintHost.

30{ return host; }

References host.

◆ get_name()

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

Implements Slic3r::PrintHost.

34{ return "FlashAir"; }

Referenced by test(), and upload().

+ Here is the caller graph for this function:

◆ get_post_upload_actions()

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

Implements Slic3r::PrintHost.

29{ return {}; }

◆ get_print_host()

PrintHost * Slic3r::PrintHost::get_print_host ( DynamicPrintConfig config)
staticinherited
35{
37
38 {
39 const auto opt = config->option<ConfigOptionEnum<PrinterTechnology>>("printer_technology");
40 if (opt != nullptr) {
41 tech = opt->value;
42 }
43 }
44
45 if (tech == ptFFF) {
46 const auto opt = config->option<ConfigOptionEnum<PrintHostType>>("host_type");
47 const auto host_type = opt != nullptr ? opt->value : htOctoPrint;
48
49 switch (host_type) {
50 case htOctoPrint: return new OctoPrint(config);
51 case htDuet: return new Duet(config);
52 case htFlashAir: return new FlashAir(config);
53 case htAstroBox: return new AstroBox(config);
54 case htRepetier: return new Repetier(config);
55 case htPrusaLink: return new PrusaLink(config);
56 case htPrusaConnect: return new PrusaConnect(config);
57 case htMKS: return new MKS(config);
58 case htMoonraker: return new Moonraker(config);
59 default: return nullptr;
60 }
61 } else {
62 return new SL1Host(config);
63 }
64}
PrinterTechnology
Definition Config.hpp:205
@ ptFFF
Definition Config.hpp:207
@ htMoonraker
Definition PrintConfig.hpp:47
@ htPrusaLink
Definition PrintConfig.hpp:47
@ htRepetier
Definition PrintConfig.hpp:47
@ htMKS
Definition PrintConfig.hpp:47
@ htPrusaConnect
Definition PrintConfig.hpp:47
@ htDuet
Definition PrintConfig.hpp:47
@ htOctoPrint
Definition PrintConfig.hpp:47
@ htFlashAir
Definition PrintConfig.hpp:47
@ htAstroBox
Definition PrintConfig.hpp:47
ConfigOptionEnum< PrinterTechnology >
Definition PrintConfig.hpp:1079

References Slic3r::htAstroBox, Slic3r::htDuet, Slic3r::htFlashAir, Slic3r::htMKS, Slic3r::htMoonraker, Slic3r::htOctoPrint, Slic3r::htPrusaConnect, Slic3r::htPrusaLink, Slic3r::htRepetier, Slic3r::ConfigBase::option(), Slic3r::ptFFF, and Slic3r::ConfigOptionSingle< T >::value.

Referenced by Slic3r::GUI::PhysicalPrinterDialog::build_printhost_settings(), 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_printers()

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

Reimplemented in Slic3r::Repetier.

66{ return false; }

◆ get_storage()

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

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

69{ return false; }

◆ get_test_failed_msg()

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

Implements Slic3r::PrintHost.

73{
74 return GUI::format_wxstr("%s: %s\n%s"
75 , _u8L("Could not connect to FlashAir")
76 , msg
77 , _u8L("Note: FlashAir with firmware 2.00.02 or newer and activated upload function is required."));
78}
#define _u8L(s)
macro used to mark string used at localization, return same string
Definition SLAPrint.cpp:29
wxString format_wxstr(const char *fmt, TArgs &&... args)
Definition format.hpp:42

References _u8L, and Slic3r::GUI::format_wxstr().

+ Here is the call graph for this function:

◆ get_test_ok_msg()

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

Implements Slic3r::PrintHost.

68{
69 return _(L("Connection to FlashAir works correctly and upload is enabled."));
70}
#define _(msgid)
Definition getopt.c:87
#define L(s)
Definition I18N.hpp:18

References _, and L.

◆ has_auto_discovery()

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

Implements Slic3r::PrintHost.

27{ return false; }

◆ make_url() [1/2]

std::string Slic3r::FlashAir::make_url ( const std::string &  path) const
private
197{
198 if (host.find("http://") == 0 || host.find("https://") == 0) {
199 if (host.back() == '/') {
200 return (boost::format("%1%%2%") % host % path).str();
201 } else {
202 return (boost::format("%1%/%2%") % host % path).str();
203 }
204 } else {
205 if (host.back() == '/') {
206 return (boost::format("http://%1%%2%") % host % path).str();
207 } else {
208 return (boost::format("http://%1%/%2%") % host % path).str();
209 }
210 }
211}

References host.

Referenced by test(), and upload().

+ Here is the caller graph for this function:

◆ make_url() [2/2]

std::string Slic3r::FlashAir::make_url ( const std::string &  path,
const std::string &  arg,
const std::string &  val 
) const
private
214{
215 if (host.find("http://") == 0 || host.find("https://") == 0) {
216 if (host.back() == '/') {
217 return (boost::format("%1%%2%?%3%=%4%") % host % path % arg % val).str();
218 } else {
219 return (boost::format("%1%/%2%?%3%=%4%") % host % path % arg % val).str();
220 }
221 } else {
222 if (host.back() == '/') {
223 return (boost::format("http://%1%%2%?%3%=%4%") % host % path % arg % val).str();
224 } else {
225 return (boost::format("http://%1%/%2%?%3%=%4%") % host % path % arg % val).str();
226 }
227 }
228}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Definition ArrayCwiseUnaryOps.h:57

References arg(), and host.

+ Here is the call graph for this function:

◆ supports_multiple_printers()

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

Reimplemented in Slic3r::Repetier.

60{ return false; }

◆ test()

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

Implements Slic3r::PrintHost.

37{
38 // Since the request is performed synchronously here,
39 // it is ok to refer to `msg` from within the closure
40
41 const char *name = get_name();
42
43 bool res = false;
44 auto url = make_url("command.cgi", "op", "118");
45
46 BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Get upload enabled at: %2%") % name % url;
47
48 auto http = Http::get(std::move(url));
49 http.on_error([&](std::string body, std::string error, unsigned status) {
50 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting upload enabled: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
51 res = false;
52 msg = format_error(body, error, status);
53 })
54 .on_complete([&](std::string body, unsigned) {
55 BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got upload enabled: %2%") % name % body;
56
57 res = boost::starts_with(body, "1");
58 if (! res) {
59 msg = _(L("Upload not enabled on FlashAir card."));
60 }
61 })
62 .perform_sync();
63
64 return res;
65}
const char * get_name() const override
Definition FlashAir.cpp:34
std::string make_url(const std::string &path) const
Definition FlashAir.cpp:196
static Http get(std::string url)
Definition Http.cpp:607
virtual wxString format_error(const std::string &body, const std::string &error, unsigned status) const
Definition PrintHost.cpp:66

References _, error, Slic3r::PrintHost::format_error(), Slic3r::Http::get(), get_name(), L, and make_url().

Referenced by upload().

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

◆ timestamp_str()

std::string Slic3r::FlashAir::timestamp_str ( ) const
private
182{
183 auto t = std::time(nullptr);
184 auto tm = *std::localtime(&t);
185
186 unsigned long fattime = ((tm.tm_year - 80) << 25) |
187 ((tm.tm_mon + 1) << 21) |
188 (tm.tm_mday << 16) |
189 (tm.tm_hour << 11) |
190 (tm.tm_min << 5) |
191 (tm.tm_sec >> 1);
192
193 return (boost::format("%1$#x") % fattime).str();
194}

Referenced by upload().

+ Here is the caller graph for this function:

◆ upload()

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

Implements Slic3r::PrintHost.

81{
82 const char *name = get_name();
83
84 const auto upload_filename = upload_data.upload_path.filename();
85 const auto upload_parent_path = upload_data.upload_path.parent_path();
86 wxString test_msg;
87 if (! test(test_msg)) {
88 error_fn(std::move(test_msg));
89 return false;
90 }
91
92 bool res = false;
93
94 std::string strDest = upload_parent_path.string();
95 if (strDest.front()!='/') // Needs a leading / else root uploads fail.
96 {
97 strDest.insert(0,"/");
98 }
99
100 auto urlPrepare = make_url("upload.cgi", "WRITEPROTECT=ON&FTIME", timestamp_str());
101 auto urlSetDir = make_url("upload.cgi","UPDIR",strDest);
102 auto urlUpload = make_url("upload.cgi");
103
104 BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Uploading file %2% at %3% / %4%, filename: %5%")
105 % name
106 % upload_data.source_path
107 % urlPrepare
108 % urlUpload
109 % upload_filename.string();
110
111 // set filetime for upload and make card writeprotect to prevent filesystem damage
112 auto httpPrepare = Http::get(std::move(urlPrepare));
113 httpPrepare.on_error([&](std::string body, std::string error, unsigned status) {
114 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error preparing upload: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
115 error_fn(format_error(body, error, status));
116 res = false;
117 })
118 .on_complete([&, this](std::string body, unsigned) {
119 BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got prepare result: %2%") % name % body;
120 res = boost::icontains(body, "SUCCESS");
121 if (! res) {
122 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Request completed but no SUCCESS message was received.") % name;
123 error_fn(format_error(body, L("Unknown error occured"), 0));
124 }
125 })
126 .perform_sync();
127
128 if(! res ) {
129 return res;
130 }
131
132 // start file upload
133 auto httpDir = Http::get(std::move(urlSetDir));
134 httpDir.on_error([&](std::string body, std::string error, unsigned status) {
135 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error setting upload dir: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
136 error_fn(format_error(body, error, status));
137 res = false;
138 })
139 .on_complete([&, this](std::string body, unsigned) {
140 BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got dir select result: %2%") % name % body;
141 res = boost::icontains(body, "SUCCESS");
142 if (! res) {
143 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Request completed but no SUCCESS message was received.") % name;
144 error_fn(format_error(body, L("Unknown error occured"), 0));
145 }
146 })
147 .perform_sync();
148
149 if(! res ) {
150 return res;
151 }
152
153 auto http = Http::post(std::move(urlUpload));
154 http.form_add_file("file", upload_data.source_path.string(), upload_filename.string())
155 .on_complete([&](std::string body, unsigned status) {
156 BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: File uploaded: HTTP %2%: %3%") % name % status % body;
157 res = boost::icontains(body, "SUCCESS");
158 if (! res) {
159 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Request completed but no SUCCESS message was received.") % name;
160 error_fn(format_error(body, L("Unknown error occured"), 0));
161 }
162 })
163 .on_error([&](std::string body, std::string error, unsigned status) {
164 BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error uploading file: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
165 error_fn(format_error(body, error, status));
166 res = false;
167 })
168 .on_progress([&](Http::Progress progress, bool &cancel) {
169 prorgess_fn(std::move(progress), cancel);
170 if (cancel) {
171 // Upload was canceled
172 BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Upload canceled") % name;
173 res = false;
174 }
175 })
176 .perform_sync();
177
178 return res;
179}
std::string timestamp_str() const
Definition FlashAir.cpp:181
bool test(wxString &curl_msg) const override
Definition FlashAir.cpp:36
static Http post(std::string url)
Definition Http.cpp:612

References error, Slic3r::PrintHost::format_error(), Slic3r::Http::get(), get_name(), L, make_url(), Slic3r::Http::post(), Slic3r::PrintHostUpload::source_path, test(), timestamp_str(), and Slic3r::PrintHostUpload::upload_path.

+ Here is the call graph for this function:

Member Data Documentation

◆ host

std::string Slic3r::FlashAir::host
private

Referenced by get_host(), make_url(), and make_url().


The documentation for this class was generated from the following files: