-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.ino
131 lines (107 loc) · 2.67 KB
/
database.ino
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
#include <Arduino.h>
#include <Adafruit_Fingerprint.h>
HardwareSerial serialPort(2);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&serialPort);
int getFingerprintIDez();
void printHex(int num, int precision);
uint8_t downloadFingerprintTemplate(uint16_t id);
void setup()
{
while (!Serial)
;
Serial.begin(9600);
Serial.println("Fingerprint template extractor");
finger.begin(57600);
if (finger.verifyPassword())
{
Serial.println("Found fingerprint sensor!");
}
else
{
Serial.println("Did not find fingerprint sensor :(");
while (1)
;
}
for (int finger = 1; finger < 10; finger++)
{
downloadFingerprintTemplate(finger);
}
}
uint8_t downloadFingerprintTemplate(uint16_t id)
{
Serial.println("------------------------------------");
Serial.print("Attempting to load #");
Serial.println(id);
uint8_t p = finger.loadModel(id);
switch (p)
{
case FINGERPRINT_OK:
Serial.print("Template ");
Serial.print(id);
Serial.println(" loaded");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
default:
Serial.print("Unknown error ");
Serial.println(p);
return p;
}
Serial.print("Attempting to get #");
Serial.println(id);
p = finger.getModel();
switch (p)
{
case FINGERPRINT_OK:
Serial.print("Template ");
Serial.print(id);
Serial.println(" transferring:");
break;
default:
Serial.print("Unknown error ");
Serial.println(p);
return p;
}
uint8_t bytesReceived[534];
memset(bytesReceived, 0xff, 534);
uint32_t starttime = millis();
int i = 0;
while (i < 534 && (millis() - starttime) < 20000)
{
if (serialPort.available())
{
bytesReceived[i++] = serialPort.read();
}
}
Serial.print(i);
Serial.println(" bytes read.");
Serial.println("Decoding packet...");
uint8_t fingerTemplate[512]; // the real template
memset(fingerTemplate, 0xff, 512);
// filtering only the data packets
int uindx = 9, index = 0;
memcpy(fingerTemplate + index, bytesReceived + uindx, 256);
uindx += 256;
uindx += 2;
uindx += 9;
index += 256;
memcpy(fingerTemplate + index, bytesReceived + uindx, 256);
for (int i = 0; i < 512; ++i)
{
printHex(fingerTemplate[i], 2);
}
Serial.println("\ndone.");
return p;
}
void printHex(int num, int precision)
{
char tmp[16];
char format[128];
sprintf(format, "%%.%dX", precision);
sprintf(tmp, format, num);
Serial.print(tmp);
}
void loop()
{
}