optimize communicate stop.
This commit is contained in:
parent
9c8194dec2
commit
2661f0729a
@ -6,6 +6,7 @@
|
|||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
#include "DateTime.h"
|
#include "DateTime.h"
|
||||||
|
#include "DeviceDiscovery.h"
|
||||||
#include "ImageDecoder.h"
|
#include "ImageDecoder.h"
|
||||||
#include "StringUtility.h"
|
#include "StringUtility.h"
|
||||||
#include "VideoFrameProvider.h"
|
#include "VideoFrameProvider.h"
|
||||||
@ -20,7 +21,6 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <mbedtls/md5.h>
|
#include <mbedtls/md5.h>
|
||||||
#include "DeviceDiscovery.h"
|
|
||||||
|
|
||||||
constexpr uint32_t ImageSliceSize = (4000 - 32);
|
constexpr uint32_t ImageSliceSize = (4000 - 32);
|
||||||
|
|
||||||
@ -145,6 +145,7 @@ bool Application::open(const QString &portName, int baudRate) {
|
|||||||
emit newStatusTip(status ? Tip : Error, status ? "串口打开成功" : "串口打开失败");
|
emit newStatusTip(status ? Tip : Error, status ? "串口打开成功" : "串口打开失败");
|
||||||
if (status) {
|
if (status) {
|
||||||
QTimer::singleShot(0, this, [this]() { m_communication->requestVersion(); });
|
QTimer::singleShot(0, this, [this]() { m_communication->requestVersion(); });
|
||||||
|
QTimer::singleShot(0, this, [this]() { m_communication->requestDebugSettings(); });
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -175,13 +176,22 @@ bool Application::openUVC(const QString &deviceName) {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::resetModule() {
|
||||||
|
if (connected()) {
|
||||||
|
m_communication->reset();
|
||||||
|
}
|
||||||
|
m_imageUploadling = false;
|
||||||
|
m_persistenceModeStarted = false;
|
||||||
|
if (m_verifyTimer->isActive()) {
|
||||||
|
m_verifyTimer->stop();
|
||||||
|
}
|
||||||
|
emit currentMessageIdChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void Application::close() {
|
void Application::close() {
|
||||||
|
resetModule();
|
||||||
m_communication.reset();
|
m_communication.reset();
|
||||||
emit connectedChanged();
|
emit connectedChanged();
|
||||||
|
|
||||||
m_persistenceModeStarted = false;
|
|
||||||
m_verifyTimer->stop();
|
|
||||||
emit isVerifyingChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::closeUVC() {
|
void Application::closeUVC() {
|
||||||
@ -294,26 +304,29 @@ bool Application::uvcOpened() const {
|
|||||||
return static_cast<bool>(m_videoPlayer);
|
return static_cast<bool>(m_videoPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::persistenceMode() const {
|
ModuleCommunication::MessageId Application::persistenceCommand() const {
|
||||||
return m_persistenceMode;
|
return m_persistenceCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setPersistenceMode(bool enabled) {
|
void Application::setPersistenceCommand(ModuleCommunication::MessageId command) {
|
||||||
if (m_persistenceMode != enabled) {
|
if (m_persistenceCommand != command) {
|
||||||
m_persistenceMode = enabled;
|
m_persistenceCommand = command;
|
||||||
emit persistenceModeChanged();
|
emit persistenceCommandChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::imageUploadPersistenceMode() const {
|
ModuleCommunication::MessageId Application::currentMessageId() const {
|
||||||
return m_imageUploadPersistenceMode;
|
ModuleCommunication::MessageId ret = ModuleCommunication::Idle;
|
||||||
}
|
if (connected()) {
|
||||||
|
if (m_persistenceModeStarted) {
|
||||||
void Application::setImageUploadPersistenceMode(bool enabled) {
|
ret = m_persistenceCommand;
|
||||||
if (m_imageUploadPersistenceMode != enabled) {
|
} else {
|
||||||
m_imageUploadPersistenceMode = enabled;
|
ret = m_communication->currentMessageId();
|
||||||
emit imageUploadPersistenceModeChanged();
|
}
|
||||||
}
|
}
|
||||||
|
// LOG(info) << "current message id: " << static_cast<int>(ret)
|
||||||
|
// << ", persistence mode started: " << m_persistenceModeStarted;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::persistenceVerifyInterval() const {
|
int Application::persistenceVerifyInterval() const {
|
||||||
@ -327,15 +340,6 @@ void Application::setPersistenceVerifyInterval(int interval) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::isVerifying() const {
|
|
||||||
if (!m_communication) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (m_persistenceMode && m_persistenceModeStarted) ||
|
|
||||||
(m_communication->currentMessageId() == ModuleCommunication::Verify) ||
|
|
||||||
(m_communication->currentMessageId() == ModuleCommunication::VerifyExtended);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::onNewPalmFeature(const PalmFeature &feature) {
|
void Application::onNewPalmFeature(const PalmFeature &feature) {
|
||||||
auto palms = m_database->palmFeatures();
|
auto palms = m_database->palmFeatures();
|
||||||
if (std::find(palms.cbegin(), palms.cend(), feature) != palms.cend()) {
|
if (std::find(palms.cbegin(), palms.cend(), feature) != palms.cend()) {
|
||||||
@ -404,7 +408,7 @@ void Application::onNewImageSliceData(const std::vector<uint8_t> &data) {
|
|||||||
|
|
||||||
void Application::onCommandStarted(ModuleCommunication::MessageId messageId) {
|
void Application::onCommandStarted(ModuleCommunication::MessageId messageId) {
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
emit isVerifyingChanged();
|
emit currentMessageIdChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::onCommandFinished(ModuleCommunication::MessageId messageId,
|
void Application::onCommandFinished(ModuleCommunication::MessageId messageId,
|
||||||
@ -416,40 +420,44 @@ void Application::onCommandFinished(ModuleCommunication::MessageId messageId,
|
|||||||
ImageSliceSize);
|
ImageSliceSize);
|
||||||
} else if (messageId == ModuleCommunication::UploadImageData) {
|
} else if (messageId == ModuleCommunication::UploadImageData) {
|
||||||
m_uploadImageSendedSize += ImageSliceSize;
|
m_uploadImageSendedSize += ImageSliceSize;
|
||||||
if (m_uploadImageSendedSize < m_uploadBuffer.size()) {
|
if (m_imageUploadling && (m_uploadImageSendedSize < m_uploadBuffer.size())) {
|
||||||
auto remainSize = m_uploadBuffer.size() - m_uploadImageSendedSize;
|
auto remainSize = m_uploadBuffer.size() - m_uploadImageSendedSize;
|
||||||
m_communication->uploadImageData(m_uploadImageSendedSize,
|
m_communication->uploadImageData(m_uploadImageSendedSize,
|
||||||
(const uint8_t *)m_uploadBuffer.data() + m_uploadImageSendedSize,
|
(const uint8_t *)m_uploadBuffer.data() + m_uploadImageSendedSize,
|
||||||
remainSize < ImageSliceSize ? remainSize : ImageSliceSize);
|
remainSize < ImageSliceSize ? remainSize : ImageSliceSize);
|
||||||
m_imageUploadling = true;
|
|
||||||
}
|
}
|
||||||
if (status != ModuleCommunication::Needmore) {
|
if (status != ModuleCommunication::Needmore) {
|
||||||
LOG(info) << "upload image finished, status: " << static_cast<int>(status)
|
LOG(info) << "upload image finished, status: " << static_cast<int>(status)
|
||||||
<< ", elapsed: " << duration_cast<milliseconds>(system_clock::now() - m_startUploadTime);
|
<< ", elapsed: " << duration_cast<milliseconds>(system_clock::now() - m_startUploadTime);
|
||||||
m_imageUploadling = false;
|
if (m_imageUploadling && (m_persistenceCommand == ModuleCommunication::UploadImageInfo)) {
|
||||||
if (m_imageUploadPersistenceMode) {
|
QTimer::singleShot(0, this,
|
||||||
QTimer::singleShot(1, this,
|
|
||||||
[this]() { uploadImage(m_uploadPath, m_uploadUsername, m_currentUploadOperation); });
|
[this]() { uploadImage(m_uploadPath, m_uploadUsername, m_currentUploadOperation); });
|
||||||
}
|
}
|
||||||
|
m_imageUploadling = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((messageId == ModuleCommunication::Verify) || (messageId == ModuleCommunication::VerifyExtended)) &&
|
// LOG(info) << "messageId: " << (int)messageId << ", m_persistenceCommand: " << (int)m_persistenceCommand;
|
||||||
m_persistenceMode) { // 持续识别逻辑
|
if (messageId == m_persistenceCommand) {
|
||||||
m_persistenceModeStarted = true;
|
m_persistenceModeStarted = true;
|
||||||
} else if (messageId == ModuleCommunication::Reset) {
|
}
|
||||||
|
if (messageId == ModuleCommunication::Reset) {
|
||||||
m_persistenceModeStarted = false;
|
m_persistenceModeStarted = false;
|
||||||
m_verifyTimer->stop();
|
if (m_verifyTimer->isActive()) {
|
||||||
|
m_verifyTimer->stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_persistenceMode && m_persistenceModeStarted &&
|
if (((m_persistenceCommand == ModuleCommunication::Verify) ||
|
||||||
|
(m_persistenceCommand == ModuleCommunication::VerifyExtended)) &&
|
||||||
|
m_persistenceModeStarted &&
|
||||||
((messageId == ModuleCommunication::Verify) || (messageId == ModuleCommunication::VerifyExtended)) &&
|
((messageId == ModuleCommunication::Verify) || (messageId == ModuleCommunication::VerifyExtended)) &&
|
||||||
((status == ModuleCommunication::Success) || (status == ModuleCommunication::Failed4UnknownUser) ||
|
((status == ModuleCommunication::Success) || (status == ModuleCommunication::Failed4UnknownUser) ||
|
||||||
(status == ModuleCommunication::Failed4Timeout) || (status == ModuleCommunication::Failed4UnknownReason) ||
|
(status == ModuleCommunication::Failed4Timeout) || (status == ModuleCommunication::Failed4UnknownReason) ||
|
||||||
(status == ModuleCommunication::Failed4LivenessCheck))) {
|
(status == ModuleCommunication::Failed4LivenessCheck))) {
|
||||||
m_verifyTimer->start(m_persistenceVerifyInterval * 1000);
|
m_verifyTimer->start(m_persistenceVerifyInterval * 1000);
|
||||||
}
|
}
|
||||||
emit isVerifyingChanged();
|
emit currentMessageIdChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::onVerifyTimeout() {
|
void Application::onVerifyTimeout() {
|
||||||
|
@ -22,12 +22,10 @@ class Application : public QObject {
|
|||||||
Q_PROPERTY(ModuleCommunication *module READ module NOTIFY connectedChanged)
|
Q_PROPERTY(ModuleCommunication *module READ module NOTIFY connectedChanged)
|
||||||
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
|
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
|
||||||
Q_PROPERTY(bool uvcOpened READ uvcOpened NOTIFY uvcOpenedChanged)
|
Q_PROPERTY(bool uvcOpened READ uvcOpened NOTIFY uvcOpenedChanged)
|
||||||
Q_PROPERTY(bool persistenceMode READ persistenceMode WRITE setPersistenceMode NOTIFY persistenceModeChanged)
|
Q_PROPERTY(ModuleCommunication::MessageId persistenceCommand READ persistenceCommand WRITE setPersistenceCommand NOTIFY persistenceCommandChanged)
|
||||||
Q_PROPERTY(bool imageUploadPersistenceMode READ imageUploadPersistenceMode WRITE setImageUploadPersistenceMode
|
|
||||||
NOTIFY imageUploadPersistenceModeChanged)
|
|
||||||
Q_PROPERTY(int persistenceVerifyInterval READ persistenceVerifyInterval WRITE setPersistenceVerifyInterval NOTIFY
|
Q_PROPERTY(int persistenceVerifyInterval READ persistenceVerifyInterval WRITE setPersistenceVerifyInterval NOTIFY
|
||||||
persistenceVerifyIntervalChanged)
|
persistenceVerifyIntervalChanged)
|
||||||
Q_PROPERTY(bool isVerifying READ isVerifying NOTIFY isVerifyingChanged)
|
Q_PROPERTY(ModuleCommunication::MessageId currentMessageId READ currentMessageId NOTIFY currentMessageIdChanged)
|
||||||
friend class Amass::Singleton<Application>;
|
friend class Amass::Singleton<Application>;
|
||||||
static constexpr auto JpgPath = "jpg";
|
static constexpr auto JpgPath = "jpg";
|
||||||
static constexpr auto YuvPath = "yuv";
|
static constexpr auto YuvPath = "yuv";
|
||||||
@ -60,23 +58,21 @@ public:
|
|||||||
Q_INVOKABLE void deleteAll();
|
Q_INVOKABLE void deleteAll();
|
||||||
Q_INVOKABLE void uploadImage(const QString &path, const QString &username, int operation);
|
Q_INVOKABLE void uploadImage(const QString &path, const QString &username, int operation);
|
||||||
ModuleCommunication *module() const;
|
ModuleCommunication *module() const;
|
||||||
|
Q_INVOKABLE void resetModule();
|
||||||
bool connected() const;
|
bool connected() const;
|
||||||
bool uvcOpened() const;
|
bool uvcOpened() const;
|
||||||
bool persistenceMode() const;
|
ModuleCommunication::MessageId persistenceCommand() const;
|
||||||
void setPersistenceMode(bool enabled);
|
void setPersistenceCommand(ModuleCommunication::MessageId command);
|
||||||
bool imageUploadPersistenceMode() const;
|
ModuleCommunication::MessageId currentMessageId() const;
|
||||||
void setImageUploadPersistenceMode(bool enabled);
|
|
||||||
|
|
||||||
int persistenceVerifyInterval() const;
|
int persistenceVerifyInterval() const;
|
||||||
void setPersistenceVerifyInterval(int interval);
|
void setPersistenceVerifyInterval(int interval);
|
||||||
bool isVerifying() const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectedChanged();
|
void connectedChanged();
|
||||||
void persistenceModeChanged();
|
void persistenceCommandChanged();
|
||||||
void persistenceVerifyIntervalChanged();
|
void persistenceVerifyIntervalChanged();
|
||||||
void imageUploadPersistenceModeChanged();
|
void currentMessageIdChanged();
|
||||||
void isVerifyingChanged();
|
|
||||||
void uvcOpenedChanged();
|
void uvcOpenedChanged();
|
||||||
void newVideoFrame();
|
void newVideoFrame();
|
||||||
void newLog(const QString &log);
|
void newLog(const QString &log);
|
||||||
@ -105,7 +101,7 @@ private:
|
|||||||
std::shared_ptr<CdcUpdater> m_updater;
|
std::shared_ptr<CdcUpdater> m_updater;
|
||||||
std::shared_ptr<Database> m_database;
|
std::shared_ptr<Database> m_database;
|
||||||
|
|
||||||
bool m_persistenceMode = true; // 模组持续识别
|
ModuleCommunication::MessageId m_persistenceCommand = ModuleCommunication::Idle; // 模组持续识别
|
||||||
bool m_verifyExtendedMode = false;
|
bool m_verifyExtendedMode = false;
|
||||||
bool m_persistenceModeStarted = false;
|
bool m_persistenceModeStarted = false;
|
||||||
int m_persistenceVerifyInterval = 1;
|
int m_persistenceVerifyInterval = 1;
|
||||||
@ -124,7 +120,6 @@ private:
|
|||||||
QString m_uploadPath;
|
QString m_uploadPath;
|
||||||
QString m_uploadUsername;
|
QString m_uploadUsername;
|
||||||
bool m_imageUploadling = false;
|
bool m_imageUploadling = false;
|
||||||
bool m_imageUploadPersistenceMode = false;
|
|
||||||
|
|
||||||
std::shared_ptr<VideoPlayer> m_videoPlayer;
|
std::shared_ptr<VideoPlayer> m_videoPlayer;
|
||||||
VideoFrameProvider *m_videoFrameProvider;
|
VideoFrameProvider *m_videoFrameProvider;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
project(Analyser VERSION 0.3 LANGUAGES C CXX)
|
project(Analyser VERSION 0.3 LANGUAGES C CXX)
|
||||||
set(APPLICATION_NAME "掌静脉测试工具")
|
set(APPLICATION_NAME "掌静脉测试工具")
|
||||||
|
|
||||||
|
find_package(Boost REQUIRED COMPONENTS json)
|
||||||
|
|
||||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Quick QuickTemplates2 SerialPort JpegPrivate BundledLibjpeg)
|
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Quick QuickTemplates2 SerialPort JpegPrivate BundledLibjpeg)
|
||||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Quick QuickTemplates2 SerialPort JpegPrivate BundledLibjpeg)
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Quick QuickTemplates2 SerialPort JpegPrivate BundledLibjpeg)
|
||||||
|
|
||||||
@ -74,6 +76,7 @@ target_link_libraries(Analyser
|
|||||||
PRIVATE avdevice
|
PRIVATE avdevice
|
||||||
PRIVATE avformat
|
PRIVATE avformat
|
||||||
$<$<PLATFORM_ID:Windows>:Ws2_32>
|
$<$<PLATFORM_ID:Windows>:Ws2_32>
|
||||||
|
PRIVATE Boost::json
|
||||||
PRIVATE Qt${QT_VERSION_MAJOR}::Quick
|
PRIVATE Qt${QT_VERSION_MAJOR}::Quick
|
||||||
PRIVATE Qt${QT_VERSION_MAJOR}::QuickTemplates2
|
PRIVATE Qt${QT_VERSION_MAJOR}::QuickTemplates2
|
||||||
PRIVATE Qt${QT_VERSION_MAJOR}::SerialPort
|
PRIVATE Qt${QT_VERSION_MAJOR}::SerialPort
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
#include "BoostLog.h"
|
#include "BoostLog.h"
|
||||||
#include "StringUtility.h"
|
#include "StringUtility.h"
|
||||||
#include <boost/describe.hpp>
|
#include <boost/describe.hpp>
|
||||||
|
#include <boost/json/object.hpp>
|
||||||
|
#include <boost/json/parse.hpp>
|
||||||
|
#include <boost/json/serialize.hpp>
|
||||||
#include <boost/mp11.hpp>
|
#include <boost/mp11.hpp>
|
||||||
#include <mbedtls/md5.h>
|
#include <mbedtls/md5.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -167,8 +170,29 @@ void ModuleCommunication::requestCurrentStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ModuleCommunication::setDebugEnabled(bool enabled) {
|
void ModuleCommunication::setDebugEnabled(bool enabled) {
|
||||||
uint8_t data = enabled ? 0x01 : 0x00;
|
DebugRequest request;
|
||||||
auto [frameData, frameSize] = generateFrame(EnableDebug, &data, sizeof(data));
|
boost::json::object object;
|
||||||
|
object["command"] = "set_configurations";
|
||||||
|
object["cdc_log_enabled"] = enabled;
|
||||||
|
auto text = boost::json::serialize(object);
|
||||||
|
std::strncpy(request.message, text.c_str(), sizeof(request.message));
|
||||||
|
request.length = htons(text.size());
|
||||||
|
|
||||||
|
auto [frameData, frameSize] =
|
||||||
|
generateFrame(EnableDebug, reinterpret_cast<const uint8_t *>(&request), sizeof(request));
|
||||||
|
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModuleCommunication::requestDebugSettings() {
|
||||||
|
DebugRequest request;
|
||||||
|
boost::json::object object;
|
||||||
|
object["command"] = "get_configurations";
|
||||||
|
auto text = boost::json::serialize(object);
|
||||||
|
std::strncpy(request.message, text.c_str(), sizeof(request.message));
|
||||||
|
request.length = htons(text.size());
|
||||||
|
|
||||||
|
auto [frameData, frameSize] =
|
||||||
|
generateFrame(EnableDebug, reinterpret_cast<const uint8_t *>(&request), sizeof(request));
|
||||||
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
|
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +352,9 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
|
|||||||
auto info = reinterpret_cast<const UploadImageReply *>(data + 7);
|
auto info = reinterpret_cast<const UploadImageReply *>(data + 7);
|
||||||
if (result == Success) {
|
if (result == Success) {
|
||||||
if (info->operation == 0) {
|
if (info->operation == 0) {
|
||||||
LOG_CAT(info, GUI) << "图片下发注册成功,用户ID: " << ntohs(info->userid);
|
uint16_t userid = ntohs(info->userid);
|
||||||
|
LOG_CAT(info, GUI) << "图片下发注册成功,用户ID: " << userid;
|
||||||
|
emit newEnrollResult(userid);
|
||||||
} else if (info->operation == 1) {
|
} else if (info->operation == 1) {
|
||||||
auto result = reinterpret_cast<const UploadImageVerifyReply *>(info);
|
auto result = reinterpret_cast<const UploadImageVerifyReply *>(info);
|
||||||
LOG_CAT(info, GUI) << "图片下发识别成功,用户ID: " << ntohs(result->userid) << ", 用户名: "
|
LOG_CAT(info, GUI) << "图片下发识别成功,用户ID: " << ntohs(result->userid) << ", 用户名: "
|
||||||
@ -390,7 +416,27 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EnableDebug: {
|
case EnableDebug: {
|
||||||
LOG(info) << "set moudle debug mode: " << (result == Success);
|
auto replyData = reinterpret_cast<const DebugReply *>(data + 7);
|
||||||
|
LOG(info) << "module debug: " << replyData->message;
|
||||||
|
std::error_code error;
|
||||||
|
auto replyValue = boost::json::parse(replyData->message, error);
|
||||||
|
if (error) {
|
||||||
|
LOG(error) << error.message();
|
||||||
|
} else {
|
||||||
|
auto &reply = replyValue.as_object();
|
||||||
|
if (reply.contains("command")) {
|
||||||
|
auto &command = reply.at("command");
|
||||||
|
if ((command == "get_configurations") || (command == "set_configurations")) {
|
||||||
|
if (reply.contains("cdc_log_enabled")) {
|
||||||
|
auto &cdcEnabled = reply.at("cdc_log_enabled").as_bool();
|
||||||
|
if (m_cdcDebugEnabled != cdcEnabled) {
|
||||||
|
m_cdcDebugEnabled = cdcEnabled;
|
||||||
|
emit cdcDebugEnabledChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -14,9 +14,9 @@ class ModuleCommunication : public QObject {
|
|||||||
static constexpr uint32_t UsernameSize = 32;
|
static constexpr uint32_t UsernameSize = 32;
|
||||||
static constexpr uint32_t VersionSize = 32;
|
static constexpr uint32_t VersionSize = 32;
|
||||||
static constexpr const char *Separator = "----------";
|
static constexpr const char *Separator = "----------";
|
||||||
Q_PROPERTY(MessageId currentMessageId READ currentMessageId NOTIFY currentMessageIdChanged)
|
|
||||||
Q_PROPERTY(QString verison MEMBER m_verison NOTIFY verisonChanged)
|
Q_PROPERTY(QString verison MEMBER m_verison NOTIFY verisonChanged)
|
||||||
Q_PROPERTY(int otaVerison MEMBER m_otaVerison NOTIFY verisonChanged)
|
Q_PROPERTY(int otaVerison MEMBER m_otaVerison NOTIFY verisonChanged)
|
||||||
|
Q_PROPERTY(bool cdcDebugEnabled MEMBER m_cdcDebugEnabled NOTIFY cdcDebugEnabledChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr static uint16_t VendorIdentifier = 0x3346;
|
constexpr static uint16_t VendorIdentifier = 0x3346;
|
||||||
@ -191,12 +191,18 @@ public:
|
|||||||
uint8_t userids[512]; // bit位
|
uint8_t userids[512]; // bit位
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DebugRequest {
|
||||||
|
uint16_t length;
|
||||||
|
char message[2000];
|
||||||
|
};
|
||||||
|
using DebugReply = DebugRequest;
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
explicit ModuleCommunication(QObject *parent = nullptr);
|
explicit ModuleCommunication(QObject *parent = nullptr);
|
||||||
bool open(const QString &portName, int baudRate);
|
bool open(const QString &portName, int baudRate);
|
||||||
void verify(uint8_t timeout);
|
void verify(uint8_t timeout);
|
||||||
void verifyExtended(bool captureImage, uint8_t timeout);
|
void verifyExtended(bool captureImage, uint8_t timeout);
|
||||||
Q_INVOKABLE void reset();
|
void reset();
|
||||||
|
|
||||||
void enroll(const std::string &username, bool strictMode, uint8_t excludeMode, bool persistence, uint8_t timeout);
|
void enroll(const std::string &username, bool strictMode, uint8_t excludeMode, bool persistence, uint8_t timeout);
|
||||||
void enrollExtended(const std::string &username, bool strictMode, uint8_t excludeMode, bool persistence,
|
void enrollExtended(const std::string &username, bool strictMode, uint8_t excludeMode, bool persistence,
|
||||||
@ -211,6 +217,7 @@ public:
|
|||||||
void uploadImageData(uint32_t offset, const uint8_t *data, uint32_t size);
|
void uploadImageData(uint32_t offset, const uint8_t *data, uint32_t size);
|
||||||
Q_INVOKABLE void requestCurrentStatus();
|
Q_INVOKABLE void requestCurrentStatus();
|
||||||
Q_INVOKABLE void setDebugEnabled(bool enabled);
|
Q_INVOKABLE void setDebugEnabled(bool enabled);
|
||||||
|
void requestDebugSettings();
|
||||||
void startOta();
|
void startOta();
|
||||||
|
|
||||||
MessageId currentMessageId() const;
|
MessageId currentMessageId() const;
|
||||||
@ -232,6 +239,7 @@ signals:
|
|||||||
void commandFinished(MessageId messageId, MessageStatus status);
|
void commandFinished(MessageId messageId, MessageStatus status);
|
||||||
void currentMessageIdChanged();
|
void currentMessageIdChanged();
|
||||||
void verisonChanged();
|
void verisonChanged();
|
||||||
|
void cdcDebugEnabledChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void processPackage(const uint8_t *data, uint16_t size);
|
void processPackage(const uint8_t *data, uint16_t size);
|
||||||
@ -246,6 +254,7 @@ private:
|
|||||||
MessageId m_currentMessageId = ModuleCommunication::Idle;
|
MessageId m_currentMessageId = ModuleCommunication::Idle;
|
||||||
QString m_verison;
|
QString m_verison;
|
||||||
int m_otaVerison;
|
int m_otaVerison;
|
||||||
|
bool m_cdcDebugEnabled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
@ -78,7 +78,9 @@ RowLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GroupBox {
|
GroupBox {
|
||||||
|
id: verifyBox
|
||||||
title: "识别用户"
|
title: "识别用户"
|
||||||
|
property bool verifying: (App.currentMessageId == ModuleCommunication.Verify) || (App.currentMessageId == ModuleCommunication.VerifyExtended)
|
||||||
GridLayout {
|
GridLayout {
|
||||||
columns: 2
|
columns: 2
|
||||||
Label {
|
Label {
|
||||||
@ -93,8 +95,14 @@ RowLayout {
|
|||||||
text: qsTr("持续识别")
|
text: qsTr("持续识别")
|
||||||
}
|
}
|
||||||
Switch {
|
Switch {
|
||||||
checked: App.persistenceMode
|
checked: (App.persistenceCommand == ModuleCommunication.Verify) || (App.persistenceCommand == ModuleCommunication.VerifyExtended)
|
||||||
onToggled: App.persistenceMode = !App.persistenceMode
|
onToggled: {
|
||||||
|
if (checked) {
|
||||||
|
App.persistenceCommand = extendedVerifyMode.checked ? ModuleCommunication.VerifyExtended : ModuleCommunication.Verify
|
||||||
|
} else {
|
||||||
|
App.persistenceCommand = ModuleCommunication.Idle
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: qsTr("保存图片")
|
text: qsTr("保存图片")
|
||||||
@ -112,10 +120,10 @@ RowLayout {
|
|||||||
}
|
}
|
||||||
Item {}
|
Item {}
|
||||||
Button {
|
Button {
|
||||||
text: App.isVerifying ? "停止" : "识别"
|
text: verifyBox.verifying ? "停止" : "识别"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (App.isVerifying) {
|
if (verifyBox.verifying) {
|
||||||
App.module.reset()
|
App.resetModule()
|
||||||
} else {
|
} else {
|
||||||
App.persistenceVerifyInterval = parseInt(verifyIntetval.text)
|
App.persistenceVerifyInterval = parseInt(verifyIntetval.text)
|
||||||
App.verify(extendedVerifyMode.checked, parseInt(verifyTimeout.text))
|
App.verify(extendedVerifyMode.checked, parseInt(verifyTimeout.text))
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import QtCore
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Dialogs
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Analyser
|
import Analyser
|
||||||
|
|
||||||
@ -58,6 +60,7 @@ Item {
|
|||||||
}
|
}
|
||||||
Switch {
|
Switch {
|
||||||
id: debugMode
|
id: debugMode
|
||||||
|
checked: App.module ? App.module.cdcDebugEnabled : false
|
||||||
onToggled: App.module.setDebugEnabled(debugMode.checked)
|
onToggled: App.module.setDebugEnabled(debugMode.checked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,8 +69,10 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GroupBox {
|
GroupBox {
|
||||||
|
id: imageBox
|
||||||
title: "图片注册"
|
title: "图片注册"
|
||||||
visible: true
|
visible: true
|
||||||
|
property bool imaging: (App.currentMessageId == ModuleCommunication.UploadImageInfo) || (App.currentMessageId == ModuleCommunication.UploadImageData)
|
||||||
GridLayout {
|
GridLayout {
|
||||||
columns: 2
|
columns: 2
|
||||||
TextField {
|
TextField {
|
||||||
@ -87,27 +92,46 @@ Item {
|
|||||||
implicitWidth: 100
|
implicitWidth: 100
|
||||||
text: "测试下发"
|
text: "测试下发"
|
||||||
}
|
}
|
||||||
|
Label {
|
||||||
|
text: qsTr("操作")
|
||||||
|
}
|
||||||
|
ComboBox {
|
||||||
|
id: imageMode
|
||||||
|
implicitWidth: 100
|
||||||
|
model: ["注册", "识别"]
|
||||||
|
}
|
||||||
Label {
|
Label {
|
||||||
text: qsTr("循环")
|
text: qsTr("循环")
|
||||||
}
|
}
|
||||||
Switch {
|
Switch {
|
||||||
checked: App.imageUploadPersistenceMode
|
checked: App.persistenceCommand == ModuleCommunication.UploadImageInfo
|
||||||
onToggled: {
|
onToggled: App.persistenceCommand = checked ? ModuleCommunication.UploadImageInfo : ModuleCommunication.Idle
|
||||||
App.imageUploadPersistenceMode = checked
|
}
|
||||||
|
Button {
|
||||||
|
text: imageBox.imaging ? "取消" : "执行"
|
||||||
|
onClicked: {
|
||||||
|
if (imageBox.imaging) {
|
||||||
|
App.resetModule()
|
||||||
|
} else {
|
||||||
|
App.uploadImage(imagePath.text, imageEnrollName.text, imageMode.currentIndex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Button {
|
|
||||||
text: "注册"
|
|
||||||
onClicked: App.uploadImage(imagePath.text, imageEnrollName.text, 0)
|
|
||||||
}
|
|
||||||
Button {
|
|
||||||
text: "识别"
|
|
||||||
onClicked: App.uploadImage(imagePath.text, imageEnrollName.text, 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileDialog {
|
||||||
|
id: fileDialog
|
||||||
|
nameFilters: ["图片 (*.jpg *.yuv)"]
|
||||||
|
currentFolder: StandardPaths.standardLocations(StandardPaths.DesktopLocation)[0]
|
||||||
|
onAccepted: {
|
||||||
|
var fileUrl = fileDialog.selectedFile.toString()
|
||||||
|
var localFilePath = fileUrl.startsWith("file:///") ? fileUrl.substring(8) : fileUrl
|
||||||
|
imagePath.text = localFilePath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: otaMouseArea
|
id: otaMouseArea
|
||||||
width: otaButton.width
|
width: otaButton.width
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import QtCore
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Dialogs
|
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Analyser
|
import Analyser
|
||||||
|
|
||||||
@ -40,18 +38,6 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
FileDialog {
|
|
||||||
id: fileDialog
|
|
||||||
nameFilters: ["图片 (*.jpg *.yuv)"]
|
|
||||||
currentFolder: StandardPaths.standardLocations(
|
|
||||||
StandardPaths.DesktopLocation)[0]
|
|
||||||
onAccepted: {
|
|
||||||
var fileUrl = fileDialog.selectedFile.toString()
|
|
||||||
var localFilePath = fileUrl.startsWith(
|
|
||||||
"file:///") ? fileUrl.substring(8) : fileUrl
|
|
||||||
imagePath.text = localFilePath
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
id: loader
|
id: loader
|
||||||
|
@ -11,7 +11,7 @@ int main(int argc, char *argv[]) {
|
|||||||
font.setPointSize(16);
|
font.setPointSize(16);
|
||||||
a.setFont(font);
|
a.setFont(font);
|
||||||
Widget w;
|
Widget w;
|
||||||
w.setWindowTitle("L015模组升级工具");
|
w.setWindowTitle("掌静脉模组升级工具");
|
||||||
w.setMinimumWidth(520);
|
w.setMinimumWidth(520);
|
||||||
w.setMinimumHeight(100);
|
w.setMinimumHeight(100);
|
||||||
w.show();
|
w.show();
|
||||||
|
@ -26,6 +26,10 @@ frame_sync_task() // L015 V200 __DUAL_SNS_FAKE__ 双sensor活体
|
|||||||
|
|
||||||
## 门锁开发环境搭建
|
## 门锁开发环境搭建
|
||||||
|
|
||||||
|
smart_doorbell 文件夹、cv181xc_qfn。
|
||||||
|
CONSOLE_UART_IDX
|
||||||
|
业务串口:2
|
||||||
|
|
||||||
安装如下 python 环境:
|
安装如下 python 环境:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
@ -61,7 +65,6 @@ HOST_TOOLS := /opt/Xuantie-900-gcc-elf-newlib-x86_64-V2.6.1/bin
|
|||||||
|
|
||||||
# 编译OTA固件,11为OTA版本号,这个版本号只做固件文件名显示。
|
# 编译OTA固件,11为OTA版本号,这个版本号只做固件文件名显示。
|
||||||
# 实际的版本设置在 cv181x_alios/solutions/smart_doorbell/package.yaml.L015_V200R002
|
# 实际的版本设置在 cv181x_alios/solutions/smart_doorbell/package.yaml.L015_V200R002
|
||||||
./rebuild-app-ota.sh y L015 V200 R002 05
|
|
||||||
600X800
|
600X800
|
||||||
|
|
||||||
docker run -it --rm --user 1000:1000 -v /opt:/opt -v $(pwd)/..:$(pwd)/.. -w $(pwd) registry.cn-shenzhen.aliyuncs.com/amass_toolset/yoctools:22.04 ./rebuild-app.sh y L015 V200 R002
|
docker run -it --rm --user 1000:1000 -v /opt:/opt -v $(pwd)/..:$(pwd)/.. -w $(pwd) registry.cn-shenzhen.aliyuncs.com/amass_toolset/yoctools:22.04 ./rebuild-app.sh y L015 V200 R002
|
||||||
|
398
resources/L015掌静脉识别模组串口通信协议V0.1 - 简化版.md
Normal file
398
resources/L015掌静脉识别模组串口通信协议V0.1 - 简化版.md
Normal file
@ -0,0 +1,398 @@
|
|||||||
|
## 1 串口配置
|
||||||
|
|
||||||
|
目前模组支持两种通信接口:UART,USB(CDC)。其中
|
||||||
|
|
||||||
|
UART:
|
||||||
|
|
||||||
|
- 波特率:115200
|
||||||
|
- 数据位:8
|
||||||
|
- 停止位:1
|
||||||
|
- 奇偶检验:无
|
||||||
|
- 流控制:无
|
||||||
|
|
||||||
|
USB(CDC):
|
||||||
|
|
||||||
|
- 波特率:2000000
|
||||||
|
- 数据位:8
|
||||||
|
- 停止位:1
|
||||||
|
- 奇偶检验:无
|
||||||
|
- 流控制:无
|
||||||
|
|
||||||
|
## 2 消息格式
|
||||||
|
|
||||||
|
主控和模块通讯的基本格式如下表所示,字节序为 **大端字节序(Big Endian)**:
|
||||||
|
|
||||||
|
| SyncWord | MsgID | DataSize | Data | ParityCheck |
|
||||||
|
| -------- | ------ | -------- | ------- | ----------- |
|
||||||
|
| 2 bytes | 1 byte | 2 bytes | N bytes | 1 byte |
|
||||||
|
|
||||||
|
下表是对上述各个字段的详细说明:
|
||||||
|
|
||||||
|
| 字段 | 长度 | 说明 |
|
||||||
|
| ----------- | ------- | ------------------------------------------------------------ |
|
||||||
|
| SyncWord | 2 bytes | 固定的消息开头同步字:0xEF 0xAA |
|
||||||
|
| MsgID | 1 byte | 消息ID(例如 MID_VERIFY) |
|
||||||
|
| DataSize | 2 bytes | Data数据的长度,0 ≤ size ≤ 65535 |
|
||||||
|
| Data | N bytes | 消息(MsgID)对应的数据内容,长度 N 为 DataSize 。<br/>0表示此消息无参数 |
|
||||||
|
| ParityCheck | 1 byte | 协议的奇偶检验码。<br/>去除SyncWord,对 MsgID、DataSize、Data 的内容字节做XOR运算 |
|
||||||
|
|
||||||
|
## 3 消息列表
|
||||||
|
|
||||||
|
| MsgID | Code | 说明 |
|
||||||
|
| ----------------- | ---- | ------------------------------------------------------------ |
|
||||||
|
| MID_REPLY | 0x00 | 模组对主控发送出的命令的应答,对于主控下发的每条命令,模组最终都会使用 MID_REPLY 进行结果应答上报 |
|
||||||
|
| MID_NOTE | 0x01 | 摸组主动上报给主控的信息,根据 NID 判断消息类型和对应的 Data 结构(详细内容见下文) |
|
||||||
|
| MID_RESET | 0x10 | 主控下发,用于打断模组当前执行的任务 |
|
||||||
|
| MID_VERIFY | 0x12 | 掌静脉识别比对 |
|
||||||
|
| MID_ENROLL_SINGLE | 0x1D | 掌静脉录入 |
|
||||||
|
| MID_DELUSER | 0x20 | 删除一个已录入的掌静脉 |
|
||||||
|
| MID_DELALL | 0x21 | 删除所有已录入的掌静脉 |
|
||||||
|
| MID_MODULE_ID | 0xAC | 获取模组ID,唯一标识 |
|
||||||
|
|
||||||
|
### 3.1 设备初始化完成
|
||||||
|
|
||||||
|
模组上电初始化完成后,会通过串口向主控发送一条 NID 为 NID_READY 的 MID_NOTE 消息: 0xEF 0xAA 0x01 0x00 0x01 0x00 0x00。(消息详细解释见 `模组状态上报(MID_NOTE)`)。
|
||||||
|
|
||||||
|
> 该消息仅支持使用串口连接,使用CDC不会上报此消息
|
||||||
|
|
||||||
|
主控在接收到 MID_NOTE 信息后,可以和模组进行指令交互。
|
||||||
|
|
||||||
|
### 3.2 模组复位(MID_RESET)
|
||||||
|
|
||||||
|
模组同一时刻,只能执行一个任务,当模组在执行耗时长的任务时(例如掌静脉识别 MID_VERIFY),主控可以向模组下发 MID_RESET 打断取消当前任务,进而再去执行其它任务。
|
||||||
|
|
||||||
|
该指令无需携带参数。
|
||||||
|
|
||||||
|
指令执行结束后,通过消息 MID_REPLY 返回结果:
|
||||||
|
|
||||||
|
- 0x00(MR_SUCCESS):复位成功
|
||||||
|
- 0x05(MR_FAILED4_UNKNOWNREASON):未知错误
|
||||||
|
|
||||||
|
### 3.3 掌静脉识别(MID_VERIFY)
|
||||||
|
|
||||||
|
主控下发该指令给模组,模组开始检测摄像头图像中的掌静脉,并和底库中的掌静脉进行比对。指令下发携带的参数 msg_verify_data 定义如下:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
struct msg_verify_data {
|
||||||
|
uint8_t reserved;
|
||||||
|
uint8_t timeout;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
参数说明:
|
||||||
|
|
||||||
|
- reserved:保留字段,暂未使用。需设置为 0x00。
|
||||||
|
- timeout:识别超时时间,默认为10s,用户可以自行设置(最大不超过255s)。**主控等待模组录入应答的超时时间应大于此参数设置值。**
|
||||||
|
|
||||||
|
主控下发消息格式如下:
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<table align="center">
|
||||||
|
<tr align="center">
|
||||||
|
<th>SyncWord</th>
|
||||||
|
<th>MsgID</th>
|
||||||
|
<th>DataSize</th>
|
||||||
|
<th colspan="2">Data</th>
|
||||||
|
<th>ParityCheck</th>
|
||||||
|
</tr>
|
||||||
|
<tr align="center">
|
||||||
|
<td>2 bytes</td>
|
||||||
|
<td>1 byte</td>
|
||||||
|
<td>2 bytes</td>
|
||||||
|
<td colspan="2">2 bytes</td>
|
||||||
|
<td>1 byte</td>
|
||||||
|
</tr>
|
||||||
|
<tr align="center">
|
||||||
|
<td>0xEF 0xAA</td>
|
||||||
|
<td>MID_VERIFY<br/>(0x12)</td>
|
||||||
|
<td>0x02</td>
|
||||||
|
<td>reserved<br/>(1 byte)</td>
|
||||||
|
<td>timeout<br/>(1 byte)</td>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
识别结果 Result 确认码的返回值见 `命令结果上报(MID_REPLY)`。
|
||||||
|
|
||||||
|
模组掌静脉识别成功后,通过消息 MID_REPLY 返回的数据 ResultData 定义如下:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
struct msg_reply_verify_data {
|
||||||
|
uint16_t user_id;
|
||||||
|
uint8_t username[32];
|
||||||
|
uint8_t reserved[2];
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
参数说明:
|
||||||
|
|
||||||
|
- user_id:识别成功的用户 ID
|
||||||
|
- username:识别成功的用户名字
|
||||||
|
- reserved:保留字段,暂未使用。需设置为 0x00。
|
||||||
|
|
||||||
|
模组识别成功上报消息格式如下:
|
||||||
|
|
||||||
|
<table align="center">
|
||||||
|
<tr align="center">
|
||||||
|
<th rowspan="3">SyncWord</th>
|
||||||
|
<th rowspan="3">MsgID</th>
|
||||||
|
<th rowspan="3">DataSize</th>
|
||||||
|
<th colspan="5">Data</th>
|
||||||
|
<th rowspan="2">ParityCheck</th>
|
||||||
|
</tr>
|
||||||
|
<td>RID</td>
|
||||||
|
<td>Result</td>
|
||||||
|
<td colspan="3">ResultData</td>
|
||||||
|
<tr>
|
||||||
|
</tr>
|
||||||
|
<tr align="center">
|
||||||
|
<td>2 bytes</td>
|
||||||
|
<td>1 byte</td>
|
||||||
|
<td>2 bytes</td>
|
||||||
|
<td colspan="5">N bytes</td>
|
||||||
|
<td>1 byte</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
</tr>
|
||||||
|
<tr align="center">
|
||||||
|
<td>0xEF 0xAA</td>
|
||||||
|
<td>MID_REPLY<br/>(0x00)</td>
|
||||||
|
<td>0x26</td>
|
||||||
|
<td>MID_VERIFY<br/>(0x12)</td>
|
||||||
|
<td>Result<br/>(1 byte)</td>
|
||||||
|
<td>user_id<br/>(2 bytes)</td>
|
||||||
|
<td>username<br/>(32 bytes)</td>
|
||||||
|
<td>reserved<br/>(2 bytes)</td>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 3.4 掌静脉录入(MID_ENROLL_SINGLE)
|
||||||
|
|
||||||
|
掌静脉录入指令下发携带的参数 `msg_enroll_data` 定义如下:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
struct msg_enroll_data {
|
||||||
|
uint8_t username[32];
|
||||||
|
uint8_t reserved1[3];
|
||||||
|
uint8_t timeout;
|
||||||
|
uint8_t reserved2[4];
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
参数说明:
|
||||||
|
|
||||||
|
- username:录入用户的用户名。
|
||||||
|
- reserved1:保留字段,暂未使用。需设置为 0x00。
|
||||||
|
- timeout:录入过程的超时时间(s),默认为10s,用户可以自行设置(最大不超过255s)。**主控等待模组录入应答的超时时间应大于此参数设置值。**
|
||||||
|
- reserved2:保留字段,暂未使用。需设置为 0x00。
|
||||||
|
|
||||||
|
录入结果 Result 确认码的返回值见 `命令结果上报(MID_REPLY)`。
|
||||||
|
|
||||||
|
模组掌静脉录入成功后,通过消息 MID_REPLY 返回的数据 ResultData 定义如下:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
struct msg_reply_enroll_data {
|
||||||
|
uint16_t user_id;
|
||||||
|
uint8_t reserved;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
参数说明:
|
||||||
|
|
||||||
|
- user_id:用户 ID
|
||||||
|
- reserved:保留,暂未使用。
|
||||||
|
|
||||||
|
### 3.5 删除单个掌静脉(MID_DELUSER)
|
||||||
|
|
||||||
|
通过传入用户 ID, 删除指定 ID 的单个用户。
|
||||||
|
|
||||||
|
删除单个用户指令携带参数 msg_deluser_data 定义如下:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
struct msg_deluser_data {
|
||||||
|
uint16_t user_id;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
参数说明:
|
||||||
|
|
||||||
|
- user_id:需要删除的用户 ID。
|
||||||
|
|
||||||
|
指令执行结束后,通过消息 MID_REPLY 返回结果(主控等待应答超时时间建议设置为 5s):
|
||||||
|
|
||||||
|
- 0x00(MR_SUCCESS):删除成功
|
||||||
|
- 0x05(MR_FAILED4_UNKNOWNREASON):未知错误
|
||||||
|
- 0x08(MR_FAILED4_UNKNOWNUSER):删除的用户ID不存在
|
||||||
|
|
||||||
|
### 3.6 删除所有掌静脉(MID_DELALL)
|
||||||
|
|
||||||
|
删除所有已录入的用户。
|
||||||
|
|
||||||
|
该指令无需携带参数。
|
||||||
|
|
||||||
|
指令执行结束后,通过消息 MID_REPLY 返回结果(主控等待应答超时时间建议设置为 5s):
|
||||||
|
|
||||||
|
- 0x00(MR_SUCCESS):删除成功
|
||||||
|
- 0x05(MR_FAILED4_UNKNOWNREASON):未知错误
|
||||||
|
|
||||||
|
### 3.7 获取模组ID
|
||||||
|
|
||||||
|
该命令用于获取模组ID,类型为长度为32的字符串。
|
||||||
|
|
||||||
|
该指令无需携带参数。
|
||||||
|
|
||||||
|
模组通过消息 MID_REPLY 返回的数据 msg_reply_module_id 定义如下:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
struct msg_reply_module_id {
|
||||||
|
char id[32];
|
||||||
|
uint8_t reserved[512];
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
参数说明:
|
||||||
|
|
||||||
|
- id:长度不超过32的字符串ID。
|
||||||
|
- reserved:保留,暂未使用。
|
||||||
|
|
||||||
|
### 3.9 命令结果上报(MID_REPLY)
|
||||||
|
|
||||||
|
模组向主控发送的 MID_REPLY 消息的完整协议如下所示:
|
||||||
|
|
||||||
|
<table align="center">
|
||||||
|
<tr align="center">
|
||||||
|
<th>SyncWord</th>
|
||||||
|
<th>MsgID</th>
|
||||||
|
<th>DataSize</th>
|
||||||
|
<th colspan="3">Data</th>
|
||||||
|
<th>ParityCheck</th>
|
||||||
|
</tr>
|
||||||
|
<tr align="center">
|
||||||
|
<td>2 bytes</td>
|
||||||
|
<td>1 byte</td>
|
||||||
|
<td>2 bytes</td>
|
||||||
|
<td colspan="3">N bytes</td>
|
||||||
|
<td>1 byte</td>
|
||||||
|
</tr>
|
||||||
|
<tr align="center">
|
||||||
|
<td>0xEF 0xAA</td>
|
||||||
|
<td>MID_REPLY(0x00)</td>
|
||||||
|
<td> </td>
|
||||||
|
<td>RID(1 byte)</td>
|
||||||
|
<td>Result(1 byte)</td>
|
||||||
|
<td>ResultData( N-2 bytes)</td>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
RID表示模组当前正在处理的任务,例如当 RID 为 MID_ENROLL_SINGLE 时,表示该消息是模组处理完掌静脉录入任务后回复的消息。
|
||||||
|
|
||||||
|
消息对应的 ResultData 会在主控下发命令(例如 MID_ENROLL_SINGLE )中进行介绍。
|
||||||
|
|
||||||
|
Result 表示该命令的最终执行结果,详细如下表所示。
|
||||||
|
|
||||||
|
| Result | Code | 说明 |
|
||||||
|
| ------------------------ | ---- | ------------------- |
|
||||||
|
| MR_SUCCESS | 0 | 指令执行成功 |
|
||||||
|
| MR_REJECTED | 1 | 模组拒绝该命令 |
|
||||||
|
| MR_ABORTED | 2 | 录入/解锁算法已终止 |
|
||||||
|
| MR_FAILED4_CAMERA | 4 | 相机打开失败 |
|
||||||
|
| MR_FAILED4_UNKNOWNREASON | 5 | 未知错误 |
|
||||||
|
| MR_FAILED4_INVALIDPARAM | 6 | 无效的参数 |
|
||||||
|
| MR_FAILED4_NOMEMORY | 7 | 内存不足 |
|
||||||
|
| MR_FAILED4_UNKNOWNUSER | 8 | 未录入的用户 |
|
||||||
|
| MR_FAILED4_MAXUSER | 9 | 录入超过最大数量 |
|
||||||
|
| MR_FAILED4_PALMENROLLED | 10 | 掌静脉已录入 |
|
||||||
|
| MR_FAILED4_LIVENESSCHECK | 12 | 活体检测失败 |
|
||||||
|
| MR_FAILED4_TIMEOUT | 13 | 录入或解锁超时 |
|
||||||
|
| MR_FAILED4_AUTHORIZATION | 14 | 加密芯片授权失败 |
|
||||||
|
| MR_FAILED4_READ_FILE | 19 | 读文件失败 |
|
||||||
|
| MR_FAILED4_WRITE_FILE | 20 | 写文件失败 |
|
||||||
|
| MR_FAILED4_NO_ENCRYPT | 21 | 未采用加密通讯 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 3.10 模组状态上报(MID_NOTE)
|
||||||
|
|
||||||
|
MID_NOTE 消息主要作用是主动向主控上报一些信息,报文格式如下:
|
||||||
|
|
||||||
|
<table align="center">
|
||||||
|
<tr align="center">
|
||||||
|
<th>SyncWord</th>
|
||||||
|
<th>MsgID</th>
|
||||||
|
<th>DataSize</th>
|
||||||
|
<th colspan="2">Data</th>
|
||||||
|
<th>ParityCheck</th>
|
||||||
|
</tr>
|
||||||
|
<tr align="center">
|
||||||
|
<td>2 bytes</td>
|
||||||
|
<td>1 byte</td>
|
||||||
|
<td>2 bytes</td>
|
||||||
|
<td colspan="2">N bytes</td>
|
||||||
|
<td>1 byte</td>
|
||||||
|
</tr>
|
||||||
|
<tr align="center">
|
||||||
|
<td>0xEF 0xAA</td>
|
||||||
|
<td>MID_NOTE(0x01)</td>
|
||||||
|
<td> </td>
|
||||||
|
<td>NID(1 byte)</td>
|
||||||
|
<td>NoteData( N-1 bytes)</td>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
目前NID主要内容如下:
|
||||||
|
|
||||||
|
| NID(*表示该消息携带 NoteData 数据) | Code | 说明 |
|
||||||
|
| ------------------------------------ | ---- | -------------------- |
|
||||||
|
| NID_READY | 0x00 | 模组已上电初始化成功 |
|
||||||
|
|
||||||
|
## 4 示例报文
|
||||||
|
|
||||||
|
- 掌静脉录入
|
||||||
|
|
||||||
|
录入 username为 test 的用户,超时时间 10s,主控发送:
|
||||||
|
|
||||||
|
0xef 0xaa 0x1d 0x00 0x28 0x74 0x65 0x73 0x74 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0a 0x00 0x00 0x00 0x00 0x29
|
||||||
|
|
||||||
|
录入成功,ID为1,模组上报:
|
||||||
|
|
||||||
|
0xef 0xaa 0x00 0x00 0x05 0x1d 0x00 0x00 0x01 0x00 0x19
|
||||||
|
|
||||||
|
- 掌静脉识别
|
||||||
|
|
||||||
|
开始识别比对,超时时间20s,主控发送:
|
||||||
|
|
||||||
|
0xef 0xaa 0x12 0x00 0x02 0x00 0x14 0x04
|
||||||
|
|
||||||
|
识别比对成功,user_id为1,username为test ,模组上报:
|
||||||
|
|
||||||
|
0xef 0xaa 0x00 0x00 0x26 0x12 0x00 0x00 0x01 0x74 0x65 0x73 0x74 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x7a 0x59
|
||||||
|
|
||||||
|
- 删除所有录入掌静脉
|
||||||
|
|
||||||
|
主控发送:
|
||||||
|
|
||||||
|
0xef 0xaa 0x21 0x00 0x00 0x21
|
||||||
|
|
||||||
|
删除成功,模组上报:
|
||||||
|
|
||||||
|
0xef 0xaa 0x00 0x00 0x02 0x21 0x00 0x23
|
||||||
|
|
||||||
|
## 5 文档修改记录
|
||||||
|
|
||||||
|
2024/10/14:V0.1版本,描述模组识别、录入、删除几个基本协议指令。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user