Compare commits

...

3 commits

Author SHA1 Message Date
Aaron Patterson 7f6640203c
Merge 65269cff7d into 226c67f729 2024-05-06 22:15:10 -05: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
Aaron Patterson 65269cff7d
Return a pointer to the Value object
Otherwise we get a copy, and the copy seems to clobber the data we want
2023-02-13 14:32:33 -08:00
3 changed files with 4 additions and 5 deletions

View file

@ -236,15 +236,14 @@ NimBLEUUID NimBLECharacteristic::getUUID() {
* @brief Retrieve the current value of the characteristic.
* @return The NimBLEAttValue containing the current characteristic value.
*/
NimBLEAttValue NimBLECharacteristic::getValue(time_t *timestamp) {
NimBLEAttValue* NimBLECharacteristic::getValue(time_t *timestamp) {
if(timestamp != nullptr) {
m_value.getValue(timestamp);
}
return m_value;
return &m_value;
} // getValue
/**
* @brief Retrieve the the current data length of the characteristic.
* @return The length of the current characteristic data.

View file

@ -95,7 +95,7 @@ public:
void removeDescriptor(NimBLEDescriptor *pDescriptor, bool deleteDsc = false);
NimBLEService* getService();
uint16_t getProperties();
NimBLEAttValue getValue(time_t *timestamp = nullptr);
NimBLEAttValue* getValue(time_t *timestamp = nullptr);
size_t getDataLength();
void setValue(const uint8_t* data, size_t size);
void setValue(const std::vector<uint8_t>& vec);

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) {