summaryrefslogtreecommitdiff
path: root/usb-i2c-sl018
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@wirdorange.org>2013-01-27 22:52:15 +0000
committerOthmar Gsenger <otti@wirdorange.org>2013-01-27 22:52:15 +0000
commitedf3eeb0aab952eba2464debdb65be58e63c0580 (patch)
treeb89e14d1e44823e699fce9c9a83ee8eb4fe43414 /usb-i2c-sl018
parentsharing credit (diff)
added check card
git-svn-id: https://svn.spreadspace.org/avr/trunk@78 aa12f405-d877-488e-9caf-2d797e2a1cc7
Diffstat (limited to 'usb-i2c-sl018')
-rw-r--r--usb-i2c-sl018/tuer-rfid.c30
1 files changed, 26 insertions, 4 deletions
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 <avr/eeprom.h>
#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; pos<uid_len; pos++)
+ card.byte[pos]=uid[pos];
+ keyslot_t * ks;
+ for(ks=keyslots;ks<keyslots+EEPROM_SIZE/sizeof(keyslot_t);ks++)
+ {
+ if(card.uint==ks->uint)
+ {
+ 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");
}
}