Skip to content

Commit b653dbd

Browse files
committed
Enabled checksum methods. Seems like they don't slow down the data download enough to be an issue. Fixed some bugs too in the checksum code.
Download methods will send 2 more bytes (byte addition checksum) after the data buffer, so you can check if the data is correct in whatever the destination device is.
1 parent 55863f8 commit b653dbd

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

src/FPS_GT511C3.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -217,32 +217,36 @@ uint8_t Response_Packet::GetLowByte(uint16_t w)
217217
#endif //__GNUC__
218218
Data_Packet::Data_Packet(uint8_t* buffer, bool UseSerialDebug)
219219
{
220-
// The checksum here is arguably useless and may make the serial buffer overflow
221-
/*CheckParsing(buffer[0], DATA_START_CODE_1, DATA_START_CODE_1, "DATA_START_CODE_1", UseSerialDebug);
222-
CheckParsing(buffer[1], DATA_START_CODE_2, DATA_START_CODE_2, "DATA_START_CODE_2", UseSerialDebug);
223-
CheckParsing(buffer[2], DATA_DEVICE_ID_1, DATA_DEVICE_ID_1, "DATA_DEVICE_ID_1", UseSerialDebug);
224-
CheckParsing(buffer[3], DATA_DEVICE_ID_2, DATA_DEVICE_ID_2, "DATA_DEVICE_ID_2", UseSerialDebug);
220+
if (UseSerialDebug)
221+
{
222+
CheckParsing(buffer[0], DATA_START_CODE_1, DATA_START_CODE_1, "DATA_START_CODE_1", UseSerialDebug);
223+
CheckParsing(buffer[1], DATA_START_CODE_2, DATA_START_CODE_2, "DATA_START_CODE_2", UseSerialDebug);
224+
CheckParsing(buffer[2], DATA_DEVICE_ID_1, DATA_DEVICE_ID_1, "DATA_DEVICE_ID_1", UseSerialDebug);
225+
CheckParsing(buffer[3], DATA_DEVICE_ID_2, DATA_DEVICE_ID_2, "DATA_DEVICE_ID_2", UseSerialDebug);
225226

226-
this->checksum = CalculateChecksum(buffer, 4);*/
227+
this->checksum = CalculateChecksum(buffer, 4);
228+
}
227229
}
228230

229231
// Get a data packet (128 bytes), calculate checksum and send it to serial
230-
void Data_Packet::GetData(uint8_t buffer[], uint16_t length)
232+
void Data_Packet::GetData(uint8_t buffer[], uint16_t length, bool UseSerialDebug)
231233
{
232234
for(uint16_t i = 0; i<length; i++) Serial.write(buffer[i]);
233-
//this->checksum = CalculateChecksum(buffer, 128); // Checksum slowdown
235+
if (UseSerialDebug) this->checksum = CalculateChecksum(buffer, 128);
234236
}
235237

236238
// Get the last data packet (<=128 bytes), calculate checksum, validate checksum received and send it to serial
237239
void Data_Packet::GetLastData(uint8_t buffer[], uint16_t length, bool UseSerialDebug)
238240
{
239-
for(uint16_t i = 0; i<(length-2); i++) Serial.write(buffer[i]);
240-
// The checksum here is arguably useless and may make the serial buffer overflow
241-
/*this->checksum = CalculateChecksum(buffer, length);
242-
uint8_t checksum_low = GetLowByte(this->checksum);
243-
uint8_t checksum_high = GetHighByte(this->checksum);
244-
CheckParsing(buffer[length-2], checksum_low, checksum_low, "Checksum_LOW", UseSerialDebug);
245-
CheckParsing(buffer[length-1], checksum_high, checksum_high, "Checksum_HIGH", UseSerialDebug);*/
241+
for(uint16_t i = 0; i<length; i++) Serial.write(buffer[i]);
242+
if (UseSerialDebug)
243+
{
244+
this->checksum = CalculateChecksum(buffer, length-2);
245+
uint8_t checksum_low = GetLowByte(this->checksum);
246+
uint8_t checksum_high = GetHighByte(this->checksum);
247+
CheckParsing(buffer[length-2], checksum_low, checksum_low, "Checksum_LOW", UseSerialDebug);
248+
CheckParsing(buffer[length-1], checksum_high, checksum_high, "Checksum_HIGH", UseSerialDebug);
249+
}
246250
}
247251

248252
// checks to see if the byte is the proper value, and logs it to the serial channel if not
@@ -251,7 +255,7 @@ bool Data_Packet::CheckParsing(uint8_t b, uint8_t propervalue, uint8_t alternate
251255
bool retval = (b != propervalue) && (b != alternatevalue);
252256
if ((UseSerialDebug) && (retval))
253257
{
254-
Serial.print("Data_Packet parsing error ");
258+
Serial.print("\nData_Packet parsing error ");
255259
Serial.print(varname);
256260
Serial.print(" ");
257261
Serial.print(propervalue, HEX);
@@ -718,7 +722,7 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
718722
return retval;
719723
}
720724

721-
// Gets an image that is 258x202 (52116 bytes) and sends it over serial
725+
// Gets an image that is 258x202 (52116 bytes + 2 bytes checksum) and sends it over serial
722726
// Returns: True (device confirming download)
723727
// It only worked with baud rate at 38400-57600 in GT-511C3.
724728
// Slower speeds and the FPS will shutdown. Higher speeds and the serial buffer will overflow.
@@ -740,7 +744,7 @@ bool FPS_GT511C3::GetImage()
740744
return retval;
741745
}
742746

743-
// Gets an image that is qvga 160x120 (19200 bytes) and sends it over serial
747+
// Gets an image that is qvga 160x120 (19200 bytes + 2 bytes checksum) and sends it over serial
744748
// Returns: True (device confirming download)
745749
// It only worked with baud rate at 38400-57600 in GT-511C3.
746750
// Slower speeds and the FPS will shutdown. Higher speeds and the serial buffer will overflow.
@@ -762,7 +766,7 @@ bool FPS_GT511C3::GetRawImage()
762766
return retval;
763767
}
764768

765-
// Gets a template from the fps (498 bytes)
769+
// Gets a template from the fps (498 bytes + 2 bvtes checksum)
766770
// Parameter: 0-199 ID number
767771
// Returns:
768772
// 0 - ACK Download starting
@@ -1093,7 +1097,7 @@ void FPS_GT511C3::GetData(uint16_t length)
10931097
}
10941098
data[i]= (uint8_t) _serial.read();
10951099
}
1096-
dp.GetData(data, 128);
1100+
dp.GetData(data, 128, UseSerialDebug);
10971101
}
10981102

10991103
uint8_t lastdata[lastPacketSize];

src/FPS_GT511C3.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class Data_Packet
157157
static const uint8_t DATA_DEVICE_ID_1 = 0x01; // Device ID Byte 1 (lesser byte) - theoretically never changes
158158
static const uint8_t DATA_DEVICE_ID_2 = 0x00; // Device ID Byte 2 (greater byte)
159159

160-
void GetData(uint8_t buffer[], uint16_t length);
160+
void GetData(uint8_t buffer[], uint16_t length, bool UseSerialDebug);
161161
void GetLastData(uint8_t buffer[], uint16_t length, bool UseSerialDebug);
162162
private:
163163
bool CheckParsing(uint8_t b, uint8_t propervalue, uint8_t alternatevalue, const char* varname, bool UseSerialDebug);
@@ -300,15 +300,15 @@ class FPS_GT511C3
300300
// Returns: True if ok, false if no finger pressed
301301
bool CaptureFinger(bool highquality);
302302

303-
// Gets an image that is 258x202 (52116 bytes) and sends it over serial
303+
// Gets an image that is 258x202 (52116 bytes + 2 bytes checksum) and sends it over serial
304304
// Returns: True (device confirming download)
305305
bool GetImage();
306306

307-
// Gets an image that is qvga 160x120 (19200 bytes) and sends it over serial
307+
// Gets an image that is qvga 160x120 (19200 bytes + 2 bytes checksum) and sends it over serial
308308
// Returns: True (device confirming download)
309309
bool GetRawImage();
310310

311-
// Gets a template from the fps (498 bytes)
311+
// Gets a template from the fps (498 bytes + 2 bytes checksum)
312312
// Parameter: 0-199 ID number
313313
// Returns:
314314
// 0 - ACK Download starting

0 commit comments

Comments
 (0)