-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathapi.h
More file actions
192 lines (173 loc) · 5.54 KB
/
Copy pathapi.h
File metadata and controls
192 lines (173 loc) · 5.54 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
void apiTX(String apiBIN, int apipulsewidth, int apidatainterval, int wait) {
wg.pause();
digitalWrite(DATA0, HIGH);
pinMode(DATA0,OUTPUT);
digitalWrite(DATA1, HIGH);
pinMode(DATA1,OUTPUT);
for (int i=0; i<=apiBIN.length(); i++) {
if (apiBIN.charAt(i) == '0') {
digitalWrite(DATA0, LOW);
delayMicroseconds(apipulsewidth);
digitalWrite(DATA0, HIGH);
}
else if (apiBIN.charAt(i) == '1') {
digitalWrite(DATA1, LOW);
delayMicroseconds(apipulsewidth);
digitalWrite(DATA1, HIGH);
}
if (apiBIN.charAt(i) == ',') {
delayMicroseconds(wait);
}
else {
delayMicroseconds(apidatainterval);
}
}
apiBIN="";
pinMode(DATA0, INPUT);
pinMode(DATA1, INPUT);
wg.clear();
}
void apiinfo(int prettify) {
FSInfo fs_info;
SPIFFS.info(fs_info);
String total;
total=fs_info.totalBytes;
String used;
used=fs_info.usedBytes;
String freespace;
freespace=fs_info.totalBytes-fs_info.usedBytes;
const size_t bufferSize = JSON_ARRAY_SIZE(5) + JSON_OBJECT_SIZE(3);
DynamicJsonDocument apilog(bufferSize);
apilog["Device"] = "ESP-RFID-Tool";
apilog["Firmware"] = version;
apilog["API"] = APIversion;
JsonObject apifs = apilog.createNestedObject("File System");
apifs["Total Space"]=total;
apifs["Used Space"]=used;
apifs["Free Space"]=freespace;
apilog["Free Memory"] = String(ESP.getFreeHeap(),DEC);
String API_Response="";
if (prettify==1) {
serializeJsonPretty(apilog, API_Response);
}
else {
serializeJson(apilog, API_Response);
}
server.send(200, "application/json", API_Response);
delay(50);
apifs.clear();
apilog.clear();
}
void apilistlogs(int prettify) {
Dir dir = SPIFFS.openDir("/");
String FileList = "";
int logcount=0;
while (dir.next()) {
File f = dir.openFile("r");
String FileName = dir.fileName();
if((!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) {
logcount++;
}
f.close();
}
const size_t bufferSize = JSON_ARRAY_SIZE(5) + JSON_OBJECT_SIZE(1);
DynamicJsonDocument apilog(bufferSize);
apilog["Device"] = "ESP-RFID-Tool";
apilog["Firmware"] = version;
apilog["API"] = APIversion;
apilog["Log Count"] = logcount;
int currentlog=0;
Dir dir2ndrun = SPIFFS.openDir("/");
while (dir2ndrun.next()) {
File f = dir2ndrun.openFile("r");
String FileName = dir2ndrun.fileName();
if ((!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) {
currentlog++;
FileName.remove(0,1);
JsonObject apilistlogs = apilog.createNestedObject(String(currentlog));
apilistlogs["File Name"]=FileName;
}
f.close();
}
String API_Response="";
if (prettify==1) {
serializeJsonPretty(apilog, API_Response);
}
else {
serializeJson(apilog, API_Response);;
}
server.send(200, "application/json", API_Response);
delay(50);
apilog.clear();
}
void apilog(String logfile,int prettify) {
File f = SPIFFS.open(String()+"/"+logfile, "r");
if (!f) {
server.send(200, "application/json", "Log file not found");
delay(50);
}
else {
int apiCAPTUREcount=0;
while(f.available()) {
String line = f.readStringUntil('\n');
if(line.indexOf(",Binary:") > 0) {
apiCAPTUREcount++;
int firstIndex = line.indexOf(",Binary:");
int secondIndex = line.indexOf(",", firstIndex + 1);
String binaryCaptureLINE=line.substring(firstIndex+8, secondIndex);
}
}
f.close();
DynamicJsonDocument apilog(2048);
apilog["Device"] = "ESP-RFID-Tool";
apilog["Firmware"] = version;
apilog["API"] = APIversion;
apilog["Log File"] = logfile;
apilog["CaptureCount"] = apiCAPTUREcount;
JsonArray captures = apilog.createNestedArray("Captures");
int apiCURRENTcapture=0;
File f = SPIFFS.open(String()+"/"+logfile, "r");
DynamicJsonDocument apiCURRENTcaptureOBJECT(1024);
while(f.available()) {
String line = f.readStringUntil('\n');
int firstIndex = line.indexOf(",Binary:");
if(firstIndex > -1) {
apiCURRENTcapture++;
int secondIndex = line.indexOf(",", firstIndex + 1);
String binaryCaptureLINE=line.substring(firstIndex+8, secondIndex);
if ( binaryCaptureLINE.indexOf(" ") > 0 ) {
binaryCaptureLINE=binaryCaptureLINE.substring(binaryCaptureLINE.indexOf(" ")+1);
}
binaryCaptureLINE.replace("\r","");
apiCURRENTcaptureOBJECT["Bit Count"] = binaryCaptureLINE.length();
apiCURRENTcaptureOBJECT["Binary"] = binaryCaptureLINE;
if(line.indexOf(",HEX:") > 0) {
int hfirstIndex = line.indexOf(",HEX:");
int hsecondIndex = line.indexOf(",", hfirstIndex + 1);
String hexCURRENT=line.substring(hfirstIndex+5, hsecondIndex);
hexCURRENT.replace("\r","");
apiCURRENTcaptureOBJECT["Hexadecimal"]=hexCURRENT;
}
if(line.indexOf(",Keypad Code:") > 0) {
int kfirstIndex = line.indexOf(",Keypad Code:");
int ksecondIndex = line.indexOf(",", kfirstIndex + 1);
String pinCURRENT = line.substring(kfirstIndex + 13, ksecondIndex);
pinCURRENT.replace("\r","");
apiCURRENTcaptureOBJECT["Keypad Press"] = pinCURRENT;
}
captures.add(apiCURRENTcaptureOBJECT);
}
}
f.close();
String API_Response="";
if (prettify==1) {
serializeJsonPretty(apilog, API_Response);
}
else {
serializeJson(apilog, API_Response);;
}
server.send(200, "application/json", API_Response);
delay(50);
apilog.clear();
}
}