8000 Merge branch 'master' of https://github.com/nkolban/esp32-snippets.git · Netoperz/esp32-snippets@2c8b0f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c8b0f2

Browse files
committed
2 parents b1922a8 + d04db84 commit 2c8b0f2

File tree

7 files changed

+70
-35
lines changed

7 files changed

+70
-35
lines changed

.DS_Store

6 KB
Binary file not shown.

cpp_utils/onhold/BLEEddystoneTLM.cpp renamed to cpp_utils/BLEEddystoneTLM.cpp

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* Created on: Mar 12, 2018
55
* Author: pcbreflux
66
*/
7-
#include "Arduino.h"
87
#include "sdkconfig.h"
98
#if defined(CONFIG_BT_ENABLED)
109
#include <string.h>
10+
#include <sstream>
1111
#include <esp_log.h>
1212
#include "BLEEddystoneTLM.h"
1313

@@ -54,46 +54,62 @@ uint32_t BLEEddystoneTLM::getTime() {
5454
} // getTime
5555

5656
std::string BLEEddystoneTLM::toString() {
57+
std::stringstream ss;
5758
std::string out = "";
58-
String buff;
5959
uint32_t rawsec;
60+
ss << "Version ";
61+
ss << std::dec << m_eddystoneData.version;
62+
ss << "\n";
6063

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";
6567

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";
7071

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";
8076

81-
out += "Time ";
77+
ss << "Time ";
78+
8279
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();
97113
} // toString
98114

99115
/**
File renamed without changes.
File renamed without changes.
File renamed without changes.

cpp_utils/BLEServer.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ BLEService* BLEServer::createService(BLEUUID uuid, uint32_t numHandles, uint8_t
9696
} // createService
9797

9898

99+
/**
100+
* @brief Get a %BLE Service by its UUID
101+
* @param [in] uuid The UUID of the new service.
102+
* @return A reference to the service object.
103+
*/
104+
BLEService* BLEServer::getServiceByUUID(const char* uuid) {
105+
return m_serviceMap.getByUUID(uuid);
106+
}
107+
108+
/**
109+
* @brief Get a %BLE Service by its UUID
110+
* @param [in] uuid The UUID of the new service.
111+
* @return A reference to the service object.
112+
*/
113+
BLEService* BLEServer::getServiceByUUID(BLEUUID uuid) {
114+
return m_serviceMap.getByUUID(uuid);
115+
}
116+
99117
/**
100118
* @brief Retrieve the advertising object that can be used to advertise the existence of the server.
101119
*
< 8374 div class="pt-3">

cpp_utils/BLEServer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class BLEServer {
6363
void setCallbacks(BLEServerCallbacks* pCallbacks);
6464
void startAdvertising();
6565
void removeService(BLEService *service);
66-
66+
BLEService* getServiceByUUID(const char* uuid);
67+
BLEService* getServiceByUUID(BLEUUID uuid);
6768

6869
private:
6970
BLEServer();

0 commit comments

Comments
 (0)
0