|
7 | 7 | #include "sdkconfig.h"
|
8 | 8 | #if defined(CONFIG_BT_ENABLED)
|
9 | 9 | #include <string.h>
|
10 |
| -#include <sstream> |
| 10 | +#include <stdio.h> |
11 | 11 | #include "esp32-hal-log.h"
|
12 | 12 | #include "BLEEddystoneTLM.h"
|
13 | 13 |
|
@@ -54,62 +54,44 @@ uint32_t BLEEddystoneTLM::getTime() {
|
54 | 54 | } // getTime
|
55 | 55 |
|
56 | 56 | std::string BLEEddystoneTLM::toString() {
|
57 |
| - std::stringstream ss; |
58 |
| - std::string out = ""; |
59 |
| - uint32_t rawsec; |
60 |
| - ss << "Version "; |
61 |
| - ss << std::dec << m_eddystoneData.version; |
62 |
| - ss << "\n"; |
63 |
| - |
64 |
| - ss << "Battery Voltage "; |
65 |
| - ss << std::dec << ENDIAN_CHANGE_U16(m_eddystoneData.volt); |
66 |
| - ss << " mV\n"; |
67 |
| - |
68 |
| - ss << "Temperature "; |
69 |
| - ss << (float) m_eddystoneData.temp; |
70 |
| - ss << " °C\n"; |
71 |
| - |
72 |
| - ss << "Adv. Count "; |
73 |
| - ss << std::dec << ENDIAN_CHANGE_U32(m_eddystoneData.advCount); |
74 |
| - |
75 |
| - ss << "\n"; |
76 |
| - |
77 |
| - ss << "Time "; |
78 |
| - |
79 |
| - rawsec = ENDIAN_CHANGE_U32(m_eddystoneData.tmil); |
80 |
| - std::stringstream buffstream; |
81 |
| - buffstream << "0000"; |
82 |
| - buffstream << std::dec << rawsec / 864000; |
83 |
| - std::string buff = buffstream.str(); |
84 |
| - |
85 |
| - ss << buff.substr(buff.length() - 4, buff.length()); |
86 |
| - ss << "."; |
87 |
| - |
88 |
| - buffstream.str(""); |
89 |
| - buffstream.clear(); |
90 |
| - buffstream << "00"; |
91 |
| - buffstream << std::dec << (rawsec / 36000) % 24; |
92 |
| - buff = buffstream.str(); |
93 |
| - ss << buff.substr(buff.length()-2, buff.length()); |
94 |
| - ss << ":"; |
95 |
| - |
96 |
| - buffstream.str(""); |
97 |
| - buffstream.clear(); |
98 |
| - buffstream << "00"; |
99 |
| - buffstream << std::dec << (rawsec / 600) % 60; |
100 |
| - buff = buffstream.str(); |
101 |
| - ss << buff.substr(buff.length() - 2, buff.length()); |
102 |
| - ss << ":"; |
103 |
| - |
104 |
| - buffstream.str(""); |
105 |
| - buffstream.clear(); |
106 |
| - buffstream << "00"; |
107 |
| - buffstream << std::dec << (rawsec / 10) % 60; |
108 |
| - buff = buffstream.str(); |
109 |
| - ss << buff.substr(buff.length() - 2, buff.length()); |
110 |
| - ss << "\n"; |
111 |
| - |
112 |
| - return ss.str(); |
| 57 | + std::string out = ""; |
| 58 | + uint32_t rawsec = ENDIAN_CHANGE_U32(m_eddystoneData.tmil); |
| 59 | + char val[6]; |
| 60 | + |
| 61 | + out += "Version " + m_eddystoneData.version; |
| 62 | + out += "\n"; |
| 63 | + out += "Battery Voltage " + ENDIAN_CHANGE_U16(m_eddystoneData.volt); |
| 64 | + out += " mV\n"; |
| 65 | + |
| 66 | + out += "Temperature "; |
| 67 | + snprintf(val, sizeof(val), "%d", m_eddystoneData.temp); |
| 68 | + out += val; |
| 69 | + out += ".0 °C\n"; |
| 70 | + |
| 71 | + out += "Adv. Count "; |
| 72 | + snprintf(val, sizeof(val), "%d", ENDIAN_CHANGE_U32(m_eddystoneData.advCount)); |
| 73 | + out += val; |
| 74 | + out += "\n"; |
| 75 | + |
| 76 | + out += "Time "; |
| 77 | + |
| 78 | + snprintf(val, sizeof(val), "%04d", rawsec / 864000); |
| 79 | + out += val; |
| 80 | + out += "."; |
| 81 | + |
| 82 | + snprintf(val, sizeof(val), "%02d", (rawsec / 36000) % 24); |
| 83 | + out += val; |
| 84 | + out += ":"; |
| 85 | + |
| 86 | + snprintf(val, sizeof(val), "%02d", (rawsec / 600) % 60); |
| 87 | + out += val; |
| 88 | + out += ":"; |
| 89 | + |
| 90 | + snprintf(val, sizeof(val), "%02d", (rawsec / 10) % 60); |
| 91 | + out += val; |
| 92 | + out += "\n"; |
| 93 | + |
| 94 | + return out; |
113 | 95 | } // toString
|
114 | 96 |
|
115 | 97 | /**
|
|
0 commit comments