FIX: device video/tunnel functions, add local video tunnel

Change-Id: I9da97406544c233d5ba6903857db6ad6f7f851e1
This commit is contained in:
chunmao.guo 2022-09-26 11:11:05 +08:00 committed by Lane.Wei
parent 80575cd269
commit b21b4aec95
7 changed files with 98 additions and 2 deletions

View File

@ -2,11 +2,17 @@
"printers": [ "printers": [
{ {
"display_name": "Bambu Lab X1", "display_name": "Bambu Lab X1",
"func": {
"FUNC_LOCAL_TUNNEL": false
},
"model_id": "BL-P002", "model_id": "BL-P002",
"printer_type": "3DPrinter-X1" "printer_type": "3DPrinter-X1"
}, },
{ {
"display_name": "Bambu Lab X1 Carbon", "display_name": "Bambu Lab X1 Carbon",
"func": {
"FUNC_LOCAL_TUNNEL": false
},
"model_id": "BL-P001", "model_id": "BL-P001",
"printer_type": "3DPrinter-X1-Carbon" "printer_type": "3DPrinter-X1-Carbon"
} }

View File

@ -1702,6 +1702,18 @@ bool MachineObject::is_function_supported(PrinterFunction func)
case FUNC_CHAMBER_TEMP: case FUNC_CHAMBER_TEMP:
func_name = "FUNC_CHAMBER_TEMP"; func_name = "FUNC_CHAMBER_TEMP";
break; break;
case FUNC_CAMERA_VIDEO:
func_name = "FUNC_CAMERA_VIDEO";
break;
case FUNC_MEDIA_FILE:
func_name = "FUNC_MEDIA_FILE";
break;
case FUNC_REMOTE_TUNNEL:
func_name = "FUNC_REMOTE_TUNNEL";
break;
case FUNC_LOCAL_TUNNEL:
func_name = "FUNC_LOCAL_TUNNEL";
break;
default: default:
return true; return true;
} }

View File

@ -65,6 +65,10 @@ enum PrinterFunction {
FUNC_FLOW_CALIBRATION, FUNC_FLOW_CALIBRATION,
FUNC_AUTO_LEVELING, FUNC_AUTO_LEVELING,
FUNC_CHAMBER_TEMP, FUNC_CHAMBER_TEMP,
FUNC_CAMERA_VIDEO,
FUNC_MEDIA_FILE,
FUNC_REMOTE_TUNNEL,
FUNC_LOCAL_TUNNEL,
FUNC_MAX FUNC_MAX
}; };

View File

@ -174,6 +174,17 @@ MediaFilePanel::~MediaFilePanel()
void MediaFilePanel::SetMachineObject(MachineObject* obj) void MediaFilePanel::SetMachineObject(MachineObject* obj)
{ {
std::string machine = obj ? obj->dev_id : ""; std::string machine = obj ? obj->dev_id : "";
if (obj && obj->is_function_supported(PrinterFunction::FUNC_MEDIA_FILE)) {
m_lan_mode = obj->is_lan_mode_printer();
m_lan_ip = obj->is_function_supported(PrinterFunction::FUNC_LOCAL_TUNNEL) ? obj->dev_ip : "";
m_lan_passwd = obj->access_code;
m_tutk_support = obj->is_function_supported(PrinterFunction::FUNC_REMOTE_TUNNEL);
} else {
m_lan_mode = false;
m_lan_ip.clear();
m_lan_passwd.clear();
m_tutk_support = true;
}
if (machine == m_machine) if (machine == m_machine)
return; return;
m_machine = machine; m_machine = machine;
@ -185,6 +196,8 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj)
} }
if (m_machine.empty()) { if (m_machine.empty()) {
m_image_grid->SetStatus(m_bmp_failed.bmp(), _L("No printers.")); m_image_grid->SetStatus(m_bmp_failed.bmp(), _L("No printers."));
} else if (m_lan_ip.empty() && (m_lan_mode && !m_tutk_support)) {
m_image_grid->SetStatus(m_bmp_failed.bmp(), _L("Not supported."));
} else { } else {
boost::shared_ptr<PrinterFileSystem> fs(new PrinterFileSystem); boost::shared_ptr<PrinterFileSystem> fs(new PrinterFileSystem);
m_image_grid->SetFileType(m_last_type); m_image_grid->SetFileType(m_last_type);
@ -259,7 +272,17 @@ void MediaFilePanel::modeChanged(wxCommandEvent& e1)
void MediaFilePanel::fetchUrl(boost::weak_ptr<PrinterFileSystem> wfs) void MediaFilePanel::fetchUrl(boost::weak_ptr<PrinterFileSystem> wfs)
{ {
NetworkAgent* agent = wxGetApp().getAgent(); if (!m_lan_ip.empty()) {
std::string url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd;
boost::shared_ptr fs(wfs.lock());
if (!fs || fs != m_image_grid->GetFileSystem()) return;
fs->SetUrl(url);
return;
}
if (m_lan_mode && !m_tutk_support) { // not support tutk
return;
}
NetworkAgent *agent = wxGetApp().getAgent();
if (agent) { if (agent) {
agent->get_camera_url(m_machine, agent->get_camera_url(m_machine,
[this, wfs](std::string url) { [this, wfs](std::string url) {

View File

@ -65,7 +65,13 @@ private:
::Button *m_button_management = nullptr; ::Button *m_button_management = nullptr;
std::string m_machine; std::string m_machine;
ImageGrid * m_image_grid = nullptr; std::string m_lan_ip;
std::string m_lan_user;
std::string m_lan_passwd;
bool m_lan_mode = false;
bool m_tutk_support = false;
ImageGrid * m_image_grid = nullptr;
int m_last_mode = 0; int m_last_mode = 0;
int m_last_type = 0; int m_last_type = 0;

View File

@ -48,6 +48,9 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const w
}; };
parent->Bind(wxEVT_SHOW, onShowHide); parent->Bind(wxEVT_SHOW, onShowHide);
parent->GetParent()->GetParent()->Bind(wxEVT_SHOW, onShowHide); parent->GetParent()->GetParent()->Bind(wxEVT_SHOW, onShowHide);
m_lan_user = "bblp";
m_lan_passwd = "bblp";
} }
MediaPlayCtrl::~MediaPlayCtrl() MediaPlayCtrl::~MediaPlayCtrl()
@ -63,6 +66,17 @@ MediaPlayCtrl::~MediaPlayCtrl()
void MediaPlayCtrl::SetMachineObject(MachineObject* obj) void MediaPlayCtrl::SetMachineObject(MachineObject* obj)
{ {
std::string machine = obj ? obj->dev_id : ""; std::string machine = obj ? obj->dev_id : "";
if (obj && obj->is_function_supported(PrinterFunction::FUNC_CAMERA_VIDEO)) {
m_lan_mode = obj->is_lan_mode_printer();
m_lan_ip = obj->is_function_supported(PrinterFunction::FUNC_LOCAL_TUNNEL) ? obj->dev_ip : "";
m_lan_passwd = obj->access_code;
m_tutk_support = obj->is_function_supported(PrinterFunction::FUNC_REMOTE_TUNNEL);
} else {
m_lan_mode = false;
m_lan_ip.clear();
m_lan_passwd.clear();
m_tutk_support = true;
}
if (machine == m_machine) { if (machine == m_machine) {
if (m_last_state == MEDIASTATE_IDLE && m_next_retry.IsValid() && wxDateTime::Now() >= m_next_retry) if (m_last_state == MEDIASTATE_IDLE && m_next_retry.IsValid() && wxDateTime::Now() >= m_next_retry)
Play(); Play();
@ -92,10 +106,36 @@ void MediaPlayCtrl::Play()
if (m_last_state != MEDIASTATE_IDLE) { if (m_last_state != MEDIASTATE_IDLE) {
return; return;
} }
m_last_state = MEDIASTATE_INITIALIZING; m_last_state = MEDIASTATE_INITIALIZING;
m_button_play->SetIcon("media_stop"); m_button_play->SetIcon("media_stop");
SetStatus(_L("Initializing...")); SetStatus(_L("Initializing..."));
if (!m_lan_ip.empty()) {
m_url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd;
m_last_state = MEDIASTATE_LOADING;
SetStatus(_L("Loading..."));
if (wxGetApp().app_config->get("dump_video") == "true") {
std::string file_h264 = data_dir() + "/video.h264";
std::string file_info = data_dir() + "/video.info";
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl dump video to " << file_h264;
// closed by BambuSource
FILE *dump_h264_file = boost::nowide::fopen(file_h264.c_str(), "wb");
FILE *dump_info_file = boost::nowide::fopen(file_info.c_str(), "wb");
m_url = m_url + "&dump_h264=" + boost::lexical_cast<std::string>(dump_h264_file);
m_url = m_url + "&dump_info=" + boost::lexical_cast<std::string>(dump_info_file);
}
boost::unique_lock lock(m_mutex);
m_tasks.push_back(m_url);
m_cond.notify_all();
return;
}
if (m_lan_mode && !m_tutk_support) { // not support tutk
Stop();
SetStatus(_L("Initialize failed (Not supported)!"));
return;
}
NetworkAgent* agent = wxGetApp().getAgent(); NetworkAgent* agent = wxGetApp().getAgent();
if (agent) { if (agent) {

View File

@ -58,6 +58,11 @@ private:
wxMediaCtrl2 * m_media_ctrl; wxMediaCtrl2 * m_media_ctrl;
wxMediaState m_last_state = MEDIASTATE_IDLE; wxMediaState m_last_state = MEDIASTATE_IDLE;
std::string m_machine; std::string m_machine;
std::string m_lan_ip;
std::string m_lan_user;
std::string m_lan_passwd;
bool m_lan_mode = false;
bool m_tutk_support = false;
wxString m_url; wxString m_url;
std::deque<wxString> m_tasks; std::deque<wxString> m_tasks;