1.加入note id处理。
This commit is contained in:
parent
48ebf2be92
commit
4febb5fb7f
@ -58,6 +58,18 @@ void ModuleCommunication::enroll(const std::string &username, uint8_t timeout) {
|
|||||||
LOG_CAT(info, GUI) << Separator;
|
LOG_CAT(info, GUI) << Separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModuleCommunication::enrollEx(const std::string &username, uint8_t timeout) {
|
||||||
|
EnrollData data = {0};
|
||||||
|
data.timeout = timeout;
|
||||||
|
strncpy(reinterpret_cast<char *>(data.username), username.c_str(), sizeof(data.username));
|
||||||
|
auto [frameData, frameSize] = generateFrame(EnrollGetImage, reinterpret_cast<const uint8_t *>(&data), sizeof(data));
|
||||||
|
m_serialPort->write(reinterpret_cast<const char *>(frameData), frameSize);
|
||||||
|
|
||||||
|
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) {
|
void ModuleCommunication::deleteUser(uint16_t userid) {
|
||||||
uint16_t n = htons(userid);
|
uint16_t n = htons(userid);
|
||||||
auto [frameData, frameSize] = generateFrame(DeleteUser, reinterpret_cast<const uint8_t *>(&n), sizeof(n));
|
auto [frameData, frameSize] = generateFrame(DeleteUser, reinterpret_cast<const uint8_t *>(&n), sizeof(n));
|
||||||
@ -74,6 +86,17 @@ void ModuleCommunication::deleteAll() {
|
|||||||
LOG_CAT(info, GUI) << Separator;
|
LOG_CAT(info, GUI) << Separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModuleCommunication::requestEnrolledImage(uint32_t offset, uint32_t size) {
|
||||||
|
ImageSliceRequest request;
|
||||||
|
request.offset = htonl(offset);
|
||||||
|
request.size = htonl(size);
|
||||||
|
auto [data, frameSize] =
|
||||||
|
generateFrame(GetEnrolledImage, reinterpret_cast<const uint8_t *>(&request), sizeof(request));
|
||||||
|
m_serialPort->write(reinterpret_cast<const char *>(data), frameSize);
|
||||||
|
LOG_CAT(info, GUI) << "发送获取图片指令: " << protocolDataFormatString(data, frameSize);
|
||||||
|
LOG_CAT(info, GUI) << Separator;
|
||||||
|
}
|
||||||
|
|
||||||
void ModuleCommunication::requestPalmFeature(uint16_t userid) {
|
void ModuleCommunication::requestPalmFeature(uint16_t userid) {
|
||||||
uint16_t n = htons(userid);
|
uint16_t n = htons(userid);
|
||||||
auto [frameData, frameSize] = generateFrame(RequestPalmFeature, reinterpret_cast<const uint8_t *>(&n), sizeof(n));
|
auto [frameData, frameSize] = generateFrame(RequestPalmFeature, reinterpret_cast<const uint8_t *>(&n), sizeof(n));
|
||||||
@ -151,6 +174,28 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
|
|||||||
LOG_CAT(info, GUI) << Separator;
|
LOG_CAT(info, GUI) << Separator;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case EnrollGetImage: {
|
||||||
|
LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size);
|
||||||
|
if (result == Success) {
|
||||||
|
auto info = reinterpret_cast<const EnrolledImageReply *>(data + 7);
|
||||||
|
uint16_t lineSize = ntohs(info->lineSize);
|
||||||
|
uint16_t height = ntohs(info->height);
|
||||||
|
LOG_CAT(info, GUI) << "图片大小: " << ntohs(info->width) << "x" << height
|
||||||
|
<< ", line size: " << lineSize;
|
||||||
|
emit newEnrolledImageInfo(lineSize * height, info->md5);
|
||||||
|
}
|
||||||
|
LOG_CAT(info, GUI) << Separator;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GetEnrolledImage: {
|
||||||
|
// LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size);
|
||||||
|
if (result == Success) {
|
||||||
|
auto info = reinterpret_cast<const ImageSliceReply *>(data + 7);
|
||||||
|
emit newImageSliceData(std::vector<uint8_t>(info->data, info->data + ntohl(info->size)));
|
||||||
|
}
|
||||||
|
// LOG_CAT(info, GUI) << Separator;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case DeleteUser: {
|
case DeleteUser: {
|
||||||
if (result == Success) {
|
if (result == Success) {
|
||||||
LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size);
|
LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size);
|
||||||
@ -180,8 +225,7 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
|
|||||||
<< ", 特征值长度: " << ntohs(info->featureTotalSize);
|
<< ", 特征值长度: " << ntohs(info->featureTotalSize);
|
||||||
PalmFeature feature;
|
PalmFeature feature;
|
||||||
feature.username = std::string_view(reinterpret_cast<const char *>(info->username));
|
feature.username = std::string_view(reinterpret_cast<const char *>(info->username));
|
||||||
const uint8_t *start = data + 7 + sizeof(PalmFeatureHeader);
|
feature.feature = std::vector<uint8_t>(info->feature, info->feature + ntohs(info->featureTotalSize));
|
||||||
feature.feature = std::vector<uint8_t>(start, start + ntohs(info->featureTotalSize));
|
|
||||||
emit newPalmFeature(feature);
|
emit newPalmFeature(feature);
|
||||||
}
|
}
|
||||||
LOG_CAT(info, GUI) << Separator;
|
LOG_CAT(info, GUI) << Separator;
|
||||||
@ -211,11 +255,17 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
|
|||||||
LOG_CAT(info, GUI) << Separator;
|
LOG_CAT(info, GUI) << Separator;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0x01: { // 模组返回的数据为当前帧的手掌状态
|
case PalmState: { // 模组返回的数据为当前帧的手掌状态
|
||||||
auto info = reinterpret_cast<const VerifyNoteInfo *>(data + 7);
|
auto info = reinterpret_cast<const VerifyNoteInfo *>(data + 7);
|
||||||
LOG(info) << info->state;
|
LOG(info) << info->state;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case UnknownError: {
|
||||||
|
LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size);
|
||||||
|
LOG_CAT(info, GUI) << "未知错误。";
|
||||||
|
LOG_CAT(info, GUI) << Separator;
|
||||||
|
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);
|
||||||
|
@ -19,6 +19,8 @@ public:
|
|||||||
Reset = 0x10,
|
Reset = 0x10,
|
||||||
Verify = 0x12,
|
Verify = 0x12,
|
||||||
EnrollSingle = 0x1D,
|
EnrollSingle = 0x1D,
|
||||||
|
EnrollGetImage = 0x1E,
|
||||||
|
GetEnrolledImage = 0x1F,
|
||||||
DeleteUser = 0x20,
|
DeleteUser = 0x20,
|
||||||
DeleteAll = 0x21,
|
DeleteAll = 0x21,
|
||||||
RegisterPalmFeature = 0xF9,
|
RegisterPalmFeature = 0xF9,
|
||||||
@ -27,6 +29,8 @@ public:
|
|||||||
|
|
||||||
enum NoteId : uint8_t {
|
enum NoteId : uint8_t {
|
||||||
Ready = 0x00,
|
Ready = 0x00,
|
||||||
|
PalmState = 0x01,
|
||||||
|
UnknownError = 0x02,
|
||||||
};
|
};
|
||||||
enum MessageStatus : uint8_t {
|
enum MessageStatus : uint8_t {
|
||||||
Success = 0,
|
Success = 0,
|
||||||
@ -77,6 +81,23 @@ public:
|
|||||||
uint8_t face_direction; // depleted, user ignore this field
|
uint8_t face_direction; // depleted, user ignore this field
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct EnrolledImageReply {
|
||||||
|
uint16_t width;
|
||||||
|
uint16_t lineSize;
|
||||||
|
uint16_t height;
|
||||||
|
uint8_t md5[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImageSliceRequest {
|
||||||
|
uint32_t offset;
|
||||||
|
uint32_t size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ImageSliceReply {
|
||||||
|
uint32_t size;
|
||||||
|
uint8_t data[0];
|
||||||
|
};
|
||||||
|
|
||||||
struct VerifyDataReply {
|
struct VerifyDataReply {
|
||||||
uint16_t userid;
|
uint16_t userid;
|
||||||
uint8_t username[UsernameSize]; // 32Bytes uint8_t admin;
|
uint8_t username[UsernameSize]; // 32Bytes uint8_t admin;
|
||||||
@ -89,6 +110,7 @@ public:
|
|||||||
uint8_t admin; // 是否管理员,YES:1 NO:0
|
uint8_t admin; // 是否管理员,YES:1 NO:0
|
||||||
uint8_t featureDataMd5[16]; // 整体特征数据的MD5值
|
uint8_t featureDataMd5[16]; // 整体特征数据的MD5值
|
||||||
uint16_t featureTotalSize; // 特征数据总长度
|
uint16_t featureTotalSize; // 特征数据总长度
|
||||||
|
uint8_t feature[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
@ -98,13 +120,17 @@ public:
|
|||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
void enroll(const std::string &username, uint8_t timeout);
|
void enroll(const std::string &username, uint8_t timeout);
|
||||||
|
void enrollEx(const std::string &username, uint8_t timeout);
|
||||||
void deleteUser(uint16_t userid);
|
void deleteUser(uint16_t userid);
|
||||||
void deleteAll();
|
void deleteAll();
|
||||||
|
void requestEnrolledImage(uint32_t offset, uint32_t size);
|
||||||
|
|
||||||
void requestPalmFeature(uint16_t userid);
|
void requestPalmFeature(uint16_t userid);
|
||||||
void enrollPalmFeature(uint16_t userid, const PalmFeature &feature);
|
void enrollPalmFeature(uint16_t userid, const PalmFeature &feature);
|
||||||
signals:
|
signals:
|
||||||
void newPalmFeature(const PalmFeature &feature);
|
void newPalmFeature(const PalmFeature &feature);
|
||||||
|
void newEnrolledImageInfo(uint32_t size, const uint8_t *md5);
|
||||||
|
void newImageSliceData(const std::vector<uint8_t> &data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void processPackage(const uint8_t *data, uint16_t size);
|
void processPackage(const uint8_t *data, uint16_t size);
|
||||||
|
@ -128,6 +128,10 @@ QGroupBox *Widget::initializeEnrollGroupBox() {
|
|||||||
connect(m_enrollButton, &QPushButton::clicked, this, &Widget::onEnrollButtonClicked);
|
connect(m_enrollButton, &QPushButton::clicked, this, &Widget::onEnrollButtonClicked);
|
||||||
layout->addRow("", m_enrollButton);
|
layout->addRow("", m_enrollButton);
|
||||||
|
|
||||||
|
auto enrollExButton = new QPushButton("注册(EX)");
|
||||||
|
connect(enrollExButton, &QPushButton::clicked, this, &Widget::onEnrollExButtonClicked);
|
||||||
|
layout->addRow("", enrollExButton);
|
||||||
|
|
||||||
ret->setLayout(layout);
|
ret->setLayout(layout);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -211,6 +215,26 @@ void Widget::onNewPalmFeature(const PalmFeature &feature) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::onNewEnrolledImageInfo(uint32_t size, const uint8_t *md5) {
|
||||||
|
m_enrolledImageSize = size;
|
||||||
|
m_receivedImageSize = 0;
|
||||||
|
m_communication->requestEnrolledImage(0, 1024);
|
||||||
|
m_ofs = std::make_shared<std::ofstream>("palm.yuv", std::ofstream::binary);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::onNewImageSliceData(const std::vector<uint8_t> &data) {
|
||||||
|
m_receivedImageSize += data.size();
|
||||||
|
LOG(info) << "onNewImageSliceData:" << data.size() << ", already received: " << m_receivedImageSize
|
||||||
|
<< ", total size: " << m_enrolledImageSize;
|
||||||
|
m_ofs->write(reinterpret_cast<const char *>(data.data()), data.size());
|
||||||
|
if (m_receivedImageSize < m_enrolledImageSize) {
|
||||||
|
m_communication->requestEnrolledImage(m_receivedImageSize, 1024);
|
||||||
|
} else {
|
||||||
|
LOG(info) << "request finished.";
|
||||||
|
m_ofs.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::onSerialConnectButtonClicked() {
|
void Widget::onSerialConnectButtonClicked() {
|
||||||
auto button = dynamic_cast<QPushButton *>(sender());
|
auto button = dynamic_cast<QPushButton *>(sender());
|
||||||
if (button == nullptr) return;
|
if (button == nullptr) return;
|
||||||
@ -219,6 +243,9 @@ void Widget::onSerialConnectButtonClicked() {
|
|||||||
auto portName = m_serialComboBox->currentText();
|
auto portName = m_serialComboBox->currentText();
|
||||||
m_communication = std::make_shared<ModuleCommunication>();
|
m_communication = std::make_shared<ModuleCommunication>();
|
||||||
connect(m_communication.get(), &ModuleCommunication::newPalmFeature, this, &Widget::onNewPalmFeature);
|
connect(m_communication.get(), &ModuleCommunication::newPalmFeature, this, &Widget::onNewPalmFeature);
|
||||||
|
connect(m_communication.get(), &ModuleCommunication::newEnrolledImageInfo, this,
|
||||||
|
&Widget::onNewEnrolledImageInfo);
|
||||||
|
connect(m_communication.get(), &ModuleCommunication::newImageSliceData, this, &Widget::onNewImageSliceData);
|
||||||
bool status = m_communication->open(portName);
|
bool status = m_communication->open(portName);
|
||||||
if (status) {
|
if (status) {
|
||||||
m_commandGroupBox->setEnabled(true);
|
m_commandGroupBox->setEnabled(true);
|
||||||
@ -248,6 +275,12 @@ void Widget::onEnrollButtonClicked() {
|
|||||||
m_communication->enroll(name.toStdString(), timeout);
|
m_communication->enroll(name.toStdString(), timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::onEnrollExButtonClicked() {
|
||||||
|
auto name = m_enrollNameEdit->text();
|
||||||
|
auto timeout = m_enrollTimeoutEdit->text().toInt();
|
||||||
|
m_communication->enrollEx(name.toStdString(), timeout);
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::onVerifyButtonClicked() {
|
void Widget::onVerifyButtonClicked() {
|
||||||
if (!m_communication) return;
|
if (!m_communication) return;
|
||||||
auto timeout = m_verifyTimeoutEdit->text().toInt();
|
auto timeout = m_verifyTimeoutEdit->text().toInt();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "DataStructure.h"
|
#include "DataStructure.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QTextBrowser;
|
class QTextBrowser;
|
||||||
@ -29,6 +30,7 @@ protected:
|
|||||||
void onUvcRefreshButtonClicked();
|
void onUvcRefreshButtonClicked();
|
||||||
|
|
||||||
void onEnrollButtonClicked();
|
void onEnrollButtonClicked();
|
||||||
|
void onEnrollExButtonClicked();
|
||||||
void onVerifyButtonClicked();
|
void onVerifyButtonClicked();
|
||||||
void onDeleteAllButtonClicked();
|
void onDeleteAllButtonClicked();
|
||||||
void onDeleteButtonClicked();
|
void onDeleteButtonClicked();
|
||||||
@ -44,6 +46,8 @@ protected:
|
|||||||
QGroupBox *initializeUvcGroupBox();
|
QGroupBox *initializeUvcGroupBox();
|
||||||
|
|
||||||
void onNewPalmFeature(const PalmFeature &feature);
|
void onNewPalmFeature(const PalmFeature &feature);
|
||||||
|
void onNewEnrolledImageInfo(uint32_t size, const uint8_t *md5);
|
||||||
|
void onNewImageSliceData(const std::vector<uint8_t> &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QComboBox *m_serialComboBox = nullptr;
|
QComboBox *m_serialComboBox = nullptr;
|
||||||
@ -69,6 +73,10 @@ private:
|
|||||||
|
|
||||||
PalmFeatureTableModel *m_featureModel = nullptr;
|
PalmFeatureTableModel *m_featureModel = nullptr;
|
||||||
QTableView *m_featureTableView = nullptr;
|
QTableView *m_featureTableView = nullptr;
|
||||||
|
|
||||||
|
uint32_t m_enrolledImageSize = 0;
|
||||||
|
uint32_t m_receivedImageSize = 0;
|
||||||
|
std::shared_ptr<std::ofstream> m_ofs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WIDGET_H
|
#endif // WIDGET_H
|
||||||
|
@ -11,7 +11,12 @@ palmDetectionProcess
|
|||||||
facePalmDetectionProcess # 处理每帧,在MPP的回调函数里面
|
facePalmDetectionProcess # 处理每帧,在MPP的回调函数里面
|
||||||
uart_msg_proc() -> cmd_exec()执行串口协议命令
|
uart_msg_proc() -> cmd_exec()执行串口协议命令
|
||||||
|
|
||||||
sock_cmd_exec() 这个函数是干啥的?
|
sock_cmd_exec() 内部线程逻辑之间通信
|
||||||
|
|
||||||
|
线程函数frame_proc_task()
|
||||||
|
algo_cb()->onFacePalmDetectionPassed()->app_server_alive()->sock_cmd_exec:SOCK_CMD__ALIVE_PALM
|
||||||
|
|
||||||
|
ST__PlamRegister()->__PalmRegister() -> PalmFeatureExtract() -> spv2_get_feature()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user