更改OTA升级步骤。

This commit is contained in:
luocai 2024-08-27 11:14:36 +08:00
parent d955e53c60
commit 7cc7b12f33
9 changed files with 127 additions and 72 deletions

View File

@ -15,9 +15,10 @@ Application::Application(int &argc, char **argv)
m_collector(new DataCollection(this)) { m_collector(new DataCollection(this)) {
QFont font; QFont font;
font.setPointSize(16); font.setPointSize(16);
font.setFamily("微软雅黑");
m_app->setFont(font); m_app->setFont(font);
m_app->setApplicationName(APPLICATION_NAME); m_app->setApplicationName(APPLICATION_NAME);
m_app->setApplicationVersion(QString("v%1").arg(APP_VERSION)); m_app->setApplicationVersion(QString("V%1").arg(APP_VERSION));
m_player->open(); m_player->open();
} }

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(AntiClipSettings VERSION 1.1 LANGUAGES C CXX) project(AntiClipSettings VERSION 1.1 LANGUAGES C CXX)
set(APPLICATION_NAME "T009上位机工具") set(APPLICATION_NAME "视觉防夹设备上位机工具")
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)

View File

@ -14,6 +14,32 @@
DeviceConnection::DeviceConnection(QObject *parent) : QObject{parent} { DeviceConnection::DeviceConnection(QObject *parent) : QObject{parent} {
} }
DeviceConnection::~DeviceConnection() {
close();
}
void DeviceConnection::close() {
if (m_otaTimer != nullptr) {
m_otaTimer->deleteLater();
m_otaTimer = nullptr;
}
if (m_timerId > 0) {
killTimer(m_timerId);
m_timerId = -1;
}
if (m_commandSocket != nullptr) {
m_commandSocket->deleteLater();
m_commandSocket = nullptr;
}
if (m_h264Socket != nullptr) {
m_h264Socket->deleteLater();
m_h264Socket = nullptr;
}
while (!m_requests.empty()) {
m_requests.pop();
}
}
DeviceConnection::Infomation DeviceConnection::infomation() const { DeviceConnection::Infomation DeviceConnection::infomation() const {
return m_infomation; return m_infomation;
} }
@ -28,15 +54,7 @@ bool DeviceConnection::isConnected() const {
} }
void DeviceConnection::connect(const Infomation &infomation) { void DeviceConnection::connect(const Infomation &infomation) {
while (!m_requests.empty()) { close();
m_requests.pop();
}
if (m_commandSocket != nullptr) {
m_commandSocket->deleteLater();
}
if (m_h264Socket != nullptr) {
m_h264Socket->deleteLater();
}
m_infomation = infomation; m_infomation = infomation;
m_commandSocket = new QTcpSocket(this); m_commandSocket = new QTcpSocket(this);
QObject::connect(m_commandSocket, &QTcpSocket::disconnected, this, &DeviceConnection::onDisconnected); QObject::connect(m_commandSocket, &QTcpSocket::disconnected, this, &DeviceConnection::onDisconnected);
@ -317,6 +335,9 @@ void DeviceConnection::requestOta(const QString &firmware, const QString &file)
killTimer(m_timerId); killTimer(m_timerId);
m_timerId = -1; m_timerId = -1;
} }
if (!m_requests.empty()) {
m_requests.pop();
}
Task task; Task task;
task.command = "a22devicefirmware_setdata"; task.command = "a22devicefirmware_setdata";
task.task = [this, file, firmware]() { task.task = [this, file, firmware]() {
@ -379,22 +400,42 @@ void DeviceConnection::transferBinContent() {
m_otaProgress < 98 ? "向设备发送升级固件......" m_otaProgress < 98 ? "向设备发送升级固件......"
: "升级固件发送完成,等待设备校验升级固件......"); : "升级固件发送完成,等待设备校验升级固件......");
if (m_sendedSize < m_uploadBuffer.size()) { if ((m_sendedSize < m_uploadBuffer.size()) && isConnected()) {
QTimer::singleShot(0, this, &DeviceConnection::transferBinContent); QTimer::singleShot(0, this, &DeviceConnection::transferBinContent);
} else if (m_sendedSize >= m_uploadBuffer.size()) { } else if (m_sendedSize >= m_uploadBuffer.size()) {
LOG(info) << "transfer ota file finished, wait " << WaitMd5CheckTime LOG(info) << "transfer ota file finished, wait " << WaitMd5CheckTime
<< " ms for send check, total sended size: " << m_sendedSize; << " ms for send check, total sended size: " << m_sendedSize;
QTimer::singleShot(WaitMd5CheckTime, this, [this]() { // QTimer::singleShot(WaitMd5CheckTime, this, [this]() {
boost::json::object request; // boost::json::object request;
request["func"] = "a22devicefirmware_setdata"; // request["func"] = "a22devicefirmware_setdata";
request["deviceid"] = "0"; // request["deviceid"] = "0";
boost::json::object data; // boost::json::object data;
data["target_linux04_firmware"] = "RD_T009_V21R003B001"; // data["target_linux04_firmware"] = "RD_T009_V21R003B001";
request["data"] = std::move(data); // request["data"] = std::move(data);
auto text = boost::json::serialize(request); // auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size()); // m_commandSocket->write(text.data(), text.size());
LOG(info) << "request md5 check result: " << text; // LOG(info) << "request md5 check result: " << text;
}); // });
if (m_otaTimer == nullptr) {
m_otaTimer = new QTimer(this);
m_otaTimer->setSingleShot(true);
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Qt::ConnectionType type = Qt::SingleShotConnection;
#else
Qt::ConnectionType type = Qt::UniqueConnection;
#endif
m_otaTimer->callOnTimeout(
this,
[this]() {
emit otaProgressChanged(false, m_otaProgress, "升级超时,请检查设备并重新尝试...");
m_otaProgress = -1;
m_commandSocket->close();
m_h264Socket->close();
},
type);
m_otaTimer->start(60 * 1000);
} }
} }
@ -515,29 +556,32 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
} else if (value == "2") { } else if (value == "2") {
LOG(info) << "md5 check finished"; LOG(info) << "md5 check finished";
m_otaProgress = 99; m_otaProgress = 99;
if (m_otaTimer != nullptr) {
m_otaTimer->stop();
}
emit otaProgressChanged(true, m_otaProgress, "设备正在升级中,请稍后......"); emit otaProgressChanged(true, m_otaProgress, "设备正在升级中,请稍后......");
QTimer::singleShot(0, this, [this]() { QTimer::singleShot(0, this, [this]() {
m_commandSocket->close(); // 等待设备重新上线后,发起广播。由搜索服务触发重连 m_commandSocket->close(); // 等待设备重新上线后,发起广播。由搜索服务触发重连
m_h264Socket->close(); m_h264Socket->close();
if (m_otaTimer == nullptr) { // if (m_otaTimer == nullptr) {
m_otaTimer = new QTimer(this); // m_otaTimer = new QTimer(this);
m_otaTimer->setSingleShot(true); // m_otaTimer->setSingleShot(true);
} // }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) // #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Qt::ConnectionType type = Qt::SingleShotConnection; // Qt::ConnectionType type = Qt::SingleShotConnection;
#else // #else
Qt::ConnectionType type = Qt::UniqueConnection; // Qt::ConnectionType type = Qt::UniqueConnection;
#endif // #endif
m_otaTimer->callOnTimeout( // m_otaTimer->callOnTimeout(
this, // this,
[this]() { // [this]() {
emit otaProgressChanged(false, m_otaProgress, "升级超时,请检查设备并重新尝试..."); // emit otaProgressChanged(false, m_otaProgress,
m_otaProgress = -1; // "升级超时,请检查设备并重新尝试..."); m_otaProgress = -1;
m_commandSocket->close(); // m_commandSocket->close();
m_h264Socket->close(); // m_h264Socket->close();
}, // },
type); // type);
m_otaTimer->start(60 * 1000); // m_otaTimer->start(60 * 1000);
}); });
} else { } else {
const char *message = nullptr; const char *message = nullptr;

View File

@ -50,7 +50,8 @@ public:
}; };
using H264FrameCallback = std::function<void(const char *data, uint32_t size)>; using H264FrameCallback = std::function<void(const char *data, uint32_t size)>;
explicit DeviceConnection(QObject *parent = nullptr); DeviceConnection(QObject *parent = nullptr);
~DeviceConnection();
Infomation infomation() const; Infomation infomation() const;
bool isConnected() const; bool isConnected() const;
void setH264FrameCallback(H264FrameCallback &&callback); void setH264FrameCallback(H264FrameCallback &&callback);
@ -102,6 +103,7 @@ protected:
std::shared_ptr<QTimer> timeoutTimer = nullptr; std::shared_ptr<QTimer> timeoutTimer = nullptr;
std::shared_ptr<QFutureInterface<bool>> future; std::shared_ptr<QFutureInterface<bool>> future;
}; };
void close();
void onConnected(); void onConnected();
void onDisconnected(); void onDisconnected();
void onH264ReadyRead(); void onH264ReadyRead();

View File

@ -246,8 +246,7 @@ Item {
columns: 2 columns: 2
spacing: 10 spacing: 10
verticalItemAlignment: Qt.AlignVCenter verticalItemAlignment: Qt.AlignVCenter
Text { Label {
text: qsTr("开门区域: ") text: qsTr("开门区域: ")
} }
Row { Row {
@ -276,7 +275,7 @@ Item {
} }
Text {text: qsTr("防夹区域: ")} Label {text: qsTr("防夹区域: ")}
Row { Row {
enabled: root.enabled enabled: root.enabled
RadioButton { RadioButton {
@ -297,7 +296,7 @@ Item {
} }
Text {text: qsTr("屏蔽区域: ")} Label {text: qsTr("屏蔽区域: ")}
Row { Row {
id: shieldedRow id: shieldedRow
RadioButton { RadioButton {

View File

@ -9,7 +9,7 @@ Column {
property bool canEmpty: false property bool canEmpty: false
property var regularExpression : /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/ property var regularExpression : /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/
TextField { TextField {
height: 40 height: 44
width: 350 width: 350
id: input id: input
selectByMouse: true selectByMouse: true

View File

@ -15,6 +15,7 @@ ApplicationWindow {
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent
Button { Button {
Layout.leftMargin: 5
Material.background: Material.Blue Material.background: Material.Blue
text: "搜索设备" text: "搜索设备"
onClicked: { onClicked: {
@ -127,8 +128,8 @@ ApplicationWindow {
footer: RowLayout { footer: RowLayout {
width: parent.width width: parent.width
Item {}
Button { Button {
Layout.leftMargin: 5
text: App.collector.enabled ? "停止采集" : "数据采集" text: App.collector.enabled ? "停止采集" : "数据采集"
onClicked: { onClicked: {
if (App.collector.enabled) { if (App.collector.enabled) {
@ -184,6 +185,31 @@ ApplicationWindow {
} }
} }
function showFileDialog(nameFilters,onSelected){
let dialog = null
if (isQt5) {
dialog = Qt.createQmlObject("import QtQuick.Dialogs 1.3; FileDialog {}", window, "myDynamicSnippet")
} else {
dialog = Qt.createQmlObject("import QtQuick.Dialogs; FileDialog {}", window, "myDynamicSnippet")
}
if (dialog) {
dialog.nameFilters = nameFilters;
dialog.visible = true
dialog.accepted.connect(function () {
let fileUrl = isQt5 ? dialog.fileUrl.toString() : dialog.selectedFile.toString()
let localFilePath = fileUrl.startsWith(
"file:///") ? fileUrl.substring(8) : fileUrl
onSelected(localFilePath)
dialog.destroy()
})
dialog.rejected.connect(function () {
dialog.destroy()
})
} else {
console.error("Failed to create FolderDialog object")
}
}
function showFolderDialog(onSelected) { function showFolderDialog(onSelected) {
let dialog = null let dialog = null
if (isQt5) { if (isQt5) {

View File

@ -9,7 +9,7 @@ Popup {
anchors.centerIn: Overlay.overlay anchors.centerIn: Overlay.overlay
modal: true modal: true
closePolicy: Popup.CloseOnEscap | Popup.NoAutoClose closePolicy: Popup.CloseOnEscap | Popup.NoAutoClose
property int inputHeight: 50 property int inputHeight: 56
background: Rectangle { background: Rectangle {
radius: 8 radius: 8
} }

View File

@ -1,7 +1,6 @@
import QtQuick 2.15 import QtQuick 2.15
import QtQuick.Controls 2.15 import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import QtQuick.Dialogs 1.3
import AntiClipSettings 1.0 import AntiClipSettings 1.0
Popup { Popup {
@ -46,7 +45,9 @@ Popup {
Button { Button {
enabled: otaFinished enabled: otaFinished
text: "选择" text: "选择"
onClicked: fileDialog.open() onClicked: showFileDialog(["OTA文件 (*.bin)"],(path)=>{
otaFile.text = path
})
} }
} }
@ -59,7 +60,7 @@ Popup {
to: 100 to: 100
value: 0.0 value: 0.0
} }
Text { Label {
id: progressText id: progressText
text: "0%" text: "0%"
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
@ -67,7 +68,7 @@ Popup {
} }
RowLayout { RowLayout {
Text { Label {
id: otaMessage id: otaMessage
text: "请选择升级文件,点击开始按钮升级模组" text: "请选择升级文件,点击开始按钮升级模组"
wrapMode: Text.Wrap wrapMode: Text.Wrap
@ -92,24 +93,6 @@ Popup {
onClose() onClose()
} }
FileDialog {
id: fileDialog
nameFilters: ["OTA文件 (*.bin)"]
onAccepted: {
let fileUrl = isQt5 ? fileDialog.fileUrl.toString() : fileDialog.selectedFile.toString()
var localFilePath = fileUrl.startsWith(
"file:///") ? fileUrl.substring(8) : fileUrl
otaFile.text = localFilePath
}
onVisibleChanged: {
if (!isQt5) {
currentFolder = StandardPaths.standardLocations(
StandardPaths.DesktopLocation)[0]
}
}
}
Connections { Connections {
target: App target: App
function onCurrentDeviceOtaProgressChanged(status, progress, message) { function onCurrentDeviceOtaProgressChanged(status, progress, message) {