@@ -222,23 +222,23 @@ Data_Packet::Data_Packet(byte* buffer, bool UseSerialDebug)
222
222
CheckParsing (buffer[2 ], DATA_DEVICE_ID_1, DATA_DEVICE_ID_1, " DATA_DEVICE_ID_1" , UseSerialDebug);
223
223
CheckParsing (buffer[3 ], DATA_DEVICE_ID_2, DATA_DEVICE_ID_2, " DATA_DEVICE_ID_2" , UseSerialDebug);
224
224
225
- Data_Packet. checksum = CalculateChecksum (buffer, 4 );
225
+ this -> checksum = CalculateChecksum (buffer, 4 );
226
226
}
227
227
228
228
// Get a data packet (128 bytes), calculate checksum and send it to serial
229
- Data_Packet::GetData (byte* buffer, bool UseSerialDebug)
229
+ void Data_Packet::GetData (byte* buffer, bool UseSerialDebug)
230
230
{
231
- FPS_GT511C3. SendToSerial (buffer, 128 );
232
- Data_Packet. checksum = CalculateChecksum (buffer, 128 );
231
+ SendToSerial (buffer, 128 );
232
+ this -> checksum = CalculateChecksum (buffer, 128 );
233
233
}
234
234
235
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)
236
+ void Data_Packet::GetLastData (byte* buffer, int length, bool UseSerialDebug)
237
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 );
238
+ SendToSerial (buffer, length-2 );
239
+ this -> checksum = CalculateChecksum (buffer, length);
240
+ byte checksum_low = GetLowByte (this -> checksum );
241
+ byte checksum_high = GetHighByte (this -> checksum );
242
242
CheckParsing (buffer[length-2 ], checksum_low, checksum_low, " Checksum_LOW" , UseSerialDebug);
243
243
CheckParsing (buffer[length-1 ], checksum_high, checksum_high, " Checksum_HIGH" , UseSerialDebug);
244
244
}
@@ -264,18 +264,7 @@ bool Data_Packet::CheckParsing(byte b, byte propervalue, byte alternatevalue, co
264
264
// calculates the checksum from the bytes in the packet
265
265
word Data_Packet::CalculateChecksum (byte* buffer, int length)
266
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 ;
267
+ word checksum = this ->checksum ;
279
268
for (int i=0 ; i<length; i++)
280
269
{
281
270
checksum +=buffer[i];
@@ -294,6 +283,27 @@ byte Data_Packet::GetLowByte(word w)
294
283
{
295
284
return (byte)w&0x00FF ;
296
285
}
286
+
287
+ // sends a byte to the serial debugger in the hex format we want EX "0F"
288
+ void Data_Packet::serialPrintHex (byte data)
289
+ {
290
+ char tmp[16 ];
291
+ sprintf (tmp, " %.2X" ,data);
292
+ Serial.print (tmp);
293
+ }
294
+
295
+ // sends the bye aray to the serial debugger in our hex format EX: "00 AF FF 10 00 13"
296
+ void Data_Packet::SendToSerial (byte data[], int length)
297
+ {
298
+ boolean first=true ;
299
+ Serial.print (" \" " );
300
+ for (int i=0 ; i<length; i++)
301
+ {
302
+ if (first) first=false ; else Serial.print (" " );
303
+ serialPrintHex (data[i]);
304
+ }
305
+ Serial.print (" \" " );
306
+ }
297
307
#ifndef __GNUC__
298
308
#pragma endregion
299
309
#endif // __GNUC__
@@ -896,10 +906,10 @@ void FPS_GT511C3::GetData(int length)
896
906
while (done == false )
897
907
{
898
908
firstbyte = (byte)_serial.read ();
899
- if (firstbyte == Data_Packet () ::DATA_START_CODE_1)
909
+ if (firstbyte == Data_Packet::DATA_START_CODE_1)
900
910
{
901
911
secondbyte = (byte)_serial.read ();
902
- if (secondbyte == Data_Packet () ::DATA_START_CODE_2)
912
+ if (secondbyte == Data_Packet::DATA_START_CODE_2)
903
913
{
904
914
done = true ;
905
915
}
@@ -924,7 +934,7 @@ void FPS_GT511C3::GetData(int length)
924
934
}
925
935
delete firstdata;
926
936
927
- numberPacketsNeeded = (length-4 ) / 128 ;
937
+ int numberPacketsNeeded = (length-4 ) / 128 ;
928
938
bool smallLastPacket = false ;
929
939
int lastPacketSize = (length-4 ) % 128 ;
930
940
if (lastPacketSize != 0 )
@@ -941,7 +951,7 @@ void FPS_GT511C3::GetData(int length)
941
951
while (_serial.available () == false ) delay (10 );
942
952
data[i]= (byte) _serial.read ();
943
953
}
944
- dp. GetData (data, UseSerialDebug);
954
+ dp-> GetData (data, UseSerialDebug);
945
955
if (UseSerialDebug)
946
956
{
947
957
Serial.print (" FPS - RECV: " );
@@ -958,7 +968,7 @@ void FPS_GT511C3::GetData(int length)
958
968
while (_serial.available () == false ) delay (10 );
959
969
lastdata[i]= (byte) _serial.read ();
960
970
}
961
- dp. GetLastData (lastdata, lastPacketSize, UseSerialDebug);
971
+ dp-> GetLastData (lastdata, lastPacketSize, UseSerialDebug);
962
972
if (UseSerialDebug)
963
973
{
964
974
Serial.print (" FPS - RECV: " );
0 commit comments