mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-02 16:30:43 +08:00
Merge branch 'dk_duet'
This commit is contained in:
commit
319d83f95f
@ -29,10 +29,28 @@
|
|||||||
#include "slic3r/GUI/format.hpp"
|
#include "slic3r/GUI/format.hpp"
|
||||||
#include "Http.hpp"
|
#include "Http.hpp"
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
namespace pt = boost::property_tree;
|
namespace pt = boost::property_tree;
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
namespace {
|
||||||
|
std::string escape_string(const std::string& unescaped)
|
||||||
|
{
|
||||||
|
std::string ret_val;
|
||||||
|
CURL* curl = curl_easy_init();
|
||||||
|
if (curl) {
|
||||||
|
char* decoded = curl_easy_escape(curl, unescaped.c_str(), unescaped.size());
|
||||||
|
if (decoded) {
|
||||||
|
ret_val = std::string(decoded);
|
||||||
|
curl_free(decoded);
|
||||||
|
}
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
}
|
||||||
|
return ret_val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Duet::Duet(DynamicPrintConfig *config) :
|
Duet::Duet(DynamicPrintConfig *config) :
|
||||||
host(config->opt_string("print_host")),
|
host(config->opt_string("print_host")),
|
||||||
@ -81,6 +99,8 @@ bool Duet::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn e
|
|||||||
auto http = (dsf ? Http::put(std::move(upload_cmd)) : Http::post(std::move(upload_cmd)));
|
auto http = (dsf ? Http::put(std::move(upload_cmd)) : Http::post(std::move(upload_cmd)));
|
||||||
if (dsf) {
|
if (dsf) {
|
||||||
http.set_put_body(upload_data.source_path);
|
http.set_put_body(upload_data.source_path);
|
||||||
|
if (connect_msg.empty())
|
||||||
|
http.header("X-Session-Key", boost::nowide::narrow(connect_msg));
|
||||||
} else {
|
} else {
|
||||||
http.set_post_body(upload_data.source_path);
|
http.set_post_body(upload_data.source_path);
|
||||||
}
|
}
|
||||||
@ -140,7 +160,20 @@ Duet::ConnectionType Duet::connect(wxString &msg) const
|
|||||||
msg = format_error(body, error, status);
|
msg = format_error(body, error, status);
|
||||||
})
|
})
|
||||||
.on_complete([&](std::string body, unsigned) {
|
.on_complete([&](std::string body, unsigned) {
|
||||||
res = ConnectionType::dsf;
|
try {
|
||||||
|
pt::ptree root;
|
||||||
|
std::istringstream iss(body);
|
||||||
|
pt::read_json(iss, root);
|
||||||
|
auto key = root.get_optional<std::string>("sessionKey");
|
||||||
|
if (key)
|
||||||
|
msg = boost::nowide::widen(*key);
|
||||||
|
res = ConnectionType::dsf;
|
||||||
|
}
|
||||||
|
catch (const std::exception&) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "Failed to parse serverKey from Duet reply to Connect request: " << body;
|
||||||
|
msg = format_error(body, L("Failed to parse a Connect reply"), 0);
|
||||||
|
res = ConnectionType::error;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.perform_sync();
|
.perform_sync();
|
||||||
})
|
})
|
||||||
@ -205,12 +238,13 @@ std::string Duet::get_upload_url(const std::string &filename, ConnectionType con
|
|||||||
std::string Duet::get_connect_url(const bool dsfUrl) const
|
std::string Duet::get_connect_url(const bool dsfUrl) const
|
||||||
{
|
{
|
||||||
if (dsfUrl) {
|
if (dsfUrl) {
|
||||||
return (boost::format("%1%machine/status")
|
return (boost::format("%1%machine/connect?password=%2%")
|
||||||
% get_base_url()).str();
|
% get_base_url()
|
||||||
|
% (password.empty() ? "reprap" : escape_string(password))).str();
|
||||||
} else {
|
} else {
|
||||||
return (boost::format("%1%rr_connect?password=%2%&%3%")
|
return (boost::format("%1%rr_connect?password=%2%&%3%")
|
||||||
% get_base_url()
|
% get_base_url()
|
||||||
% (password.empty() ? "reprap" : password)
|
% (password.empty() ? "reprap" : escape_string(password))
|
||||||
% timestamp_str()).str();
|
% timestamp_str()).str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
std::string get_host() const override { return host; }
|
std::string get_host() const override { return host; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class ConnectionType { rrf, dsf, error };
|
enum class ConnectionType { rrf, dsf, error }; // rrf = RepRapFirmware, dsf = DuetSoftwareFramework
|
||||||
std::string host;
|
std::string host;
|
||||||
std::string password;
|
std::string password;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user