FIX: error log reduce

Change-Id: I836ba41eefb3a8c12a57a22d208ee7d60140e345
This commit is contained in:
chunmao.guo 2023-05-05 10:32:00 +08:00 committed by Lane.Wei
parent f343b4d1db
commit c58baa6b16
7 changed files with 29 additions and 16 deletions

View File

@ -208,6 +208,7 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj)
if (machine == m_machine) if (machine == m_machine)
return; return;
m_machine = machine; m_machine = machine;
m_last_errors.clear();
auto fs = m_image_grid->GetFileSystem(); auto fs = m_image_grid->GetFileSystem();
if (fs) { if (fs) {
m_image_grid->SetFileSystem(nullptr); m_image_grid->SetFileSystem(nullptr);
@ -265,7 +266,7 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj)
if (e.GetInt() == PrinterFileSystem::Initializing) if (e.GetInt() == PrinterFileSystem::Initializing)
fetchUrl(boost::weak_ptr(fs)); fetchUrl(boost::weak_ptr(fs));
if (status == PrinterFileSystem::Failed if ((status == PrinterFileSystem::Failed && m_last_errors.find(fs->GetLastError()) == m_last_errors.end())
|| status == PrinterFileSystem::ListReady) { || status == PrinterFileSystem::ListReady) {
json j; json j;
j["code"] = fs->GetLastError(); j["code"] = fs->GetLastError();
@ -281,6 +282,7 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj)
if (agent) if (agent)
agent->track_event("download_video_conn", j.dump()); agent->track_event("download_video_conn", j.dump());
} }
m_last_errors.insert(fs->GetLastError());
} }
}); });
fs->Bind(EVT_DOWNLOAD, [this, wfs = boost::weak_ptr(fs)](auto& e) { fs->Bind(EVT_DOWNLOAD, [this, wfs = boost::weak_ptr(fs)](auto& e) {

View File

@ -85,6 +85,7 @@ private:
int m_last_mode = 0; int m_last_mode = 0;
int m_last_type = 0; int m_last_type = 0;
std::set<int> m_last_errors;
}; };

View File

@ -100,6 +100,7 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj)
m_machine = machine; m_machine = machine;
BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl switch machine: " << m_machine; BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl switch machine: " << m_machine;
m_failed_retry = 0; m_failed_retry = 0;
m_last_failed_codes.clear();
std::string stream_url; std::string stream_url;
if (get_stream_url(&stream_url)) { if (get_stream_url(&stream_url)) {
m_streaming = boost::algorithm::contains(stream_url, "device=" + m_machine); m_streaming = boost::algorithm::contains(stream_url, "device=" + m_machine);
@ -215,7 +216,7 @@ void MediaPlayCtrl::Play()
void MediaPlayCtrl::Stop(wxString const &msg) void MediaPlayCtrl::Stop(wxString const &msg)
{ {
bool init_failed = m_last_state != wxMEDIASTATE_PLAYING; int last_state = m_last_state;
if (m_last_state != MEDIASTATE_IDLE) { if (m_last_state != MEDIASTATE_IDLE) {
m_media_ctrl->InvalidateBestSize(); m_media_ctrl->InvalidateBestSize();
@ -238,19 +239,22 @@ void MediaPlayCtrl::Stop(wxString const &msg)
m_failed_code = 0; m_failed_code = 0;
} }
if (init_failed && m_failed_code != 0 && m_last_failed_code != m_failed_code) { if (last_state != wxMEDIASTATE_PLAYING && m_failed_code != 0
&& m_last_failed_codes.find(m_failed_code) == m_last_failed_codes.end()
&& (m_user_triggered || m_failed_retry > 3)) {
json j; json j;
j["stage"] = std::to_string(m_last_state); j["stage"] = last_state;
j["dev_id"] = m_machine; j["dev_id"] = m_machine;
j["dev_ip"] = m_lan_ip; j["dev_ip"] = m_lan_ip;
j["result"] = "failed"; j["result"] = "failed";
j["user_triggered"] = m_user_triggered;
j["code"] = m_failed_code; j["code"] = m_failed_code;
j["msg"] = into_u8(msg); j["msg"] = into_u8(msg);
NetworkAgent *agent = wxGetApp().getAgent(); NetworkAgent *agent = wxGetApp().getAgent();
if (agent) if (agent)
agent->track_event("start_liveview", j.dump()); agent->track_event("start_liveview", j.dump());
m_last_failed_codes.insert(m_failed_code);
} }
m_last_failed_code = m_failed_code;
++m_failed_retry; ++m_failed_retry;
if (m_failed_code != 0 && !m_tutk_support && (m_failed_retry > 1 || m_user_triggered)) { if (m_failed_code != 0 && !m_tutk_support && (m_failed_retry > 1 || m_user_triggered)) {
@ -258,7 +262,7 @@ void MediaPlayCtrl::Stop(wxString const &msg)
if (wxGetApp().show_modal_ip_address_enter_dialog(_L("LAN Connection Failed (Failed to start liveview)"))) { if (wxGetApp().show_modal_ip_address_enter_dialog(_L("LAN Connection Failed (Failed to start liveview)"))) {
m_failed_retry = 0; m_failed_retry = 0;
m_user_triggered = true; m_user_triggered = true;
m_last_failed_code = 0; m_last_failed_codes.clear();
m_next_retry = wxDateTime::Now(); m_next_retry = wxDateTime::Now();
return; return;
} }
@ -276,7 +280,7 @@ void MediaPlayCtrl::TogglePlay()
} else { } else {
m_failed_retry = 0; m_failed_retry = 0;
m_user_triggered = true; m_user_triggered = true;
m_last_failed_code = 0; m_last_failed_codes.clear();
m_next_retry = wxDateTime::Now(); m_next_retry = wxDateTime::Now();
Play(); Play();
} }

View File

@ -16,6 +16,7 @@
#include <boost/thread/condition_variable.hpp> #include <boost/thread/condition_variable.hpp>
#include <deque> #include <deque>
#include <set>
class Button; class Button;
class Label; class Label;
@ -86,7 +87,7 @@ private:
bool m_user_triggered = false; bool m_user_triggered = false;
int m_failed_retry = 0; int m_failed_retry = 0;
int m_failed_code = 0; int m_failed_code = 0;
int m_last_failed_code = 0; std::set<int> m_last_failed_codes;
wxDateTime m_next_retry; wxDateTime m_next_retry;
::Button *m_button_play; ::Button *m_button_play;

View File

@ -21,12 +21,12 @@
extern "C" { extern "C" {
#endif // __cplusplus #endif // __cplusplus
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef __cplusplus
typedef wchar_t tchar; typedef wchar_t tchar;
#else
typedef unsigned short tchar;
#endif
#else #else
typedef char tchar; typedef char tchar;
#endif #endif
@ -117,7 +117,7 @@ BAMBU_EXPORT void BAMBU_FUNC(Bambu_SetLogger)(Bambu_Tunnel tunnel, Logger logger
BAMBU_EXPORT int BAMBU_FUNC(Bambu_Open)(Bambu_Tunnel tunnel); BAMBU_EXPORT int BAMBU_FUNC(Bambu_Open)(Bambu_Tunnel tunnel);
BAMBU_EXPORT int BAMBU_FUNC(Bambu_StartStream)(Bambu_Tunnel tunnel, bool video); BAMBU_EXPORT int BAMBU_FUNC(Bambu_StartStream)(Bambu_Tunnel tunnel, int video);
BAMBU_EXPORT int BAMBU_FUNC(Bambu_GetStreamCount)(Bambu_Tunnel tunnel); BAMBU_EXPORT int BAMBU_FUNC(Bambu_GetStreamCount)(Bambu_Tunnel tunnel);

View File

@ -1074,9 +1074,14 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
if (ret == 0) if (ret == 0)
ret = Bambu_StartStream(tunnel, false); ret = Bambu_StartStream(tunnel, false);
l.lock(); l.lock();
m_session.tunnel = tunnel; if (ret == 0) {
if (ret == 0) m_session.tunnel = tunnel;
break; break;
}
if (tunnel) {
Bambu_Close(tunnel);
Bambu_Destroy(tunnel);
}
m_last_error = ret; m_last_error = ret;
} }
m_status = Status::Failed; m_status = Status::Failed;

View File

@ -89,8 +89,8 @@ void wxMediaCtrl2::Load(wxURI url)
BambuPlayer * player = (BambuPlayer *) m_player; BambuPlayer * player = (BambuPlayer *) m_player;
if (player) { if (player) {
[player close]; [player close];
[player open: url.BuildURI().ToUTF8()];
m_error = 0; m_error = 0;
[player open: url.BuildURI().ToUTF8()];
} }
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED); wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
event.SetId(GetId()); event.SetId(GetId());