-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwiegand_skimmer.ino
95 lines (73 loc) · 1.85 KB
/
wiegand_skimmer.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
/*
* Copyright (c) 2013 jgor <jgor@indiecom.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
int wiegand[64];
int wiegand_idx, waiting;
void decode35() {
int i;
long facility = 0, card = 0;
for (i = 2; i < 14; i++) {
facility |= (wiegand[i] << (13-i));
}
for (i = 14; i < 34; i++) {
card |= ((long)wiegand[i] << (33-i));
}
Serial.print("F=");
Serial.print(facility);
Serial.print(" C=");
Serial.println(card);
}
void decode26() {
int i;
long facility = 0, card = 0;
for (i = 1; i < 9; i++) {
facility |= (wiegand[i] << (8-i));
}
for (i = 9; i < 25; i++) {
card |= ((long)wiegand[i] << (24-i));
}
Serial.print("F=");
Serial.print(facility);
Serial.print(" C=");
Serial.println(card);
}
void decode(int len) {
switch(len) {
case 26: decode26(); break;
case 35: decode35(); break;
}
}
void data0() {
wiegand[wiegand_idx++] = 0;
waiting = 10000;
}
void data1() {
wiegand[wiegand_idx++] = 1;
waiting = 10000;
}
void setup() {
wiegand_idx = 0;
attachInterrupt(0, data0, FALLING);
attachInterrupt(1, data1, FALLING);
Serial.begin(9600);
}
void loop() {
if (!waiting && wiegand_idx) {
decode(wiegand_idx);
wiegand_idx = 0;
}
else if (waiting) {
waiting--;
}
}