Bank Account Security System

Dependencies:   FatFileSystemSD mbed

Committer:
Dhruv_Varun
Date:
Thu Oct 11 20:49:25 2012 +0000
Revision:
0:7e4786a3584b
Code For Bank Account Security System

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Dhruv_Varun 0:7e4786a3584b 1 /* mbed ID12 RFID Library
Dhruv_Varun 0:7e4786a3584b 2 * Copyright (c) 2007-2010, sford, http://mbed.org
Dhruv_Varun 0:7e4786a3584b 3 *
Dhruv_Varun 0:7e4786a3584b 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
Dhruv_Varun 0:7e4786a3584b 5 * of this software and associated documentation files (the "Software"), to deal
Dhruv_Varun 0:7e4786a3584b 6 * in the Software without restriction, including without limitation the rights
Dhruv_Varun 0:7e4786a3584b 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Dhruv_Varun 0:7e4786a3584b 8 * copies of the Software, and to permit persons to whom the Software is
Dhruv_Varun 0:7e4786a3584b 9 * furnished to do so, subject to the following conditions:
Dhruv_Varun 0:7e4786a3584b 10 *
Dhruv_Varun 0:7e4786a3584b 11 * The above copyright notice and this permission notice shall be included in
Dhruv_Varun 0:7e4786a3584b 12 * all copies or substantial portions of the Software.
Dhruv_Varun 0:7e4786a3584b 13 *
Dhruv_Varun 0:7e4786a3584b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Dhruv_Varun 0:7e4786a3584b 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Dhruv_Varun 0:7e4786a3584b 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Dhruv_Varun 0:7e4786a3584b 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Dhruv_Varun 0:7e4786a3584b 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Dhruv_Varun 0:7e4786a3584b 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Dhruv_Varun 0:7e4786a3584b 20 * THE SOFTWARE.
Dhruv_Varun 0:7e4786a3584b 21 */
Dhruv_Varun 0:7e4786a3584b 22
Dhruv_Varun 0:7e4786a3584b 23 #include "ID12RFID.h"
Dhruv_Varun 0:7e4786a3584b 24
Dhruv_Varun 0:7e4786a3584b 25 #include "mbed.h"
Dhruv_Varun 0:7e4786a3584b 26
Dhruv_Varun 0:7e4786a3584b 27 ID12RFID::ID12RFID(PinName rx)
Dhruv_Varun 0:7e4786a3584b 28 : _rfid(NC, rx) {
Dhruv_Varun 0:7e4786a3584b 29 }
Dhruv_Varun 0:7e4786a3584b 30
Dhruv_Varun 0:7e4786a3584b 31 int ID12RFID::readable() {
Dhruv_Varun 0:7e4786a3584b 32 return _rfid.readable();
Dhruv_Varun 0:7e4786a3584b 33 }
Dhruv_Varun 0:7e4786a3584b 34
Dhruv_Varun 0:7e4786a3584b 35 int ID12RFID::read() {
Dhruv_Varun 0:7e4786a3584b 36 while (_rfid.getc() != 2);
Dhruv_Varun 0:7e4786a3584b 37
Dhruv_Varun 0:7e4786a3584b 38 int v = 0;
Dhruv_Varun 0:7e4786a3584b 39 _rfid.getc(); // drop 1st 2 bytes - we actually only read the lower 32-bits of the code
Dhruv_Varun 0:7e4786a3584b 40 _rfid.getc();
Dhruv_Varun 0:7e4786a3584b 41
Dhruv_Varun 0:7e4786a3584b 42 for (int i=7; i>=0; i--) {
Dhruv_Varun 0:7e4786a3584b 43 char c = _rfid.getc(); // a ascii hex char
Dhruv_Varun 0:7e4786a3584b 44 int part = c - '0';
Dhruv_Varun 0:7e4786a3584b 45 v |= part << (i * 4);
Dhruv_Varun 0:7e4786a3584b 46 }
Dhruv_Varun 0:7e4786a3584b 47
Dhruv_Varun 0:7e4786a3584b 48 for (int i=0; i<5; i++) {
Dhruv_Varun 0:7e4786a3584b 49 _rfid.getc();
Dhruv_Varun 0:7e4786a3584b 50 }
Dhruv_Varun 0:7e4786a3584b 51
Dhruv_Varun 0:7e4786a3584b 52 return v;
Dhruv_Varun 0:7e4786a3584b 53 }