-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddfinger_testing1.txt
141 lines (116 loc) · 3.85 KB
/
addfinger_testing1.txt
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
135
136
137
138
139
140
141
#include <SoftwareSerial.h>
#define DEBUG 0
SoftwareSerial mySerial(10, 11); // RX, TX
/************************************************************************
Communication Packet
************************************************************************/
byte addFingerPrint0[] = {0x4D, 0x58, 0x10, 0x03, 0x40, 0x00, 0x00, 0xF8};
byte receiveCorrect[] = {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7};
byte operationSuccessAdd[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x31, 0x48};
byte parameterErrorAdd[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x35, 0x4C};
byte processFailureAdd[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x34, 0x4B};
byte timeOutAdd[] = {0x4D, 0x58, 0x30, 0x02, 0x40, 0x33, 0x4A};
/************************************************************************
Variables
************************************************************************/
byte respond[6], operation[7], operationSecond[7];
byte a,b,c,d,e,f,g,h;
int A = 0;
void setup()
{
mySerial.begin(57600);
Serial.begin(9600);
}
void loop()
{
if(A == 0)
{
addFinger0();
if(correctRespond())
operationStart();
delay(1000); // a delay for next operation
}
}
void addFinger0() {
Serial.println("Add fingerprint at ID #0");
mySerial.write(addFingerPrint0, sizeof(addFingerPrint0));
}
bool correctRespond()
{
while(mySerial.available() <= 0) {}; //wait for incoming data
delay(10); // give some time for all incoming bytes to be stored into serial buffer
while(mySerial.available() > 6) // this is to make sure removal of respond from previous command
mySerial.read();
memset(respond, '\0', 6); // clear respond buffer
mySerial.readBytes(respond, 6); //store the remaining data to respond buffer
#if DEBUG
for(byte x=0; x<sizeof(respond); x++)
Serial.print(respond[x], HEX);
Serial.println();
#endif
a = memcmp(receiveCorrect, respond, sizeof(receiveCorrect));
if (a == 0)
{
Serial.println("Receive Correct");
return 1;
}
else
{
Serial.println("Error!");
return 0;
}
}
void operationStart()
{
while(mySerial.available() <= 0) {}; //wait for incoming data
memset(operation, '\0', 7); // clear operation buffer
mySerial.readBytes(operation, 7); //store data
#if DEBUG
for(byte x=0; x<6; x++)
Serial.print(operation[x], HEX);
Serial.println();
#endif
b = memcmp(operationSuccessAdd, operation, sizeof(operationSuccessAdd));
c = memcmp(processFailureAdd, operation, sizeof(processFailureAdd));
d = memcmp(parameterErrorAdd, operation, sizeof(parameterErrorAdd));
e = memcmp(timeOutAdd, operation, sizeof(timeOutAdd));
if (b == 0)
{
Serial.println("First Fingerprint Scanned");
while(mySerial.available() <= 0) {}; //wait for incoming data
memset(operation, '\0', 7); //clear operation buffer
mySerial.readBytes(operation, 7); //store data to buffer
#if DEBUG
for(byte x=0; x<6; x++)
Serial.print(operation[x], HEX);
Serial.println();
#endif
f = memcmp(operationSuccessAdd, operation, sizeof(operationSuccessAdd));
g = memcmp(processFailureAdd, operation, sizeof(processFailureAdd));
h = memcmp(timeOutAdd, operation, sizeof(timeOutAdd));
if (f == 0)
{
Serial.println("Second Fingerprint Scanned");
Serial.println("Fingerprint Added");
A = 1;
}
else
{
if (g == 0)
Serial.println("Fingerprint Process Failure");
else if (h == 0)
Serial.println("Time Out");
Serial.println("Starting new operation!");
}
}
else
{
if (c == 0)
Serial.println("Fingerprint Process Failure");
else if (d == 0)
Serial.println("Parameter Error");
else if (e == 0)
Serial.println("Time Out");
Serial.println("Starting new operation!");
}
}