@@ -217,30 +217,32 @@ uint8_t Response_Packet::GetLowByte(uint16_t w)
217
217
#endif // __GNUC__
218
218
Data_Packet::Data_Packet (uint8_t * buffer, bool UseSerialDebug)
219
219
{
220
- CheckParsing (buffer[0 ], DATA_START_CODE_1, DATA_START_CODE_1, " DATA_START_CODE_1" , UseSerialDebug);
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);
221
222
CheckParsing(buffer[1], DATA_START_CODE_2, DATA_START_CODE_2, "DATA_START_CODE_2", UseSerialDebug);
222
223
CheckParsing(buffer[2], DATA_DEVICE_ID_1, DATA_DEVICE_ID_1, "DATA_DEVICE_ID_1", UseSerialDebug);
223
224
CheckParsing(buffer[3], DATA_DEVICE_ID_2, DATA_DEVICE_ID_2, "DATA_DEVICE_ID_2", UseSerialDebug);
224
225
225
- this ->checksum = CalculateChecksum (buffer, 4 );
226
+ this->checksum = CalculateChecksum(buffer, 4);*/
226
227
}
227
228
228
229
// Get a data packet (128 bytes), calculate checksum and send it to serial
229
- void Data_Packet::GetData (uint8_t * buffer, bool UseSerialDebug )
230
+ void Data_Packet::GetData (uint8_t buffer[], uint16_t length )
230
231
{
231
- SendToSerial (buffer, 128 );
232
- this ->checksum = CalculateChecksum (buffer, 128 );
232
+ for ( uint16_t i = 0 ; i<length; i++) Serial. write (buffer[i] );
233
+ // this->checksum = CalculateChecksum(buffer, 128); // Checksum slowdown
233
234
}
234
235
235
236
// Get the last data packet (<=128 bytes), calculate checksum, validate checksum received and send it to serial
236
237
void Data_Packet::GetLastData (uint8_t * buffer, uint16_t length, bool UseSerialDebug)
237
238
{
238
- SendToSerial (buffer, length-2 );
239
- this ->checksum = CalculateChecksum (buffer, length);
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);
240
242
uint8_t checksum_low = GetLowByte(this->checksum);
241
243
uint8_t checksum_high = GetHighByte(this->checksum);
242
244
CheckParsing(buffer[length-2], checksum_low, checksum_low, "Checksum_LOW", UseSerialDebug);
243
- CheckParsing (buffer[length-1 ], checksum_high, checksum_high, " Checksum_HIGH" , UseSerialDebug);
245
+ CheckParsing(buffer[length-1], checksum_high, checksum_high, "Checksum_HIGH", UseSerialDebug);*/
244
246
}
245
247
246
248
// checks to see if the byte is the proper value, and logs it to the serial channel if not
@@ -284,26 +286,6 @@ uint8_t Data_Packet::GetLowByte(uint16_t w)
284
286
return (uint8_t )w&0x00FF ;
285
287
}
286
288
287
- // sends a byte to the serial debugger in the hex format we want EX "0F"
288
- void Data_Packet::serialPrintHex (uint8_t data)
289
- {
290
- char tmp[16 ];
291
- sprintf (tmp, " %.2X" ,data);
292
- Serial.print (tmp);
293
- }
294
-
295
- // sends the byte array to the serial debugger in our hex format EX: "00 AF FF 10 00 13"
296
- void Data_Packet::SendToSerial (uint8_t data[], uint16_t length)
297
- {
298
- boolean first=true ;
299
- Serial.print (" \" " );
300
- for (uint16_t i=0 ; i<length; i++)
301
- {
302
- if (first) first=false ; else Serial.print (" " );
303
- serialPrintHex (data[i]);
304
- }
305
- Serial.print (" \" " );
306
- }
307
289
#ifndef __GNUC__
308
290
#pragma endregion
309
291
#endif // __GNUC__
@@ -764,6 +746,10 @@ bool FPS_GT511C3::GetImage()
764
746
765
747
// Gets an image that is qvga 160x120 (19200 bytes) and sends it over serial
766
748
// Returns: True (device confirming download)
749
+ // It only worked with baud rate at 38400-57600 in GT-511C3.
750
+ // Slower speeds and the FPS will shutdown. Higher speeds and the serial buffer will overflow.
751
+ // Make sure you are allocating enough CPU time for this task or you will overflow nonetheless.
752
+ // Also, avoid using UseSerialDebug for this task, since it's easier to overflow.
767
753
bool FPS_GT511C3::GetRawImage ()
768
754
{
769
755
if (UseSerialDebug) Serial.println (" FPS - GetRawImage" );
@@ -1027,23 +1013,15 @@ void FPS_GT511C3::GetData(uint16_t length)
1027
1013
}
1028
1014
}
1029
1015
1030
- uint8_t * firstdata = new uint8_t [4 ];
1016
+ uint8_t firstdata[4 ];
1031
1017
firstdata[0 ] = firstbyte;
1032
1018
firstdata[1 ] = secondbyte;
1033
1019
for (uint8_t i=2 ; i < 4 ; i++)
1034
1020
{
1035
1021
while (_serial.available () == false ) delay (10 );
1036
1022
firstdata[i]= (uint8_t ) _serial.read ();
1037
1023
}
1038
- Data_Packet* dp = new Data_Packet (firstdata, UseSerialDebug);
1039
- if (UseSerialDebug)
1040
- {
1041
- Serial.print (" FPS - RECV: " );
1042
- SendToSerial (firstdata, 4 );
1043
- Serial.println ();
1044
- Serial.println ();
1045
- }
1046
- delete firstdata;
1024
+ Data_Packet dp (firstdata, UseSerialDebug);
1047
1025
1048
1026
uint16_t numberPacketsNeeded = (length-4 ) / 128 ;
1049
1027
bool smallLastPacket = false ;
@@ -1054,42 +1032,36 @@ void FPS_GT511C3::GetData(uint16_t length)
1054
1032
smallLastPacket = true ;
1055
1033
}
1056
1034
1057
- uint8_t * data = new uint8_t [128 ];
1035
+ uint8_t data[128 ];
1058
1036
for (uint16_t packetCount=1 ; packetCount < numberPacketsNeeded; packetCount++)
1059
1037
{
1060
1038
for (uint8_t i=0 ; i < 128 ; i++)
1061
1039
{
1062
- while (_serial.available () == false ) delay (10 );
1040
+ while (_serial.available () == false ) delay (1 );
1041
+ if (_serial.overflow ())
1042
+ {
1043
+ Serial.println (" Overflow! Data download stopped" );
1044
+ Serial.println (" Cleaning serial buffer..." );
1045
+ for (uint16_t j = 0 ; j<length; j++)
1046
+ {
1047
+ _serial.read ();
1048
+ delay (1 );
1049
+ }
1050
+ Serial.println (" Done!" );
1051
+ return ;
1052
+ }
1063
1053
data[i]= (uint8_t ) _serial.read ();
1064
1054
}
1065
- dp->GetData (data, UseSerialDebug);
1066
- if (UseSerialDebug)
1067
- {
1068
- Serial.print (" FPS - RECV: " );
1069
- SendToSerial (data, 128 );
1070
- Serial.println ();
1071
- Serial.println ();
1072
- }
1055
+ dp.GetData (data, 128 );
1073
1056
}
1074
- delete data;
1075
1057
1076
- uint8_t * lastdata = new uint8_t [lastPacketSize];
1058
+ uint8_t lastdata[lastPacketSize];
1077
1059
for (uint8_t i=0 ; i < lastPacketSize; i++)
1078
1060
{
1079
1061
while (_serial.available () == false ) delay (10 );
1080
1062
lastdata[i]= (uint8_t ) _serial.read ();
1081
1063
}
1082
- dp->GetLastData (lastdata, lastPacketSize, UseSerialDebug);
1083
- if (UseSerialDebug)
1084
- {
1085
- Serial.print (" FPS - RECV: " );
1086
- SendToSerial (lastdata, lastPacketSize);
1087
- Serial.println ();
1088
- Serial.println ();
1089
- }
1090
- delete lastdata;
1091
-
1092
- return ;
1064
+ dp.GetLastData (lastdata, lastPacketSize, UseSerialDebug);
1093
1065
};
1094
1066
1095
1067
// sends the byte array to the serial debugger in our hex format EX: "00 AF FF 10 00 13"
0 commit comments