|
4 | 4 | * Created on: Mar 12, 2018
|
5 | 5 | * Author: pcbreflux
|
6 | 6 | */
|
7 |
| -#include "Arduino.h" |
8 | 7 | #include "sdkconfig.h"
|
9 | 8 | #if defined(CONFIG_BT_ENABLED)
|
10 | 9 | #include <string.h>
|
| 10 | +#include <sstream> |
11 | 11 | #include <esp_log.h>
|
12 | 12 | #include "BLEEddystoneTLM.h"
|
13 | 13 |
|
@@ -54,46 +54,62 @@ uint32_t BLEEddystoneTLM::getTime() {
|
54 | 54 | } // getTime
|
55 | 55 |
|
56 | 56 | std::string BLEEddystoneTLM::toString() {
|
| 57 | + std::stringstream ss; |
57 | 58 | std::string out = "";
|
58 |
| - String buff; |
59 | 59 | uint32_t rawsec;
|
| 60 | + ss << "Version "; |
| 61 | + ss << std::dec << m_eddystoneData.version; |
| 62 | + ss << "\n"; |
60 | 63 |
|
61 |
| - out += "Version "; |
62 |
| - buff = String(m_eddystoneData.version, DEC); |
63 |
| - out += buff.c_str(); |
64 |
| - out += "\n"; |
| 64 | + ss << "Battery Voltage "; |
| 65 | + ss << std::dec << ENDIAN_CHANGE_U16(m_eddystoneData.volt); |
| 66 | + ss << " mV\n"; |
65 | 67 |
|
66 |
| - out += "Battery Voltage "; |
67 |
| - buff = String(ENDIAN_CHANGE_U16(m_eddystoneData.volt), DEC); |
68 |
| - out += buff.c_str(); |
69 |
| - out += " mV\n"; |
| 68 | + ss << "Temperature "; |
| 69 | + ss << (float)m_eddystoneData.temp; |
| 70 | + ss << " °C\n"; |
70 | 71 |
|
71 |
| - out += "Temperature "; |
72 |
| - buff = String((float)m_eddystoneData.temp, 1); |
73 |
| - out += buff.c_str(); |
74 |
| - out += " °C\n"; |
75 |
| - |
76 |
| - out += "Adv. Count "; |
77 |
| - buff = String(ENDIAN_CHANGE_U32(m_eddystoneData.advCount), DEC); |
78 |
| - out += buff.c_str(); |
79 |
| - out += "\n"; |
| 72 | + ss << "Adv. Count "; |
| 73 | + ss << std::dec << ENDIAN_CHANGE_U32(m_eddystoneData.advCount); |
| 74 | + |
| 75 | + ss << "\n"; |
80 | 76 |
|
81 |
| - out += "Time "; |
| 77 | + ss << "Time "; |
| 78 | + |
82 | 79 | rawsec = ENDIAN_CHANGE_U32(m_eddystoneData.tmil);
|
83 |
| - buff = "0000"+String(rawsec/864000, DEC); |
84 |
| - out += buff.substring(buff.length()-4,buff.length()).c_str(); |
85 |
| - out += "."; |
86 |
| - buff = "00"+String((rawsec/36000)%24, DEC); |
87 |
| - out += buff.substring(buff.length()-2,buff.length()).c_str(); |
88 |
| - out += ":"; |
89 |
| - buff = "00"+String((rawsec/600)%60, DEC); |
90 |
| - out += buff.substring(buff.length()-2,buff.length()).c_str(); |
91 |
| - out += ":"; |
92 |
| - buff = "00"+String((rawsec/10)%60, DEC); |
93 |
| - out += buff.substring(buff.length()-2,buff.length()).c_str(); |
94 |
| - out += "\n"; |
95 |
| - |
96 |
| - return out; |
| 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(); |
97 | 113 | } // toString
|
98 | 114 |
|
99 | 115 | /**
|
|
0 commit comments