forked from Sucareto/Arduino-Aime-Reader
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSpicetool_Reader.h
More file actions
122 lines (120 loc) · 3.76 KB
/
Spicetool_Reader.h
File metadata and controls
122 lines (120 loc) · 3.76 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "lib/Spicetool/connection.h"
uint8_t spice_buffer[64];
// spiceapi::Connection CON(spice_buffer,64);
extern uint8_t system_mode;
extern uint8_t switch_flag;
char hex2str(uint8_t hex){
//注意这里传输的必须是半字节
if(hex < 0xA){
return (hex + 48);//ascii 0 = 48
}
else{
return (hex - 0xA + 65);//ascii A = 65
}
}
void Spice_Mode_Init(){
#ifndef CDC
SerialDevice.begin(115200);
#endif
LED_Init();
nfc.begin();
while (!nfc.getFirmwareVersion()) {
delay(500);
SerialDevice.println("error");
if((system_setting[0] & 0b100)){
LED_show(system_setting[1],0x00,0x00);
}
}
#if defined(CONFIG_IDF_TARGET_ESP32C3)
digitalWrite(nfccommled, 1);
#endif
nfc.setPassiveActivationRetries(0x10);
nfc.SAMConfig();
LED_show(255,0,64);
delay(1000);
}
void Spice_Mode_Loop(){
LED_show(0,0,0);
uint16_t SystemCode;
char card_id[17];
uint8_t cmd_switch = 0;
while(SerialDevice.available()){
uint8_t c = SerialDevice.read();
if(c == 0xaf){
cmd_switch++;
}else{
cmd_switch=0;
}
if(cmd_switch == 30){
system_mode = 0;
switch_flag = 1;
EEPROM.write(23,0);
#if defined(ESP8266)
EEPROM.commit();
#endif
return;
}
}
uint8_t AimeKey[6] = {0x57, 0x43, 0x43, 0x46, 0x76, 0x32};
uint8_t mifare_uid[4] = {0};
uint8_t id_len = 0;
uint8_t block[16];
if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, mifare_uid, &id_len)
&& nfc.mifareclassic_AuthenticateBlock(mifare_uid, id_len, 1, 1, AimeKey)
&& nfc.mifareclassic_ReadDataBlock(2, block)) {
LED_show(0,255,0);
char hex2str_buffer[2] = {0,0};
char buffer[90] = "{\"id\":1,\"module\":\"card\",\"function\":\"insert\",\"params\":[0,\"E00401AF87654321\"]}";//应为E00401开头
if(system_setting[0] & 0b100000){ //开启了传入真实卡号
for(uint8_t i = 0;i<8;i++){
buffer[57+2*i] = hex2str(block[8+i] >> 4);//高4位转换为字符
buffer[58+2*i] = hex2str(block[8+i] & 0xF);//低4位转换为字符
}
}else{
for(uint8_t i = 0;i<4;i++){
buffer[65+2*i] = hex2str(mifare_uid[i] >> 4);
buffer[66+2*i] = hex2str(mifare_uid[i] & 0xF);
}
}
if(system_setting[0] & 0b1000000){//开启了2P刷卡
buffer[54] = 49;
}
spice_request(buffer,1000,spice_buffer);
delay(1000);
return;
}
if(nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, mifare_uid, &id_len) && nfc.mifareclassic_AuthenticateBlock(mifare_uid, id_len, 1, 0, BanaKey)){
LED_show(255,0,0);
char hex2str_buffer[2] = {0,0};
char buffer[90] = "{\"id\":1,\"module\":\"card\",\"function\":\"insert\",\"params\":[0,\"E00401AF87654321\"]}";//应为E00401开头
for(uint8_t i = 0;i<4;i++){
buffer[65+2*i] = hex2str(mifare_uid[i] >> 4);
buffer[66+2*i] = hex2str(mifare_uid[i] & 0xF);
}
if(system_setting[0] & 0b1000000){//开启了2P刷卡
buffer[54] = 49;
}
spice_request(buffer,1000,spice_buffer);
delay(1000);
return;
}
uint8_t IDm[8] = {0};
uint8_t PMm[8] = {0};
if (nfc.felica_Polling(0xFFFF, 0x01, IDm, PMm, &SystemCode, 200) == 1) {
LED_show(0,0,255);
char buffer[90] = "{\"id\":1,\"module\":\"card\",\"function\":\"insert\",\"params\":[0,\"1234567887654321\"]}";
char hex2str_buffer[2] = {0,0};
for(uint8_t i = 0;i<8;i++){
buffer[57+2*i] = hex2str(IDm[i] >> 4);//高4位转换为字符
buffer[58+2*i] = hex2str(IDm[i] & 0xF);//低4位转换为字符
}
if(system_setting[0] & 0b1000000){//开启了2P刷卡
buffer[54] = 49;//"params\":[1,......
}
spice_request(buffer,1000,spice_buffer);
delay(1000);
return;
}
// char light_cmd_buffer[58] = "{\"id\":3,\"module\":\"lights\",\"function\":\"read\",\"params\":[]}"
// CON.request(light_cmd_buffer);
}