Skip to content

Commit 0f67779

Browse files
committed
Since the template doesn't require much memory storage (500 bytes will do), I implemented a function that allows you to return the template, instead of just simply sending it over Serial. Have fun.
1 parent d831fcd commit 0f67779

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

src/FPS_GT511C3.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,39 @@ uint8_t FPS_GT511C3::GetTemplate(uint16_t id)
863863
}
864864
}
865865

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+
866899
// Uploads a template to the fps
867900
// Parameter: the template (498 bytes)
868901
// Parameter: the ID number to upload
@@ -1173,6 +1206,72 @@ void FPS_GT511C3::GetData(uint16_t length)
11731206
dp.GetLastData(lastdata, lastPacketSize);
11741207
};
11751208

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+
11761275
// sends the byte array to the serial debugger in our hex format EX: "00 AF FF 10 00 13"
11771276
void FPS_GT511C3::SendToSerial(uint8_t data[], uint16_t length)
11781277
{

src/FPS_GT511C3.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ class FPS_GT511C3
321321
// 1 - Invalid position
322322
// 2 - ID not used (no template to download
323323
uint8_t GetTemplate(uint16_t id);
324+
325+
// Gets a template from the fps (498 bytes + 2 bytes checksum) and store it in an array
326+
// Parameter: 0-199 ID number, array pointer to store the data
327+
// Returns:
328+
// 0 - ACK Download starting
329+
// 1 - Invalid position
330+
// 2 - ID not used (no template to download
331+
uint8_t GetTemplate(uint16_t id, uint8_t data[]);
324332

325333
// Uploads a template to the fps
326334
// Parameter: the template (498 bytes)
@@ -374,6 +382,7 @@ class FPS_GT511C3
374382
void SendCommand(uint8_t cmd[], uint16_t length);
375383
Response_Packet* GetResponse();
376384
void GetData(uint16_t length);
385+
bool ReturnData(uint16_t length, uint8_t data[]);
377386
uint8_t pin_RX,pin_TX;
378387
SoftwareSerial _serial;
379388
};

0 commit comments

Comments
 (0)