Library for R306 fingerprint module
Dependents: R306_fingerprintmodule_WizwikiW7500
Fork of GT511C3 by
Diff: FPC_R306.cpp
- Revision:
- 2:12ca31a7364e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FPC_R306.cpp Mon Jul 16 10:14:28 2018 +0000 @@ -0,0 +1,268 @@ + + + +//......Created by the CDI KENGERI TEAM (CHRIST(Deemed to be University)) Bangalore, Karnataka, India..........// + + +#include "mbed.h" +#include "FPC_R306.hpp" +Serial FPC(PA_13,PA_14); +Serial lib(USBTX,USBRX); +#define SET_AND_SUMADD(idx,val) sendbuf[idx]=((unsigned char)(val));//sum += sendbuf[idx] + +/*int FPC_R306::Init(void) +{ + baud(57600); + ClearLine(); + return 0; +}*/ + +int FPC_R306::CMD_GETIMG() +{ + FPC.baud(57600); + FPC.putc(0xEF); //start_code + FPC.putc(0x01); //start_code + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0x01); //type + FPC.putc(0x00); //length + FPC.putc(0x03); //length + FPC.putc(0x01); //command + FPC.putc(0x00); //Checksum + FPC.putc(0x05); //Checksum + uint8_t resp = RecvResponse(); + return resp; +} + + +int FPC_R306::CMD_IMG2Tz1() +{ + FPC.baud(57600); + FPC.putc(0xEF); //start_code + FPC.putc(0x01); //start_code + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0x01); //type (package identifier) + FPC.putc(0x00); //datalength + FPC.putc(0x04); //datalength + FPC.putc(0x02); //command + FPC.putc(0x01); //slot number + FPC.putc(0x00); //Checksum + FPC.putc(0x08); //Checksum + uint8_t resp = RecvResponse(); + return resp; + } + +int FPC_R306::CMD_IMG2Tz2() +{ + FPC.baud(57600); + FPC.putc(0xEF); //start_code + FPC.putc(0x01); //start_code + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0x01); //type (package identifier) + FPC.putc(0x00); //datalength + FPC.putc(0x04); //datalength + FPC.putc(0x02); //command + FPC.putc(0x02); //slot number + FPC.putc(0x00); //Checksum + FPC.putc(0x09); //Checksum + uint8_t resp = RecvResponse(); + return resp; + } + + +int FPC_R306::createModel() +{ + FPC.baud(57600); + FPC.putc(0xEF); //start_code + FPC.putc(0x01); //start_code + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0x01); //type (package identifier) + FPC.putc(0x00); //datalength + FPC.putc(0x03); //datalength + FPC.putc(0x05); //command + FPC.putc(0x00); //Checksum + FPC.putc(0x09); //Checksum + uint8_t resp = RecvResponse(); + return resp; + } + + +int FPC_R306:: STORE_MODEL(uint16_t id) +{ + FPC.baud(57600); + FPC.putc(0xEF); //start_code + FPC.putc(0x01); //start_code + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0x01); //type (package identifier) + FPC.putc(0x00); //datalength + FPC.putc(0x06); //datalength + FPC.putc(0x06); //command + FPC.putc(0x01); //bufferID + uint8_t sum = 0x0E; //type + datalength + command + BufferID + FPC.putc((uint8_t)(id >> 8)); + FPC.putc((uint8_t)(id & 0xFF)); + uint16_t checksum = ((uint8_t)(sum & 0xFF) + (uint8_t)(id >> 8) + (uint8_t)(id & 0xFF)); //checkssum = type + datalength + command + BufferID + ID + FPC.putc((uint8_t)(checksum >> 8)); //Checksum + FPC.putc((uint8_t) (checksum & 0xFF)); //Checksum + uint8_t resp = RecvResponse(); + return resp; + } + +uint8_t FPC_R306::RecvResponse() +{ + FPC.baud(57600); + //lib.printf("Waiting for response\n"); + uint8_t byte[12]; + int i=0; + for(i=0;i<12;i++) + { + byte[i] = FPC.getc(); + } + //lib.printf("Reading Done\n"); + return byte[9]; + +} + +uint8_t FPC_R306 :: FAST_SEARCH() +{ + FPC.baud(57600); + FPC.putc(0xEF); //start_code + FPC.putc(0x01); //start_code + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0x01); //type (package identifier) + FPC.putc(0x00); //datalength + FPC.putc(0x08); //datalength + FPC.putc(0x1B); //command + FPC.putc(0x01); //CharBuffer + FPC.putc(0x00); //Start Page + FPC.putc(0x00); //Start Page + FPC.putc(0x00); //Page Num + FPC.putc(0xA3); //Page Num + FPC.putc(0x00); //Checksum + FPC.putc(0xC8); //Checksum + uint8_t resp = Recv_FAST_SEARCH(); + return resp; + } + +uint8_t FPC_R306 :: TMPL_COUNT() +{ + FPC.baud(57600); + FPC.putc(0xEF); //start_code + FPC.putc(0x01); //start_code + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0x01); //type (package identifier) + FPC.putc(0x00); //datalength + FPC.putc(0x03); //datalength + FPC.putc(0x1D); //command + FPC.putc(0x00); //Checksum + FPC.putc(0x21); //Checksum + uint8_t resp = Recv_TMPL_COUNT(); + return resp; + } + + +uint8_t FPC_R306 :: DELETE_ID(uint16_t id) +{ + FPC.baud(57600); + FPC.putc(0xEF); //start_code + FPC.putc(0x01); //start_code + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0x01); //type (package identifier) + FPC.putc(0x00); //datalength + FPC.putc(0x07); //datalength + FPC.putc(0x0C); //command + FPC.putc((uint8_t) id >>8 ); //ID num (Page Num) + FPC.putc((uint8_t) id & 0xFF); //ID num (Page Num) + FPC.putc(0x00); //Number of templates + FPC.putc(0x01); //Number of templates + uint8_t sum = 0x15; // sum = type + datalength + command + no. of templates + uint16_t checksum = ((uint8_t)(sum & 0xFF) + (uint8_t)(id >> 8) + (uint8_t)(id & 0xFF)); + FPC.putc((uint8_t)(checksum >> 8)); //Checksum + FPC.putc((uint8_t)(checksum & 0xFF)); //Checksum + uint8_t resp = RecvResponse(); + return resp; + } + + +uint8_t FPC_R306 :: EMPTY_LIB() +{ + FPC.baud(57600); + FPC.putc(0xEF); //start_code + FPC.putc(0x01); //start_code + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0xFF); //address + FPC.putc(0x01); //type (package identifier) + FPC.putc(0x00); //datalength + FPC.putc(0x03); //datalength + FPC.putc(0x0D); //command + FPC.putc(0x00); //Checksum + FPC.putc(0x11); //Checksum + uint8_t resp = RecvResponse(); + return resp; + } + + +uint8_t FPC_R306 :: Recv_TMPL_COUNT() +{ + FPC.baud(57600); + //lib.printf("Waiting for response\n"); + uint8_t byte[14]; + int i=0; + for(i=0;i<14;i++) + { + byte[i] = FPC.getc(); + } + templatecount = byte[10]; + templatecount <<=8; + templatecount |= byte[11]; + + return byte[9]; + } + + +uint8_t FPC_R306:: Recv_FAST_SEARCH() +{ + FPC.baud(57600); + //lib.printf("Waiting for response\n"); + uint8_t byte[16]; + int i=0; + for(i=0;i<16;i++) + { + byte[i] = FPC.getc(); + } + fingerID = byte[10]; + fingerID <<=8; + fingerID |= byte[11]; + + MatchScore = byte[12]; + MatchScore <<=8; + MatchScore |= byte[13]; + + return byte[9]; + } + \ No newline at end of file