|
@@ -1,6 +1,7 @@
|
1
|
1
|
#include <Arduino.h>
|
2
|
2
|
#include <pins_arduino.h>
|
3
|
3
|
#include <SoftwareSerial.h>
|
|
4
|
+#include <SCLib.h>
|
4
|
5
|
|
5
|
6
|
#define ledPin 13
|
6
|
7
|
|
|
@@ -11,17 +12,22 @@
|
11
|
12
|
#define READER_VPP
|
12
|
13
|
#define READER_IO 2
|
13
|
14
|
|
14
|
|
-#define CARD_VCC
|
15
|
|
-#define CARD_RST
|
16
|
|
-#define CARD_CLK
|
|
15
|
+#define CARD_VCC 11
|
|
16
|
+#define CARD_RST 7
|
|
17
|
+#define CARD_CLK 9
|
17
|
18
|
#define CARD_GND
|
18
|
19
|
#define CARD_VPP
|
19
|
|
-#define CARD_IO
|
|
20
|
+#define CARD_IO 10
|
|
21
|
+#define CARD_PRE 12
|
|
22
|
+
|
|
23
|
+SmartCardReader cardReader(CARD_IO, CARD_RST, CARD_VCC, CARD_PRE, CARD_CLK, true);
|
|
24
|
+uint8_t atr[MAX_ATR_BYTES];
|
|
25
|
+int atr_size;
|
20
|
26
|
|
21
|
27
|
bool readerReset = false;
|
22
|
28
|
int baudRate = -1;
|
23
|
29
|
int etu = -1;
|
24
|
|
-
|
|
30
|
+#ifndef digitalPinToInterrupt
|
25
|
31
|
int digitalPinToInterrupt(int pin)
|
26
|
32
|
{
|
27
|
33
|
if (pin == 2)
|
|
@@ -35,6 +41,8 @@ int digitalPinToInterrupt(int pin)
|
35
|
41
|
return -1;
|
36
|
42
|
}
|
37
|
43
|
|
|
44
|
+#endif
|
|
45
|
+
|
38
|
46
|
void onReaderReset()
|
39
|
47
|
{
|
40
|
48
|
readerReset = true;
|
|
@@ -81,10 +89,8 @@ void sendAtrByte(char byte)
|
81
|
89
|
}
|
82
|
90
|
}
|
83
|
91
|
|
84
|
|
-void sendAtr()
|
|
92
|
+void sendAtr(const uint8_t* atr, size_t size)
|
85
|
93
|
{
|
86
|
|
- const char atr[] = {0x3B, 0x65, 0x00, 0x00, 0x20, 0x63, 0xCB, 0x6C, 0x81};
|
87
|
|
- int size = sizeof(atr);
|
88
|
94
|
pinMode(READER_IO, OUTPUT);
|
89
|
95
|
for (int i = 0; i < size; ++i)
|
90
|
96
|
{
|
|
@@ -103,16 +109,12 @@ void setup() {
|
103
|
109
|
digitalWrite(READER_IO, HIGH);
|
104
|
110
|
|
105
|
111
|
pinMode(ledPin, OUTPUT);
|
106
|
|
-
|
107
|
112
|
digitalWrite (ledPin, LOW);
|
108
|
113
|
Serial.println("Initialized");
|
109
|
|
-}
|
110
|
114
|
|
111
|
|
-void delayMs(unsigned int ms)
|
112
|
|
-{
|
113
|
|
- for (unsigned i = 0; i < ms; i++) {
|
114
|
|
- delayMicroseconds(1000);
|
115
|
|
- }
|
|
115
|
+
|
|
116
|
+ atr_size = cardReader.activate(atr, sizeof(atr));
|
|
117
|
+ cardReader.deactivate();
|
116
|
118
|
}
|
117
|
119
|
|
118
|
120
|
void loop() {
|
|
@@ -121,10 +123,16 @@ void loop() {
|
121
|
123
|
{
|
122
|
124
|
if (!readerReset)
|
123
|
125
|
{
|
|
126
|
+// atr_size = cardReader.activate(atr, sizeof(atr));
|
|
127
|
+
|
|
128
|
+// uint8_t atr[] = {0x3B, 0x65, 0x00, 0x00, 0x20, 0x63, 0xCB, 0x6C, 0x80};
|
|
129
|
+// int atr_size = sizeof(atr);
|
124
|
130
|
computeEtu();
|
125
|
|
- sendAtr();
|
|
131
|
+ sendAtr(atr, atr_size);
|
126
|
132
|
readerReset = true;
|
127
|
133
|
digitalWrite(ledPin, !digitalRead(ledPin));
|
|
134
|
+
|
|
135
|
+// cardReader.deactivate();
|
128
|
136
|
}
|
129
|
137
|
}
|
130
|
138
|
else
|