实现获取版本号显示。

This commit is contained in:
luocai 2024-08-16 11:34:21 +08:00
parent a2a79ac084
commit bdc7711bbb
7 changed files with 56 additions and 5 deletions

View File

@ -125,6 +125,9 @@ bool Application::open(const QString &portName, int baudRate) {
auto status = m_communication->open(portName, baudRate);
emit newStatusTip(status ? Tip : Error, status ? "串口打开成功" : "串口打开失败");
if (status) {
QTimer::singleShot(0, this, [this]() { m_communication->requestVersion(); });
}
return status;
}

View File

@ -171,6 +171,13 @@ void ModuleCommunication::requestUniqueId() {
LOG_CAT(info, GUI) << Separator;
}
void ModuleCommunication::requestVersion() {
auto [frameData, frameSize] = generateFrame(GetVersion);
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
LOG_CAT(info, GUI) << "发送获取版本指令: " << protocolDataFormatString(frameData, frameSize);
LOG_CAT(info, GUI) << Separator;
}
ModuleCommunication::MessageId ModuleCommunication::currentMessageId() const {
return m_currentMessageId;
}
@ -312,6 +319,22 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
LOG_CAT(info, GUI) << Separator;
break;
}
case GetVersion: {
LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size);
auto version = reinterpret_cast<const ModuleVersion *>(data + 7);
int length = std::strlen(version->version);
if (length > sizeof(version->version)) {
length = sizeof(version->version);
}
int ota = ntohl(version->otaVersion);
LOG_CAT(info, GUI) << "模组烧录版本: " << std::string_view(version->version, length)
<< ", OTA版本: " << ntohl(version->otaVersion);
LOG_CAT(info, GUI) << Separator;
m_verison = QString::fromLocal8Bit(version->version, length);
m_otaVerison = ota;
emit verisonChanged();
break;
}
case EnableDebug: {
LOG(info) << "set moudle debug mode: " << (result == Success);
break;

View File

@ -11,8 +11,11 @@ class ModuleCommunication : public QObject {
Q_OBJECT
QML_ELEMENT
static constexpr uint32_t UsernameSize = 32;
static constexpr uint32_t VersionSize = 32;
static constexpr const char *Separator = "----------";
Q_PROPERTY(MessageId currentMessageId READ currentMessageId NOTIFY currentMessageIdChanged)
Q_PROPERTY(QString verison MEMBER m_verison NOTIFY verisonChanged)
Q_PROPERTY(int otaVerison MEMBER m_otaVerison NOTIFY verisonChanged)
public:
constexpr static uint16_t InvalidUserId = std::numeric_limits<uint16_t>::max();
@ -28,6 +31,7 @@ public:
GetImage = 0x1F, // 获取图片数据通过VerifyExtended或EnrollExtended保存的
DeleteUser = 0x20,
DeleteAll = 0x21,
GetVersion = 0x30,
StartOta = 0x40, // 模组进入boot模式进行ota升级
EnableDebug = 0x82,
GetUniqueID = 0xAC,
@ -142,6 +146,11 @@ public:
uint8_t data[0];
};
struct ModuleVersion {
char version[VersionSize];
uint32_t otaVersion;
};
struct ModuleId {
char id[32];
};
@ -158,6 +167,7 @@ public:
Q_INVOKABLE void deleteUser(uint16_t userid);
Q_INVOKABLE void deleteAll();
Q_INVOKABLE void requestUniqueId();
Q_INVOKABLE void requestVersion();
void requestEnrolledImage(uint32_t offset, uint32_t size);
void uploadImageInfo(const UploadImageInformation &info);
@ -184,6 +194,7 @@ signals:
void commandStarted(ModuleCommunication::MessageId messageId);
void commandFinished(MessageId messageId, MessageStatus status);
void currentMessageIdChanged();
void verisonChanged();
protected:
void processPackage(const uint8_t *data, uint16_t size);
@ -195,8 +206,9 @@ protected:
private:
std::shared_ptr<QSerialPort> m_serialPort;
QByteArray m_receivedBuffer;
MessageId m_currentMessageId = ModuleCommunication::Idle;
QString m_verison;
int m_otaVerison;
};
#endif // MODULECOMMUNICATION_H

View File

@ -10,6 +10,16 @@ Item {
ColumnLayout {
anchors.fill: parent
ConnectionItem {}
Column {
Text{
width: 50
text: "烧录版本: "+ (App.module!==null? App.module.verison:"")
}
Text{
width: 50
text: "OTA版本: "+(App.module!==null?App.module.otaVerison:"")
}
}
GroupBox {
id: commandBox

View File

@ -5,7 +5,7 @@ import Analyser
Window {
width: 1120
height: 700
height: 770
visible: true
title: qsTr(Qt.application.name + " " + Qt.application.version)

View File

@ -8,8 +8,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(Projects_ROOT E:/Projects)
set(Libraries_ROOT ${Projects_ROOT}/Libraries)
set(BOOST_ROOT ${Libraries_ROOT}/boost_1_85_0_msvc2022_64bit)
set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include/boost-1_85)
set(BOOST_ROOT ${Libraries_ROOT}/boost_1_86_0_msvc2022_64bit)
set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include/boost-1_86)
option(Boost_USE_STATIC_LIBS OFF)
add_compile_definitions(
BOOST_USE_WINAPI_VERSION=BOOST_WINAPI_VERSION_WIN10

View File

@ -58,7 +58,10 @@ HOST_TOOLS := /opt/Xuantie-900-gcc-elf-newlib-x86_64-V2.6.1/bin
```shell
./boot-rebuild.sh # 编译boot
./rebuild-app.sh y L015 V200 R002 # 编译烧录固件
./rebuild-app-ota.sh y L015 V200 R002 14 # 编译OTA固件11为OTA版本号
# 编译OTA固件11为OTA版本号,这个版本号只做固件文件名显示。
# 实际的版本设置在 cv181x_alios/solutions/smart_doorbell/package.yaml.L015_V200R002
./rebuild-app-ota.sh y L015 V200 R002 01
600X800
```