mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-26 02:11:18 +00:00
Merge impl branch
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
#include "I18N.hpp"
|
||||
#include "libslic3r/Time.hpp"
|
||||
#include "libslic3r/Thread.hpp"
|
||||
#include "slic3r/Utils/Http.hpp"
|
||||
#include "slic3r/Utils/NetworkAgent.hpp"
|
||||
#include "slic3r/plugin/PluginManager.hpp"
|
||||
#include "slic3r/Utils/NetworkAgentFactory.hpp"
|
||||
#include "GuiColor.hpp"
|
||||
|
||||
@@ -1790,20 +1792,10 @@ int MachineObject::command_ams_filament_settings(int ams_id, int slot_id, std::s
|
||||
return this->publish_json(j);
|
||||
}
|
||||
|
||||
int MachineObject::command_ams_refresh_rfid(std::string tray_id)
|
||||
int MachineObject::command_ams_refresh_rfid(int ams_id, int slot_id)
|
||||
{
|
||||
if (!m_agent) return -1;
|
||||
return command_with_dialog(m_agent->command_ams_refresh_rfid(get_dev_id(), tray_id, MachineObject::m_sequence_id++, is_lan_mode_printer()));
|
||||
}
|
||||
|
||||
int MachineObject::command_ams_refresh_rfid2(int ams_id, int slot_id)
|
||||
{
|
||||
json j;
|
||||
j["print"]["command"] = "ams_get_rfid";
|
||||
j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
|
||||
j["print"]["ams_id"] = ams_id;
|
||||
j["print"]["slot_id"] = slot_id;
|
||||
return this->publish_json(j);
|
||||
return command_with_dialog(m_agent->command_ams_refresh_rfid(get_dev_id(), ams_id, slot_id, MachineObject::m_sequence_id++, is_lan_mode_printer()));
|
||||
}
|
||||
|
||||
int MachineObject::command_start_camera()
|
||||
@@ -2613,7 +2605,15 @@ void MachineObject::reset()
|
||||
|
||||
void MachineObject::set_print_state(std::string status)
|
||||
{
|
||||
const bool changed = (print_status != status);
|
||||
print_status = status;
|
||||
if (changed) {
|
||||
LifecycleEventContext ctx;
|
||||
ctx.name = dev_id;
|
||||
ctx.code = LifecycleEvtCode::Ok;
|
||||
ctx.msg = print_status;
|
||||
fire_lifecycle_event(LifecycleEvent::PrintStateChanged, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
// why: printer agents can report progress without BBL cloud task identity.
|
||||
@@ -2635,15 +2635,44 @@ void MachineObject::update_print_progress(const json& value)
|
||||
curr_task->task_progress = mc_print_percent;
|
||||
}
|
||||
|
||||
int MachineObject::connect(bool use_openssl)
|
||||
int MachineObject::connect()
|
||||
{
|
||||
if (get_dev_ip().empty()) return -1;
|
||||
std::string username = m_agent ? m_agent->default_lan_username() : std::string();
|
||||
std::string password = get_access_code();
|
||||
|
||||
std::string port;
|
||||
std::string input = get_dev_ip();
|
||||
|
||||
const bool use_ssl = input.rfind("https", 0) == 0;
|
||||
|
||||
// This strips out the http/https prefix
|
||||
std::string host = Http::get_host_from_url(input, &port);
|
||||
std::string ca_file;
|
||||
|
||||
if (GUI::wxGetApp().preset_bundle) {
|
||||
const auto& config = GUI::wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
||||
if (port.empty())
|
||||
port = config.opt_string("printhost_port");
|
||||
ca_file = config.opt_string("printhost_cafile");
|
||||
}
|
||||
|
||||
if (host.empty())
|
||||
host = get_dev_ip();
|
||||
|
||||
|
||||
if (m_agent) {
|
||||
try {
|
||||
return m_agent->connect_printer(get_dev_id(), get_dev_ip(), username, password, use_openssl);
|
||||
PrinterConnectionParams params{
|
||||
get_dev_id(),
|
||||
host,
|
||||
port,
|
||||
username,
|
||||
password,
|
||||
use_ssl,
|
||||
ca_file
|
||||
};
|
||||
return m_agent->connect_printer(params);
|
||||
} catch (...) {
|
||||
;
|
||||
}
|
||||
@@ -2654,7 +2683,10 @@ int MachineObject::connect(bool use_openssl)
|
||||
int MachineObject::disconnect()
|
||||
{
|
||||
if (m_agent) {
|
||||
return m_agent->disconnect_printer();
|
||||
const int result = m_agent->disconnect_printer();
|
||||
if (result == 0)
|
||||
set_online_state(false);
|
||||
return result;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -2684,8 +2716,16 @@ bool MachineObject::is_connecting()
|
||||
|
||||
void MachineObject::set_online_state(bool on_off)
|
||||
{
|
||||
const bool changed = (m_is_online != on_off);
|
||||
m_is_online = on_off;
|
||||
if (!on_off) m_active_state = NotActive;
|
||||
if (changed) {
|
||||
LifecycleEventContext ctx;
|
||||
ctx.name = dev_id;
|
||||
ctx.code = LifecycleEvtCode::Ok;
|
||||
ctx.msg = on_off ? "online" : "offline";
|
||||
fire_lifecycle_event(on_off ? LifecycleEvent::DeviceOnline : LifecycleEvent::DeviceOffline, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
bool MachineObject::is_info_ready(bool check_version) const
|
||||
@@ -2821,13 +2861,6 @@ int MachineObject::parse_json(std::string tunnel, std::string payload, bool key_
|
||||
|
||||
parse_msg_count++;
|
||||
std::chrono::system_clock::time_point clock_start = std::chrono::system_clock::now();
|
||||
this->set_online_state(true);
|
||||
|
||||
std::chrono::system_clock::time_point curr_time = std::chrono::system_clock::now();
|
||||
auto diff1 = std::chrono::duration_cast<std::chrono::microseconds>(curr_time - last_update_time);
|
||||
|
||||
/* update last received time */
|
||||
last_update_time = std::chrono::system_clock::now();
|
||||
|
||||
json j_pre;
|
||||
bool parse_ok = false;
|
||||
@@ -2840,8 +2873,29 @@ int MachineObject::parse_json(std::string tunnel, std::string payload, bool key_
|
||||
/* post process payload */
|
||||
sanitizeToUtf8(payload);
|
||||
BOOST_LOG_TRIVIAL(info) << "parse_json: sanitize to utf8";
|
||||
try {
|
||||
j_pre = json::parse(payload);
|
||||
parse_ok = true;
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
|
||||
bool client_disconnected = false;
|
||||
if (parse_ok && j_pre.is_object() && j_pre.contains("event") && j_pre["event"].is_object() &&
|
||||
j_pre["event"].contains("event") && j_pre["event"]["event"].is_string()) {
|
||||
client_disconnected = j_pre["event"]["event"].get<std::string>() == "client.disconnected";
|
||||
}
|
||||
|
||||
// A disconnect notification is a transport message too, but it must not first mark an
|
||||
// already-offline device as online through the generic message-received path.
|
||||
set_online_state(!client_disconnected);
|
||||
|
||||
std::chrono::system_clock::time_point curr_time = std::chrono::system_clock::now();
|
||||
auto diff1 = std::chrono::duration_cast<std::chrono::microseconds>(curr_time - last_update_time);
|
||||
|
||||
/* update last received time */
|
||||
last_update_time = std::chrono::system_clock::now();
|
||||
|
||||
try {
|
||||
bool restored_json = false;
|
||||
// A frame is authoritative for removals only when it is a full snapshot
|
||||
@@ -4683,19 +4737,6 @@ int MachineObject::parse_json(std::string tunnel, std::string payload, bool key_
|
||||
}
|
||||
}
|
||||
|
||||
// event info
|
||||
try {
|
||||
if (j.contains("event")) {
|
||||
if (j["event"].contains("event")) {
|
||||
if (j["event"]["event"].get<std::string>() == "client.disconnected")
|
||||
set_online_state(false);
|
||||
else if (j["event"]["event"].get<std::string>() == "client.connected")
|
||||
set_online_state(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
|
||||
if (!key_field_only) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "parse_json m_active_state =" << m_active_state;
|
||||
parse_state_changed_event();
|
||||
|
||||
Reference in New Issue
Block a user