@@ -168,6 +168,24 @@ int Response_Packet::IntFromParameter()
168168 return retval;
169169}
170170
171+ // checks to see if the byte is the proper value, and logs it to the serial channel if not
172+ bool Response_Packet::CheckParsing (byte b, byte propervalue, byte alternatevalue, const char * varname, bool UseSerialDebug)
173+ {
174+ bool retval = (b != propervalue) && (b != alternatevalue);
175+ if ((UseSerialDebug) && (retval))
176+ {
177+ Serial.print (" Response_Packet parsing error " );
178+ Serial.print (varname);
179+ Serial.print (" " );
180+ Serial.print (propervalue, HEX);
181+ Serial.print (" || " );
182+ Serial.print (alternatevalue, HEX);
183+ Serial.print (" != " );
184+ Serial.println (b, HEX);
185+ }
186+ return retval;
187+ }
188+
171189// calculates the checksum from the bytes in the packet
172190word Response_Packet::CalculateChecksum (byte* buffer, int length)
173191{
@@ -190,14 +208,48 @@ byte Response_Packet::GetLowByte(word w)
190208{
191209 return (byte)w&0x00FF ;
192210}
211+ #ifndef __GNUC__
212+ #pragma endregion
213+ #endif // __GNUC__
214+
215+ #ifndef __GNUC__
216+ #pragma region -= Data_Packet =-
217+ #endif // __GNUC__
218+ Data_Packet::Data_Packet (byte* buffer, bool UseSerialDebug)
219+ {
220+ CheckParsing (buffer[0 ], DATA_START_CODE_1, DATA_START_CODE_1, " DATA_START_CODE_1" , UseSerialDebug);
221+ CheckParsing (buffer[1 ], DATA_START_CODE_2, DATA_START_CODE_2, " DATA_START_CODE_2" , UseSerialDebug);
222+ CheckParsing (buffer[2 ], DATA_DEVICE_ID_1, DATA_DEVICE_ID_1, " DATA_DEVICE_ID_1" , UseSerialDebug);
223+ CheckParsing (buffer[3 ], DATA_DEVICE_ID_2, DATA_DEVICE_ID_2, " DATA_DEVICE_ID_2" , UseSerialDebug);
224+
225+ Data_Packet.checksum = CalculateChecksum (buffer, 4 );
226+ }
227+
228+ // Get a data packet (128 bytes), calculate checksum and send it to serial
229+ Data_Packet::GetData (byte* buffer, bool UseSerialDebug)
230+ {
231+ FPS_GT511C3.SendToSerial (buffer, 128 );
232+ Data_Packet.checksum = CalculateChecksum (buffer, 128 );
233+ }
234+
235+ // Get the last data packet (<=128 bytes), calculate checksum, validate checksum received and send it to serial
236+ Data_Packet::GetLastData (byte* buffer, int length, bool UseSerialDebug)
237+ {
238+ FPS_GT511C3.SendToSerial (buffer, length-2 );
239+ Data_Packet.checksum = CalculateChecksum (buffer, length);
240+ byte checksum_low = GetLowByte (Data_Packet.checksum );
241+ byte checksum_high = GetHighByte (Data_Packet.checksum );
242+ CheckParsing (buffer[length-2 ], checksum_low, checksum_low, " Checksum_LOW" , UseSerialDebug);
243+ CheckParsing (buffer[length-1 ], checksum_high, checksum_high, " Checksum_HIGH" , UseSerialDebug);
244+ }
193245
194246// checks to see if the byte is the proper value, and logs it to the serial channel if not
195- bool Response_Packet ::CheckParsing (byte b, byte propervalue, byte alternatevalue, const char * varname, bool UseSerialDebug)
247+ bool Data_Packet ::CheckParsing (byte b, byte propervalue, byte alternatevalue, const char * varname, bool UseSerialDebug)
196248{
197249 bool retval = (b != propervalue) && (b != alternatevalue);
198250 if ((UseSerialDebug) && (retval))
199251 {
200- Serial.print (" Response_Packet parsing error " );
252+ Serial.print (" Data_Packet parsing error " );
201253 Serial.print (varname);
202254 Serial.print (" " );
203255 Serial.print (propervalue, HEX);
@@ -208,18 +260,40 @@ bool Response_Packet::CheckParsing(byte b, byte propervalue, byte alternatevalue
208260 }
209261 return retval;
210262}
211- #ifndef __GNUC__
212- #pragma endregion
213- #endif // __GNUC__
214263
215- #ifndef __GNUC__
216- #pragma region -= Data_Packet =-
217- #endif // __GNUC__
218- // void Data_Packet::StartNewPacket()
219- // {
220- // Data_Packet::NextPacketID = 0;
221- // Data_Packet::CheckSum = 0;
222- // }
264+ // calculates the checksum from the bytes in the packet
265+ word Data_Packet::CalculateChecksum (byte* buffer, int length)
266+ {
267+ word checksum = Data_Packet.checksum ;
268+ for (int i=0 ; i<length; i++)
269+ {
270+ checksum +=buffer[i];
271+ }
272+ return checksum;
273+ }
274+
275+ // Returns the high byte from a word// calculates the checksum from the bytes in the packet
276+ word Data_Packet::CalculateChecksum (byte* buffer, int length)
277+ {
278+ word checksum = 0 ;
279+ for (int i=0 ; i<length; i++)
280+ {
281+ checksum +=buffer[i];
282+ }
283+ return checksum;
284+ }
285+
286+ // Returns the high byte from a word
287+ byte Data_Packet::GetHighByte (word w)
288+ {
289+ return (byte)(w>>8 )&0x00FF ;
290+ }
291+
292+ // Returns the low byte from a word
293+ byte Data_Packet::GetLowByte (word w)
294+ {
295+ return (byte)w&0x00FF ;
296+ }
223297#ifndef __GNUC__
224298#pragma endregion
225299#endif // __GNUC__
@@ -655,6 +729,28 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
655729 return retval;
656730
657731}
732+
733+ // Gets an image that is qvga 160x120 (19200 bytes) and returns it in 150 Data_Packets
734+ // Use StartDataDownload, and then GetNextDataPacket until done
735+ // Returns: True (device confirming download starting)
736+ // Not implemented due to memory restrictions on the arduino
737+ // may revisit this if I find a need for it
738+ /* bool FPS_GT511C3::GetRawImage()
739+ {
740+ if (UseSerialDebug) Serial.println("FPS - GetRawImage");
741+ Command_Packet* cp = new Command_Packet();
742+ cp->Command = Command_Packet::Commands::GetRawImage;
743+ byte* packetbytes = cp->GetPacketBytes();
744+ delete cp;
745+ SendCommand(packetbytes, 12);
746+ Response_Packet* rp = GetResponse();
747+ bool retval = rp->ACK;
748+ delete rp;
749+ delete packetbytes;
750+ return retval;
751+
752+ //return false;
753+ }*/
658754#ifndef __GNUC__
659755#pragma endregion
660756#endif // __GNUC__
@@ -674,18 +770,6 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
674770 // return false;
675771// }
676772
677- // Gets an image that is qvga 160x120 (19200 bytes) and returns it in 150 Data_Packets
678- // Use StartDataDownload, and then GetNextDataPacket until done
679- // Returns: True (device confirming download starting)
680- // Not implemented due to memory restrictions on the arduino
681- // may revisit this if I find a need for it
682- // bool FPS_GT511C3::GetRawImage()
683- // {
684- // Not implemented due to memory restrictions on the arduino
685- // may revisit this if I find a need for it
686- // return false;
687- // }
688-
689773// Gets a template from the fps (498 bytes) in 4 Data_Packets
690774// Use StartDataDownload, and then GetNextDataPacket until done
691775// Parameter: 0-199 ID number
@@ -721,23 +805,6 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
721805 // return -1;
722806// }
723807
724- // resets the Data_Packet class, and gets ready to download
725- // Not implemented due to memory restrictions on the arduino
726- // may revisit this if I find a need for it
727- // void FPS_GT511C3::StartDataDownload()
728- // {
729- // Not implemented due to memory restrictions on the arduino
730- // may revisit this if I find a need for it
731- // }
732-
733- // Returns the next data packet
734- // Not implemented due to memory restrictions on the arduino
735- // may revisit this if I find a need for it
736- // Data_Packet GetNextDataPacket()
737- // {
738- // return 0;
739- // }
740-
741808// Commands that are not implemented (and why)
742809// VerifyTemplate1_1 - Couldn't find a good reason to implement this on an arduino
743810// IdentifyTemplate1_N - Couldn't find a good reason to implement this on an arduino
@@ -802,6 +869,92 @@ Response_Packet* FPS_GT511C3::GetResponse()
802869 return rp;
803870};
804871
872+ // Gets the data (length bytes) from the software serial channel (and waits for it)
873+ // and sends it over serial sommunications
874+ void FPS_GT511C3::GetData (int length)
875+ {
876+ byte firstbyte = 0 ;
877+ byte secondbyte = 0 ;
878+ bool done = false ;
879+ _serial.listen ();
880+ while (done == false )
881+ {
882+ firstbyte = (byte)_serial.read ();
883+ if (firstbyte == Data_Packet ()::DATA_START_CODE_1)
884+ {
885+ secondbyte = (byte)_serial.read ();
886+ if (secondbyte == Data_Packet ()::DATA_START_CODE_2)
887+ {
888+ done = true ;
889+ }
890+ }
891+ }
892+
893+ byte* firstdata = new byte[4 ];
894+ firstdata[0 ] = firstbyte;
895+ firstdata[1 ] = secondbyte;
896+ for (int i=2 ; i < 4 ; i++)
897+ {
898+ while (_serial.available () == false ) delay (10 );
899+ firstdata[i]= (byte) _serial.read ();
900+ }
901+ Data_Packet* dp = new Data_Packet (firstdata, UseSerialDebug);
902+ if (UseSerialDebug)
903+ {
904+ Serial.print (" FPS - RECV: " );
905+ SendToSerial (firstdata, 4 );
906+ Serial.println ();
907+ Serial.println ();
908+ }
909+ delete firstdata;
910+
911+ numberPacketsNeeded = (length-4 ) / 128 ;
912+ bool smallLastPacket = false ;
913+ int lastPacketSize = (length-4 ) % 128 ;
914+ if (lastPacketSize != 0 )
915+ {
916+ numberPacketsNeeded++;
917+ smallLastPacket = true ;
918+ }
919+
920+ for (int packetCount=1 ; packetCount < numberPacketsNeeded; packetCount++)
921+ {
922+ byte* data = new byte[128 ];
923+ for (int i=0 ; i < 128 ; i++)
924+ {
925+ while (_serial.available () == false ) delay (10 );
926+ data[i]= (byte) _serial.read ();
927+ }
928+ dp.GetData (data, UseSerialDebug);
929+ if (UseSerialDebug)
930+ {
931+ Serial.print (" FPS - RECV: " );
932+ SendToSerial (data, 128 );
933+ Serial.println ();
934+ Serial.println ();
935+ }
936+ delete data;
937+ }
938+
939+ byte* lastdata = new byte[lastPacketSize];
940+ for (int i=0 ; i < lastPacketSize; i++)
941+ {
942+ while (_serial.available () == false ) delay (10 );
943+ lastdata[i]= (byte) _serial.read ();
944+ }
945+ dp.GetLastData (lastdata, lastPacketSize, UseSerialDebug);
946+ if (UseSerialDebug)
947+ {
948+ Serial.print (" FPS - RECV: " );
949+ SendToSerial (lastdata, lastPacketSize);
950+ Serial.println ();
951+ Serial.println ();
952+ }
953+ delete lastdata;
954+
955+ return ;
956+ };
957+
805958// sends the bye aray to the serial debugger in our hex format EX: "00 AF FF 10 00 13"
806959void FPS_GT511C3::SendToSerial (byte data[], int length)
807960{
0 commit comments