Compare commits

...

5 Commits

Author SHA1 Message Date
David Lehrian 17f419ceac
Merge e94c081378 into 226c67f729 2024-04-21 09:55:19 +02:00
Sebastian Holder 226c67f729
Initialize ble_gatt_chr_def[]. Fixes #148 (#150)
IDF 5.2 introduced a new member, cpfd, to the
ble_gatt_chr_def struct. It needs to be initialized
to nullptr in order to avoid accessing uninitialized
memory. By initializing the whole struct, we get
everything initialized in a backward-compatible way.
2024-04-20 09:14:55 -06:00
David Lehrian e94c081378
Merge branch 'h2zero:master' into master 2024-02-04 10:14:40 -08:00
David Lehrian 217d06ca3a Update NimBLEAdvertising.cpp
Apparently a name length of 19 is a magic number because if it is longer than this then adding the null at the end isn't necessary, shortening the name works. Furthermore, adding the null appears to step on something and cause the uP to reboot. However if the name is shorter than 19 then adding a null at the end allows the name to be shortened without having the end of the previous longer name tacked onto the end of the shorter name AND it doesn't seem to step on anything as the uP appears to continue to operate fine.
2023-10-22 15:05:29 -07:00
David Lehrian 6b555d763b Update NimBLEAdvertising.cpp
Null terminate the m_name vector because for some reason if you shorten the advertising name it will keep the length the same as the longest name that has been set until the uP is restarted. This means that if you set the name to "longest" and then set it to "short" it will advertise as "shortst" (note two letters from the end of "longest".
2023-10-06 13:12:15 -07:00
2 changed files with 2 additions and 1 deletions

View File

@ -138,6 +138,7 @@ void NimBLEAdvertising::addTxPower() {
*/
void NimBLEAdvertising::setName(const std::string &name) {
m_name.assign(name.begin(), name.end());
if (name.length() <= 19) m_name[name.length()] = 0;
m_advData.name = &m_name[0];
m_advData.name_len = m_name.size();
m_advDataSet = false;

View File

@ -159,7 +159,7 @@ bool NimBLEService::start() {
// Nimble requires the last characteristic to have it's uuid = 0 to indicate the end
// of the characteristics for the service. We create 1 extra and set it to null
// for this purpose.
pChr_a = new ble_gatt_chr_def[numChrs + 1];
pChr_a = new ble_gatt_chr_def[numChrs + 1]{};
int i = 0;
for(auto chr_it = m_chrVec.begin(); chr_it != m_chrVec.end(); ++chr_it) {
if((*chr_it)->m_removed > 0) {