From 31aa3d86acc25f70c6573f07922c074a53a359b3 Mon Sep 17 00:00:00 2001 From: luocai Date: Thu, 22 Aug 2024 15:32:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8D=87=E7=BA=A7=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E5=8F=8A=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AntiClipSettings.rc | 2 +- Application.cpp | 13 ++++++++++++- DeviceConnection.cpp | 29 ++++++++++++++++++++++------- DeviceConnection.h | 2 +- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/AntiClipSettings.rc b/AntiClipSettings.rc index 215aef4..bf3ae14 100644 --- a/AntiClipSettings.rc +++ b/AntiClipSettings.rc @@ -42,7 +42,7 @@ LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. - IDI_ICON1 ICON "resources\\logo.ico" + // IDI_ICON1 ICON "resources\\logo.ico" #endif // 中文(简体,中国) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/Application.cpp b/Application.cpp index 0be4d12..1845d8b 100644 --- a/Application.cpp +++ b/Application.cpp @@ -3,6 +3,7 @@ #include "Configuration.h" #include "H264Palyer.h" #include "VideoFrameProvider.h" +#include #include #include #include @@ -219,10 +220,20 @@ void Application::startSearchDevice() { } void Application::upgradeDevice(const QString &file) { + constexpr auto versionPrefix = "RD_T009"; + constexpr auto version = "RD_T009_V21R003B013"; + QFileInfo fileInfo(file); + QString baseName = fileInfo.baseName(); + int position = baseName.indexOf(versionPrefix); + if (position < 0 || ((baseName.length() - position) < std::strlen(version))) { + emit newMessage(2, "OTA升级", "文件名格式不合法!"); + return; + } + QString firmware = baseName.mid(position, std::strlen(version)); if (!m_device.expired()) { auto device = m_device.lock(); if (device->isConnected()) { - device->requestOta(file); + device->requestOta(firmware, file); } else { emit newMessage(2, "OTA升级", "设备已离线,请重新连接设备!"); } diff --git a/DeviceConnection.cpp b/DeviceConnection.cpp index 67fcd04..7eac525 100644 --- a/DeviceConnection.cpp +++ b/DeviceConnection.cpp @@ -300,7 +300,7 @@ QFuture DeviceConnection::updateNetworkInfomation(bool dhcp, const QString return ret; } -void DeviceConnection::requestOta(const QString &file) { +void DeviceConnection::requestOta(const QString &firmware, const QString &file) { m_otaProgress = 0; emit otaProgressChanged(true, m_otaProgress, "正在向设备发起OTA请求......"); if (m_timerId > 0) { @@ -309,7 +309,7 @@ void DeviceConnection::requestOta(const QString &file) { } Task task; task.command = "a22devicefirmware_setdata"; - task.task = [this, file]() { + task.task = [this, file, firmware]() { std::ifstream ifs(Amass::StringUtility::UTF8ToGBK(file.toStdString()), std::ifstream::binary); m_uploadBuffer = std::vector((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); m_sendedSize = 0; @@ -326,18 +326,17 @@ void DeviceConnection::requestOta(const QString &file) { for (int i = 0; i < 16; i++) { oss << std::setw(2) << static_cast(md5[i]); } - boost::json::object request; request["func"] = "a22devicefirmware_setdata"; request["deviceid"] = "0"; boost::json::object data; - data["target_linux04_firmware"] = "RD_T009_V21R003B002"; + data["target_linux04_firmware"] = firmware.toStdString(); data["datasize"] = std::filesystem::file_size(file.toStdString()); data["md5"] = oss.str(); request["data"] = std::move(data); auto text = boost::json::serialize(request); m_commandSocket->write(text.data(), text.size()); - LOG(info) << "requestOta: " << text << ": " << text.size(); + LOG(info) << "requestOta: " << text; }; if (m_requests.empty()) { task.task(); @@ -520,7 +519,7 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const m_h264Socket->close(); }, Qt::SingleShotConnection); - m_otaTimer->start(120 * 1000); + m_otaTimer->start(60 * 1000); }); QTimer::singleShot(25000, this, [this]() { LOG(info) << "try connect after ota."; @@ -528,7 +527,23 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const m_h264Socket->connectToHost(m_infomation.ip, 8000); }); } else { - emit otaProgressChanged(false, m_otaProgress, QString("升级失败,错误码: %1").arg(value.c_str())); + const char *message = nullptr; + if (value == "3") { + message = "升级固件MD5校验错误(3)"; + } else if (value == "4") { + message = "升级固件大小错误(4)"; + } else if (value == "5") { + message = "升级固件太大(5)"; + } else if (value == "6") { + message = "升级固件版本不匹配(6)"; + } + QString tip; + if (message == nullptr) { + tip = QString("升级失败,错误码: %1").arg(value.c_str()); + } else { + tip = QString("升级失败: %1").arg(message); + } + emit otaProgressChanged(false, m_otaProgress, tip); } } else { LOG(warning) << "unknown reply: " << replyText; diff --git a/DeviceConnection.h b/DeviceConnection.h index 93eee65..792d93b 100644 --- a/DeviceConnection.h +++ b/DeviceConnection.h @@ -81,7 +81,7 @@ public: * * @param file */ - void requestOta(const QString &file); + void requestOta(const QString &firmware, const QString &file); signals: void connected();