@@ -222,23 +222,23 @@ Data_Packet::Data_Packet(byte* buffer, bool UseSerialDebug)
222222 CheckParsing (buffer[2 ], DATA_DEVICE_ID_1, DATA_DEVICE_ID_1, " DATA_DEVICE_ID_1" , UseSerialDebug);
223223 CheckParsing (buffer[3 ], DATA_DEVICE_ID_2, DATA_DEVICE_ID_2, " DATA_DEVICE_ID_2" , UseSerialDebug);
224224
225- Data_Packet. checksum = CalculateChecksum (buffer, 4 );
225+ this -> checksum = CalculateChecksum (buffer, 4 );
226226}
227227
228228// 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)
230230{
231- FPS_GT511C3. SendToSerial (buffer, 128 );
232- Data_Packet. checksum = CalculateChecksum (buffer, 128 );
231+ SendToSerial (buffer, 128 );
232+ this -> checksum = CalculateChecksum (buffer, 128 );
233233}
234234
235235// 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)
237237{
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 );
242242 CheckParsing (buffer[length-2 ], checksum_low, checksum_low, " Checksum_LOW" , UseSerialDebug);
243243 CheckParsing (buffer[length-1 ], checksum_high, checksum_high, " Checksum_HIGH" , UseSerialDebug);
244244}
@@ -264,18 +264,7 @@ bool Data_Packet::CheckParsing(byte b, byte propervalue, byte alternatevalue, co
264264// calculates the checksum from the bytes in the packet
265265word Data_Packet::CalculateChecksum (byte* buffer, int length)
266266{
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 ;
279268 for (int i=0 ; i<length; i++)
280269 {
281270 checksum +=buffer[i];
@@ -294,6 +283,27 @@ byte Data_Packet::GetLowByte(word w)
294283{
295284 return (byte)w&0x00FF ;
296285}
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+ }
297307#ifndef __GNUC__
298308#pragma endregion
299309#endif // __GNUC__
@@ -896,10 +906,10 @@ void FPS_GT511C3::GetData(int length)
896906 while (done == false )
897907 {
898908 firstbyte = (byte)_serial.read ();
899- if (firstbyte == Data_Packet () ::DATA_START_CODE_1)
909+ if (firstbyte == Data_Packet::DATA_START_CODE_1)
900910 {
901911 secondbyte = (byte)_serial.read ();
902- if (secondbyte == Data_Packet () ::DATA_START_CODE_2)
912+ if (secondbyte == Data_Packet::DATA_START_CODE_2)
903913 {
904914 done = true ;
905915 }
@@ -924,7 +934,7 @@ void FPS_GT511C3::GetData(int length)
924934 }
925935 delete firstdata;
926936
927- numberPacketsNeeded = (length-4 ) / 128 ;
937+ int numberPacketsNeeded = (length-4 ) / 128 ;
928938 bool smallLastPacket = false ;
929939 int lastPacketSize = (length-4 ) % 128 ;
930940 if (lastPacketSize != 0 )
@@ -941,7 +951,7 @@ void FPS_GT511C3::GetData(int length)
941951 while (_serial.available () == false ) delay (10 );
942952 data[i]= (byte) _serial.read ();
943953 }
944- dp. GetData (data, UseSerialDebug);
954+ dp-> GetData (data, UseSerialDebug);
945955 if (UseSerialDebug)
946956 {
947957 Serial.print (" FPS - RECV: " );
@@ -958,7 +968,7 @@ void FPS_GT511C3::GetData(int length)
958968 while (_serial.available () == false ) delay (10 );
959969 lastdata[i]= (byte) _serial.read ();
960970 }
961- dp. GetLastData (lastdata, lastPacketSize, UseSerialDebug);
971+ dp-> GetLastData (lastdata, lastPacketSize, UseSerialDebug);
962972 if (UseSerialDebug)
963973 {
964974 Serial.print (" FPS - RECV: " );
0 commit comments