@@ -90,7 +90,7 @@ Command_Packet::Command_Packet()
9090#pragma region -= Response_Packet Definitions =-
9191#endif // __GNUC__
9292// creates and parses a response packet from the finger print scanner
93- Response_Packet::Response_Packet (uint8_t * buffer)
93+ Response_Packet::Response_Packet (uint8_t buffer[] )
9494{
9595 CheckParsing (buffer[0 ], RESPONSE_START_CODE_1, RESPONSE_START_CODE_1, F (" RESPONSE_START_CODE_1" ));
9696 CheckParsing (buffer[1 ], RESPONSE_START_CODE_2, RESPONSE_START_CODE_2, F (" RESPONSE_START_CODE_2" ));
@@ -189,7 +189,7 @@ bool Response_Packet::CheckParsing(uint8_t b, uint8_t propervalue, uint8_t alter
189189}
190190
191191// calculates the checksum from the bytes in the packet
192- uint16_t Response_Packet::CalculateChecksum (uint8_t * buffer, uint16_t length)
192+ uint16_t Response_Packet::CalculateChecksum (uint8_t buffer[] , uint16_t length)
193193{
194194 uint16_t checksum = 0 ;
195195 for (uint16_t i=0 ; i<length; i++)
@@ -217,7 +217,68 @@ uint8_t Response_Packet::GetLowByte(uint16_t w)
217217#ifndef __GNUC__
218218#pragma region -= Data_Packet =-
219219#endif // __GNUC__
220- Data_Packet::Data_Packet (uint8_t * buffer)
220+ // creates a data packet and send it to the finger print scanner
221+ Data_Packet::Data_Packet (uint8_t buffer[], uint16_t length, SoftwareSerial _serial)
222+ {
223+
224+ uint8_t * data_code= new uint8_t [4 ];
225+
226+ data_code[0 ] = DATA_START_CODE_1;
227+ data_code[1 ] = DATA_START_CODE_2;
228+ data_code[2 ] = DATA_DEVICE_ID_1;
229+ data_code[3 ] = DATA_DEVICE_ID_2;
230+
231+ #if FPS_DEBUG
232+ Serial.println (F (" FPS - Template" ));
233+ Serial.print (F (" FPS - SEND: " ));
234+ Serial.print (" \" " );
235+ bool first=true ;
236+ for (uint16_t i=0 ; i<4 ; i++)
237+ {
238+ if (first) first=false ; else Serial.print (" " );
239+ char tmp[16 ];
240+ sprintf (tmp, " %.2X" , data_code[i]);
241+ Serial.print (tmp);
242+ }
243+ for (uint16_t i=0 ; i<length; i++)
244+ {
245+ if (first) first=false ; else Serial.print (" " );
246+ char tmp[16 ];
247+ sprintf (tmp, " %.2X" , buffer[i]);
248+ Serial.print (tmp);
249+ }
250+ {
251+ if (first) first=false ; else Serial.print (" " );
252+ char tmp[16 ];
253+ sprintf (tmp, " %.2X" , GetLowByte (this ->checksum ));
254+ Serial.print (tmp);
255+ }
256+ {
257+ if (first) first=false ; else Serial.print (" " );
258+ char tmp[16 ];
259+ sprintf (tmp, " %.2X" , GetHighByte (this ->checksum ));
260+ Serial.print (tmp);
261+ }
262+ Serial.print (" \" " );
263+ Serial.println ();
264+ #endif
265+
266+ // Calculate checksum
267+ this ->checksum = CalculateChecksum (data_code, 4 );
268+ this ->checksum = CalculateChecksum (buffer, length);
269+
270+ // Send everything to the finger print scanner
271+ _serial.write (data_code, 4 );
272+ _serial.write (buffer, length);
273+ _serial.write (GetLowByte (this ->checksum ));
274+ _serial.write (GetHighByte (this ->checksum ));
275+
276+ // clean up
277+ delete data_code;
278+
279+ }
280+ // creates and parses a data packet from the finger print scanner
281+ Data_Packet::Data_Packet (uint8_t buffer[])
221282{
222283#if FPS_DEBUG
223284 CheckParsing (buffer[0 ], DATA_START_CODE_1, DATA_START_CODE_1, F (" DATA_START_CODE_1" ));
@@ -273,7 +334,7 @@ bool Data_Packet::CheckParsing(uint8_t b, uint8_t propervalue, uint8_t alternate
273334}
274335
275336// calculates the checksum from the bytes in the packet
276- uint16_t Data_Packet::CalculateChecksum (uint8_t * buffer, uint16_t length)
337+ uint16_t Data_Packet::CalculateChecksum (uint8_t buffer[] , uint16_t length)
277338{
278339 uint16_t checksum = this ->checksum ;
279340 for (uint16_t i=0 ; i<length; i++)
@@ -907,7 +968,7 @@ uint8_t FPS_GT511C3::GetTemplate(uint16_t id, uint8_t data[])
907968// 2 - Invalid position
908969// 3 - Communications error
909970// 4 - Device error
910- uint16_t FPS_GT511C3::SetTemplate (byte* tmplt, uint16_t id, bool duplicateCheck)
971+ uint16_t FPS_GT511C3::SetTemplate (uint8_t tmplt[] , uint16_t id, bool duplicateCheck)
911972{
912973#if FPS_DEBUG
913974 Serial.println (F (" FPS - SetTemplate" ));
@@ -926,7 +987,7 @@ uint16_t FPS_GT511C3::SetTemplate(byte* tmplt, uint16_t id, bool duplicateCheck)
926987 return 2 ;
927988 } else
928989 {
929- SendCommand (tmplt, 498 ); // Not actually a command ;)
990+ Data_Packet dp (tmplt, 498 , _serial ); // This makes the data packet and sends it immediately
930991 rp = GetResponse ();
931992 if (rp->ACK )
932993 {
@@ -954,7 +1015,7 @@ uint16_t FPS_GT511C3::SetTemplate(byte* tmplt, uint16_t id, bool duplicateCheck)
9541015#endif // __GNUC__
9551016
9561017#ifndef __GNUC__
957- #pragma region -= Not imlemented commands =-
1018+ #pragma region -= Not implemented commands =-
9581019#endif // __GNUC__
9591020// Commands that are not implemented (and why)
9601021// VerifyTemplate1_1 - Couldn't find a good reason to implement this on an arduino
@@ -1266,7 +1327,7 @@ bool FPS_GT511C3::ReturnData(uint16_t length, uint8_t data[])
12661327// sends the byte array to the serial debugger in our hex format EX: "00 AF FF 10 00 13"
12671328void FPS_GT511C3::SendToSerial (uint8_t data[], uint16_t length)
12681329{
1269- boolean first=true ;
1330+ bool first=true ;
12701331 Serial.print (" \" " );
12711332 for (uint16_t i=0 ; i<length; i++)
12721333 {
0 commit comments