From c1191e08232b5996db491bd44eb5115e6db90268 Mon Sep 17 00:00:00 2001 From: huangziyi Date: Thu, 14 Dec 2023 10:32:46 +0800 Subject: [PATCH] enhance connection stability Signed-off-by: huangziyi --- src/plugins/openmv/openmvplugin.cpp | 26 ------------------- src/plugins/openmv/openmvpluginserialport.cpp | 20 +++++++++----- 2 files changed, 13 insertions(+), 33 deletions(-) mode change 100644 => 100755 src/plugins/openmv/openmvpluginserialport.cpp diff --git a/src/plugins/openmv/openmvplugin.cpp b/src/plugins/openmv/openmvplugin.cpp index d1e8a41a4aa..3f2ca15daf4 100755 --- a/src/plugins/openmv/openmvplugin.cpp +++ b/src/plugins/openmv/openmvplugin.cpp @@ -2792,32 +2792,6 @@ bool OpenMVPlugin::delayedInitialize() Tr::tr("Failed to create the documents folder!")); } - if(Core::EditorManager::currentEditor() - ? Core::EditorManager::currentEditor()->document() - ? Core::EditorManager::currentEditor()->document()->displayName() == QStringLiteral("helloworld_1.py") - : false - : false) - { - QTimer::singleShot(2000, this, [] { - Utils::CheckableMessageBox::doNotShowAgainInformation(Core::ICore::dialogParent(), - Tr::tr("OpenMV Cam LED Colors"), - Tr::tr("Thanks for using the OpenMV Cam and OpenMV IDE!\n\n" - "Your OpenMV Cam's onboard LED blinks with diffent colors to indicate its state:\n\n" - "Blinking Green:\n\nYour OpenMV Cam's onboard bootloader is running. " - "The onboard bootloader runs for a few seconds when your OpenMV Cam is powered via USB to allow OpenMV IDE to reprogram your OpenMV Cam.\n\n" - "Blinking Blue:\n\nYour OpenMV Cam is running the default main.py script onboard.\n\n" - "If you have an SD card installed or overwrote the main.py script on your OpenMV Cam then it will run whatever code you loaded on it instead.\n\n" - "If the LED is blinking blue but OpenMV IDE can't connect to your OpenMV Cam " - "please make sure you are connecting your OpenMV Cam to your PC with a USB cable that supplies both data and power.\n\n" - "Blinking White:\n\nYour OpenMV Cam's firmware is panicking because of a hardware failure. " - "Please check that your OpenMV Cam's camera module is installed securely.\n\n"), - ExtensionSystem::PluginManager::settings(), - QStringLiteral(DONT_SHOW_LED_STATES_AGAIN), - QDialogButtonBox::Ok, - QDialogButtonBox::Ok); - }); - } - return true; } diff --git a/src/plugins/openmv/openmvpluginserialport.cpp b/src/plugins/openmv/openmvpluginserialport.cpp old mode 100644 new mode 100755 index db2f468b16b..8f3192e3908 --- a/src/plugins/openmv/openmvpluginserialport.cpp +++ b/src/plugins/openmv/openmvpluginserialport.cpp @@ -16,7 +16,7 @@ #define WRITE_TIMEOUT 6000 #define SERIAL_READ_TIMEOUT 10000 #define WIFI_READ_TIMEOUT 10000 -#define SERIAL_READ_STALL_TIMEOUT 1000 +#define SERIAL_READ_STALL_TIMEOUT 2000 #define WIFI_READ_STALL_TIMEOUT 3000 #define BOOTLOADER_WRITE_TIMEOUT 6 #define BOOTLOADER_READ_TIMEOUT 10 @@ -586,6 +586,7 @@ void OpenMVPluginSerialPort_private::command(const OpenMVPluginSerialPortCommand QElapsedTimer elaspedTimer2; elaspedTimer.start(); elaspedTimer2.start(); + static unsigned noResponseCount = 0; do { @@ -656,17 +657,22 @@ void OpenMVPluginSerialPort_private::command(const OpenMVPluginSerialPortCommand if(response.size() >= responseLen) { + noResponseCount = 0; emit commandResult(OpenMVPluginSerialPortCommandResult(true, response.left(command.m_responseLen))); } else { - if(m_port) - { - delete m_port; - m_port = Q_NULLPTR; + noResponseCount += 1; + qDebug() << "no response:" << noResponseCount; + if (noResponseCount > 20) { + if(m_port) { + delete m_port; + m_port = Q_NULLPTR; + } + emit commandResult(OpenMVPluginSerialPortCommandResult(false, QByteArray())); + } else { + emit commandResult(OpenMVPluginSerialPortCommandResult(true, QByteArray())); } - - emit commandResult(OpenMVPluginSerialPortCommandResult(false, QByteArray())); } } }