精简代码,便于同步客户对接。
This commit is contained in:
parent
34294c5c85
commit
40c60193d1
@ -58,13 +58,12 @@ void Application::onNewEnrollResult(uint16_t userid) {
|
||||
});
|
||||
}
|
||||
|
||||
void Application::onNewVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed) {
|
||||
void Application::onNewVerifyResult(uint16_t userid, const QString &username) {
|
||||
m_palmUsername = username;
|
||||
m_palmId = userid;
|
||||
QTimer::singleShot(0, this, [this, userid, username, elapsed]() {
|
||||
emit newStatusTip(Info, QString("%1,识别耗时: %2ms")
|
||||
.arg(userid == ModuleCommunication::InvalidUserId ? "未录入用户" : username)
|
||||
.arg(elapsed));
|
||||
QTimer::singleShot(0, this, [this, userid, username]() {
|
||||
emit newStatusTip(Info,
|
||||
QString("%1").arg(userid == ModuleCommunication::InvalidUserId ? "未录入用户" : username));
|
||||
});
|
||||
}
|
||||
|
||||
@ -192,24 +191,19 @@ void Application::closeUVC() {
|
||||
emit uvcOpenedChanged();
|
||||
}
|
||||
|
||||
void Application::verify(bool captureImage, uint8_t timeout) {
|
||||
void Application::verify(uint8_t timeout) {
|
||||
if (m_communication->currentMessageId() != ModuleCommunication::Idle) {
|
||||
m_communication->reset();
|
||||
}
|
||||
if (captureImage) {
|
||||
m_communication->verifyExtended(captureImage, timeout);
|
||||
} else {
|
||||
|
||||
m_communication->verify(timeout);
|
||||
}
|
||||
m_verifyExtendedMode = captureImage;
|
||||
}
|
||||
|
||||
void Application::enroll(const QString &username, bool strictMode, uint8_t excludeMode, bool persistence,
|
||||
uint8_t timeout) {
|
||||
void Application::enroll(const QString &username, uint8_t timeout) {
|
||||
if (m_communication->currentMessageId() != ModuleCommunication::Idle) {
|
||||
m_communication->reset();
|
||||
}
|
||||
m_communication->enroll(username.toStdString(), strictMode, excludeMode, persistence, timeout);
|
||||
m_communication->enroll(username.toStdString(), timeout);
|
||||
m_palmUsername = username;
|
||||
}
|
||||
|
||||
@ -227,15 +221,6 @@ void Application::deleteAll() {
|
||||
m_communication->deleteAll();
|
||||
}
|
||||
|
||||
void Application::enrollExtended(const QString &username, bool strictMode, uint8_t excludeMode, bool persistence,
|
||||
uint8_t timeout) {
|
||||
if (m_communication->currentMessageId() != ModuleCommunication::Idle) {
|
||||
m_communication->reset();
|
||||
}
|
||||
m_communication->enrollExtended(username.toStdString(), strictMode, excludeMode, persistence, timeout);
|
||||
m_palmUsername = username;
|
||||
}
|
||||
|
||||
void Application::uploadImage(const QString &path, const QString &username, int operation) {
|
||||
m_uploadImageSendedSize = 0;
|
||||
ModuleCommunication::UploadImageInformation request;
|
||||
@ -453,11 +438,7 @@ void Application::onCommandFinished(ModuleCommunication::MessageId messageId,
|
||||
}
|
||||
|
||||
void Application::onVerifyTimeout() {
|
||||
if (m_verifyExtendedMode) {
|
||||
m_communication->verifyExtended(m_verifyExtendedMode, 120);
|
||||
} else {
|
||||
m_communication->verify(120);
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::startOta(const QString &path) {
|
||||
|
@ -51,11 +51,8 @@ public:
|
||||
Q_INVOKABLE void close();
|
||||
Q_INVOKABLE void closeUVC();
|
||||
Q_INVOKABLE bool startOta(const QString &path);
|
||||
Q_INVOKABLE void verify(bool captureImage, uint8_t timeout);
|
||||
Q_INVOKABLE void enroll(const QString &username, bool strictMode, uint8_t excludeMode, bool persistence,
|
||||
uint8_t timeout);
|
||||
Q_INVOKABLE void enrollExtended(const QString &username, bool strictMode, uint8_t excludeMode, bool persistence,
|
||||
uint8_t timeout);
|
||||
Q_INVOKABLE void verify(uint8_t timeout);
|
||||
Q_INVOKABLE void enroll(const QString &username, uint8_t timeout);
|
||||
Q_INVOKABLE void deleteUser(uint16_t userid);
|
||||
Q_INVOKABLE void deleteAll();
|
||||
Q_INVOKABLE void uploadImage(const QString &path, const QString &username, int operation);
|
||||
@ -88,7 +85,7 @@ signals:
|
||||
protected:
|
||||
Application(int &argc, char **argv);
|
||||
void onNewEnrollResult(uint16_t userid);
|
||||
void onNewVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed);
|
||||
void onNewVerifyResult(uint16_t userid, const QString &username);
|
||||
void onNewPalmFeature(const PalmFeature &feature);
|
||||
void onErrorOccurred(ModuleCommunication::NoteId note, const QString &error, const QString &detailMessage);
|
||||
void onNewImageInfo(ModuleCommunication::MessageId messageId, uint32_t size, const uint8_t *md5);
|
||||
@ -106,7 +103,6 @@ private:
|
||||
std::shared_ptr<Database> m_database;
|
||||
|
||||
bool m_persistenceMode = true; // 模组持续识别
|
||||
bool m_verifyExtendedMode = false;
|
||||
bool m_persistenceModeStarted = false;
|
||||
int m_persistenceVerifyInterval = 1;
|
||||
QTimer *m_verifyTimer = nullptr;
|
||||
|
@ -52,18 +52,6 @@ void ModuleCommunication::verify(uint8_t timeout) {
|
||||
LOG_CAT(info, GUI) << Separator;
|
||||
}
|
||||
|
||||
void ModuleCommunication::verifyExtended(bool captureImage, uint8_t timeout) {
|
||||
VerifyRequest data = {0};
|
||||
data.timeout = timeout;
|
||||
data.save_image = captureImage ? 0x01 : 0x00;
|
||||
auto [frameData, frameSize] = generateFrame(VerifyExtended, reinterpret_cast<const uint8_t *>(&data), sizeof(data));
|
||||
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
|
||||
setCurrentMessageIdStatus(VerifyExtended);
|
||||
|
||||
LOG_CAT(info, GUI) << "发送扩展识别指令: " << protocolDataFormatString(frameData, frameSize);
|
||||
LOG_CAT(info, GUI) << Separator;
|
||||
}
|
||||
|
||||
void ModuleCommunication::reset() {
|
||||
auto [frameData, frameSize] = generateFrame(Reset);
|
||||
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
|
||||
@ -72,13 +60,9 @@ void ModuleCommunication::reset() {
|
||||
LOG_CAT(info, GUI) << Separator;
|
||||
}
|
||||
|
||||
void ModuleCommunication::enroll(const std::string &username, bool strictMode, uint8_t excludeMode, bool persistence,
|
||||
uint8_t timeout) {
|
||||
void ModuleCommunication::enroll(const std::string &username, uint8_t timeout) {
|
||||
EnrollRequest data = {0};
|
||||
data.strictMode = strictMode ? 1 : 0;
|
||||
data.excludeMode = excludeMode;
|
||||
data.timeout = timeout;
|
||||
data.skipSave = persistence ? 0 : 1;
|
||||
strncpy(reinterpret_cast<char *>(data.username), username.c_str(), sizeof(data.username));
|
||||
auto [frameData, frameSize] = generateFrame(EnrollSingle, reinterpret_cast<const uint8_t *>(&data), sizeof(data));
|
||||
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
|
||||
@ -89,22 +73,6 @@ void ModuleCommunication::enroll(const std::string &username, bool strictMode, u
|
||||
LOG_CAT(info, GUI) << Separator;
|
||||
}
|
||||
|
||||
void ModuleCommunication::enrollExtended(const std::string &username, bool strictMode, uint8_t excludeMode,
|
||||
bool persistence, uint8_t timeout) {
|
||||
EnrollRequest data = {};
|
||||
data.strictMode = strictMode ? 1 : 0;
|
||||
data.excludeMode = excludeMode;
|
||||
data.timeout = timeout;
|
||||
data.skipSave = persistence ? 0 : 1;
|
||||
strncpy(reinterpret_cast<char *>(data.username), username.c_str(), sizeof(data.username));
|
||||
auto [frameData, frameSize] = generateFrame(EnrollExtended, reinterpret_cast<const uint8_t *>(&data), sizeof(data));
|
||||
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
|
||||
setCurrentMessageIdStatus(EnrollExtended);
|
||||
LOG_CAT(info, GUI) << "发送获取注册照片指令: " << protocolDataFormatString(frameData, frameSize);
|
||||
LOG_CAT(info, GUI) << "用户名: " << username << ", 超时时间: " << static_cast<int>(timeout) << "s";
|
||||
LOG_CAT(info, GUI) << Separator;
|
||||
}
|
||||
|
||||
void ModuleCommunication::deleteUser(uint16_t userid) {
|
||||
uint16_t n = htons(userid);
|
||||
auto [frameData, frameSize] = generateFrame(DeleteUser, reinterpret_cast<const uint8_t *>(&n), sizeof(n));
|
||||
@ -216,25 +184,21 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
|
||||
if (result == Success) {
|
||||
auto info = reinterpret_cast<const VerifyReply *>(data + 7);
|
||||
uint16_t userid = ntohs(info->userid);
|
||||
uint16_t elapsed = ntohs(info->elapsed);
|
||||
LOG_CAT(info, GUI) << "用户ID: " << userid
|
||||
<< ", 用户名: " << std::string_view(reinterpret_cast<const char *>(info->username))
|
||||
<< ", 耗时: " << elapsed << "ms";
|
||||
emit newVerifyResult(userid, reinterpret_cast<const char *>(info->username), elapsed);
|
||||
<< ", 用户名: " << std::string_view(reinterpret_cast<const char *>(info->username));
|
||||
emit newVerifyResult(userid, reinterpret_cast<const char *>(info->username));
|
||||
} else if (result == Failed4Timeout) {
|
||||
LOG_CAT(info, GUI) << "识别超时。";
|
||||
} else if (result == Rejected) {
|
||||
LOG_CAT(info, GUI) << "模组拒绝该命令。";
|
||||
} else if (result == Failed4UnknownUser) {
|
||||
auto info = reinterpret_cast<const VerifyReply *>(data + 7);
|
||||
uint16_t elapsed = ntohs(info->elapsed);
|
||||
emit newVerifyResult(InvalidUserId, "", elapsed);
|
||||
LOG_CAT(info, GUI) << "未录入用户, 耗时: " << elapsed << "ms";
|
||||
emit newVerifyResult(InvalidUserId, "");
|
||||
LOG_CAT(info, GUI) << "未录入用户";
|
||||
} else if (result == Failed4UnknownReason) {
|
||||
auto info = reinterpret_cast<const VerifyReply *>(data + 7);
|
||||
uint16_t elapsed = ntohs(info->elapsed);
|
||||
emit newVerifyResult(InvalidUserId, "", elapsed);
|
||||
LOG_CAT(info, GUI) << "未知错误, 耗时: " << elapsed << "ms";
|
||||
emit newVerifyResult(InvalidUserId, "");
|
||||
LOG_CAT(info, GUI) << "未知错误";
|
||||
} else {
|
||||
LOG_CAT(info, GUI) << "未知错误(" << static_cast<int>(result) << ")。";
|
||||
}
|
||||
@ -324,27 +288,6 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
|
||||
case UploadImageInfo: {
|
||||
break;
|
||||
}
|
||||
case UploadImageData: {
|
||||
auto info = reinterpret_cast<const UploadImageReply *>(data + 7);
|
||||
if (result == Success) {
|
||||
if (info->operation == 0) {
|
||||
LOG_CAT(info, GUI) << "图片下发注册成功,用户ID: " << ntohs(info->userid);
|
||||
} else if (info->operation == 1) {
|
||||
auto result = reinterpret_cast<const UploadImageVerifyReply *>(info);
|
||||
LOG_CAT(info, GUI) << "图片下发识别成功,用户ID: " << ntohs(result->userid) << ", 用户名: "
|
||||
<< std::string_view(reinterpret_cast<const char *>(result->result.username))
|
||||
<< ", 耗时: " << ntohs(result->result.elapsed) << "ms";
|
||||
} else {
|
||||
LOG(warning) << "unknown upload image operation: " << info->operation;
|
||||
}
|
||||
LOG_CAT(info, GUI) << Separator;
|
||||
} else if (result == Needmore) {
|
||||
} else {
|
||||
LOG(info) << "upload image failed, operation: " << static_cast<uint16_t>(info->operation)
|
||||
<< ", status: " << static_cast<uint16_t>(result);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GetCurrentStatus: {
|
||||
LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size);
|
||||
LOG_CAT(info, GUI) << "模组当前状态: " << static_cast<int>(data[7]);
|
||||
|
@ -87,8 +87,8 @@ public:
|
||||
|
||||
#pragma pack(1)
|
||||
struct VerifyRequest {
|
||||
uint8_t save_image;
|
||||
uint8_t timeout; // timeout, unit second, default 10s
|
||||
uint8_t reserved;
|
||||
uint8_t timeout;
|
||||
};
|
||||
|
||||
struct PalmStateNote {
|
||||
@ -102,16 +102,14 @@ public:
|
||||
|
||||
struct EnrollRequest {
|
||||
uint8_t username[32];
|
||||
uint8_t strictMode = 0;
|
||||
uint8_t excludeMode = 0; // 掌静脉库里面是否已经存在 0:不进行验证 1:只进行比对 2:如果存在,则现在不予录入
|
||||
uint8_t skipSave = 0;
|
||||
uint8_t reserved1[3];
|
||||
uint8_t timeout;
|
||||
uint8_t reserved[4];
|
||||
uint8_t reserved2[4];
|
||||
};
|
||||
|
||||
struct EnrollReply {
|
||||
uint16_t userid;
|
||||
uint8_t operation;
|
||||
uint8_t reserved;
|
||||
};
|
||||
|
||||
struct PalmVeinInformation {
|
||||
@ -148,7 +146,7 @@ public:
|
||||
struct VerifyReply {
|
||||
uint16_t userid;
|
||||
uint8_t username[UsernameSize]; // 32Bytes
|
||||
uint16_t elapsed; // 此时识别耗时时间
|
||||
uint8_t reserved[2];
|
||||
};
|
||||
|
||||
struct VerifyExtendReply : public VerifyReply {
|
||||
@ -195,12 +193,9 @@ public:
|
||||
explicit ModuleCommunication(QObject *parent = nullptr);
|
||||
bool open(const QString &portName, int baudRate);
|
||||
void verify(uint8_t timeout);
|
||||
void verifyExtended(bool captureImage, uint8_t timeout);
|
||||
Q_INVOKABLE void reset();
|
||||
|
||||
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,
|
||||
uint8_t timeout);
|
||||
void enroll(const std::string &username, uint8_t timeout);
|
||||
Q_INVOKABLE void deleteUser(uint16_t userid);
|
||||
Q_INVOKABLE void deleteAll();
|
||||
Q_INVOKABLE void requestUniqueId();
|
||||
@ -222,7 +217,7 @@ signals:
|
||||
* @param username
|
||||
* @param elapsed ms毫秒
|
||||
*/
|
||||
void newVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed);
|
||||
void newVerifyResult(uint16_t userid, const QString &username);
|
||||
void newEnrollResult(uint16_t userid);
|
||||
void newPalmFeature(const PalmFeature &feature);
|
||||
void newImageInfo(MessageId id, uint32_t size, const uint8_t *md5);
|
||||
|
@ -16,19 +16,6 @@ RowLayout {
|
||||
id: enrollName
|
||||
implicitWidth: 100
|
||||
}
|
||||
Label {
|
||||
text: qsTr("严格模式")
|
||||
}
|
||||
Switch {
|
||||
id: strictMode
|
||||
}
|
||||
Label {
|
||||
text: qsTr("互斥模式")
|
||||
}
|
||||
ComboBox {
|
||||
id: excludeMode
|
||||
model: ["无", "仅比对", "互斥"]
|
||||
}
|
||||
Label {
|
||||
text: qsTr("超时时间")
|
||||
}
|
||||
@ -38,21 +25,6 @@ RowLayout {
|
||||
text: "30"
|
||||
}
|
||||
|
||||
Label {
|
||||
text: qsTr("持久化")
|
||||
}
|
||||
Switch {
|
||||
id: persistence
|
||||
checked: true
|
||||
}
|
||||
|
||||
Label {
|
||||
text: qsTr("保存图片")
|
||||
}
|
||||
Switch {
|
||||
id: extendedMode
|
||||
}
|
||||
|
||||
Button {
|
||||
property bool enrolling: App.module ? (App.module.currentMessageId
|
||||
=== ModuleCommunication.EnrollSingle)
|
||||
@ -61,16 +33,8 @@ RowLayout {
|
||||
onClicked: {
|
||||
if (enrolling) {
|
||||
App.module.reset()
|
||||
} else if (extendedMode.checked) {
|
||||
App.enrollExtended(enrollName.text, strictMode.checked,
|
||||
excludeMode.currentIndex,
|
||||
persistence.checked,
|
||||
parseInt(enrollTimeout.text))
|
||||
} else {
|
||||
App.enroll(enrollName.text, strictMode.checked,
|
||||
excludeMode.currentIndex,
|
||||
persistence.checked,
|
||||
parseInt(enrollTimeout.text))
|
||||
App.enroll(enrollName.text, parseInt(enrollTimeout.text))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -96,12 +60,6 @@ RowLayout {
|
||||
checked: App.persistenceMode
|
||||
onToggled: App.persistenceMode = !App.persistenceMode
|
||||
}
|
||||
Label {
|
||||
text: qsTr("保存图片")
|
||||
}
|
||||
Switch {
|
||||
id: extendedVerifyMode
|
||||
}
|
||||
Label {
|
||||
text: qsTr("识别间隔(s)")
|
||||
}
|
||||
@ -118,7 +76,7 @@ RowLayout {
|
||||
App.module.reset()
|
||||
} else {
|
||||
App.persistenceVerifyInterval = parseInt(verifyIntetval.text)
|
||||
App.verify(extendedVerifyMode.checked, parseInt(verifyTimeout.text))
|
||||
App.verify(parseInt(verifyTimeout.text))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,57 +52,6 @@ Item {
|
||||
text: "OTA升级"
|
||||
onClicked: loader.active = true
|
||||
}
|
||||
Row {
|
||||
Label {
|
||||
text: qsTr("日志")
|
||||
}
|
||||
Switch {
|
||||
id: debugMode
|
||||
onToggled: App.module.setDebugEnabled(debugMode.checked)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GroupBox {
|
||||
title: "图片注册"
|
||||
visible: true
|
||||
GridLayout {
|
||||
columns: 2
|
||||
TextField {
|
||||
id: imagePath
|
||||
Layout.columnSpan: 2
|
||||
implicitWidth: 200
|
||||
placeholderText: "请选择图片"
|
||||
onPressed: {
|
||||
fileDialog.open()
|
||||
}
|
||||
}
|
||||
Label {
|
||||
text: qsTr("用户姓名")
|
||||
}
|
||||
TextField {
|
||||
id: imageEnrollName
|
||||
implicitWidth: 100
|
||||
text: "测试下发"
|
||||
}
|
||||
Label {
|
||||
text: qsTr("循环")
|
||||
}
|
||||
Switch {
|
||||
checked: App.imageUploadPersistenceMode
|
||||
onToggled: {
|
||||
App.imageUploadPersistenceMode = checked
|
||||
}
|
||||
}
|
||||
Button {
|
||||
text: "注册"
|
||||
onClicked: App.uploadImage(imagePath.text, imageEnrollName.text, 0)
|
||||
}
|
||||
Button {
|
||||
text: "识别"
|
||||
onClicked: App.uploadImage(imagePath.text, imageEnrollName.text, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user