101 lines
2.7 KiB
C
101 lines
2.7 KiB
C
|
#ifndef MODULECOMMUNICATION_H
|
||
|
#define MODULECOMMUNICATION_H
|
||
|
|
||
|
#include <QObject>
|
||
|
#include <memory>
|
||
|
|
||
|
class QSerialPort;
|
||
|
|
||
|
class ModuleCommunication : public QObject {
|
||
|
Q_OBJECT
|
||
|
static constexpr uint32_t UsernameSize = 32;
|
||
|
static constexpr const char *Separator = "----------";
|
||
|
|
||
|
public:
|
||
|
enum MessageId : uint8_t {
|
||
|
Reply = 0,
|
||
|
Note = 0x01,
|
||
|
Verify = 0x12,
|
||
|
EnrollSingle = 0x1D,
|
||
|
DeleteUser = 0x20,
|
||
|
DeleteAll = 0x21,
|
||
|
};
|
||
|
|
||
|
enum NoteId : uint8_t {
|
||
|
Ready = 0x00,
|
||
|
};
|
||
|
enum MessageStatus : uint8_t {
|
||
|
Success = 0,
|
||
|
Rejected = 1,
|
||
|
Aborted = 2,
|
||
|
Failed4Camera = 4,
|
||
|
Failed4UnknownReason = 5,
|
||
|
Failed4InvalidParam = 6,
|
||
|
Failed4NoMemory = 7,
|
||
|
Failed4UnknownUser = 8,
|
||
|
Failed4MaxUser = 9,
|
||
|
Failed4FaceEnrolled = 10,
|
||
|
Failed4LivenessCheck = 12,
|
||
|
Failed4Timeout = 13,
|
||
|
Failed4Authorization = 14,
|
||
|
Failed4ReadFile = 19,
|
||
|
Failed4WriteFile = 20,
|
||
|
Failed4NoEncrypt = 21,
|
||
|
};
|
||
|
|
||
|
#pragma pack(1)
|
||
|
struct VerifyInfo {
|
||
|
uint8_t powerDownRightAway; // power down right away after verifying
|
||
|
uint8_t timeout; // timeout, unit second, default 10s
|
||
|
};
|
||
|
struct VerifyNoteInfo {
|
||
|
int16_t state; // corresponding to PALM_STATE_*
|
||
|
// position
|
||
|
int16_t left; // in pixel
|
||
|
int16_t top;
|
||
|
int16_t right;
|
||
|
int16_t bottom;
|
||
|
// pose
|
||
|
int16_t yaw; // up and down in vertical orientation
|
||
|
int16_t pitch; // right or left turned in horizontal orientation
|
||
|
int16_t roll; // slope
|
||
|
};
|
||
|
|
||
|
struct EnrollData {
|
||
|
uint8_t admin = 0;
|
||
|
uint8_t username[32];
|
||
|
uint8_t palmDirection;
|
||
|
uint8_t timeout;
|
||
|
};
|
||
|
|
||
|
struct EnrollDataReply {
|
||
|
uint16_t userid;
|
||
|
uint8_t face_direction; // depleted, user ignore this field
|
||
|
};
|
||
|
|
||
|
struct VerifyDataReply {
|
||
|
uint16_t userid;
|
||
|
uint8_t username[UsernameSize]; // 32Bytes uint8_t admin;
|
||
|
uint8_t unlockStatus;
|
||
|
};
|
||
|
|
||
|
#pragma pack()
|
||
|
explicit ModuleCommunication(QObject *parent = nullptr);
|
||
|
bool open(const QString &portName);
|
||
|
void verify(uint8_t timeout);
|
||
|
|
||
|
void enroll(const std::string &username, uint8_t timeout);
|
||
|
void deleteUser(uint16_t userid);
|
||
|
void deleteAll();
|
||
|
|
||
|
protected:
|
||
|
void onReadyRead();
|
||
|
std::pair<uint8_t *, uint32_t> generateFrame(MessageId command, const uint8_t *data = nullptr, uint16_t size = 0);
|
||
|
std::string protocolDataFormatString(const uint8_t *data, int size);
|
||
|
|
||
|
private:
|
||
|
std::shared_ptr<QSerialPort> m_serialPort;
|
||
|
};
|
||
|
|
||
|
#endif // MODULECOMMUNICATION_H
|