Skip to content

Commit

Permalink
Updated to latest version (V1.2.2 HOTFIX).
Browse files Browse the repository at this point in the history
  • Loading branch information
Fasgort committed Dec 9, 2018
2 parents 41e37ca + a55b22f commit a3be6ae
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 14 deletions.
77 changes: 69 additions & 8 deletions src/FPS_GT511C3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Command_Packet::Command_Packet()
#pragma region -= Response_Packet Definitions =-
#endif //__GNUC__
// creates and parses a response packet from the finger print scanner
Response_Packet::Response_Packet(uint8_t* buffer)
Response_Packet::Response_Packet(uint8_t buffer[])
{
CheckParsing(buffer[0], RESPONSE_START_CODE_1, RESPONSE_START_CODE_1, F("RESPONSE_START_CODE_1"));
CheckParsing(buffer[1], RESPONSE_START_CODE_2, RESPONSE_START_CODE_2, F("RESPONSE_START_CODE_2"));
Expand Down Expand Up @@ -189,7 +189,7 @@ bool Response_Packet::CheckParsing(uint8_t b, uint8_t propervalue, uint8_t alter
}

// calculates the checksum from the bytes in the packet
uint16_t Response_Packet::CalculateChecksum(uint8_t* buffer, uint16_t length)
uint16_t Response_Packet::CalculateChecksum(uint8_t buffer[], uint16_t length)
{
uint16_t checksum = 0;
for (uint16_t i=0; i<length; i++)
Expand Down Expand Up @@ -217,7 +217,68 @@ uint8_t Response_Packet::GetLowByte(uint16_t w)
#ifndef __GNUC__
#pragma region -= Data_Packet =-
#endif //__GNUC__
Data_Packet::Data_Packet(uint8_t* buffer)
// creates a data packet and send it to the finger print scanner
Data_Packet::Data_Packet(uint8_t buffer[], uint16_t length, SoftwareSerial _serial)
{

uint8_t* data_code= new uint8_t[4];

data_code[0] = DATA_START_CODE_1;
data_code[1] = DATA_START_CODE_2;
data_code[2] = DATA_DEVICE_ID_1;
data_code[3] = DATA_DEVICE_ID_2;

#if FPS_DEBUG
Serial.println(F("FPS - Template"));
Serial.print(F("FPS - SEND: "));
Serial.print("\"");
bool first=true;
for(uint16_t i=0; i<4; i++)
{
if (first) first=false; else Serial.print(" ");
char tmp[16];
sprintf(tmp, "%.2X", data_code[i]);
Serial.print(tmp);
}
for(uint16_t i=0; i<length; i++)
{
if (first) first=false; else Serial.print(" ");
char tmp[16];
sprintf(tmp, "%.2X", buffer[i]);
Serial.print(tmp);
}
{
if (first) first=false; else Serial.print(" ");
char tmp[16];
sprintf(tmp, "%.2X", GetLowByte(this->checksum));
Serial.print(tmp);
}
{
if (first) first=false; else Serial.print(" ");
char tmp[16];
sprintf(tmp, "%.2X", GetHighByte(this->checksum));
Serial.print(tmp);
}
Serial.print("\"");
Serial.println();
#endif

// Calculate checksum
this->checksum = CalculateChecksum(data_code, 4);
this->checksum = CalculateChecksum(buffer, length);

// Send everything to the finger print scanner
_serial.write(data_code, 4);
_serial.write(buffer, length);
_serial.write(GetLowByte(this->checksum));
_serial.write(GetHighByte(this->checksum));

// clean up
delete data_code;

}
// creates and parses a data packet from the finger print scanner
Data_Packet::Data_Packet(uint8_t buffer[])
{
#if FPS_DEBUG
CheckParsing(buffer[0], DATA_START_CODE_1, DATA_START_CODE_1, F("DATA_START_CODE_1"));
Expand Down Expand Up @@ -273,7 +334,7 @@ bool Data_Packet::CheckParsing(uint8_t b, uint8_t propervalue, uint8_t alternate
}

// calculates the checksum from the bytes in the packet
uint16_t Data_Packet::CalculateChecksum(uint8_t* buffer, uint16_t length)
uint16_t Data_Packet::CalculateChecksum(uint8_t buffer[], uint16_t length)
{
uint16_t checksum = this->checksum;
for (uint16_t i=0; i<length; i++)
Expand Down Expand Up @@ -907,7 +968,7 @@ uint8_t FPS_GT511C3::GetTemplate(uint16_t id, uint8_t data[])
// 2 - Invalid position
// 3 - Communications error
// 4 - Device error
uint16_t FPS_GT511C3::SetTemplate(byte* tmplt, uint16_t id, bool duplicateCheck)
uint16_t FPS_GT511C3::SetTemplate(uint8_t tmplt[], uint16_t id, bool duplicateCheck)
{
#if FPS_DEBUG
Serial.println(F("FPS - SetTemplate"));
Expand All @@ -926,7 +987,7 @@ uint16_t FPS_GT511C3::SetTemplate(byte* tmplt, uint16_t id, bool duplicateCheck)
return 2;
} else
{
SendCommand(tmplt, 498); // Not actually a command ;)
Data_Packet dp(tmplt, 498, _serial); // This makes the data packet and sends it immediately
rp = GetResponse();
if (rp->ACK)
{
Expand Down Expand Up @@ -954,7 +1015,7 @@ uint16_t FPS_GT511C3::SetTemplate(byte* tmplt, uint16_t id, bool duplicateCheck)
#endif //__GNUC__

#ifndef __GNUC__
#pragma region -= Not imlemented commands =-
#pragma region -= Not implemented commands =-
#endif //__GNUC__
// Commands that are not implemented (and why)
// VerifyTemplate1_1 - Couldn't find a good reason to implement this on an arduino
Expand Down Expand Up @@ -1266,7 +1327,7 @@ bool FPS_GT511C3::ReturnData(uint16_t length, uint8_t data[])
// sends the byte array to the serial debugger in our hex format EX: "00 AF FF 10 00 13"
void FPS_GT511C3::SendToSerial(uint8_t data[], uint16_t length)
{
boolean first=true;
bool first=true;
Serial.print("\"");
for(uint16_t i=0; i<length; i++)
{
Expand Down
13 changes: 7 additions & 6 deletions src/FPS_GT511C3.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Debug level:
// 0: Disabled
// 1: Enables verbose debug output using hardware Serial
#define FPS_DEBUG 0
#define FPS_DEBUG 1

#ifndef __GNUC__
#pragma region -= Command_Packet =-
Expand Down Expand Up @@ -126,7 +126,7 @@ class Response_Packet

static Errors_Enum ParseFromBytes(byte high, byte low);
};
Response_Packet(uint8_t* buffer);
Response_Packet(uint8_t buffer[]);
ErrorCodes::Errors_Enum Error;
uint8_t RawBytes[12];
uint8_t ParameterBytes[4];
Expand All @@ -140,7 +140,7 @@ class Response_Packet

private:
bool CheckParsing(uint8_t b, uint8_t propervalue, uint8_t alternatevalue, const String varname);
uint16_t CalculateChecksum(uint8_t* buffer, uint16_t length);
uint16_t CalculateChecksum(uint8_t buffer[], uint16_t length);
uint8_t GetHighByte(uint16_t w);
uint8_t GetLowByte(uint16_t w);
};
Expand All @@ -156,7 +156,8 @@ class Response_Packet
class Data_Packet
{
public:
Data_Packet(uint8_t* buffer);
Data_Packet(uint8_t buffer[], uint16_t length, SoftwareSerial _serial);
Data_Packet(uint8_t buffer[]);
uint16_t checksum = 0;
static const uint8_t DATA_START_CODE_1 = 0x5A; // Static byte to mark the beginning of a data packet - never changes
static const uint8_t DATA_START_CODE_2 = 0xA5; // Static byte to mark the beginning of a data packet - never changes
Expand All @@ -167,7 +168,7 @@ class Data_Packet
void GetLastData(uint8_t buffer[], uint16_t length);
private:
bool CheckParsing(uint8_t b, uint8_t propervalue, uint8_t alternatevalue, const String varname);
uint16_t CalculateChecksum(uint8_t* buffer, uint16_t length);
uint16_t CalculateChecksum(uint8_t buffer[], uint16_t length);
uint8_t GetHighByte(uint16_t w);
uint8_t GetLowByte(uint16_t w);
};
Expand Down Expand Up @@ -341,7 +342,7 @@ class FPS_GT511C3
// 2 - Invalid position
// 3 - Communications error
// 4 - Device error
uint16_t SetTemplate(byte* tmplt, uint16_t id, bool duplicateCheck);
uint16_t SetTemplate(uint8_t tmplt[], uint16_t id, bool duplicateCheck);
#ifndef __GNUC__
#pragma endregion
#endif //__GNUC__
Expand Down

0 comments on commit a3be6ae

Please sign in to comment.