@@ -863,6 +863,39 @@ uint8_t FPS_GT511C3::GetTemplate(uint16_t id)
863
863
}
864
864
}
865
865
866
+ // Gets a template from the fps (498 bytes + 2 bytes checksum) and store it in an array
867
+ // Parameter: 0-199 ID number, array pointer to store the data
868
+ // Returns:
869
+ // 0 - ACK Download starting
870
+ // 1 - Invalid position
871
+ // 2 - ID not used (no template to download
872
+ // 3 - Data download failed (Serial overflow)
873
+ uint8_t FPS_GT511C3::GetTemplate (uint16_t id, uint8_t data[])
874
+ {
875
+ #if FPS_DEBUG
876
+ Serial.println (" FPS - GetTemplate" );
877
+ #endif
878
+ Command_Packet* cp = new Command_Packet ();
879
+ cp->Command = Command_Packet::Commands::GetTemplate;
880
+ cp->ParameterFrom (id);
881
+ uint8_t * packetbytes = cp->GetPacketBytes ();
882
+ delete cp;
883
+ SendCommand (packetbytes, 12 );
884
+ delete packetbytes;
885
+ Response_Packet* rp = GetResponse ();
886
+ if (rp->ACK )
887
+ {
888
+ delete rp;
889
+ if (ReturnData (498 +6 , data)) return 0 ;
890
+ else return 3 ;
891
+ } else
892
+ {
893
+ uint32_t retval = rp->FromParameter ();
894
+ delete rp;
895
+ return retval;
896
+ }
897
+ }
898
+
866
899
// Uploads a template to the fps
867
900
// Parameter: the template (498 bytes)
868
901
// Parameter: the ID number to upload
@@ -1173,6 +1206,72 @@ void FPS_GT511C3::GetData(uint16_t length)
1173
1206
dp.GetLastData (lastdata, lastPacketSize);
1174
1207
};
1175
1208
1209
+ // Gets the data (length bytes) from the software serial channel (and waits for it)
1210
+ // and store it in an array
1211
+ // Return: True if the data was succesfully downloaded
1212
+ bool FPS_GT511C3::ReturnData (uint16_t length, uint8_t data[])
1213
+ {
1214
+ uint8_t firstbyte, secondbyte = 0 ;
1215
+ bool done = false ;
1216
+ _serial.listen ();
1217
+ while (done == false )
1218
+ {
1219
+ while (_serial.available () == false ) delay (10 );
1220
+ firstbyte = (uint8_t )_serial.read ();
1221
+ if (firstbyte == Data_Packet::DATA_START_CODE_1)
1222
+ {
1223
+ while (_serial.available () == false ) delay (10 );
1224
+ secondbyte = (uint8_t )_serial.read ();
1225
+ if (secondbyte == Data_Packet::DATA_START_CODE_2)
1226
+ {
1227
+ done = true ;
1228
+ }
1229
+ }
1230
+ }
1231
+
1232
+ uint8_t firstdata[4 ];
1233
+ firstdata[0 ] = firstbyte;
1234
+ firstdata[1 ] = secondbyte;
1235
+ for (uint8_t i=2 ; i < 4 ; i++)
1236
+ {
1237
+ while (_serial.available () == false ) delay (10 );
1238
+ firstdata[i]= (uint8_t ) _serial.read ();
1239
+ }
1240
+ Data_Packet dp (firstdata);
1241
+
1242
+ uint16_t numberPacketsNeeded = (length-4 ) / 64 ;
1243
+ bool smallLastPacket = false ;
1244
+ uint8_t lastPacketSize = (length-4 ) % 64 ;
1245
+ if (lastPacketSize != 0 )
1246
+ {
1247
+ numberPacketsNeeded++;
1248
+ smallLastPacket = true ;
1249
+ }
1250
+
1251
+ for (uint16_t i=0 ; i < length-4 ; i++)
1252
+ {
1253
+ while (_serial.available () == false ) delay (1 );
1254
+ if (_serial.overflow ())
1255
+ {
1256
+ #if FPS_DEBUG
1257
+ Serial.println (" Overflow! Data download stopped" );
1258
+ Serial.println (" Cleaning serial buffer..." );
1259
+ #endif
1260
+ for (uint16_t j = 0 ; j<length; j++)
1261
+ {
1262
+ _serial.read ();
1263
+ delay (1 );
1264
+ }
1265
+ #if FPS_DEBUG
1266
+ Serial.println (" Done!" );
1267
+ #endif
1268
+ return false ;
1269
+ }
1270
+ data[i]= (uint8_t ) _serial.read ();
1271
+ }
1272
+ return true ;
1273
+ };
1274
+
1176
1275
// sends the byte array to the serial debugger in our hex format EX: "00 AF FF 10 00 13"
1177
1276
void FPS_GT511C3::SendToSerial (uint8_t data[], uint16_t length)
1178
1277
{
0 commit comments