完善升级功能。
This commit is contained in:
parent
2610c40189
commit
9d495d487d
@ -12,6 +12,7 @@
|
|||||||
#include "VideoFrameProvider.h"
|
#include "VideoFrameProvider.h"
|
||||||
#include "VideoPlayer.h"
|
#include "VideoPlayer.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QFile>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
@ -408,7 +409,22 @@ void Application::onVerifyTimeout() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::startOta(const QString &path) {
|
bool Application::startOta(const QString &path) {
|
||||||
|
if (!QFile::exists(path)) {
|
||||||
|
emit otaMessage("文件不存在");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto device = CdcUpdater::searchDevice();
|
||||||
|
if (device) {
|
||||||
|
LOG(info) << "device already in ota mode.";
|
||||||
|
} else {
|
||||||
|
if (m_communication) {
|
||||||
|
m_communication->startOta();
|
||||||
|
} else {
|
||||||
|
emit otaMessage("请先打开设备");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
LOG(info) << "start ota, ota path: " << path.toStdString();
|
LOG(info) << "start ota, ota path: " << path.toStdString();
|
||||||
m_updater = std::make_shared<CdcUpdater>();
|
m_updater = std::make_shared<CdcUpdater>();
|
||||||
connect(m_updater.get(), &CdcUpdater::deviceDiscovered, this, &Application::onCdcDeviceDiscovered);
|
connect(m_updater.get(), &CdcUpdater::deviceDiscovered, this, &Application::onCdcDeviceDiscovered);
|
||||||
@ -416,8 +432,8 @@ void Application::startOta(const QString &path) {
|
|||||||
connect(m_updater.get(), &CdcUpdater::progressChanged, this, &Application::otaProgressChanged);
|
connect(m_updater.get(), &CdcUpdater::progressChanged, this, &Application::otaProgressChanged);
|
||||||
connect(m_updater.get(), &CdcUpdater::message, this, &Application::otaMessage);
|
connect(m_updater.get(), &CdcUpdater::message, this, &Application::otaMessage);
|
||||||
|
|
||||||
m_communication->startOta();
|
m_updater->start(path, device ? *device : QSerialPortInfo());
|
||||||
m_updater->start(path);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::onCdcDeviceDiscovered(const QSerialPortInfo &info) {
|
void Application::onCdcDeviceDiscovered(const QSerialPortInfo &info) {
|
||||||
|
@ -45,7 +45,7 @@ public:
|
|||||||
Q_INVOKABLE bool openUVC(const QString &deviceName);
|
Q_INVOKABLE bool openUVC(const QString &deviceName);
|
||||||
Q_INVOKABLE void close();
|
Q_INVOKABLE void close();
|
||||||
Q_INVOKABLE void closeUVC();
|
Q_INVOKABLE void closeUVC();
|
||||||
Q_INVOKABLE void startOta(const QString &path);
|
Q_INVOKABLE bool startOta(const QString &path);
|
||||||
Q_INVOKABLE void verify(bool captureImage, uint8_t timeout);
|
Q_INVOKABLE void verify(bool captureImage, uint8_t timeout);
|
||||||
Q_INVOKABLE void enroll(const QString &username, bool persistence, uint8_t timeout);
|
Q_INVOKABLE void enroll(const QString &username, bool persistence, uint8_t timeout);
|
||||||
Q_INVOKABLE void enrollExtended(const QString &username, bool persistence, uint8_t timeout);
|
Q_INVOKABLE void enrollExtended(const QString &username, bool persistence, uint8_t timeout);
|
||||||
|
@ -5,10 +5,14 @@ import QtQuick.Dialogs
|
|||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Analyser
|
import Analyser
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: root
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
anchors.fill: parent
|
||||||
ConnectionItem {}
|
ConnectionItem {}
|
||||||
|
|
||||||
GroupBox {
|
GroupBox {
|
||||||
|
id: commandBox
|
||||||
title: "命令"
|
title: "命令"
|
||||||
Layout.columnSpan: 2
|
Layout.columnSpan: 2
|
||||||
enabled: App.connected
|
enabled: App.connected
|
||||||
@ -50,15 +54,14 @@ ColumnLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
property bool enrolling: App.module ? (App.module.currentMessageId === 0x1d)
|
property bool enrolling: App.module ? (App.module.currentMessageId === 0x1d) || (App.module.currentMessageId === 0x1e) : false
|
||||||
|| (App.module.currentMessageId
|
|
||||||
=== 0x1e) : false
|
|
||||||
text: enrolling ? "取消" : "注册"
|
text: enrolling ? "取消" : "注册"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (enrolling) {
|
if (enrolling) {
|
||||||
App.module.reset()
|
App.module.reset()
|
||||||
} else if (extendedMode.checked) {
|
} else if (extendedMode.checked) {
|
||||||
App.enrollExtended(enrollName.text,
|
App.enrollExtended(
|
||||||
|
enrollName.text,
|
||||||
persistence.checked,
|
persistence.checked,
|
||||||
parseInt(enrollTimeout.text))
|
parseInt(enrollTimeout.text))
|
||||||
} else {
|
} else {
|
||||||
@ -132,7 +135,8 @@ ColumnLayout {
|
|||||||
}
|
}
|
||||||
Button {
|
Button {
|
||||||
text: "删除"
|
text: "删除"
|
||||||
onClicked: App.deleteUser(parseInt(deleteUserId.text))
|
onClicked: App.deleteUser(parseInt(
|
||||||
|
deleteUserId.text))
|
||||||
}
|
}
|
||||||
Button {
|
Button {
|
||||||
text: "删除所有"
|
text: "删除所有"
|
||||||
@ -176,6 +180,7 @@ ColumnLayout {
|
|||||||
onClicked: App.module.requestUniqueId()
|
onClicked: App.module.requestUniqueId()
|
||||||
}
|
}
|
||||||
Button {
|
Button {
|
||||||
|
id: otaButton
|
||||||
text: "OTA升级"
|
text: "OTA升级"
|
||||||
onClicked: loader.active = true
|
onClicked: loader.active = true
|
||||||
}
|
}
|
||||||
@ -190,7 +195,7 @@ ColumnLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: fileDialog
|
id: fileDialog
|
||||||
nameFilters: ["图片 (*.jpg *.yuv)"]
|
nameFilters: ["图片 (*.jpg *.yuv)"]
|
||||||
@ -204,6 +209,19 @@ ColumnLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
width: otaButton.width
|
||||||
|
height: otaButton.height
|
||||||
|
enabled: !commandBox.enabled
|
||||||
|
onClicked: {
|
||||||
|
loader.active = true
|
||||||
|
}
|
||||||
|
Component.onCompleted: {
|
||||||
|
x = Qt.binding(() => otaButton.mapToItem(root, 0, 0).x)
|
||||||
|
y = Qt.binding(() => otaButton.mapToItem(root, 0, 0).y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
id: loader
|
id: loader
|
||||||
source: "OtaPage.qml"
|
source: "OtaPage.qml"
|
||||||
|
@ -72,8 +72,7 @@ Popup {
|
|||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignRight
|
||||||
onClicked: {
|
onClicked: {
|
||||||
otaMessage.color = "black"
|
otaMessage.color = "black"
|
||||||
App.startOta(otaFile.text)
|
enabled = !App.startOta(otaFile.text)
|
||||||
enabled = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,9 +106,8 @@ Popup {
|
|||||||
otaMessage.text = message
|
otaMessage.text = message
|
||||||
}
|
}
|
||||||
function onOtaProgressChanged(progress) {
|
function onOtaProgressChanged(progress) {
|
||||||
progressBar.value = progress;
|
progressBar.value = progress
|
||||||
progressText.text = `${progress}%`
|
progressText.text = `${progress}%`
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,10 @@ void Widget::start() {
|
|||||||
QMessageBox::warning(this, "升级", "升级文件不存在!");
|
QMessageBox::warning(this, "升级", "升级文件不存在!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto device = CdcUpdater::searchDevice();
|
||||||
|
if (device) {
|
||||||
|
LOG(info) << "device already in ota mode.";
|
||||||
|
} else {
|
||||||
auto discovery = std::make_shared<DeviceDiscovery>();
|
auto discovery = std::make_shared<DeviceDiscovery>();
|
||||||
|
|
||||||
std::error_code error;
|
std::error_code error;
|
||||||
@ -73,12 +77,13 @@ void Widget::start() {
|
|||||||
}
|
}
|
||||||
setMessage("发现设备成功,进入BOOT模式......");
|
setMessage("发现设备成功,进入BOOT模式......");
|
||||||
discovery->enterOtaMode(device, error);
|
discovery->enterOtaMode(device, error);
|
||||||
|
}
|
||||||
m_updater = std::make_shared<CdcUpdater>();
|
m_updater = std::make_shared<CdcUpdater>();
|
||||||
connect(m_updater.get(), &CdcUpdater::deviceDiscovered, this, &Widget::onCdcDeviceDiscovered);
|
connect(m_updater.get(), &CdcUpdater::deviceDiscovered, this, &Widget::onCdcDeviceDiscovered);
|
||||||
connect(m_updater.get(), &CdcUpdater::updateFinished, this, &Widget::onUpdateFinished);
|
connect(m_updater.get(), &CdcUpdater::updateFinished, this, &Widget::onUpdateFinished);
|
||||||
connect(m_updater.get(), &CdcUpdater::progressChanged, this, &Widget::setProgress);
|
connect(m_updater.get(), &CdcUpdater::progressChanged, this, &Widget::setProgress);
|
||||||
connect(m_updater.get(), &CdcUpdater::message, this, &Widget::setMessage);
|
connect(m_updater.get(), &CdcUpdater::message, this, &Widget::setMessage);
|
||||||
m_updater->start(filePath);
|
m_updater->start(filePath, device ? *device : QSerialPortInfo());
|
||||||
setControlsEnabled(false);
|
setControlsEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include "StringUtility.h"
|
#include "StringUtility.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSerialPort>
|
#include <QSerialPort>
|
||||||
#include <QSerialPortInfo>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <mbedtls/md5.h>
|
#include <mbedtls/md5.h>
|
||||||
@ -41,10 +40,15 @@ CdcUpdater::CdcUpdater(QObject *parent) : QObject(parent) {
|
|||||||
CdcUpdater::~CdcUpdater() {
|
CdcUpdater::~CdcUpdater() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CdcUpdater::start(const QString &path) {
|
void CdcUpdater::start(const QString &path, const QSerialPortInfo &info) {
|
||||||
|
if (info.isNull()) {
|
||||||
if (m_timerId < 0) {
|
if (m_timerId < 0) {
|
||||||
m_timerId = startTimer(1000);
|
m_timerId = startTimer(1000);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
open(info);
|
||||||
|
}
|
||||||
|
|
||||||
m_path = Amass::StringUtility::UTF8ToGBK(path.toStdString());
|
m_path = Amass::StringUtility::UTF8ToGBK(path.toStdString());
|
||||||
LOG(info) << "ota file: " << m_path;
|
LOG(info) << "ota file: " << m_path;
|
||||||
emit progressChanged(++m_progress);
|
emit progressChanged(++m_progress);
|
||||||
@ -84,20 +88,29 @@ bool CdcUpdater::write(Command command, const uint8_t *data, uint32_t size) {
|
|||||||
return m_serialPort->write(reinterpret_cast<const char *>(packet.data()), packet.size());
|
return m_serialPort->write(reinterpret_cast<const char *>(packet.data()), packet.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CdcUpdater::timerEvent(QTimerEvent *event) {
|
std::optional<QSerialPortInfo> CdcUpdater::searchDevice() {
|
||||||
|
std::optional<QSerialPortInfo> ret = std::nullopt;
|
||||||
const auto serialPortInfos = QSerialPortInfo::availablePorts();
|
const auto serialPortInfos = QSerialPortInfo::availablePorts();
|
||||||
for (const QSerialPortInfo &portInfo : serialPortInfos) {
|
for (const QSerialPortInfo &portInfo : serialPortInfos) {
|
||||||
LOG(info) << "portName:" << portInfo.portName().toStdString()
|
LOG(info) << "portName:" << portInfo.portName().toStdString()
|
||||||
<< ", vendorIdentifier: " << portInfo.vendorIdentifier()
|
<< ", vendorIdentifier: " << portInfo.vendorIdentifier()
|
||||||
<< ", productIdentifier: " << portInfo.productIdentifier();
|
<< ", productIdentifier: " << portInfo.productIdentifier();
|
||||||
if (portInfo.vendorIdentifier() == 0xffff) {
|
if (portInfo.vendorIdentifier() == 0xffff) {
|
||||||
LOG(info) << "founded device: " << portInfo.portName().toStdString();
|
ret = portInfo;
|
||||||
emit deviceDiscovered(portInfo);
|
|
||||||
killTimer(m_timerId);
|
|
||||||
m_timerId = -1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CdcUpdater::timerEvent(QTimerEvent *event) {
|
||||||
|
auto device = searchDevice();
|
||||||
|
if (device) {
|
||||||
|
LOG(info) << "founded device: " << device->portName().toStdString();
|
||||||
|
emit deviceDiscovered(*device);
|
||||||
|
killTimer(m_timerId);
|
||||||
|
m_timerId = -1;
|
||||||
|
}
|
||||||
LOG(info) << "----------";
|
LOG(info) << "----------";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
#define __CDCUPDATER_H__
|
#define __CDCUPDATER_H__
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QSerialPortInfo>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
class QSerialPort;
|
class QSerialPort;
|
||||||
class QSerialPortInfo;
|
|
||||||
|
|
||||||
class CdcUpdater : public QObject {
|
class CdcUpdater : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -35,8 +36,10 @@ public:
|
|||||||
};
|
};
|
||||||
CdcUpdater(QObject *parent = nullptr);
|
CdcUpdater(QObject *parent = nullptr);
|
||||||
~CdcUpdater();
|
~CdcUpdater();
|
||||||
void start(const QString &path);
|
void start(const QString &path, const QSerialPortInfo &info = QSerialPortInfo());
|
||||||
bool open(const QSerialPortInfo &info);
|
bool open(const QSerialPortInfo &info);
|
||||||
|
static std::optional<QSerialPortInfo> searchDevice();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceDiscovered(const QSerialPortInfo &info);
|
void deviceDiscovered(const QSerialPortInfo &info);
|
||||||
void updateFinished();
|
void updateFinished();
|
||||||
|
Loading…
Reference in New Issue
Block a user