Fingerprint Scanner API using GT511C3 fingerprint scanner.

Dependencies:   4DGL-uLCD-SE GT511C3 SDFileSystem mbed

Fork of GT511C3test by Toshihisa T

The fingerprint scanner is designed to take attendance over a group of students. It requires a the group owner to store a preloaded list of student id numbers in a .txt file to the memory (SD card) in return of a 5 digits keypass to gain access to the database when taking attendance.

While there may exist multiple group owner and a group owner with multiple databases, each group will be uniquely identified by the 5 digits keypass. The program limits each scanner to open ONE session at a time where only one group will be able to take attendance during its session. Once a session is closed, a report of the attendance taken during the open session is generated and sent via ethernet to owner and there is no way to reopen the session again.

For the initial setup, each fingerprint database needs to be populated by the students. This set up can be done continuously during a session while taking attendance that session.

Committer:
yoshua0207
Date:
Tue Dec 01 19:10:10 2015 +0000
Revision:
8:a1ba925cf903
Parent:
7:8b9ef3211cd0
Current fingerprint scanner code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tosihisa 6:016ad8f480d3 1 #include "GT511C3.hpp"
yoshua0207 8:a1ba925cf903 2 #include "uLCD_4DGL.h"
yoshua0207 8:a1ba925cf903 3 #include "SDFileSystem.h"
yoshua0207 8:a1ba925cf903 4 #include <string>
tosihisa 0:b11b455d4997 5
yoshua0207 8:a1ba925cf903 6
yoshua0207 8:a1ba925cf903 7 // LCD, IO
yoshua0207 8:a1ba925cf903 8 uLCD_4DGL uLCD(p28, p27, p30);
tosihisa 0:b11b455d4997 9 Serial debug(USBTX,USBRX);
yoshua0207 8:a1ba925cf903 10 GT511C3 finger(p9,p10);
yoshua0207 8:a1ba925cf903 11 SDFileSystem sd(p5, p6, p7, p8, "sd");
yoshua0207 8:a1ba925cf903 12
yoshua0207 8:a1ba925cf903 13 // Set these variables to 0 after each read
yoshua0207 8:a1ba925cf903 14 // KEYPAD_BOTTOM LEFT
yoshua0207 8:a1ba925cf903 15 DigitalOut is_cancelled(LED1);//10
yoshua0207 8:a1ba925cf903 16 // KEYPAD_BOTTOM_RIGHT
yoshua0207 8:a1ba925cf903 17 DigitalOut is_entered(LED2); //11
tosihisa 0:b11b455d4997 18
yoshua0207 8:a1ba925cf903 19 // FUNCTIONS:
yoshua0207 8:a1ba925cf903 20 void user_menu();
yoshua0207 8:a1ba925cf903 21 void open_existing_system();
yoshua0207 8:a1ba925cf903 22 void start_session();
yoshua0207 8:a1ba925cf903 23 void close_session();
yoshua0207 8:a1ba925cf903 24 void read_from_fingerprint_scanner();
yoshua0207 8:a1ba925cf903 25 void close_session();
yoshua0207 8:a1ba925cf903 26 int read_keypad(char* readable, int how_many);
yoshua0207 8:a1ba925cf903 27 void upload_to_scanner();
yoshua0207 8:a1ba925cf903 28 void download_to_memory();
yoshua0207 8:a1ba925cf903 29 void send_file_via_wifi();
yoshua0207 8:a1ba925cf903 30 int owner_database_contains(char* gid);
yoshua0207 8:a1ba925cf903 31 void wait_cancelled_or_entered();
tosihisa 0:b11b455d4997 32
yoshua0207 8:a1ba925cf903 33 // CONSTANT VARIABLES
yoshua0207 8:a1ba925cf903 34 const int id_size = 5;
yoshua0207 8:a1ba925cf903 35 const int group_size = 200;
yoshua0207 8:a1ba925cf903 36 const int owner_id_size = 20;
yoshua0207 8:a1ba925cf903 37 string owner_id_file = "owner_id_file.txt";
yoshua0207 8:a1ba925cf903 38 string sid_file = "sid_file.txt";
yoshua0207 8:a1ba925cf903 39
yoshua0207 8:a1ba925cf903 40 // VARIABLES
yoshua0207 8:a1ba925cf903 41 char group_id[id_size]; // group_id null >> no open session
yoshua0207 8:a1ba925cf903 42 int this_session_id[group_size];
yoshua0207 8:a1ba925cf903 43 int student_id_number[group_size];
yoshua0207 8:a1ba925cf903 44 char* from_user;
yoshua0207 8:a1ba925cf903 45
yoshua0207 8:a1ba925cf903 46 int main() {
yoshua0207 8:a1ba925cf903 47 user_menu();
tosihisa 3:459a4f985a45 48 return 0;
tosihisa 2:34a647292050 49 }
tosihisa 2:34a647292050 50
yoshua0207 8:a1ba925cf903 51 void user_menu() {
yoshua0207 8:a1ba925cf903 52
yoshua0207 8:a1ba925cf903 53 uLCD.printf("***********************\n");
yoshua0207 8:a1ba925cf903 54 uLCD.printf("* Fingerprint Scanner *\n");
yoshua0207 8:a1ba925cf903 55 uLCD.printf("***********************\n\n");
yoshua0207 8:a1ba925cf903 56 uLCD.printf("Welcome!\n\n");
yoshua0207 8:a1ba925cf903 57 open_existing_system();
yoshua0207 8:a1ba925cf903 58 }
yoshua0207 8:a1ba925cf903 59
yoshua0207 8:a1ba925cf903 60 /*
yoshua0207 8:a1ba925cf903 61 * Starts the program by asking the user which database
yoshua0207 8:a1ba925cf903 62 * the user is going to be using for the session.
yoshua0207 8:a1ba925cf903 63 */
yoshua0207 8:a1ba925cf903 64 void open_existing_system() {
yoshua0207 8:a1ba925cf903 65
yoshua0207 8:a1ba925cf903 66 int is_done = 0;
yoshua0207 8:a1ba925cf903 67 while (!is_done){
yoshua0207 8:a1ba925cf903 68
yoshua0207 8:a1ba925cf903 69 //Ask for user input
yoshua0207 8:a1ba925cf903 70 uLCD.printf("Enter group ID: ");
yoshua0207 8:a1ba925cf903 71
yoshua0207 8:a1ba925cf903 72 // get user input >> read group id ******
yoshua0207 8:a1ba925cf903 73 from_user = "41811";
yoshua0207 8:a1ba925cf903 74
yoshua0207 8:a1ba925cf903 75 // check the input against owner data
yoshua0207 8:a1ba925cf903 76 if (owner_database_contains(from_user)) {
yoshua0207 8:a1ba925cf903 77 start_session();
yoshua0207 8:a1ba925cf903 78 }
yoshua0207 8:a1ba925cf903 79 }
yoshua0207 8:a1ba925cf903 80 }
tosihisa 0:b11b455d4997 81
yoshua0207 8:a1ba925cf903 82 /*
yoshua0207 8:a1ba925cf903 83 * This method checks whether the database contains the specific group
yoshua0207 8:a1ba925cf903 84 * that the user specified using the id
yoshua0207 8:a1ba925cf903 85 *
yoshua0207 8:a1ba925cf903 86 * @param char* gid user specified string id "****" of length id_size
yoshua0207 8:a1ba925cf903 87 * @return int 1 if true, 0 otherwise
yoshua0207 8:a1ba925cf903 88 */
yoshua0207 8:a1ba925cf903 89 int owner_database_contains(char* gid) {
yoshua0207 8:a1ba925cf903 90 string fileName = "/sd/" + owner_id_file;
yoshua0207 8:a1ba925cf903 91 const char* conv_file = fileName.c_str();
yoshua0207 8:a1ba925cf903 92 FILE *file = fopen(conv_file, "r");
yoshua0207 8:a1ba925cf903 93 debug.printf("Opening file %s \n",fileName);
yoshua0207 8:a1ba925cf903 94 if (file) {
yoshua0207 8:a1ba925cf903 95 char c;
yoshua0207 8:a1ba925cf903 96 char* temp[id_size];
yoshua0207 8:a1ba925cf903 97 c = fgetc(file);
yoshua0207 8:a1ba925cf903 98 while(c != "\n")
yoshua0207 8:a1ba925cf903 99 {
yoshua0207 8:a1ba925cf903 100 temp.putc(c);
yoshua0207 8:a1ba925cf903 101 c = fgetc(file);
yoshua0207 8:a1ba925cf903 102 }
yoshua0207 8:a1ba925cf903 103 debug.printf("temp is %s\n", temp);
yoshua0207 8:a1ba925cf903 104 while (temp) {
yoshua0207 8:a1ba925cf903 105 if (int(*gid) == int(*temp)) {
yoshua0207 8:a1ba925cf903 106 fclose(file);
yoshua0207 8:a1ba925cf903 107 return 1;
yoshua0207 8:a1ba925cf903 108 }
yoshua0207 8:a1ba925cf903 109 char c;
yoshua0207 8:a1ba925cf903 110 char temp[id_size];
yoshua0207 8:a1ba925cf903 111 c = fgetc(file);
yoshua0207 8:a1ba925cf903 112 while(c ~= "\n")
yoshua0207 8:a1ba925cf903 113 {
yoshua0207 8:a1ba925cf903 114 temp.putc(c);
yoshua0207 8:a1ba925cf903 115 c = fgetc(file);
yoshua0207 8:a1ba925cf903 116 }
yoshua0207 8:a1ba925cf903 117 }
tosihisa 7:8b9ef3211cd0 118
yoshua0207 8:a1ba925cf903 119 }
yoshua0207 8:a1ba925cf903 120 fclose(file);
yoshua0207 8:a1ba925cf903 121 return -1;
yoshua0207 8:a1ba925cf903 122 }
yoshua0207 8:a1ba925cf903 123
yoshua0207 8:a1ba925cf903 124 int sid_file_contains(char* sid) {
yoshua0207 8:a1ba925cf903 125 string fileName = "/sd/" + string(group_id) + "/" + sid_file;
yoshua0207 8:a1ba925cf903 126 const char* conv_file = fileName.c_str();
yoshua0207 8:a1ba925cf903 127 FILE *file = fopen(conv_file, "r");
yoshua0207 8:a1ba925cf903 128 debug.printf("Opening file %s\n",fileName);
yoshua0207 8:a1ba925cf903 129 if (file) {
yoshua0207 8:a1ba925cf903 130 char temp[15];
yoshua0207 8:a1ba925cf903 131 file.getline(temp, 15);
yoshua0207 8:a1ba925cf903 132 while(temp)
yoshua0207 8:a1ba925cf903 133 {
yoshua0207 8:a1ba925cf903 134 digitC = strtok(temp, " ");
yoshua0207 8:a1ba925cf903 135 if(strcmp(digitC[1],sid))
yoshua0207 8:a1ba925cf903 136 {
yoshua0207 8:a1ba925cf903 137 fclose(file);
yoshua0207 8:a1ba925cf903 138 return (int)digitC[0];
yoshua0207 8:a1ba925cf903 139 }
yoshua0207 8:a1ba925cf903 140 file.getline(temp, 15);
tosihisa 4:3dd0f98e6f09 141 }
tosihisa 4:3dd0f98e6f09 142 }
yoshua0207 8:a1ba925cf903 143 fclose(file);
yoshua0207 8:a1ba925cf903 144 return -1;
yoshua0207 8:a1ba925cf903 145 }
yoshua0207 8:a1ba925cf903 146
yoshua0207 8:a1ba925cf903 147 /*
yoshua0207 8:a1ba925cf903 148 * Start session is called once a group database has been identified
yoshua0207 8:a1ba925cf903 149 * and loaded to the fingerprint scanner. Start session will allow
yoshua0207 8:a1ba925cf903 150 * users to start scanning fingerprints for the current session.
yoshua0207 8:a1ba925cf903 151 *
yoshua0207 8:a1ba925cf903 152 * @param: none
yoshua0207 8:a1ba925cf903 153 * @return: none
yoshua0207 8:a1ba925cf903 154 */
yoshua0207 8:a1ba925cf903 155 void start_session() {
yoshua0207 8:a1ba925cf903 156
yoshua0207 8:a1ba925cf903 157 // upload the specified database to the fingerprint
yoshua0207 8:a1ba925cf903 158 upload_to_scanner();
tosihisa 0:b11b455d4997 159
yoshua0207 8:a1ba925cf903 160 // display options to user via LCD
yoshua0207 8:a1ba925cf903 161 uLCD.printf("Session <session_name> is open.\n");
yoshua0207 8:a1ba925cf903 162 uLCD.printf("Press (1) Scan fingerprint!\n\n");
yoshua0207 8:a1ba925cf903 163 uLCD.printf("Press (2) Add fingerprint!\n\n");
yoshua0207 8:a1ba925cf903 164 uLCD.printf("Press (11) to close session\n");
yoshua0207 8:a1ba925cf903 165 uLCD.printf("Press (10) to go back\n");
yoshua0207 8:a1ba925cf903 166
yoshua0207 8:a1ba925cf903 167 int is_closed = 0;
yoshua0207 8:a1ba925cf903 168 while (!is_closed) {
yoshua0207 8:a1ba925cf903 169
yoshua0207 8:a1ba925cf903 170 // int digit = get_digit_keypad();
yoshua0207 8:a1ba925cf903 171 int digit = 2;
yoshua0207 8:a1ba925cf903 172 if (digit = 1) {
yoshua0207 8:a1ba925cf903 173 // scan the fingerprint
yoshua0207 8:a1ba925cf903 174 read_from_fingerprint_scanner();
yoshua0207 8:a1ba925cf903 175 }
yoshua0207 8:a1ba925cf903 176
yoshua0207 8:a1ba925cf903 177 if(digit = 2){
yoshua0207 8:a1ba925cf903 178 // add new fingerprints
yoshua0207 8:a1ba925cf903 179 add_new_fingerprint();
yoshua0207 8:a1ba925cf903 180
yoshua0207 8:a1ba925cf903 181 }
yoshua0207 8:a1ba925cf903 182
yoshua0207 8:a1ba925cf903 183 // read whether is_closed is updated
yoshua0207 8:a1ba925cf903 184 if (digit = 10) {
yoshua0207 8:a1ba925cf903 185
yoshua0207 8:a1ba925cf903 186 // read the keypad for group id and put it in input_group_id
yoshua0207 8:a1ba925cf903 187 char input_group_id[id_size];
yoshua0207 8:a1ba925cf903 188 read_keypad(input_group_id, id_size);
yoshua0207 8:a1ba925cf903 189
yoshua0207 8:a1ba925cf903 190 if (atoi(input_group_id) - atoi(group_id) == 0) {
yoshua0207 8:a1ba925cf903 191 is_closed = 1;
yoshua0207 8:a1ba925cf903 192 } else {
yoshua0207 8:a1ba925cf903 193 uLCD.printf("Group ID does not match!\nUnable to close session.\n");
tosihisa 6:016ad8f480d3 194 }
tosihisa 6:016ad8f480d3 195 }
tosihisa 3:459a4f985a45 196 }
yoshua0207 8:a1ba925cf903 197 close_session();
yoshua0207 8:a1ba925cf903 198 }
tosihisa 3:459a4f985a45 199
yoshua0207 8:a1ba925cf903 200 /*
yoshua0207 8:a1ba925cf903 201 * Compare whether the currently scanned fingerprint is contained
yoshua0207 8:a1ba925cf903 202 * in the existing database. Set the this_session_id data structure
yoshua0207 8:a1ba925cf903 203 * to 1 if yes to notify that the person has signed in for this
yoshua0207 8:a1ba925cf903 204 * session.
yoshua0207 8:a1ba925cf903 205 *
yoshua0207 8:a1ba925cf903 206 * @param none
yoshua0207 8:a1ba925cf903 207 * @return none
yoshua0207 8:a1ba925cf903 208 */
yoshua0207 8:a1ba925cf903 209 void read_from_fingerprint_scanner() {
yoshua0207 8:a1ba925cf903 210 int FID = -1;
yoshua0207 8:a1ba925cf903 211
yoshua0207 8:a1ba925cf903 212 //Talk to the fingerprint and get an ID back
yoshua0207 8:a1ba925cf903 213 uLCD.printf("Press finger for Identify\n");
yoshua0207 8:a1ba925cf903 214 finger.WaitPress(1);
yoshua0207 8:a1ba925cf903 215 if(finger.Capture(1) != 0)
yoshua0207 8:a1ba925cf903 216 continue;
yoshua0207 8:a1ba925cf903 217 FID = finger.Identify();
yoshua0207 8:a1ba925cf903 218 uLCD.printf("ID = %d\n",ID);
yoshua0207 8:a1ba925cf903 219 uLCD.printf("Remove finger\n");
yoshua0207 8:a1ba925cf903 220 finger.WaitPress(0);
yoshua0207 8:a1ba925cf903 221
yoshua0207 8:a1ba925cf903 222 if (FID >= 0 & FID < group_size) {
yoshua0207 8:a1ba925cf903 223 this_session_id[FID] = 1;
yoshua0207 8:a1ba925cf903 224
yoshua0207 8:a1ba925cf903 225 uLCD.printf("Welcome, %s!", STUDENT_NAME);
yoshua0207 8:a1ba925cf903 226 // make this
yoshua0207 8:a1ba925cf903 227 } else {
yoshua0207 8:a1ba925cf903 228 uLCD.printf("Sorry, ID failed!");
tosihisa 0:b11b455d4997 229 }
tosihisa 0:b11b455d4997 230 }
yoshua0207 8:a1ba925cf903 231 /*
yoshua0207 8:a1ba925cf903 232 * Add new fingerprint into the existing class session
yoshua0207 8:a1ba925cf903 233 *
yoshua0207 8:a1ba925cf903 234 * @param none
yoshua0207 8:a1ba925cf903 235 * @return none
yoshua0207 8:a1ba925cf903 236 */
yoshua0207 8:a1ba925cf903 237 void add_new_fingerprint() {
yoshua0207 8:a1ba925cf903 238
yoshua0207 8:a1ba925cf903 239 while(finger.CheckEnrolled(EnrollID)==0) {
yoshua0207 8:a1ba925cf903 240 EnrollID++;
yoshua0207 8:a1ba925cf903 241 }
yoshua0207 8:a1ba925cf903 242 uLCD.printf("Insert student ID :\n");
yoshua0207 8:a1ba925cf903 243 temp = "903091568";
yoshua0207 8:a1ba925cf903 244 debug.printf("%s\n", temp);
yoshua0207 8:a1ba925cf903 245 EnrollID = sid_file_contains(temp);
yoshua0207 8:a1ba925cf903 246 finger.Enroll(EnrollID, progress);
yoshua0207 8:a1ba925cf903 247
yoshua0207 8:a1ba925cf903 248 }
yoshua0207 8:a1ba925cf903 249
yoshua0207 8:a1ba925cf903 250
yoshua0207 8:a1ba925cf903 251 /*
yoshua0207 8:a1ba925cf903 252 * Close session is called when a group database
yoshua0207 8:a1ba925cf903 253 * has been uploaded to the fingerprint scanner
yoshua0207 8:a1ba925cf903 254 *
yoshua0207 8:a1ba925cf903 255 */
yoshua0207 8:a1ba925cf903 256 void close_session() {
yoshua0207 8:a1ba925cf903 257 download_to_memory();
yoshua0207 8:a1ba925cf903 258 send_file_via_wifi();
yoshua0207 8:a1ba925cf903 259 // TODO: put changed data in mbed to the micro sd and other housekeeping stuff
yoshua0207 8:a1ba925cf903 260 // Reset the id to be none
yoshua0207 8:a1ba925cf903 261 group_id = 0;
yoshua0207 8:a1ba925cf903 262 }
yoshua0207 8:a1ba925cf903 263
yoshua0207 8:a1ba925cf903 264 /* Reads from the keypad id_size digits of input
yoshua0207 8:a1ba925cf903 265 * until the user presses the enter button.
yoshua0207 8:a1ba925cf903 266 * If the user presses the cancel button, discard the
yoshua0207 8:a1ba925cf903 267 * digits read and return.
yoshua0207 8:a1ba925cf903 268 * @param char* readable the pointer to put the input read from user
yoshua0207 8:a1ba925cf903 269 * @return int 0 if no change made to the parameter, 1 otherwise
yoshua0207 8:a1ba925cf903 270 */
yoshua0207 8:a1ba925cf903 271 int read_keypad(char* readable, int how_many) {
yoshua0207 8:a1ba925cf903 272
yoshua0207 8:a1ba925cf903 273 char from_user[how_many];
yoshua0207 8:a1ba925cf903 274
yoshua0207 8:a1ba925cf903 275 int index = 0;
yoshua0207 8:a1ba925cf903 276 while (1) {
yoshua0207 8:a1ba925cf903 277 if (index < how_many) {
yoshua0207 8:a1ba925cf903 278 int keypad = get_digit_keypad();
yoshua0207 8:a1ba925cf903 279
yoshua0207 8:a1ba925cf903 280 if (keypad = 10) {
yoshua0207 8:a1ba925cf903 281 return 0;
yoshua0207 8:a1ba925cf903 282 } else if (keypad = 11) {
yoshua0207 8:a1ba925cf903 283 from_user = readable;
yoshua0207 8:a1ba925cf903 284 return 1;
yoshua0207 8:a1ba925cf903 285 } else {
yoshua0207 8:a1ba925cf903 286 from_user[index] = keypad;
yoshua0207 8:a1ba925cf903 287 }
yoshua0207 8:a1ba925cf903 288
yoshua0207 8:a1ba925cf903 289 uLCD.printf("%d\n",from_user[index]);
yoshua0207 8:a1ba925cf903 290 uLCD.printf(" * \n");
yoshua0207 8:a1ba925cf903 291 } else if (index == how_many) {
yoshua0207 8:a1ba925cf903 292 index--;
yoshua0207 8:a1ba925cf903 293 }
yoshua0207 8:a1ba925cf903 294 index++;
yoshua0207 8:a1ba925cf903 295 }
yoshua0207 8:a1ba925cf903 296 }
yoshua0207 8:a1ba925cf903 297
yoshua0207 8:a1ba925cf903 298 int get_digit_keypad() {
yoshua0207 8:a1ba925cf903 299 int key_code=0;
yoshua0207 8:a1ba925cf903 300 int i=0;
yoshua0207 8:a1ba925cf903 301 int value=keypad.read(0x00);
yoshua0207 8:a1ba925cf903 302 value +=keypad.read(0x01)<<8;
yoshua0207 8:a1ba925cf903 303
yoshua0207 8:a1ba925cf903 304 i=0;
yoshua0207 8:a1ba925cf903 305 // puts key number out to LEDs for demo
yoshua0207 8:a1ba925cf903 306 for (i=0; i<12; i++) {
yoshua0207 8:a1ba925cf903 307 if (((value>>i)&0x01)==1) key_code=i+1;
yoshua0207 8:a1ba925cf903 308 }
yoshua0207 8:a1ba925cf903 309
yoshua0207 8:a1ba925cf903 310 if
yoshua0207 8:a1ba925cf903 311
yoshua0207 8:a1ba925cf903 312 uLCD.printf("Key pressed is: %d",key_code); // TODO: DEBUG ONLY
yoshua0207 8:a1ba925cf903 313 return key_code;
yoshua0207 8:a1ba925cf903 314 }
yoshua0207 8:a1ba925cf903 315
yoshua0207 8:a1ba925cf903 316 void upload_to_scanner()
yoshua0207 8:a1ba925cf903 317 {
yoshua0207 8:a1ba925cf903 318 if(finger.DeleteAll == 0)
yoshua0207 8:a1ba925cf903 319 {
yoshua0207 8:a1ba925cf903 320 debug.printf("All fingerprints deleted");
yoshua0207 8:a1ba925cf903 321 }
yoshua0207 8:a1ba925cf903 322 EnrollID = 1;
yoshua0207 8:a1ba925cf903 323 // group_id = "4180";
yoshua0207 8:a1ba925cf903 324 directory = "/sd/" + group_id ;
yoshua0207 8:a1ba925cf903 325 char ID[3];
yoshua0207 8:a1ba925cf903 326 sprintf(ID, "%d\n",EnrollID);
yoshua0207 8:a1ba925cf903 327 fileName = directory + "/" + ID + ".dat";
yoshua0207 8:a1ba925cf903 328 debug.printf("Attempt to find file %s", fileName);
yoshua0207 8:a1ba925cf903 329 const char* conv_file = fileName.c_str();
yoshua0207 8:a1ba925cf903 330 FILE *templateFile = fopen(conv_file, "r");
yoshua0207 8:a1ba925cf903 331 while(templateFile != NULL)
yoshua0207 8:a1ba925cf903 332 {
yoshua0207 8:a1ba925cf903 333 if(finger.SetTemplate(templateFile, EnrollID, 0 ) == 0)
yoshua0207 8:a1ba925cf903 334 {
yoshua0207 8:a1ba925cf903 335 EnrollID++;
yoshua0207 8:a1ba925cf903 336 fclose(templateFile);
yoshua0207 8:a1ba925cf903 337 }
yoshua0207 8:a1ba925cf903 338 char ID[3];
yoshua0207 8:a1ba925cf903 339 sprintf(ID, "%d\n",EnrollID);
yoshua0207 8:a1ba925cf903 340 fileName = directory + "/" + ID + ".dat";
yoshua0207 8:a1ba925cf903 341 const char* conv_file = fileName.c_str();
yoshua0207 8:a1ba925cf903 342 FILE *templateFile = fopen(conv_file, "r");
yoshua0207 8:a1ba925cf903 343 }
yoshua0207 8:a1ba925cf903 344 }
yoshua0207 8:a1ba925cf903 345
yoshua0207 8:a1ba925cf903 346 void download_to_memory()
yoshua0207 8:a1ba925cf903 347 {
yoshua0207 8:a1ba925cf903 348 EnrollID = 1;
yoshua0207 8:a1ba925cf903 349 directory = "/sd/" + group_id ;
yoshua0207 8:a1ba925cf903 350 const char* conv_dir = directory.c_str();
yoshua0207 8:a1ba925cf903 351 debug.printf("%s", directory);
yoshua0207 8:a1ba925cf903 352 mkdir(conv_dir, 0777);
yoshua0207 8:a1ba925cf903 353 while(finger.GetTemplate(EnrollID)==0)
yoshua0207 8:a1ba925cf903 354 {
yoshua0207 8:a1ba925cf903 355 finger.RecvData(data, 498);
yoshua0207 8:a1ba925cf903 356 char ID[3];
yoshua0207 8:a1ba925cf903 357 sprintf(ID, "%d\n",EnrollID);
yoshua0207 8:a1ba925cf903 358 fileName = directory + "/" + ID + ".dat";
yoshua0207 8:a1ba925cf903 359 debug.printf("Attempt to write to file %s", fileName);
yoshua0207 8:a1ba925cf903 360 const char* conv_file = fileName.c_str();
yoshua0207 8:a1ba925cf903 361 FILE *templateFile = fopen(conv_file, "w");
yoshua0207 8:a1ba925cf903 362 if(templateFile == NULL) {
yoshua0207 8:a1ba925cf903 363 debug.printf("Could not open file for write\n");
yoshua0207 8:a1ba925cf903 364 }
yoshua0207 8:a1ba925cf903 365 fprintf(templateFile, data, EnrollID);
yoshua0207 8:a1ba925cf903 366 fclose(templateFile);
yoshua0207 8:a1ba925cf903 367 EnrollID++;
yoshua0207 8:a1ba925cf903 368 }
yoshua0207 8:a1ba925cf903 369 }
yoshua0207 8:a1ba925cf903 370
yoshua0207 8:a1ba925cf903 371 void send_file_via_wifi() {
yoshua0207 8:a1ba925cf903 372 // TODO: Yo
yoshua0207 8:a1ba925cf903 373 // make file
yoshua0207 8:a1ba925cf903 374
yoshua0207 8:a1ba925cf903 375 for (int i = 0; i < group_size; i++) {
yoshua0207 8:a1ba925cf903 376 if (this_session_id[i]) {
yoshua0207 8:a1ba925cf903 377 // append the data to the file to be exported
yoshua0207 8:a1ba925cf903 378 }
yoshua0207 8:a1ba925cf903 379 }
yoshua0207 8:a1ba925cf903 380 // send data
yoshua0207 8:a1ba925cf903 381 }
yoshua0207 8:a1ba925cf903 382 void getNewLine(File *fp, char *buf, size_t bufsize)
yoshua0207 8:a1ba925cf903 383 {
yoshua0207 8:a1ba925cf903 384 char c;
yoshua0207 8:a1ba925cf903 385 size_t receivedChars = 0;
yoshua0207 8:a1ba925cf903 386 for(;;)
yoshua0207 8:a1ba925cf903 387 {
yoshua0207 8:a1ba925cf903 388 c = fgetc(fp);
yoshua0207 8:a1ba925cf903 389 if (c == '\r' || c == '\n')
yoshua0207 8:a1ba925cf903 390 break;
yoshua0207 8:a1ba925cf903 391 buf.putc(c);
yoshua0207 8:a1ba925cf903 392 }
yoshua0207 8:a1ba925cf903 393 return buf;
yoshua0207 8:a1ba925cf903 394 }