forked from IntelRealSense/RealSenseID
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerialPacket.h
134 lines (117 loc) · 3.02 KB
/
SerialPacket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020-2021 Intel Corporation. All Rights Reserved.
#pragma once
//
// Serial packet spec (little endian for all uint16_t and uint32_t fields)
//
#include <cstdint>
#include <string.h>
#pragma pack(push)
#pragma pack(1)
namespace RealSenseID
{
namespace PacketManager
{
static const unsigned char ProtocolVer = 0;
static const size_t MaxUserIdSize = 15;
struct FaMessage
{
char user_id[MaxUserIdSize+1]; // ascii only. '\0' terminated
char fa_status; // ascii status number (e.g. '0', '1', etc.)
};
struct DataMessage
{
char data[1936]; // any binary data
};
enum class SyncByte : char
{
Sync1 = '@',
Sync2 = 'F',
EndOfMessage = '$' // end of message
};
enum class MsgId : char
{
MinFa = 'A',
Reply = 'Y',
Result = 'R',
Progress = 'P',
Hint = 'H',
Enroll = 'E',
EnrollFaceprintsExtraction = 'T',
Authenticate = 'A',
AuthenticateFaceprintsExtraction = 'X',
AuthenticateLoop = 'O',
AuthenticateLoopFaceprintsExtraction = 'L',
RemoveUser = 'D',
RemoveAllUsers = 'C',
Cancel = 'S',
MaxFa = 'Z',
SetAuthSettings = 'k',
GetAuthSettings = 'g',
GetUserIds = 'u',
GetNumberOfUsers = 'n',
StandBy = 't',
Faceprints = 'f',
HostEcdhKey = 'c',
DeviceEcdhKey = 's',
HostEcdsaKey = 'h',
DeviceEcdsaKey = 'd',
Versioning = 'v',
SerialNumber = 'i',
Ping = 'p'
};
struct SerialPacket
{
SyncByte sync1;
SyncByte sync2;
unsigned char protocol_ver;
MsgId id; //'A'-'Z' fa message, 'a-'z' data message
unsigned char iv[16];
struct
{
uint32_t sequence_number;
char sequence_number_pad[12]; // 0 pad for encryption purposes
union {
FaMessage fa_msg;
DataMessage data_msg;
} message;
} payload;
// end of message bytes
SyncByte eom[3]; // "$$$"
char eol;
char hmac[32];
SerialPacket();
};
//
// fa packet
//
struct FaPacket : public SerialPacket
{
FaPacket(MsgId id, const char* user_id, char status);
FaPacket(MsgId id);
const char* GetUserId() const;
char GetStatusCode();
};
// data packet
struct DataPacket : public SerialPacket
{
// copy data to packet. pad with zeros if data_size is smaller than actual reserved data size
DataPacket(MsgId id, char* data, size_t data_size);
DataPacket(MsgId id);
const DataMessage& Data() const;
};
bool IsFaPacket(const SerialPacket& packet); // if MsgId in the 'A'..'Z' range
bool IsDataPacket(const SerialPacket& packet); // if MsgId in the 'a'..'z' range
namespace Commands
{
static const char* binmode0 = "\nbinmode 0\n";
static const char* init_debug_uart = "\ninit 0\n";
static const char* init_host_uart = "\ninit 1 1\n";
static const char* init_usb = "\ninit 2 1\n";
static const char* binary1 = "\n@Fbinary 1\n";
static const char* binary2 = "\n@Fbinary 2\n";
static const char* reset = "\nreset\n";
} // namespace Commands
} // namespace PacketManager
}; // namespace RealSenseID
#pragma pack(pop)