-
Notifications
You must be signed in to change notification settings - Fork 1
/
FPS_GT511C3.cpp
792 lines (729 loc) · 22.3 KB
/
FPS_GT511C3.cpp
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
#include "FPS_GT511C3.h"
#pragma region -= Command_Packet Definitions =-
// returns the 12 bytes of the generated command packet
// remember to call delete on the returned array
byte* Command_Packet::GetPacketBytes()
{
byte* packetbytes= new byte[12];
// update command before calculating checksum (important!)
word cmd = Command;
command[0] = GetLowByte(cmd);
command[1] = GetHighByte(cmd);
word checksum = _CalculateChecksum();
packetbytes[0] = COMMAND_START_CODE_1;
packetbytes[1] = COMMAND_START_CODE_2;
packetbytes[2] = COMMAND_DEVICE_ID_1;
packetbytes[3] = COMMAND_DEVICE_ID_2;
packetbytes[4] = Parameter[0];
packetbytes[5] = Parameter[1];
packetbytes[6] = Parameter[2];
packetbytes[7] = Parameter[3];
packetbytes[8] = command[0];
packetbytes[9] = command[1];
packetbytes[10] = GetLowByte(checksum);
packetbytes[11] = GetHighByte(checksum);
return packetbytes;
}
// Converts the int to bytes and puts them into the paramter array
void Command_Packet::ParameterFromInt(int i)
{
Parameter[0] = (i & 0x000000ff);
Parameter[1] = (i & 0x0000ff00) >> 8;
Parameter[2] = (i & 0x00ff0000) >> 16;
Parameter[3] = (i & 0xff000000) >> 24;
}
// Returns the high byte from a word
byte Command_Packet::GetHighByte(word w)
{
return (byte)(w>>8)&0x00FF;
}
// Returns the low byte from a word
byte Command_Packet::GetLowByte(word w)
{
return (byte)w&0x00FF;
}
word Command_Packet::_CalculateChecksum()
{
word w = 0;
w += COMMAND_START_CODE_1;
w += COMMAND_START_CODE_2;
w += COMMAND_DEVICE_ID_1;
w += COMMAND_DEVICE_ID_2;
w += Parameter[0];
w += Parameter[1];
w += Parameter[2];
w += Parameter[3];
w += command[0];
w += command[1];
return w;
}
Command_Packet::Command_Packet()
{
};
#pragma endregion
#pragma region -= Response_Packet Definitions =-
// creates and parses a response packet from the finger print scanner
Response_Packet::Response_Packet(byte* buffer, bool UseSerialDebug)
{
CheckParsing(buffer[0], COMMAND_START_CODE_1, COMMAND_START_CODE_1, "COMMAND_START_CODE_1", UseSerialDebug);
CheckParsing(buffer[1], COMMAND_START_CODE_2, COMMAND_START_CODE_2, "COMMAND_START_CODE_2", UseSerialDebug);
CheckParsing(buffer[2], COMMAND_DEVICE_ID_1, COMMAND_DEVICE_ID_1, "COMMAND_DEVICE_ID_1", UseSerialDebug);
CheckParsing(buffer[3], COMMAND_DEVICE_ID_2, COMMAND_DEVICE_ID_2, "COMMAND_DEVICE_ID_2", UseSerialDebug);
CheckParsing(buffer[8], 0x30, 0x31, "AckNak_LOW", UseSerialDebug);
if (buffer[8] == 0x30) ACK = true; else ACK = false;
CheckParsing(buffer[9], 0x00, 0x00, "AckNak_HIGH", UseSerialDebug);
word checksum = CalculateChecksum(buffer, 10);
byte checksum_low = GetLowByte(checksum);
byte checksum_high = GetHighByte(checksum);
CheckParsing(buffer[10], checksum_low, checksum_low, "Checksum_LOW", UseSerialDebug);
CheckParsing(buffer[11], checksum_high, checksum_high, "Checksum_HIGH", UseSerialDebug);
Error = ErrorCodes::ParseFromBytes(buffer[5], buffer[4]);
ParameterBytes[0] = buffer[4];
ParameterBytes[1] = buffer[5];
ParameterBytes[2] = buffer[6];
ParameterBytes[3] = buffer[7];
ResponseBytes[0]=buffer[8];
ResponseBytes[1]=buffer[9];
for (int i=0; i < 12; i++)
{
RawBytes[i]=buffer[i];
}
}
// parses bytes into one of the possible errors from the finger print scanner
Response_Packet::ErrorCodes::Errors_Enum Response_Packet::ErrorCodes::ParseFromBytes(byte high, byte low)
{
Errors_Enum e = INVALID;
if (high == 0x00)
{
}
// grw 01/03/15 - replaced if clause with else clause for any non-zero high byte
// if (high == 0x01)
// {
else {
switch(low)
{
case 0x00: e = NO_ERROR; break;
case 0x01: e = NACK_TIMEOUT; break;
case 0x02: e = NACK_INVALID_BAUDRATE; break;
case 0x03: e = NACK_INVALID_POS; break;
case 0x04: e = NACK_IS_NOT_USED; break;
case 0x05: e = NACK_IS_ALREADY_USED; break;
case 0x06: e = NACK_COMM_ERR; break;
case 0x07: e = NACK_VERIFY_FAILED; break;
case 0x08: e = NACK_IDENTIFY_FAILED; break;
case 0x09: e = NACK_DB_IS_FULL; break;
case 0x0A: e = NACK_DB_IS_EMPTY; break;
case 0x0B: e = NACK_TURN_ERR; break;
case 0x0C: e = NACK_BAD_FINGER; break;
case 0x0D: e = NACK_ENROLL_FAILED; break;
case 0x0E: e = NACK_IS_NOT_SUPPORTED; break;
case 0x0F: e = NACK_DEV_ERR; break;
case 0x10: e = NACK_CAPTURE_CANCELED; break;
case 0x11: e = NACK_INVALID_PARAM; break;
case 0x12: e = NACK_FINGER_IS_NOT_PRESSED; break;
}
}
return e;
}
// Gets an int from the parameter bytes
int Response_Packet::IntFromParameter()
{
int retval = 0;
retval = (retval << 8) + ParameterBytes[3];
retval = (retval << 8) + ParameterBytes[2];
retval = (retval << 8) + ParameterBytes[1];
retval = (retval << 8) + ParameterBytes[0];
return retval;
}
// calculates the checksum from the bytes in the packet
word Response_Packet::CalculateChecksum(byte* buffer, int length)
{
word checksum = 0;
for (int i=0; i<length; i++)
{
checksum +=buffer[i];
}
return checksum;
}
// Returns the high byte from a word
byte Response_Packet::GetHighByte(word w)
{
return (byte)(w>>8)&0x00FF;
}
// Returns the low byte from a word
byte Response_Packet::GetLowByte(word w)
{
return (byte)w&0x00FF;
}
// checks to see if the byte is the proper value, and logs it to the serial channel if not
bool Response_Packet::CheckParsing(byte b, byte propervalue, byte alternatevalue, char* varname, bool UseSerialDebug)
{
bool retval = (b != propervalue) && (b != alternatevalue);
if ((UseSerialDebug) && (retval))
{
Serial.print("Response_Packet parsing error ");
Serial.print(varname);
Serial.print(" ");
Serial.print(propervalue, HEX);
Serial.print(" || ");
Serial.print(alternatevalue, HEX);
Serial.print(" != ");
Serial.println(b, HEX);
}
}
#pragma endregion
#pragma region -= Data_Packet =-
//void Data_Packet::StartNewPacket()
//{
// Data_Packet::NextPacketID = 0;
// Data_Packet::CheckSum = 0;
//}
#pragma endregion
#pragma region -= FPS_GT511C3 Definitions =-
#pragma region -= Constructor/Destructor =-
// Creates a new object to interface with the fingerprint scanner
FPS_GT511C3::FPS_GT511C3(uint8_t rx, uint8_t tx)
//: Serial(rx,tx)
{
pin_RX = rx;
pin_TX = tx;
Serial1.begin(9600);
this->UseSerialDebug = false;
};
// destructor
FPS_GT511C3::~FPS_GT511C3()
{
//Serial1.~SoftwareSerial();
}
#pragma endregion
#pragma region -= Device Commands =-
//Initialises the device and gets ready for commands
void FPS_GT511C3::Open()
{
if (UseSerialDebug) Serial.println("FPS - Open");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::Open;
cp->Parameter[0] = 0x01;
cp->Parameter[1] = 0x00;
cp->Parameter[2] = 0x00;
cp->Parameter[3] = 0x00;
/*
if (on)
{
cp->Parameter[0] = 0x01;
}
else
{
cp->Parameter[0] = 0x00;
*/
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
delete rp;
delete packetbytes;
}
// According to the DataSheet, this does nothing...
// Implemented it for completeness.
void FPS_GT511C3::Close()
{
if (UseSerialDebug) Serial.println("FPS - Close");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::Close;
cp->Parameter[0] = 0x00;
cp->Parameter[1] = 0x00;
cp->Parameter[2] = 0x00;
cp->Parameter[3] = 0x00;
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
delete rp;
delete packetbytes;
};
// Turns on or off the LED backlight
// Parameter: true turns on the backlight, false turns it off
// Returns: True if successful, false if not
bool FPS_GT511C3::SetLED(bool on)
{
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::CmosLed;
if (on)
{
if (UseSerialDebug) Serial.println("FPS - LED on");
cp->Parameter[0] = 0x01;
}
else
{
if (UseSerialDebug) Serial.println("FPS - LED off");
cp->Parameter[0] = 0x00;
}
cp->Parameter[1] = 0x00;
cp->Parameter[2] = 0x00;
cp->Parameter[3] = 0x00;
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
bool retval = true;
if (rp->ACK == false) retval = false;
delete rp;
delete packetbytes;
return retval;
};
// Changes the baud rate of the connection
// Parameter: 9600, 19200, 38400, 57600, 115200
// Returns: True if success, false if invalid baud
// NOTE: Untested (don't have a logic level changer and a voltage divider is too slow)
bool FPS_GT511C3::ChangeBaudRate(int baud)
{
if ((baud == 9600) || (baud == 19200) || (baud == 38400) || (baud == 57600) || (baud == 115200))
{
if (UseSerialDebug) Serial.println("FPS - ChangeBaudRate");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::Open;
cp->ParameterFromInt(baud);
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
bool retval = rp->ACK;
if (retval)
{
Serial1.end();
Serial1.begin(baud);
}
delete rp;
delete packetbytes;
return retval;
}
return false;
}
// Gets the number of enrolled fingerprints
// Return: The total number of enrolled fingerprints
int FPS_GT511C3::GetEnrollCount()
{
if (UseSerialDebug) Serial.println("FPS - GetEnrolledCount");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::GetEnrollCount;
cp->Parameter[0] = 0x00;
cp->Parameter[1] = 0x00;
cp->Parameter[2] = 0x00;
cp->Parameter[3] = 0x00;
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
int retval = rp->IntFromParameter();
delete rp;
delete packetbytes;
return retval;
}
// checks to see if the ID number is in use or not
// Parameter: 0-199
// Return: True if the ID number is enrolled, false if not
bool FPS_GT511C3::CheckEnrolled(int id)
{
if (UseSerialDebug) Serial.println("FPS - CheckEnrolled");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::CheckEnrolled;
cp->ParameterFromInt(id);
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
delete packetbytes;
Response_Packet* rp = GetResponse();
bool retval = false;
retval = rp->ACK;
delete rp;
return retval;
}
// Starts the Enrollment Process
// Parameter: 0-199
// Return:
// 0 - ACK
// 1 - Database is full
// 2 - Invalid Position
// 3 - Position(ID) is already used
int FPS_GT511C3::EnrollStart(int id)
{
if (UseSerialDebug) Serial.println("FPS - EnrollStart");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::EnrollStart;
cp->ParameterFromInt(id);
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
delete packetbytes;
Response_Packet* rp = GetResponse();
int retval = 0;
if (rp->ACK == false)
{
if (rp->Error == Response_Packet::ErrorCodes::NACK_DB_IS_FULL) retval = 1;
if (rp->Error == Response_Packet::ErrorCodes::NACK_INVALID_POS) retval = 2;
if (rp->Error == Response_Packet::ErrorCodes::NACK_IS_ALREADY_USED) retval = 3;
}
delete rp;
return retval;
}
// Gets the first scan of an enrollment
// Return:
// 0 - ACK
// 1 - Enroll Failed
// 2 - Bad finger
// 3 - ID in use
int FPS_GT511C3::Enroll1()
{
if (UseSerialDebug) Serial.println("FPS - Enroll1");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::Enroll1;
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
delete packetbytes;
Response_Packet* rp = GetResponse();
int retval = rp->IntFromParameter();
if (retval < 200) retval = 3; else retval = 0;
if (rp->ACK == false)
{
if (rp->Error == Response_Packet::ErrorCodes::NACK_ENROLL_FAILED) retval = 1;
if (rp->Error == Response_Packet::ErrorCodes::NACK_BAD_FINGER) retval = 2;
}
delete rp;
if (rp->ACK) return 0; else return retval;
}
// Gets the Second scan of an enrollment
// Return:
// 0 - ACK
// 1 - Enroll Failed
// 2 - Bad finger
// 3 - ID in use
int FPS_GT511C3::Enroll2()
{
if (UseSerialDebug) Serial.println("FPS - Enroll2");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::Enroll2;
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
delete packetbytes;
Response_Packet* rp = GetResponse();
int retval = rp->IntFromParameter();
if (retval < 200) retval = 3; else retval = 0;
if (rp->ACK == false)
{
if (rp->Error == Response_Packet::ErrorCodes::NACK_ENROLL_FAILED) retval = 1;
if (rp->Error == Response_Packet::ErrorCodes::NACK_BAD_FINGER) retval = 2;
}
delete rp;
if (rp->ACK) return 0; else return retval;
}
// Gets the Third scan of an enrollment
// Finishes Enrollment
// Return:
// 0 - ACK
// 1 - Enroll Failed
// 2 - Bad finger
// 3 - ID in use
int FPS_GT511C3::Enroll3()
{
if (UseSerialDebug) Serial.println("FPS - Enroll3");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::Enroll3;
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
delete packetbytes;
Response_Packet* rp = GetResponse();
int retval = rp->IntFromParameter();
if (retval < 200) retval = 3; else retval = 0;
if (rp->ACK == false)
{
if (rp->Error == Response_Packet::ErrorCodes::NACK_ENROLL_FAILED) retval = 1;
if (rp->Error == Response_Packet::ErrorCodes::NACK_BAD_FINGER) retval = 2;
}
delete rp;
if (rp->ACK) return 0; else return retval;
}
// Checks to see if a finger is pressed on the FPS
// Return: true if finger pressed, false if not
bool FPS_GT511C3::IsPressFinger()
{
if (UseSerialDebug) Serial.println("FPS - IsPressFinger");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::IsPressFinger;
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
bool retval = false;
int pval = rp->ParameterBytes[0];
pval += rp->ParameterBytes[1];
pval += rp->ParameterBytes[2];
pval += rp->ParameterBytes[3];
if (pval == 0) retval = true;
delete rp;
delete packetbytes;
return retval;
}
// Deletes the specified ID (enrollment) from the database
// Parameter: 0-199 (id number to be deleted)
// Returns: true if successful, false if position invalid
bool FPS_GT511C3::DeleteID(int id)
{
if (UseSerialDebug) Serial.println("FPS - DeleteID");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::DeleteID;
cp->ParameterFromInt(id);
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
bool retval = rp->ACK;
delete rp;
delete packetbytes;
return retval;
}
// Deletes all IDs (enrollments) from the database
// Returns: true if successful, false if db is empty
bool FPS_GT511C3::DeleteAll()
{
if (UseSerialDebug) Serial.println("FPS - DeleteAll");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::DeleteAll;
byte* packetbytes = cp->GetPacketBytes();
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
bool retval = rp->ACK;
delete rp;
delete packetbytes;
delete cp;
return retval;
}
// Checks the currently pressed finger against a specific ID
// Parameter: 0-199 (id number to be checked)
// Returns:
// 0 - Verified OK (the correct finger)
// 1 - Invalid Position
// 2 - ID is not in use
// 3 - Verified FALSE (not the correct finger)
int FPS_GT511C3::Verify1_1(int id)
{
if (UseSerialDebug) Serial.println("FPS - Verify1_1");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::Verify1_1;
cp->ParameterFromInt(id);
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
int retval = 0;
if (rp->ACK == false)
{
retval = 3; // grw 01/03/15 - set default value of not verified before assignment
if (rp->Error == Response_Packet::ErrorCodes::NACK_INVALID_POS) retval = 1;
if (rp->Error == Response_Packet::ErrorCodes::NACK_IS_NOT_USED) retval = 2;
if (rp->Error == Response_Packet::ErrorCodes::NACK_VERIFY_FAILED) retval = 3;
}
delete rp;
delete packetbytes;
return retval;
}
// Checks the currently pressed finger against all enrolled fingerprints
// Returns:
// 0-199: Verified against the specified ID (found, and here is the ID number)
// 200: Failed to find the fingerprint in the database
int FPS_GT511C3::Identify1_N()
{
if (UseSerialDebug) Serial.println("FPS - Identify1_N");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::Identify1_N;
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
int retval = rp->IntFromParameter();
if (retval > 200) retval = 200;
delete rp;
delete packetbytes;
return retval;
}
// Captures the currently pressed finger into onboard ram use this prior to other commands
// Parameter: true for high quality image(slower), false for low quality image (faster)
// Generally, use high quality for enrollment, and low quality for verification/identification
// Returns: True if ok, false if no finger pressed
bool FPS_GT511C3::CaptureFinger(bool highquality)
{
if (UseSerialDebug) Serial.println("FPS - CaptureFinger");
Command_Packet* cp = new Command_Packet();
cp->Command = Command_Packet::Commands::CaptureFinger;
if (highquality)
{
cp->ParameterFromInt(1);
}
else
{
cp->ParameterFromInt(0);
}
byte* packetbytes = cp->GetPacketBytes();
delete cp;
SendCommand(packetbytes, 12);
Response_Packet* rp = GetResponse();
bool retval = rp->ACK;
delete rp;
delete packetbytes;
return retval;
}
#pragma endregion
#pragma region -= Not imlemented commands =-
// Gets an image that is 258x202 (52116 bytes) and returns it in 407 Data_Packets
// Use StartDataDownload, and then GetNextDataPacket until done
// Returns: True (device confirming download starting)
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//bool FPS_GT511C3::GetImage()
//{
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//return false;
//}
// Gets an image that is qvga 160x120 (19200 bytes) and returns it in 150 Data_Packets
// Use StartDataDownload, and then GetNextDataPacket until done
// Returns: True (device confirming download starting)
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//bool FPS_GT511C3::GetRawImage()
//{
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//return false;
//}
// Gets a template from the fps (498 bytes) in 4 Data_Packets
// Use StartDataDownload, and then GetNextDataPacket until done
// Parameter: 0-199 ID number
// Returns:
// 0 - ACK Download starting
// 1 - Invalid position
// 2 - ID not used (no template to download
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//int FPS_GT511C3::GetTemplate(int id)
//{
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//return false;
//}
// Uploads a template to the fps
// Parameter: the template (498 bytes)
// Parameter: the ID number to upload
// Parameter: Check for duplicate fingerprints already on fps
// Returns:
// 0-199 - ID duplicated
// 200 - Uploaded ok (no duplicate if enabled)
// 201 - Invalid position
// 202 - Communications error
// 203 - Device error
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//int FPS_GT511C3::SetTemplate(byte* tmplt, int id, bool duplicateCheck)
//{
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//return -1;
//}
// resets the Data_Packet class, and gets ready to download
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//void FPS_GT511C3::StartDataDownload()
//{
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//}
// Returns the next data packet
// Not implemented due to memory restrictions on the arduino
// may revisit this if I find a need for it
//Data_Packet GetNextDataPacket()
//{
// return 0;
//}
// Commands that are not implemented (and why)
// VerifyTemplate1_1 - Couldn't find a good reason to implement this on an arduino
// IdentifyTemplate1_N - Couldn't find a good reason to implement this on an arduino
// MakeTemplate - Couldn't find a good reason to implement this on an arduino
// UsbInternalCheck - not implemented - Not valid config for arduino
// GetDatabaseStart - historical command, no longer supported
// GetDatabaseEnd - historical command, no longer supported
// UpgradeFirmware - Data sheet says not supported
// UpgradeISOCDImage - Data sheet says not supported
// SetIAPMode - for upgrading firmware (which data sheet says is not supported)
// Ack and Nack are listed as commands for some unknown reason... not implemented
#pragma endregion
#pragma region -= Private Methods =-
// Sends the command to the software serial channel
void FPS_GT511C3::SendCommand(byte cmd[], int length)
{
Serial1.write(cmd, length);
delay(50);
if (UseSerialDebug)
{
Serial.print("FPS - SEND: ");
SendToSerial(cmd, length);
Serial.println();
}
};
// Gets the response to the command from the software serial channel (and waits for it)
Response_Packet* FPS_GT511C3::GetResponse()
{
byte firstbyte = 0;
bool done = false;
//Serial1.listen();
if (UseSerialDebug) Serial.print("FPS - GetResponse");
while (done == false)
{
firstbyte = (byte)Serial1.read();
if (firstbyte == Response_Packet::COMMAND_START_CODE_1)
{
done = true;
if (UseSerialDebug) Serial.print("FPS - GetResponse done");
}
}
byte* resp = new byte[12];
resp[0] = firstbyte;
for (int i=1; i < 12; i++)
{
while (Serial1.available() == false) delay(10);
resp[i]= (byte) Serial1.read();
}
Response_Packet* rp = new Response_Packet(resp, UseSerialDebug);
delete resp;
delay(50);
if (UseSerialDebug)
{
Serial.print("FPS - RECV: ");
SendToSerial(rp->RawBytes, 12);
Serial.println();
Serial.println();
}
return rp;
};
// sends the bye aray to the serial debugger in our hex format EX: "00 AF FF 10 00 13"
void FPS_GT511C3::SendToSerial(byte data[], int length)
{
boolean first=true;
Serial.print("\"");
for(int i=0; i<length; i++)
{
if (first) first=false; else Serial.print(" ");
serialPrintHex(data[i]);
}
Serial.print("\"");
}
// sends a byte to the serial debugger in the hex format we want EX "0F"
void FPS_GT511C3::serialPrintHex(byte data)
{
char tmp[16];
sprintf(tmp, "%.2X",data);
Serial.print(tmp);
}
#pragma endregion
#pragma endregion