实现识别图片上传。

This commit is contained in:
luocai 2024-07-31 16:08:38 +08:00
parent 5c2440c32c
commit 5009528f3a
5 changed files with 132 additions and 50 deletions

View File

@ -52,6 +52,7 @@ Application::Application(int &argc, char **argv) : m_app(std::make_shared<QAppli
} }
void Application::onNewVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed) { void Application::onNewVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed) {
m_palmUsername = username;
QTimer::singleShot(0, this, [this, userid, username, elapsed]() { QTimer::singleShot(0, this, [this, userid, username, elapsed]() {
emit newStatusTip(Info, QString("%1,识别耗时: %2ms") emit newStatusTip(Info, QString("%1,识别耗时: %2ms")
.arg(userid == ModuleCommunication::InvalidUserId ? "未录入用户" : username) .arg(userid == ModuleCommunication::InvalidUserId ? "未录入用户" : username)
@ -106,8 +107,7 @@ bool Application::open(const QString &portName, int baudRate) {
connect(m_communication.get(), &ModuleCommunication::commandFinished, this, &Application::onCommandFinished); connect(m_communication.get(), &ModuleCommunication::commandFinished, this, &Application::onCommandFinished);
connect(m_communication.get(), &ModuleCommunication::newVerifyResult, this, &Application::onNewVerifyResult); connect(m_communication.get(), &ModuleCommunication::newVerifyResult, this, &Application::onNewVerifyResult);
connect(m_communication.get(), &ModuleCommunication::newPalmFeature, this, &Application::onNewPalmFeature); connect(m_communication.get(), &ModuleCommunication::newPalmFeature, this, &Application::onNewPalmFeature);
connect(m_communication.get(), &ModuleCommunication::newEnrolledImageInfo, this, connect(m_communication.get(), &ModuleCommunication::newImageInfo, this, &Application::onNewImageInfo);
&Application::onNewEnrolledImageInfo);
connect(m_communication.get(), &ModuleCommunication::newImageSliceData, this, &Application::onNewImageSliceData); connect(m_communication.get(), &ModuleCommunication::newImageSliceData, this, &Application::onNewImageSliceData);
connect(m_communication.get(), &ModuleCommunication::errorOccurred, this, &Application::onErrorOccurred); connect(m_communication.get(), &ModuleCommunication::errorOccurred, this, &Application::onErrorOccurred);
emit connectedChanged(); emit connectedChanged();
@ -160,19 +160,24 @@ void Application::closeUVC() {
emit uvcOpenedChanged(); emit uvcOpenedChanged();
} }
void Application::verify(uint8_t timeout) { void Application::verify(bool captureImage, uint8_t timeout) {
if (m_communication->currentMessageId() != ModuleCommunication::Idle) { if (m_communication->currentMessageId() != ModuleCommunication::Idle) {
m_communication->reset(); m_communication->reset();
} }
if (captureImage) {
m_communication->verifyExtended(captureImage, timeout);
} else {
m_communication->verify(timeout); m_communication->verify(timeout);
} }
m_verifyExtendedMode = captureImage;
}
void Application::enroll(const QString &username, bool persistence, uint8_t timeout) { void Application::enroll(const QString &username, bool persistence, uint8_t timeout) {
if (m_communication->currentMessageId() != ModuleCommunication::Idle) { if (m_communication->currentMessageId() != ModuleCommunication::Idle) {
m_communication->reset(); m_communication->reset();
} }
m_communication->enroll(username.toStdString(), persistence, timeout); m_communication->enroll(username.toStdString(), persistence, timeout);
m_enrollUsername = username; m_palmUsername = username;
} }
void Application::deleteUser(uint16_t userid) { void Application::deleteUser(uint16_t userid) {
@ -194,7 +199,7 @@ void Application::enrollExtended(const QString &username, bool persistence, uint
m_communication->reset(); m_communication->reset();
} }
m_communication->enrollExtended(username.toStdString(), persistence, timeout); m_communication->enrollExtended(username.toStdString(), persistence, timeout);
m_enrollUsername = username; m_palmUsername = username;
} }
void Application::uploadImage() { void Application::uploadImage() {
@ -269,7 +274,8 @@ bool Application::isVerifying() const {
return false; return false;
} }
return (m_persistenceMode && m_persistenceModeStarted) || return (m_persistenceMode && m_persistenceModeStarted) ||
(m_communication->currentMessageId() == ModuleCommunication::Verify); (m_communication->currentMessageId() == ModuleCommunication::Verify) ||
(m_communication->currentMessageId() == ModuleCommunication::VerifyExtended);
} }
void Application::onNewPalmFeature(const PalmFeature &feature) { void Application::onNewPalmFeature(const PalmFeature &feature) {
@ -287,36 +293,37 @@ void Application::onErrorOccurred(const QString &error) {
QTimer::singleShot(0, this, [this]() { close(); }); QTimer::singleShot(0, this, [this]() { close(); });
} }
void Application::onNewEnrolledImageInfo(uint32_t size, const uint8_t *md5) { void Application::onNewImageInfo(ModuleCommunication::MessageId messageId, uint32_t size, const uint8_t *md5) {
using namespace std::chrono; using namespace std::chrono;
m_enrolledImageSize = size; m_palmImageId = messageId;
m_palmImageSize = size;
m_communication->requestEnrolledImage(0, ImageSliceSize); m_communication->requestEnrolledImage(0, ImageSliceSize);
m_enrollYImageBuffer.clear(); m_palmYImageBuffer.clear();
m_startUploadTime = system_clock::now(); m_startUploadTime = system_clock::now();
} }
void Application::onNewImageSliceData(const std::vector<uint8_t> &data) { void Application::onNewImageSliceData(const std::vector<uint8_t> &data) {
using namespace std::chrono; using namespace std::chrono;
// LOG(info) << "onNewImageSliceData:" << data.size() << ", already received: " << m_enrollYImageBuffer.size() // LOG(info) << "onNewImageSliceData:" << data.size() << ", already received: " << m_palmYImageBuffer.size()
// << ", total size: " << m_enrolledImageSize; // << ", total size: " << m_palmImageSize;
m_enrollYImageBuffer.append(reinterpret_cast<const char *>(data.data()), data.size()); m_palmYImageBuffer.append(reinterpret_cast<const char *>(data.data()), data.size());
if (m_enrollYImageBuffer.size() < m_enrolledImageSize) { if (m_palmYImageBuffer.size() < m_palmImageSize) {
m_communication->requestEnrolledImage(m_enrollYImageBuffer.size(), ImageSliceSize); m_communication->requestEnrolledImage(m_palmYImageBuffer.size(), ImageSliceSize);
} else { } else {
auto username = m_enrollUsername.toStdString(); auto username = m_palmUsername.toStdString();
auto way = (m_palmImageId == ModuleCommunication::VerifyExtended) ? "verify" : "enroll";
LOG(info) << "request finished, username: " << username LOG(info) << "request finished, username: " << username
<< ", elapsed: " << duration_cast<milliseconds>(system_clock::now() - m_startUploadTime); << ", elapsed: " << duration_cast<milliseconds>(system_clock::now() - m_startUploadTime);
std::ostringstream oss; std::ostringstream oss;
oss << YuvPath << "/" << username << "_" << DateTime::toString(std::chrono::system_clock::now(), "%Y%m%d%H%M%S") oss << YuvPath << "/" << username << "_" << way << "_"
<< ".yuv"; << DateTime::toString(std::chrono::system_clock::now(), "%Y%m%d%H%M%S") << ".yuv";
std::ofstream ofs(Amass::StringUtility::UTF8ToGBK(oss.str()), std::ofstream::binary); std::ofstream ofs(Amass::StringUtility::UTF8ToGBK(oss.str()), std::ofstream::binary);
ofs.write(m_enrollYImageBuffer.data(), m_enrollYImageBuffer.size()); ofs.write(m_palmYImageBuffer.data(), m_palmYImageBuffer.size());
QImage image(reinterpret_cast<const uint8_t *>(m_enrollYImageBuffer.data()), 600, 800, QImage image(reinterpret_cast<const uint8_t *>(m_palmYImageBuffer.data()), 600, 800, QImage::Format_Grayscale8);
QImage::Format_Grayscale8);
oss.str(""); oss.str("");
oss << JpgPath << "/" << username << "_" << DateTime::toString(std::chrono::system_clock::now(), "%Y%m%d%H%M%S") oss << JpgPath << "/" << username << "_" << way << "_"
<< ".jpg"; << DateTime::toString(std::chrono::system_clock::now(), "%Y%m%d%H%M%S") << ".jpg";
image.save(QString::fromStdString(oss.str()), "jpg", 100); image.save(QString::fromStdString(oss.str()), "jpg", 100);
} }
} }
@ -346,14 +353,16 @@ void Application::onCommandFinished(ModuleCommunication::MessageId messageId,
} }
} }
if (messageId == ModuleCommunication::Verify && m_persistenceMode) { // 持续识别逻辑 if (((messageId == ModuleCommunication::Verify) || (messageId == ModuleCommunication::VerifyExtended)) &&
m_persistenceMode) { // 持续识别逻辑
m_persistenceModeStarted = true; m_persistenceModeStarted = true;
} else if (messageId == ModuleCommunication::Reset) { } else if (messageId == ModuleCommunication::Reset) {
m_persistenceModeStarted = false; m_persistenceModeStarted = false;
m_verifyTimer->stop(); m_verifyTimer->stop();
} }
if (m_persistenceMode && m_persistenceModeStarted && messageId == ModuleCommunication::Verify && if (m_persistenceMode && m_persistenceModeStarted &&
((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))) {
m_verifyTimer->start(m_persistenceVerifyInterval * 1000); m_verifyTimer->start(m_persistenceVerifyInterval * 1000);
@ -367,5 +376,9 @@ void Application::onCommandFinished(ModuleCommunication::MessageId messageId,
} }
void Application::onVerifyTimeout() { void Application::onVerifyTimeout() {
if (m_verifyExtendedMode) {
m_communication->verifyExtended(m_verifyExtendedMode, 120);
} else {
m_communication->verify(120); m_communication->verify(120);
} }
}

View File

@ -44,7 +44,7 @@ public:
Q_INVOKABLE bool openUVC(const QString &deviceName); Q_INVOKABLE bool openUVC(const QString &deviceName);
Q_INVOKABLE void close(); Q_INVOKABLE void close();
Q_INVOKABLE void closeUVC(); Q_INVOKABLE void closeUVC();
Q_INVOKABLE void verify(uint8_t timeout); Q_INVOKABLE void verify(bool captureImage, uint8_t timeout);
Q_INVOKABLE void enroll(const QString &username, bool persistence, 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); Q_INVOKABLE void enrollExtended(const QString &username, bool persistence, uint8_t timeout);
Q_INVOKABLE void deleteUser(uint16_t userid); Q_INVOKABLE void deleteUser(uint16_t userid);
@ -75,7 +75,7 @@ protected:
void onNewVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed); void onNewVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed);
void onNewPalmFeature(const PalmFeature &feature); void onNewPalmFeature(const PalmFeature &feature);
void onErrorOccurred(const QString &error); void onErrorOccurred(const QString &error);
void onNewEnrolledImageInfo(uint32_t size, const uint8_t *md5); void onNewImageInfo(ModuleCommunication::MessageId messageId, uint32_t size, const uint8_t *md5);
void onNewImageSliceData(const std::vector<uint8_t> &data); void onNewImageSliceData(const std::vector<uint8_t> &data);
void onCommandStarted(ModuleCommunication::MessageId messageId); void onCommandStarted(ModuleCommunication::MessageId messageId);
void onCommandFinished(ModuleCommunication::MessageId messageId, ModuleCommunication::MessageStatus status); void onCommandFinished(ModuleCommunication::MessageId messageId, ModuleCommunication::MessageStatus status);
@ -87,13 +87,15 @@ private:
std::shared_ptr<Database> m_database; std::shared_ptr<Database> m_database;
bool m_persistenceMode = true; // 模组持续识别 bool m_persistenceMode = true; // 模组持续识别
bool m_verifyExtendedMode = false;
bool m_persistenceModeStarted = false; bool m_persistenceModeStarted = false;
int m_persistenceVerifyInterval = 1; int m_persistenceVerifyInterval = 1;
QTimer *m_verifyTimer = nullptr; QTimer *m_verifyTimer = nullptr;
uint32_t m_enrolledImageSize = 0; ModuleCommunication::MessageId m_palmImageId; // 通过哪个指令获取的图片
QString m_enrollUsername; uint32_t m_palmImageSize = 0;
QByteArray m_enrollYImageBuffer; QString m_palmUsername;
QByteArray m_palmYImageBuffer;
std::chrono::system_clock::time_point m_startUploadTime; std::chrono::system_clock::time_point m_startUploadTime;
uint32_t m_uploadImageSendedSize; uint32_t m_uploadImageSendedSize;

View File

@ -34,7 +34,7 @@ bool ModuleCommunication::open(const QString &portName, int baudRate) {
} }
void ModuleCommunication::verify(uint8_t timeout) { void ModuleCommunication::verify(uint8_t timeout) {
VerifyInfo data = {0}; VerifyRequest data = {0};
data.timeout = timeout; data.timeout = timeout;
auto [frameData, frameSize] = generateFrame(Verify, reinterpret_cast<const uint8_t *>(&data), sizeof(data)); auto [frameData, frameSize] = generateFrame(Verify, reinterpret_cast<const uint8_t *>(&data), sizeof(data));
@ -45,6 +45,18 @@ void ModuleCommunication::verify(uint8_t timeout) {
LOG_CAT(info, GUI) << Separator; 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() { void ModuleCommunication::reset() {
auto [frameData, frameSize] = generateFrame(Reset); auto [frameData, frameSize] = generateFrame(Reset);
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize); m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
@ -102,8 +114,7 @@ void ModuleCommunication::requestEnrolledImage(uint32_t offset, uint32_t size) {
ImageSliceRequest request; ImageSliceRequest request;
request.offset = htonl(offset); request.offset = htonl(offset);
request.size = htonl(size); request.size = htonl(size);
auto [data, frameSize] = auto [data, frameSize] = generateFrame(GetImage, reinterpret_cast<const uint8_t *>(&request), sizeof(request));
generateFrame(GetEnrolledImage, reinterpret_cast<const uint8_t *>(&request), sizeof(request));
m_serialPort->write(reinterpret_cast<const char *>(data), frameSize); m_serialPort->write(reinterpret_cast<const char *>(data), frameSize);
// 打印太耗时 // 打印太耗时
// LOG_CAT(info, GUI) << "发送获取图片指令: " << protocolDataFormatString(data, frameSize); // LOG_CAT(info, GUI) << "发送获取图片指令: " << protocolDataFormatString(data, frameSize);
@ -142,6 +153,12 @@ void ModuleCommunication::requestCurrentStatus() {
LOG_CAT(info, GUI) << Separator; LOG_CAT(info, GUI) << Separator;
} }
void ModuleCommunication::setDebugEnabled(bool enabled) {
uint8_t data = enabled ? 0x01 : 0x00;
auto [frameData, frameSize] = generateFrame(EnableDebug, &data, sizeof(data));
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
}
void ModuleCommunication::requestUniqueId() { void ModuleCommunication::requestUniqueId() {
auto [frameData, frameSize] = generateFrame(GetUniqueID); auto [frameData, frameSize] = generateFrame(GetUniqueID);
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize); m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
@ -168,10 +185,11 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
LOG_CAT(info, GUI) << Separator; LOG_CAT(info, GUI) << Separator;
break; break;
} }
case Verify: { case Verify:
case VerifyExtended: {
LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size); LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size);
if (result == Success) { if (result == Success) {
auto info = reinterpret_cast<const VerifyDataReply *>(data + 7); auto info = reinterpret_cast<const VerifyReply *>(data + 7);
uint16_t userid = ntohs(info->userid); uint16_t userid = ntohs(info->userid);
uint16_t elapsed = ntohs(info->elapsed); uint16_t elapsed = ntohs(info->elapsed);
LOG_CAT(info, GUI) << "用户ID: " << userid LOG_CAT(info, GUI) << "用户ID: " << userid
@ -183,18 +201,26 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
} else if (result == Rejected) { } else if (result == Rejected) {
LOG_CAT(info, GUI) << "模组拒绝该命令。"; LOG_CAT(info, GUI) << "模组拒绝该命令。";
} else if (result == Failed4UnknownUser) { } else if (result == Failed4UnknownUser) {
auto info = reinterpret_cast<const VerifyDataReply *>(data + 7); auto info = reinterpret_cast<const VerifyReply *>(data + 7);
uint16_t elapsed = ntohs(info->elapsed); uint16_t elapsed = ntohs(info->elapsed);
emit newVerifyResult(InvalidUserId, "", elapsed); emit newVerifyResult(InvalidUserId, "", elapsed);
LOG_CAT(info, GUI) << "未录入用户, 耗时: " << elapsed << "ms"; LOG_CAT(info, GUI) << "未录入用户, 耗时: " << elapsed << "ms";
} else if (result == Failed4UnknownReason) { } else if (result == Failed4UnknownReason) {
auto info = reinterpret_cast<const VerifyDataReply *>(data + 7); auto info = reinterpret_cast<const VerifyReply *>(data + 7);
uint16_t elapsed = ntohs(info->elapsed); uint16_t elapsed = ntohs(info->elapsed);
emit newVerifyResult(InvalidUserId, "", elapsed); emit newVerifyResult(InvalidUserId, "", elapsed);
LOG_CAT(info, GUI) << "未知错误, 耗时: " << elapsed << "ms"; LOG_CAT(info, GUI) << "未知错误, 耗时: " << elapsed << "ms";
} else { } else {
LOG_CAT(info, GUI) << "未知错误(" << static_cast<int>(result) << ")。"; LOG_CAT(info, GUI) << "未知错误(" << static_cast<int>(result) << ")。";
} }
if (replyId == VerifyExtended) {
auto info = reinterpret_cast<const VerifyExtendReply *>(data + 7);
uint16_t width = ntohs(info->image_width);
uint16_t height = ntohs(info->image_height);
if ((width > 0) && (height > 0)) {
emit newImageInfo(static_cast<MessageId>(replyId), width * height, info->md5);
}
}
LOG_CAT(info, GUI) << Separator; LOG_CAT(info, GUI) << Separator;
break; break;
} }
@ -205,6 +231,8 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
LOG_CAT(info, GUI) << "注册成功,用户ID: " << ntohs(info->userid); LOG_CAT(info, GUI) << "注册成功,用户ID: " << ntohs(info->userid);
} else if (result == Failed4Timeout) { } else if (result == Failed4Timeout) {
LOG_CAT(info, GUI) << "识别超时。"; LOG_CAT(info, GUI) << "识别超时。";
} else {
LOG_CAT(info, GUI) << "未知错误(" << static_cast<int>(result) << ")。";
} }
LOG_CAT(info, GUI) << Separator; LOG_CAT(info, GUI) << Separator;
break; break;
@ -217,19 +245,21 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
uint16_t height = ntohs(info->image_height); uint16_t height = ntohs(info->image_height);
LOG_CAT(info, GUI) << "注册成功,用户ID: " << ntohs(info->userid) << ", 图片大小: " << width << "x" LOG_CAT(info, GUI) << "注册成功,用户ID: " << ntohs(info->userid) << ", 图片大小: " << width << "x"
<< height; << height;
emit newEnrolledImageInfo(width * height, info->md5); emit newImageInfo(static_cast<MessageId>(replyId), width * height, info->md5);
} else {
LOG_CAT(info, GUI) << "未知错误(" << static_cast<int>(result) << ")。";
} }
LOG_CAT(info, GUI) << Separator; LOG_CAT(info, GUI) << Separator;
break; break;
} }
case GetEnrolledImage: { case GetImage: {
// LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size);
if (result == Success) { if (result == Success) {
auto info = reinterpret_cast<const ImageSliceReply *>(data + 7); auto info = reinterpret_cast<const ImageSliceReply *>(data + 7);
uint32_t sliceSize = ntohl(info->size); uint32_t sliceSize = ntohl(info->size);
emit newImageSliceData(std::vector<uint8_t>(info->data, info->data + sliceSize)); emit newImageSliceData(std::vector<uint8_t>(info->data, info->data + sliceSize));
} else {
LOG(info) << "GetImage failed, status: " << static_cast<int>(result);
} }
// LOG_CAT(info, GUI) << Separator;
break; break;
} }
case DeleteUser: { case DeleteUser: {
@ -279,6 +309,10 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
LOG_CAT(info, GUI) << Separator; LOG_CAT(info, GUI) << Separator;
break; break;
} }
case EnableDebug: {
LOG(info) << "set moudle debug mode: " << (result == Success);
break;
}
default: default:
LOG(warning) << "unknown reply command: 0x" << (static_cast<int>(replyId) & 0xff) LOG(warning) << "unknown reply command: 0x" << (static_cast<int>(replyId) & 0xff)
<< ", data: " << protocolDataFormatString(data, size); << ", data: " << protocolDataFormatString(data, size);
@ -307,6 +341,11 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
LOG_CAT(info, GUI) << Separator; LOG_CAT(info, GUI) << Separator;
break; break;
} }
case DebugInfo: {
auto message = reinterpret_cast<const char *>(data + 6);
LOG_CAT(info, GUI) << "模组日志: " << message;
break;
}
default: default:
LOG(warning) << "unknown note command: 0x" << (static_cast<int>(noteId) & 0xff) LOG(warning) << "unknown note command: 0x" << (static_cast<int>(noteId) & 0xff)
<< ", data: " << protocolDataFormatString(data, size); << ", data: " << protocolDataFormatString(data, size);

View File

@ -22,11 +22,13 @@ public:
Reset = 0x10, Reset = 0x10,
GetCurrentStatus = 0x11, GetCurrentStatus = 0x11,
Verify = 0x12, Verify = 0x12,
VerifyExtended = 0x16,
EnrollSingle = 0x1D, EnrollSingle = 0x1D,
EnrollExtended = 0x1E, EnrollExtended = 0x1E,
GetEnrolledImage = 0x1F, GetImage = 0x1F, // 获取图片数据通过VerifyExtended或EnrollExtended保存的
DeleteUser = 0x20, DeleteUser = 0x20,
DeleteAll = 0x21, DeleteAll = 0x21,
EnableDebug = 0x82,
GetUniqueID = 0xAC, GetUniqueID = 0xAC,
UploadImageInfo = 0xF6, UploadImageInfo = 0xF6,
UploadImageData = 0xF7, UploadImageData = 0xF7,
@ -38,6 +40,7 @@ public:
Ready = 0x00, Ready = 0x00,
PalmState = 0x01, PalmState = 0x01,
UnknownError = 0x02, UnknownError = 0x02,
DebugInfo = 0x55,
}; };
enum MessageStatus : uint8_t { enum MessageStatus : uint8_t {
Success = 0, Success = 0,
@ -60,8 +63,8 @@ public:
}; };
#pragma pack(1) #pragma pack(1)
struct VerifyInfo { struct VerifyRequest {
uint8_t powerDownRightAway; // power down right away after verifying uint8_t save_image;
uint8_t timeout; // timeout, unit second, default 10s uint8_t timeout; // timeout, unit second, default 10s
}; };
struct VerifyNoteInfo { struct VerifyNoteInfo {
@ -106,12 +109,19 @@ public:
uint8_t data[0]; uint8_t data[0];
}; };
struct VerifyDataReply { struct VerifyReply {
uint16_t userid; uint16_t userid;
uint8_t username[UsernameSize]; // 32Bytes uint8_t username[UsernameSize]; // 32Bytes
uint16_t elapsed; // 此时识别耗时时间 uint16_t elapsed; // 此时识别耗时时间
}; };
struct VerifyExtendReply : public VerifyReply {
uint16_t image_width;
uint16_t image_height;
uint8_t image_format; // 0: 只有Y分量,灰度图
uint8_t md5[16];
};
struct UploadImageInformation { struct UploadImageInformation {
uint8_t operation; // 0:图片录入掌静脉 uint8_t operation; // 0:图片录入掌静脉
uint8_t format; // 0: 灰度图(纯Y分量) uint8_t format; // 0: 灰度图(纯Y分量)
@ -136,7 +146,8 @@ public:
#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);
Q_INVOKABLE void verify(uint8_t timeout); void verify(uint8_t timeout);
void verifyExtended(bool captureImage, uint8_t timeout);
Q_INVOKABLE void reset(); Q_INVOKABLE void reset();
void enroll(const std::string &username, bool persistence, uint8_t timeout); void enroll(const std::string &username, bool persistence, uint8_t timeout);
@ -149,6 +160,7 @@ public:
void uploadImageInfo(const UploadImageInformation &info); void uploadImageInfo(const UploadImageInformation &info);
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);
MessageId currentMessageId() const; MessageId currentMessageId() const;
static std::string protocolDataFormatString(const uint8_t *data, int size); static std::string protocolDataFormatString(const uint8_t *data, int size);
@ -161,7 +173,7 @@ signals:
*/ */
void newVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed); void newVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed);
void newPalmFeature(const PalmFeature &feature); void newPalmFeature(const PalmFeature &feature);
void newEnrolledImageInfo(uint32_t size, const uint8_t *md5); void newImageInfo(MessageId id, uint32_t size, const uint8_t *md5);
void newImageSliceData(const std::vector<uint8_t> &data); void newImageSliceData(const std::vector<uint8_t> &data);
void errorOccurred(const QString &error); void errorOccurred(const QString &error);
void commandStarted(ModuleCommunication::MessageId messageId); void commandStarted(ModuleCommunication::MessageId messageId);

View File

@ -87,6 +87,12 @@ ColumnLayout {
checked: App.persistenceMode checked: App.persistenceMode
onToggled: App.persistenceMode = !App.persistenceMode onToggled: App.persistenceMode = !App.persistenceMode
} }
Text {
text: qsTr("保存图片")
}
Switch {
id: extendedVerifyMode
}
Text { Text {
text: qsTr("识别间隔(s)") text: qsTr("识别间隔(s)")
} }
@ -104,7 +110,8 @@ ColumnLayout {
} else { } else {
App.persistenceVerifyInterval = parseInt( App.persistenceVerifyInterval = parseInt(
verifyIntetval.text) verifyIntetval.text)
App.verify(parseInt(verifyTimeout.text)) App.verify(extendedVerifyMode.checked,
parseInt(verifyTimeout.text))
} }
} }
} }
@ -153,6 +160,15 @@ ColumnLayout {
text: "ID查询" text: "ID查询"
onClicked: App.module.requestUniqueId() onClicked: App.module.requestUniqueId()
} }
Row {
Text {
text: qsTr("日志")
}
Switch {
id: debugMode
onToggled: App.module.setDebugEnabled(debugMode.checked)
}
}
} }
} }
} }