-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tools.cpp
83 lines (74 loc) · 1.85 KB
/
Tools.cpp
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
#include "Tools.h"
String Tools::GetChipId() {
uint64_t chipmacid;
esp_efuse_mac_get_default((uint8_t*)(&chipmacid));
String r1((uint16_t)(chipmacid >> 32), HEX);
String r2((uint32_t)(chipmacid), HEX);
r1.toUpperCase();
r2.toUpperCase();
return r1 + r2;
}
String Tools::GetChipRevision() {
String result;
byte revision = (REG_READ(EFUSE_BLK0_RDATA3_REG) >> EFUSE_RD_CHIP_VER_RESERVE_S) && EFUSE_RD_CHIP_VER_RESERVE_V;
switch (revision) {
case 0:
result = "0 (2016.09)";
break;
case 1:
result = "1 (2017.02)";
break;
default:
result = String(revision) + "(unknown)";
break;
}
return result;
}
IPAddress Tools::IPAddressFromString(String ipString) {
byte o1p = ipString.indexOf(".", 0);
byte o2p = ipString.indexOf(".", o1p + 1);
byte o3p = ipString.indexOf(".", o2p + 1);
byte o4p = ipString.indexOf(".", o3p + 1);
return IPAddress(strtol(ipString.substring(0, o1p).c_str(), NULL, 10),
strtol(ipString.substring(o1p + 1, o2p).c_str(), NULL, 10),
strtol(ipString.substring(o2p + 1, o3p).c_str(), NULL, 10),
strtol(ipString.substring(o3p + 1, o4p).c_str(), NULL, 10));
}
byte Tools::UTF8ToASCII(byte utf8Char) {
byte result = 0;
static byte lastChar;
if (utf8Char < 128) {
lastChar = 0;
result = utf8Char;
}
else {
switch (lastChar) {
case 0xC2:
result = utf8Char;
break;
case 0xC3:
result = utf8Char | 0xC0;
break;
case 0x82:
if (utf8Char == 0xAC) {
result = 0x80;
}
else {
result = 0;
}
break;
}
lastChar = utf8Char;
}
return result;
}
String Tools::UTF8ToASCII(String utf8) {
String result = "";
for (uint i = 0; i < utf8.length(); i++) {
char c = UTF8ToASCII(utf8.charAt(i));
if (c != 0) {
result += c;
}
}
return result;
}