完善升级功能。

This commit is contained in:
luocai
2024-08-08 17:05:32 +08:00
parent 2610c40189
commit 9d495d487d
7 changed files with 251 additions and 198 deletions

View File

@ -12,6 +12,7 @@
#include "VideoFrameProvider.h"
#include "VideoPlayer.h"
#include <QApplication>
#include <QFile>
#include <QFont>
#include <QImage>
#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();
m_updater = std::make_shared<CdcUpdater>();
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::message, this, &Application::otaMessage);
m_communication->startOta();
m_updater->start(path);
m_updater->start(path, device ? *device : QSerialPortInfo());
return true;
}
void Application::onCdcDeviceDiscovered(const QSerialPortInfo &info) {

View File

@ -45,7 +45,7 @@ public:
Q_INVOKABLE bool openUVC(const QString &deviceName);
Q_INVOKABLE void close();
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 enroll(const QString &username, bool persistence, uint8_t timeout);
Q_INVOKABLE void enrollExtended(const QString &username, bool persistence, uint8_t timeout);

View File

@ -5,192 +5,197 @@ import QtQuick.Dialogs
import QtQuick.Layouts
import Analyser
ColumnLayout {
ConnectionItem {}
Item {
id: root
ColumnLayout {
anchors.fill: parent
ConnectionItem {}
GroupBox {
title: "命令"
Layout.columnSpan: 2
enabled: App.connected
GridLayout {
columns: 2
GroupBox {
title: "注册用户"
GridLayout {
columns: 2
Text {
text: qsTr("用户姓名")
}
TextField {
id: enrollName
implicitWidth: 100
}
Text {
text: qsTr("超时时间")
}
TextField {
id: enrollTimeout
implicitWidth: 100
text: "10"
}
GroupBox {
id: commandBox
title: "命令"
Layout.columnSpan: 2
enabled: App.connected
GridLayout {
columns: 2
GroupBox {
title: "注册用户"
GridLayout {
columns: 2
Text {
text: qsTr("用户姓名")
}
TextField {
id: enrollName
implicitWidth: 100
}
Text {
text: qsTr("超时时间")
}
TextField {
id: enrollTimeout
implicitWidth: 100
text: "10"
}
Text {
text: qsTr("持久化")
}
Switch {
id: persistence
checked: true
}
Text {
text: qsTr("持久化")
}
Switch {
id: persistence
checked: true
}
Text {
text: qsTr("保存图片")
}
Switch {
id: extendedMode
}
Text {
text: qsTr("保存图片")
}
Switch {
id: extendedMode
}
Button {
property bool enrolling: App.module ? (App.module.currentMessageId === 0x1d)
|| (App.module.currentMessageId
=== 0x1e) : false
text: enrolling ? "取消" : "注册"
onClicked: {
if (enrolling) {
App.module.reset()
} else if (extendedMode.checked) {
App.enrollExtended(enrollName.text,
persistence.checked,
parseInt(enrollTimeout.text))
} else {
App.enroll(enrollName.text,
persistence.checked,
parseInt(enrollTimeout.text))
Button {
property bool enrolling: App.module ? (App.module.currentMessageId === 0x1d) || (App.module.currentMessageId === 0x1e) : false
text: enrolling ? "取消" : "注册"
onClicked: {
if (enrolling) {
App.module.reset()
} else if (extendedMode.checked) {
App.enrollExtended(
enrollName.text,
persistence.checked,
parseInt(enrollTimeout.text))
} else {
App.enroll(enrollName.text,
persistence.checked,
parseInt(enrollTimeout.text))
}
}
}
}
}
}
GroupBox {
title: "识别用户"
GridLayout {
columns: 2
Text {
text: qsTr("超时时间(s)")
}
TextField {
id: verifyTimeout
implicitWidth: 80
text: "10"
}
Text {
text: qsTr("持续识别")
}
Switch {
checked: App.persistenceMode
onToggled: App.persistenceMode = !App.persistenceMode
}
Text {
text: qsTr("保存图片")
}
Switch {
id: extendedVerifyMode
}
Text {
text: qsTr("识别间隔(s)")
}
TextField {
id: verifyIntetval
implicitWidth: 80
text: App.persistenceVerifyInterval
}
Item {}
Button {
text: App.isVerifying ? "停止" : "识别"
onClicked: {
if (App.isVerifying) {
App.module.reset()
} else {
App.persistenceVerifyInterval = parseInt(
verifyIntetval.text)
App.verify(extendedVerifyMode.checked,
parseInt(verifyTimeout.text))
GroupBox {
title: "识别用户"
GridLayout {
columns: 2
Text {
text: qsTr("超时时间(s)")
}
TextField {
id: verifyTimeout
implicitWidth: 80
text: "10"
}
Text {
text: qsTr("持续识别")
}
Switch {
checked: App.persistenceMode
onToggled: App.persistenceMode = !App.persistenceMode
}
Text {
text: qsTr("保存图片")
}
Switch {
id: extendedVerifyMode
}
Text {
text: qsTr("识别间隔(s)")
}
TextField {
id: verifyIntetval
implicitWidth: 80
text: App.persistenceVerifyInterval
}
Item {}
Button {
text: App.isVerifying ? "停止" : "识别"
onClicked: {
if (App.isVerifying) {
App.module.reset()
} else {
App.persistenceVerifyInterval = parseInt(
verifyIntetval.text)
App.verify(extendedVerifyMode.checked,
parseInt(verifyTimeout.text))
}
}
}
}
}
}
GroupBox {
title: "删除用户"
GridLayout {
columns: 2
Text {
text: qsTr("用户ID")
}
TextField {
id: deleteUserId
implicitWidth: 100
}
Button {
text: "删除"
onClicked: App.deleteUser(parseInt(deleteUserId.text))
}
Button {
text: "删除所有"
onClicked: App.deleteAll()
}
}
}
GroupBox {
title: "图片注册"
GridLayout {
columns: 2
TextField {
id: imagePath
Layout.columnSpan: 2
implicitWidth: 180
placeholderText: "请选择图片"
onPressed: {
fileDialog.open()
GroupBox {
title: "删除用户"
GridLayout {
columns: 2
Text {
text: qsTr("用户ID")
}
TextField {
id: deleteUserId
implicitWidth: 100
}
Button {
text: "删除"
onClicked: App.deleteUser(parseInt(
deleteUserId.text))
}
Button {
text: "删除所有"
onClicked: App.deleteAll()
}
}
Button {
text: "注册"
onClicked: App.uploadImage(imagePath.text, 0)
}
Button {
text: "识别"
onClicked: App.uploadImage(imagePath.text, 1)
}
GroupBox {
title: "图片注册"
GridLayout {
columns: 2
TextField {
id: imagePath
Layout.columnSpan: 2
implicitWidth: 180
placeholderText: "请选择图片"
onPressed: {
fileDialog.open()
}
}
Button {
text: "注册"
onClicked: App.uploadImage(imagePath.text, 0)
}
Button {
text: "识别"
onClicked: App.uploadImage(imagePath.text, 1)
}
}
}
}
Button {
text: "复位"
onClicked: App.module.reset()
}
Button {
text: "状态查询"
onClicked: App.module.requestCurrentStatus()
}
Button {
text: "ID查询"
onClicked: App.module.requestUniqueId()
}
Button {
text: "OTA升级"
onClicked: loader.active = true
}
Row {
Text {
text: qsTr("日志")
Button {
text: "复位"
onClicked: App.module.reset()
}
Switch {
id: debugMode
onToggled: App.module.setDebugEnabled(debugMode.checked)
Button {
text: "状态查询"
onClicked: App.module.requestCurrentStatus()
}
Button {
text: "ID查询"
onClicked: App.module.requestUniqueId()
}
Button {
id: otaButton
text: "OTA升级"
onClicked: loader.active = true
}
Row {
Text {
text: qsTr("日志")
}
Switch {
id: debugMode
onToggled: App.module.setDebugEnabled(debugMode.checked)
}
}
}
}
}
FileDialog {
id: fileDialog
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 {
id: loader
source: "OtaPage.qml"

View File

@ -45,14 +45,14 @@ Popup {
RowLayout {
spacing: 10
ProgressBar {
id:progressBar
id: progressBar
Layout.fillWidth: true
from: 0
to:100
to: 100
value: 0.0
}
Text {
id:progressText
id: progressText
text: "0%"
verticalAlignment: Text.AlignVCenter
}
@ -72,8 +72,7 @@ Popup {
Layout.alignment: Qt.AlignRight
onClicked: {
otaMessage.color = "black"
App.startOta(otaFile.text)
enabled = false
enabled = !App.startOta(otaFile.text)
}
}
}
@ -106,10 +105,9 @@ Popup {
function onOtaMessage(message) {
otaMessage.text = message
}
function onOtaProgressChanged(progress){
progressBar.value = progress;
function onOtaProgressChanged(progress) {
progressBar.value = progress
progressText.text = `${progress}%`
}
}
}