From edf3eeb0aab952eba2464debdb65be58e63c0580 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Sun, 27 Jan 2013 22:52:15 +0000 Subject: added check card git-svn-id: https://svn.spreadspace.org/avr/trunk@78 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- usb-i2c-sl018/tuer-rfid.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'usb-i2c-sl018') diff --git a/usb-i2c-sl018/tuer-rfid.c b/usb-i2c-sl018/tuer-rfid.c index 878e731..244315c 100644 --- a/usb-i2c-sl018/tuer-rfid.c +++ b/usb-i2c-sl018/tuer-rfid.c @@ -43,7 +43,11 @@ #include #define EEPROM_SIZE 1024 -typedef unsigned char keyslot_t[8]; +typedef union +{ + uint64_t uint; + unsigned char byte[8]; +} keyslot_t; keyslot_t EEMEM keyslots[EEPROM_SIZE/sizeof(keyslot_t)]; const uint8_t SL018_ADDR = 0xa0; @@ -155,6 +159,24 @@ unsigned char sl018_send_buffer(const unsigned char * buffer) } +bool check_card(unsigned char * uid, uint8_t uid_len) +{ + keyslot_t card; + card.uint=0; + for (uint8_t pos=0; posuint) + { + fprintf(usb,"Found\n"); + return 1; + } + } + return 0; +} + void flash_eeprom_from_usb(void) { keyslot_t keyslot; @@ -166,12 +188,12 @@ void flash_eeprom_from_usb(void) { int16_t BytesReceived = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); while(BytesReceived >0) { - keyslot[byte_pos++]=fgetc(usb); + keyslot.byte[byte_pos++]=fgetc(usb); BytesReceived--; if (byte_pos == sizeof(keyslot)) { byte_pos=0; - eeprom_write_block(&keyslot,&keyslots[keyslot_pos],sizeof(keyslot)); + eeprom_update_block(&keyslot,&keyslots[keyslot_pos],sizeof(keyslot)); keyslot_pos++; fprintf(usb,"."); fflush(usb); @@ -193,7 +215,7 @@ void dump_eeprom_to_usb(void) { eeprom_read_block(&keyslot,&keyslots[keyslot_pos],sizeof(keyslot)); for (uint8_t i=0; i< sizeof(keyslot); i++) - fprintf(usb,"%02X",keyslot[i]); + fprintf(usb,"%02X",keyslot.byte[i]); fprintf(usb,"\n\r"); } } -- cgit v1.2.3