完善升级校验及错误提示。
This commit is contained in:
parent
eeb1fc088c
commit
31aa3d86ac
@ -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
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "Configuration.h"
|
||||
#include "H264Palyer.h"
|
||||
#include "VideoFrameProvider.h"
|
||||
#include <QFileInfo>
|
||||
#include <QFont>
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
@ -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升级", "设备已离线,请重新连接设备!");
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ QFuture<bool> 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<uint8_t>((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
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<int>(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;
|
||||
|
@ -81,7 +81,7 @@ public:
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
void requestOta(const QString &file);
|
||||
void requestOta(const QString &firmware, const QString &file);
|
||||
|
||||
signals:
|
||||
void connected();
|
||||
|
Loading…
Reference in New Issue
Block a user