From 46eba0048b73f1741b4b7b57f788830c08a8d7f1 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Mon, 8 Apr 2024 09:48:36 +0800 Subject: [PATCH] ENH: liveview remote protocols with agora Change-Id: Id86aa4bfa5f5e09675a6fe627668c63d20c7d1bf Jira: none --- resources/printers/BL-P001.json | 4 ++-- resources/printers/BL-P002.json | 4 ++-- resources/printers/C11.json | 4 ++-- resources/printers/C12.json | 4 ++-- resources/printers/C13.json | 4 ++-- resources/printers/N1.json | 4 ++-- resources/printers/N2S.json | 4 ++-- src/slic3r/GUI/DeviceManager.cpp | 19 +++++++++++++---- src/slic3r/GUI/DeviceManager.hpp | 20 +++++++++++++++--- src/slic3r/GUI/GUI_App.cpp | 6 ++++-- src/slic3r/GUI/MediaFilePanel.cpp | 24 +++++++++++---------- src/slic3r/GUI/MediaFilePanel.h | 4 ++-- src/slic3r/GUI/MediaPlayCtrl.cpp | 35 ++++++++++++++++++------------- src/slic3r/GUI/MediaPlayCtrl.h | 4 ++-- src/slic3r/Utils/NetworkAgent.hpp | 1 + 15 files changed, 88 insertions(+), 53 deletions(-) diff --git a/resources/printers/BL-P001.json b/resources/printers/BL-P001.json index fbdea5d75..0004806aa 100644 --- a/resources/printers/BL-P001.json +++ b/resources/printers/BL-P001.json @@ -6,10 +6,10 @@ "resolution_supported": [ "720p", "1080p" ], "virtual_camera": "enabled", "liveview": { - "remote": "enabled" + "remote": "tutk" }, "file": { - "remote": "enabled", + "remote": "tutk", "model_download": "enabled" } }, diff --git a/resources/printers/BL-P002.json b/resources/printers/BL-P002.json index 286e55271..3c2e7ed04 100644 --- a/resources/printers/BL-P002.json +++ b/resources/printers/BL-P002.json @@ -6,10 +6,10 @@ "resolution_supported": [ "720p", "1080p" ], "virtual_camera": "enabled", "liveview": { - "remote": "enabled" + "remote": "tutk" }, "file": { - "remote": "enabled", + "remote": "tutk", "model_download": "enabled" } }, diff --git a/resources/printers/C11.json b/resources/printers/C11.json index 5fb53b3f0..a2cbbb078 100644 --- a/resources/printers/C11.json +++ b/resources/printers/C11.json @@ -58,7 +58,7 @@ "print": { "ipcam": { "liveview": { - "remote": "enabled" + "remote": "tutk" } } } @@ -79,7 +79,7 @@ "print": { "ipcam": { "file": { - "remote": "enabled" + "remote": "tutk" } }, "support_user_preset":true diff --git a/resources/printers/C12.json b/resources/printers/C12.json index d3a6c6d99..5cc12a1a6 100644 --- a/resources/printers/C12.json +++ b/resources/printers/C12.json @@ -60,7 +60,7 @@ "print": { "ipcam": { "liveview": { - "remote": "enabled" + "remote": "tutk" } }, "support_mqtt_alive":true, @@ -71,7 +71,7 @@ "print": { "ipcam": { "file": { - "remote": "enabled" + "remote": "tutk" } }, "support_user_preset":true diff --git a/resources/printers/C13.json b/resources/printers/C13.json index c8bce2ad6..44c4ecda2 100644 --- a/resources/printers/C13.json +++ b/resources/printers/C13.json @@ -6,10 +6,10 @@ "resolution_supported": [ "720p", "1080p" ], "virtual_camera": "enabled", "liveview": { - "remote": "enabled" + "remote": "tutk" }, "file": { - "remote": "enabled", + "remote": "tutk", "model_download": "enabled" } }, diff --git a/resources/printers/N1.json b/resources/printers/N1.json index 8bcd035a5..ac161ed7b 100644 --- a/resources/printers/N1.json +++ b/resources/printers/N1.json @@ -6,7 +6,7 @@ "resolution_supported": [ "720p" ], "liveview": { "local": "local", - "remote": "enabled" + "remote": "tutk" } }, "support_motor_noise_cali":true, @@ -53,7 +53,7 @@ "print": { "ipcam": { "file": { - "remote": "enabled" + "remote": "tutk" } }, "support_user_preset":true diff --git a/resources/printers/N2S.json b/resources/printers/N2S.json index 2857bb17e..a87b08d08 100644 --- a/resources/printers/N2S.json +++ b/resources/printers/N2S.json @@ -6,7 +6,7 @@ "resolution_supported": [ "720p" ], "liveview": { "local": "local", - "remote": "enabled" + "remote": "tutk" } }, "support_motor_noise_cali":true, @@ -53,7 +53,7 @@ "print": { "ipcam": { "file": { - "remote": "enabled" + "remote": "tutk" } } } diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 4c01f873b..52c8d0739 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -1420,6 +1420,10 @@ void MachineObject::parse_status(int flag) } sdcard_state = MachineObject::SdcardState((flag >> 8) & 0x11); + + is_support_agora = ((flag >> 30) & 0x1) != 0; + if (is_support_agora) + is_support_tunnel_mqtt = false; } PrintingSpeedLevel MachineObject::_parse_printing_speed_lvl(int lvl) @@ -2945,7 +2949,7 @@ int MachineObject::parse_json(std::string payload, bool key_field_only) } if (!key_field_only) { - if (!DeviceManager::EnableMultiMachine) { + if (!DeviceManager::EnableMultiMachine && !is_support_agora) { if (jj.contains("support_tunnel_mqtt")) { if (jj["support_tunnel_mqtt"].is_boolean()) { is_support_tunnel_mqtt = jj["support_tunnel_mqtt"].get(); @@ -3740,11 +3744,18 @@ int MachineObject::parse_json(std::string payload, bool key_field_only) if (ipcam.contains("liveview")) { char const *local_protos[] = {"none", "disabled", "local", "rtsps", "rtsp"}; liveview_local = enum_index_of(ipcam["liveview"].value("local", "none").c_str(), local_protos, 5, LiveviewLocal::LVL_None); - liveview_remote = ipcam["liveview"].value("remote", "disabled") == "enabled"; + char const *remote_protos[] = {"none", "tutk", "agora", "tutk_agaro"}; + liveview_remote = enum_index_of(ipcam["liveview"].value("remote", "none").c_str(), remote_protos, 4, LiveviewRemote::LVR_None); + if (is_support_agora) + liveview_remote = liveview_remote == LVR_None ? LVR_Agora : liveview_remote == LVR_Tutk ? LVR_TutkAgora : liveview_remote; } if (ipcam.contains("file")) { - file_local = ipcam["file"].value("local", "disabled") == "enabled"; - file_remote = ipcam["file"].value("remote", "disabled") == "enabled"; + char const *local_protos[] = {"none", "local"}; + file_local = enum_index_of(ipcam["file"].value("local", "none").c_str(), local_protos, 2, FileLocal::FL_None); + char const *remote_protos[] = {"none", "tutk", "agora", "tutk_agaro"}; + file_remote = enum_index_of(ipcam["file"].value("remote", "none").c_str(), remote_protos, 4, FileRemote::FR_None); + if (is_support_agora) + file_remote = file_remote == FR_None ? FR_Agora : file_remote == FR_Tutk ? FR_TutkAgora : file_remote; file_model_download = ipcam["file"].value("model_download", "disabled") == "enabled"; } virtual_camera = ipcam.value("virtual_camera", "disabled") == "enabled"; diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index ae4130c80..aa5f0c9e4 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -708,9 +708,22 @@ public: LVL_Rtsps, LVL_Rtsp } liveview_local{ LVL_None }; - bool liveview_remote{false}; - bool file_local{false}; - bool file_remote{false}; + enum LiveviewRemote { + LVR_None, + LVR_Tutk, + LVR_Agora, + LVR_TutkAgora + } liveview_remote{ LVR_None }; + enum FileLocal { + FL_None, + FL_Local + } file_local{ FL_None }; + enum FileRemote { + FR_None, + FR_Tutk, + FR_Agora, + FR_TutkAgora + } file_remote{ FR_None }; bool file_model_download{false}; bool virtual_camera{false}; @@ -763,6 +776,7 @@ public: bool is_support_nozzle_blob_detection{false}; bool is_support_air_print_detection{false}; bool is_support_filament_setting_inprinting{false}; + bool is_support_agora{false}; int nozzle_max_temperature = -1; int bed_temperature_limit = -1; diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 0d1a6cb55..759e3f325 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1351,8 +1351,10 @@ void GUI_App::post_init() for (auto& it : boost::filesystem::directory_iterator(log_folder)) { auto temp_path = it.path(); try { - std::time_t lw_t = boost::filesystem::last_write_time(temp_path) ; - files_vec.push_back({ lw_t, temp_path.filename().string() }); + if (it.status().type() == boost::filesystem::regular_file) { + std::time_t lw_t = boost::filesystem::last_write_time(temp_path) ; + files_vec.push_back({ lw_t, temp_path.filename().string() }); + } } catch (const std::exception &ex) { } } diff --git a/src/slic3r/GUI/MediaFilePanel.cpp b/src/slic3r/GUI/MediaFilePanel.cpp index c39c54473..4e4ca4126 100644 --- a/src/slic3r/GUI/MediaFilePanel.cpp +++ b/src/slic3r/GUI/MediaFilePanel.cpp @@ -219,10 +219,10 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj) m_lan_ip = obj->dev_ip; m_lan_passwd = obj->get_access_code(); m_dev_ver = obj->get_ota_version(); - m_device_busy = obj->is_camera_busy_off(); + m_device_busy = obj->is_camera_busy_off(); m_sdcard_exist = obj->has_sdcard(); - m_local_support = obj->file_local; - m_remote_support = obj->file_remote; + m_local_proto = obj->file_local; + m_remote_proto = obj->file_remote; m_model_download_support = obj->file_model_download; } else { m_lan_mode = false; @@ -231,13 +231,13 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj) m_dev_ver.clear(); m_sdcard_exist = false; m_device_busy = false; - m_local_support = false; - m_remote_support = false; + m_local_proto = 0; + m_remote_proto = 0; m_model_download_support = false; } Enable(obj && obj->is_connected() && obj->m_push_count > 0); if (machine == m_machine) { - if ((m_waiting_enable && IsEnabled()) || (m_waiting_support && (m_local_support || m_remote_support))) { + if ((m_waiting_enable && IsEnabled()) || (m_waiting_support && (m_local_proto || m_remote_proto))) { auto fs = m_image_grid->GetFileSystem(); if (fs) fs->Retry(); } @@ -452,7 +452,7 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) return; } m_waiting_enable = false; - if (!m_local_support && !m_remote_support) { + if (!m_local_proto && !m_remote_proto) { m_waiting_support = true; m_image_grid->SetStatus(m_bmp_failed, _L("Browsing file in SD card is not supported in current firmware. Please update the printer firmware.")); fs->SetUrl("0"); @@ -471,7 +471,7 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) m_waiting_support = false; NetworkAgent *agent = wxGetApp().getAgent(); std::string agent_version = agent ? agent->get_version() : ""; - if ((m_lan_mode || !m_remote_support) && m_local_support && !m_lan_ip.empty()) { + if ((m_lan_mode || !m_remote_proto) && m_local_proto && !m_lan_ip.empty()) { std::string url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd; url += "&device=" + m_machine; url += "&net_ver=" + agent_version; @@ -481,7 +481,7 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) fs->SetUrl(url); return; } - if (!m_remote_support && m_local_support) { // not support tutk + if (!m_remote_proto && m_local_proto) { // not support tutk m_image_grid->SetStatus(m_bmp_failed, _L("Please enter the IP of printer to connect.")); fs->SetUrl("0"); fs.reset(); @@ -497,12 +497,14 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) return; } if (agent) { - agent->get_camera_url(m_machine, - [this, wfs, m = m_machine, v = agent->get_version(), dv = m_dev_ver](std::string url) { + std::string protocols[] = {"", "\"tutk\"", "\"agora\"", "\"tutk\",\"agora\""}; + agent->get_camera_url(m_machine + "|" + m_dev_ver + "|" + protocols[m_remote_proto], + [this, wfs, m = m_machine, v = agent->get_version(), dv = m_dev_ver, agent](std::string url) { if (boost::algorithm::starts_with(url, "bambu:///")) { url += "&device=" + m; url += "&net_ver=" + v; url += "&dev_ver=" + dv; + url += "&network_agent=" + boost::lexical_cast(agent->get_network_agent()); url += "&cli_id=" + wxGetApp().app_config->get("slicer_uuid"); url += "&cli_ver=" + std::string(SLIC3R_VERSION); } diff --git a/src/slic3r/GUI/MediaFilePanel.h b/src/slic3r/GUI/MediaFilePanel.h index 2ab2bdd6f..270542c5d 100644 --- a/src/slic3r/GUI/MediaFilePanel.h +++ b/src/slic3r/GUI/MediaFilePanel.h @@ -85,8 +85,8 @@ private: std::string m_dev_ver; bool m_lan_mode = false; bool m_sdcard_exist = false; - bool m_local_support = false; - bool m_remote_support = false; + int m_local_proto = false; + int m_remote_proto = false; bool m_model_download_support = false; bool m_device_busy = false; bool m_waiting_enable = false; diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index c5c74a594..273602cd5 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -156,7 +156,7 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj) m_dev_ver = obj->get_ota_version(); m_lan_mode = obj->is_lan_mode_printer(); m_lan_proto = obj->liveview_local; - m_remote_support = obj->liveview_remote; + m_remote_proto = obj->liveview_remote; m_lan_ip = obj->dev_ip; m_lan_passwd = obj->get_access_code(); m_device_busy = obj->is_camera_busy_off(); @@ -169,7 +169,7 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj) m_lan_passwd.clear(); m_dev_ver.clear(); m_tutk_state.clear(); - m_remote_support = false; + m_remote_proto = 0; m_device_busy = false; } Enable(obj && obj->is_connected() && obj->m_push_count > 0); @@ -290,8 +290,8 @@ void MediaPlayCtrl::Play() NetworkAgent *agent = wxGetApp().getAgent(); std::string agent_version = agent ? agent->get_version() : ""; - if (m_lan_proto > MachineObject::LVL_Disable && (m_lan_mode || !m_remote_support) && !m_disable_lan && !m_lan_ip.empty()) { - m_disable_lan = m_remote_support && !m_lan_mode; // try remote next time + if (m_lan_proto > MachineObject::LVL_Disable && (m_lan_mode || !m_remote_proto) && !m_disable_lan && !m_lan_ip.empty()) { + m_disable_lan = m_remote_proto && !m_lan_mode; // try remote next time std::string url; if (m_lan_proto == MachineObject::LVL_Local) url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd; @@ -314,12 +314,12 @@ void MediaPlayCtrl::Play() // m_lan_mode && m_lan_proto > LVL_Disable (use local tunnel) // m_lan_mode && m_lan_proto == LVL_Disable (*) // m_lan_mode && m_lan_proto == LVL_None (x) - // !m_lan_mode && m_remote_support (go on) - // !m_lan_mode && !m_remote_support && m_lan_proto > LVL_None (use local tunnel) - // !m_lan_mode && !m_remote_support && m_lan_proto == LVL_Disable (*) - // !m_lan_mode && !m_remote_support && m_lan_proto == LVL_None (x) + // !m_lan_mode && m_remote_proto (go on) + // !m_lan_mode && !m_remote_proto && m_lan_proto > LVL_None (use local tunnel) + // !m_lan_mode && !m_remote_proto && m_lan_proto == LVL_Disable (*) + // !m_lan_mode && !m_remote_proto && m_lan_proto == LVL_None (x) - if (m_lan_proto <= MachineObject::LVL_Disable && (m_lan_mode || !m_remote_support)) { + if (m_lan_proto <= MachineObject::LVL_Disable && (m_lan_mode || !m_remote_proto)) { Stop(m_lan_proto == MachineObject::LVL_None ? _L("Problem occured. Please update the printer firmware and try again.") : _L("LAN Only Liveview is off. Please turn on the liveview on printer screen.")); @@ -343,12 +343,14 @@ void MediaPlayCtrl::Play() m_play_timer = std::chrono::system_clock::now(); if (agent) { - agent->get_camera_url(m_machine, - [this, m = m_machine, v = agent_version, dv = m_dev_ver](std::string url) { + std::string protocols[] = {"", "\"tutk\"", "\"agora\"", "\"tutk\",\"agora\""}; + agent->get_camera_url(m_machine + "|" + m_dev_ver + "|" + protocols[m_remote_proto], + [this, m = m_machine, v = agent_version, dv = m_dev_ver, agent](std::string url) { if (boost::algorithm::starts_with(url, "bambu:///")) { url += "&device=" + into_u8(m); url += "&net_ver=" + v; url += "&dev_ver=" + dv; + url += "&network_agent=" + boost::lexical_cast(agent->get_network_agent()); url += "&cli_id=" + wxGetApp().app_config->get("slicer_uuid"); url += "&cli_ver=" + std::string(SLIC3R_VERSION); } @@ -362,7 +364,7 @@ void MediaPlayCtrl::Play() if (m_last_state == MEDIASTATE_INITIALIZING) { if (url.empty() || !boost::algorithm::starts_with(url, "bambu:///")) { m_failed_code = 3; - Stop(_L("Connection Failed. Please check the network and try again")); + Stop(_L("Connection Failed. Please check the network and try again"), from_u8(url)); } else { m_url = url; load(); @@ -377,7 +379,7 @@ void MediaPlayCtrl::Play() void start_ping_test(); -void MediaPlayCtrl::Stop(wxString const &msg) +void MediaPlayCtrl::Stop(wxString const &msg, wxString const &msg2) { int last_state = m_last_state; @@ -440,6 +442,8 @@ void MediaPlayCtrl::Stop(wxString const &msg) j["tutk_state"] = m_tutk_state; } j["msg"] = into_u8(msg); + if (!msg2.IsEmpty()) + j["msg2"] = into_u8(msg2); NetworkAgent *agent = wxGetApp().getAgent(); if (agent) agent->track_event("start_liveview", j.dump()); @@ -558,7 +562,7 @@ void MediaPlayCtrl::ToggleStream() wxGetApp().app_config->set("not_show_vcamera_stop_prev", "1"); if (res == wxID_CANCEL) return; } - if (m_lan_proto > MachineObject::LVL_Disable && (m_lan_mode || !m_remote_support) && !m_disable_lan && !m_lan_ip.empty()) { + if (m_lan_proto > MachineObject::LVL_Disable && (m_lan_mode || !m_remote_proto) && !m_disable_lan && !m_lan_ip.empty()) { std::string url; if (m_lan_proto == MachineObject::LVL_Local) url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd; @@ -579,11 +583,12 @@ void MediaPlayCtrl::ToggleStream() } NetworkAgent *agent = wxGetApp().getAgent(); if (!agent) return; - agent->get_camera_url(m_machine, [this, m = m_machine, v = agent->get_version(), dv = m_dev_ver](std::string url) { + agent->get_camera_url(m_machine, [this, m = m_machine, v = agent->get_version(), dv = m_dev_ver, agent](std::string url) { if (boost::algorithm::starts_with(url, "bambu:///")) { url += "&device=" + m; url += "&net_ver=" + v; url += "&dev_ver=" + dv; + url += "&network_agent=" + boost::lexical_cast(agent->get_network_agent()); url += "&cli_id=" + wxGetApp().app_config->get("slicer_uuid"); url += "&cli_ver=" + std::string(SLIC3R_VERSION); } diff --git a/src/slic3r/GUI/MediaPlayCtrl.h b/src/slic3r/GUI/MediaPlayCtrl.h index 5f78413ce..4744a674f 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.h +++ b/src/slic3r/GUI/MediaPlayCtrl.h @@ -50,7 +50,7 @@ protected: void Play(); - void Stop(wxString const &msg = {}); + void Stop(wxString const &msg = {}, wxString const &msg2 = {}); void TogglePlay(); @@ -84,7 +84,7 @@ private: std::string m_tutk_state; bool m_camera_exists = false; bool m_lan_mode = false; - bool m_remote_support = false; + int m_remote_proto = 0; bool m_device_busy = false; bool m_disable_lan = false; wxString m_url; diff --git a/src/slic3r/Utils/NetworkAgent.hpp b/src/slic3r/Utils/NetworkAgent.hpp index 945433f8b..1f419a191 100644 --- a/src/slic3r/Utils/NetworkAgent.hpp +++ b/src/slic3r/Utils/NetworkAgent.hpp @@ -227,6 +227,7 @@ public: int get_mw_user_preference(std::function callback); int get_mw_user_4ulist(int seed, int limit, std::function callback); + void *get_network_agent() { return network_agent; } private: bool enable_track = false;