-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabase.ino
98 lines (79 loc) · 2.68 KB
/
database.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
NFC Door lock
Auther Michael Burton
Creative Commons License
NFC Door lock
by Michael Dale Burton
is licensed under a Creative Commons Attribution-NonCommercial
4.0 International License.
*/
/**************************************
compairUid return bool
in: card ids
out: true if they are the same else false
**************************************/
bool compairUid(uint8_t uid1[], uint8_t uid2[], uint8_t j) {
for (int i = 0; i < j; i++) {
if (uid1[i] != uid2[i]) {
return false;
}
}
return true;
}
/*****************************************************
findUid
takes uid and length
return index of uid in array or 0 if not found
*/
int findUid(String suid) {
for (int i = 1; i <= rowIndex; i++) {
if (!(suid.compareTo(String(&cardId[i][0])))) {
return i; // index of card found
}
}
return 0;
}
/**************************************
storeCard
in: row index, card Id, id length, card holder name
places the uid and the name in the hardware memory at index location ri
out: none
**************************************/
//put card id in memory
void storeCard(int ri, String suid2, String holder, int af) {
if(openspiffs()){
uint16_t buffer_offset;
buffer_offset = ri * recordlength;
cardId[ri] = suid2; // save uid as a string
cardHolder[ri] = holder; // save name of card holder
accessFlags[ri] = af;
Blynk.virtualWrite(vcount, rowIndex); //save the card count on the server
write16data(DATASTART, rowIndex); //save the card count at offset 0
write16data(buffer_offset, ri);
buffer_offset += 2;
writestringdata(buffer_offset, maxnamelength, cardHolder[ri]);
buffer_offset += maxnamelength;
writestringdata(buffer_offset, maxuidlength, cardId[ri]);
buffer_offset += maxuidlength;
write16data(buffer_offset, accessFlags[ri]);
buffer_offset += 2;
Blynk.virtualWrite(indexdisplay, ri);
closespiffs();
}
}
void getCard(int index) {
cardId[0] = cardId[index]; // get cardId
cardHolder[0] = cardHolder[index]; // get name of card holder
accessFlags[0] = accessFlags[index]; // get access flags
}
/***************************************
get card id access flags and user name from file or the cloud
in: card Id, card holder name, access flags, index
datastore is the virtual pin for the card data
**************************************/
void readFromCloud(int count) {
getdatafromfile();
getCard(1);
Blynk.virtualWrite(namedisplay, cardHolder[0]);
Blynk.virtualWrite(cardiddisplay, cardId[0]);
}