OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{CrealityHostDiscovery.cpp} Namespace Reference

Functions

bool is_cfs_capable (const std::string &code)
std::string model_name_for (const std::string &code)
std::string hostname_from_service (const std::string &service_name)
void probe_info (CrealityHost &host)

Function Documentation

◆ hostname_from_service()

std::string Slic3r::anonymous_namespace{CrealityHostDiscovery.cpp}::hostname_from_service ( const std::string & service_name)
35{
36 auto dash = service_name.find_last_of('-');
37 if (dash == std::string::npos) return {};
38 auto dot = service_name.find('.', dash);
39 if (dot == std::string::npos) return {};
40 std::string suffix = service_name.substr(dash + 1, dot - dash - 1);
41 if (suffix.size() >= 4) {
42 return "K2-" + suffix.substr(suffix.size() - 4);
43 }
44 return suffix.empty() ? std::string{} : "K2-" + suffix;
45}
T dot(const boost::geometry::model::d2::point_xy< T > &v1, const boost::geometry::model::d2::point_xy< T > &v2)
Definition ExtrusionSimulator.cpp:154

References Slic3r::dot(), and hostname_from_service().

Referenced by hostname_from_service().

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

◆ is_cfs_capable()

bool Slic3r::anonymous_namespace{CrealityHostDiscovery.cpp}::is_cfs_capable ( const std::string & code)
22{
24}
static bool model_supports_multi_color(const std::string &model)
Definition CrealityPrint.cpp:330

References is_cfs_capable(), and Slic3r::CrealityPrint::model_supports_multi_color().

Referenced by is_cfs_capable(), and probe_info().

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

◆ model_name_for()

std::string Slic3r::anonymous_namespace{CrealityHostDiscovery.cpp}::model_name_for ( const std::string & code)
27{
29}
static std::string model_display_name(const std::string &model)
Definition CrealityPrint.cpp:335

References Slic3r::CrealityPrint::model_display_name(), and model_name_for().

Referenced by model_name_for(), and probe_info().

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

◆ probe_info()

void Slic3r::anonymous_namespace{CrealityHostDiscovery.cpp}::probe_info ( CrealityHost & host)
50{
51 const std::string url = "http://" + host.ip + "/info";
52 auto http = Http::get(url);
53 http.timeout_connect(2)
54 .timeout_max(4)
55 .on_complete([&host](std::string body, unsigned /*status*/) {
56 try {
57 auto j = nlohmann::json::parse(body);
58 if (j.contains("model") && j["model"].is_string())
59 host.model_code = j["model"].get<std::string>();
60 if (j.contains("mac") && j["mac"].is_string())
61 host.mac = j["mac"].get<std::string>();
62 if (is_cfs_capable(host.model_code)) {
63 host.cfs_capable = true;
65 }
66 } catch (const std::exception& e) {
67 BOOST_LOG_TRIVIAL(warning)
68 << "CrealityHostDiscovery: /info parse failed for "
69 << host.ip << ": " << e.what();
70 }
71 })
72 .on_error([&host](std::string /*body*/, std::string error, unsigned status) {
73 BOOST_LOG_TRIVIAL(info)
74 << "CrealityHostDiscovery: /info GET failed for "
75 << host.ip << ": " << error << " (HTTP " << status << ")";
76 })
77 .perform_sync();
78}
static Http get(std::string url)
Definition Http.cpp:886
std::string model_name_for(const std::string &code)
Definition CrealityHostDiscovery.cpp:26
bool is_cfs_capable(const std::string &code)
Definition CrealityHostDiscovery.cpp:21
std::string mac
Definition CrealityHostDiscovery.hpp:17
std::string model_code
Definition CrealityHostDiscovery.hpp:15
std::string ip
Definition CrealityHostDiscovery.hpp:12
@ http
Definition IPrinterAgent.hpp:64
std::string model_name
Definition CrealityHostDiscovery.hpp:16
bool cfs_capable
Definition CrealityHostDiscovery.hpp:18

References Slic3r::CrealityHost::cfs_capable, Slic3r::Http::get(), Slic3r::http, Slic3r::CrealityHost::ip, is_cfs_capable(), Slic3r::CrealityHost::mac, Slic3r::CrealityHost::model_code, Slic3r::CrealityHost::model_name, model_name_for(), and probe_info().

Referenced by probe_info().

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