Repository navigation
Expand file tree
/
Copy pathBlinkerUtility.cpp
More file actions
265 lines (215 loc) · 7.85 KB
/
Copy pathBlinkerUtility.cpp
File metadata and controls
265 lines (215 loc) · 7.85 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include "utility/BlinkerUtility.h"
#if defined(ESP8266)
extern "C" {
#include "user_interface.h"
}
String macDeviceName()
{
uint8_t mac[6];
char macStr[13] = { 0 };
#define STATION_IF 0x00
wifi_get_macaddr(STATION_IF, mac);
sprintf(macStr, "%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
String macStr_l = STRING_format(macStr);
//macStr_l.toLowerCase();
//BLINKER_LOG("MACADDR: ", macStr_l);
return macStr_l;
}
#elif defined(ESP32)
#include "esp_wifi.h"
String macDeviceName()
{
uint8_t mac[6];
char macStr[13] = { 0 };
// #define WIFI_IF_STA 0x00
esp_wifi_get_mac(WIFI_IF_STA, mac);
sprintf(macStr, "%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
String macStr_l = STRING_format(macStr);
//macStr_l.toLowerCase();
//BLINKER_LOG("MACADDR: ", macStr_l);
return macStr_l;
}
#endif
String STRING_find_string(const String & src, const String & targetStart, const String & targetEnd, uint8_t skipNum) {
int addr_start = src.indexOf(targetStart);
int addr_end;
if (targetEnd.length()) {
addr_end = src.indexOf(targetEnd, addr_start + targetStart.length() + skipNum);
}
else {
addr_end = src.length();
}
if (addr_start == -1 || addr_end == -1) {
return "";
}
else {
return src.substring(addr_start + targetStart.length() + skipNum, addr_end);
}
}
bool STRING_contains_string(const String & src, const String & key)
{
int addr_start = src.indexOf(key);
uint8_t keyLen = key.length();
return key == src.substring(addr_start, addr_start + keyLen);
}
bool STRING_find_string_value(const String & src, String & dst, const String & key)
{
int addr_start = src.indexOf(key);
uint8_t keyLen = key.length();
// BLINKER_LOG("addr_start: ", addr_start);
// BLINKER_LOG("keyLen: ", keyLen);
int addr_end = src.indexOf(STRING_VALUE_END, addr_start + keyLen + STRING_VALUE_SKIP);
// BLINKER_LOG("addr_end: ", addr_end);
if (addr_start == -1 || addr_end == -1) {
return false;
}
else {
dst = src.substring(addr_start + keyLen + STRING_VALUE_SKIP, addr_end);
// BLINKER_LOG("dst: ", dst);
return true;
}
}
int32_t STRING_find_numberic_value(const String & src, const String & key)
{
int addr_start = src.indexOf(key);
uint8_t keyLen = key.length();
if ( key != src.substring(addr_start, addr_start + keyLen)) {
return FIND_KEY_VALUE_FAILED;
}
int addr_end1 = src.indexOf(NUMBERIC_VALUE_END_1, addr_start + keyLen + NUMBERIC_VALUE_SKIP);
int addr_end2 = src.indexOf(NUMBERIC_VALUE_END_2, addr_start + keyLen + NUMBERIC_VALUE_SKIP);
int addr_end = BlinkerMin(addr_end1, addr_end2);
if (addr_end == -1) {
addr_end = BlinkerMax(addr_end1, addr_end2);
}
if (addr_start == -1 || addr_end == -1) {
return FIND_KEY_VALUE_FAILED;
}
else {
String value = src.substring(addr_start + keyLen + NUMBERIC_VALUE_SKIP, addr_end);
return value.toInt();
}
}
float STRING_find_float_value(const String & src, const String & key)
{
int addr_start = src.indexOf(key);
uint8_t keyLen = key.length();
if ( key != src.substring(addr_start, addr_start + keyLen)) {
return FIND_KEY_VALUE_FAILED;
}
int addr_end1 = src.indexOf(NUMBERIC_VALUE_END_1, addr_start + keyLen + NUMBERIC_VALUE_SKIP);
int addr_end2 = src.indexOf(NUMBERIC_VALUE_END_2, addr_start + keyLen + NUMBERIC_VALUE_SKIP);
int addr_end = BlinkerMin(addr_end1, addr_end2);
if (addr_end == -1) {
addr_end = BlinkerMax(addr_end1, addr_end2);
}
if (addr_start == -1 || addr_end == -1) {
return (float)FIND_KEY_VALUE_FAILED;
}
else {
String value = src.substring(addr_start + keyLen + NUMBERIC_VALUE_SKIP, addr_end);
return value.toFloat();
}
}
int32_t STRING_find_array_numberic_value(const String & src, const String & key, uint8_t num)
{
int addr_start = src.indexOf(key);
uint8_t keyLen = key.length();
if ( key != src.substring(addr_start, addr_start + keyLen) ) {
return FIND_KEY_VALUE_FAILED;
}
addr_start = addr_start + keyLen + ARRAY_NUMBERIC_VALUE_SKIP_START;
if (num > 0) {
int value_start1, value_start2, temp;
for (uint8_t times = 0; times < num; ++times) {
value_start1 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_1, addr_start);
value_start2 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_2, addr_start);
temp = BlinkerMin(value_start1, value_start2);
if(temp == -1) {
temp = BlinkerMax(value_start1, value_start2);
}
addr_start = temp + ARRAY_NUMBERIC_VALUE_SKIP_IN;
}
}
int addr_end1 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_1, addr_start);
int addr_end2 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_2, addr_start);
int addr_end = BlinkerMin(addr_end1, addr_end2);
if (addr_end == -1) {
addr_end = BlinkerMax(addr_end1, addr_end2);
}
if (addr_start == -1 || addr_end == -1) {
return FIND_KEY_VALUE_FAILED;
}
else {
String value = src.substring(addr_start, addr_end);
return value.toInt();
}
}
float STRING_find_array_float_value(const String & src, const String & key, uint8_t num)
{
int addr_start = src.indexOf(key);
uint8_t keyLen = key.length();
if ( key != src.substring(addr_start, addr_start + keyLen)) {
return FIND_KEY_VALUE_FAILED;
}
addr_start = addr_start + keyLen + ARRAY_NUMBERIC_VALUE_SKIP_START;
if (num > 0) {
int value_start1, value_start2, temp;
for (uint8_t times = 0; times < num; ++times) {
value_start1 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_1, addr_start);
value_start2 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_2, addr_start);
temp = BlinkerMin(value_start1, value_start2);
if(temp == -1) {
temp = BlinkerMax(value_start1, value_start2);
}
addr_start = temp + ARRAY_NUMBERIC_VALUE_SKIP_IN;
}
}
int addr_end1 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_1, addr_start);
int addr_end2 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_2, addr_start);
int addr_end = BlinkerMin(addr_end1, addr_end2);
if (addr_end == -1) {
addr_end = BlinkerMax(addr_end1, addr_end2);
}
if (addr_start == -1 || addr_end == -1) {
return (float)FIND_KEY_VALUE_FAILED;
}
else {
String value = src.substring(addr_start, addr_end);
return value.toFloat();
}
}
String STRING_find_array_string_value(const String & src, const String & key, uint8_t num)
{
int addr_start = src.indexOf(key);
uint8_t keyLen = key.length();
if ( key != src.substring(addr_start, addr_start + keyLen) ) {
return "";
}
addr_start = addr_start + keyLen + ARRAY_NUMBERIC_VALUE_SKIP_START;
if (num > 0) {
int value_start1, value_start2, temp;
for (uint8_t times = 0; times < num; ++times) {
value_start1 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_1, addr_start);
value_start2 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_2, addr_start);
temp = BlinkerMin(value_start1, value_start2);
if(temp == -1) {
temp = BlinkerMax(value_start1, value_start2);
}
addr_start = temp + ARRAY_NUMBERIC_VALUE_SKIP_IN;
}
}
int addr_end1 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_1, addr_start);
int addr_end2 = src.indexOf(ARRAY_NUMBERIC_VALUE_END_2, addr_start);
int addr_end = BlinkerMin(addr_end1, addr_end2);
if (addr_end == -1) {
addr_end = BlinkerMax(addr_end1, addr_end2);
}
if (addr_start == -1 || addr_end == -1) {
return "";
}
else {
String value = src.substring(addr_start, addr_end);
return value;
}
}