Add secondary services as an include on the primary.

This commit is contained in:
h2zero 2021-09-13 08:39:59 -06:00
parent 79f442d24b
commit 4c8a13afe4
2 changed files with 22 additions and 7 deletions

View file

@ -53,6 +53,7 @@ NimBLEService::NimBLEService(const NimBLEUUID &uuid, uint16_t numHandles, NimBLE
m_pSvcDef = nullptr; m_pSvcDef = nullptr;
m_removed = 0; m_removed = 0;
m_secondary = false; m_secondary = false;
m_pSecSvcDef = nullptr;
} // NimBLEService } // NimBLEService
@ -71,6 +72,13 @@ NimBLEService::~NimBLEService() {
delete(m_pSvcDef); delete(m_pSvcDef);
} }
if(m_pSecSvcDef != nullptr) {
for(auto &it : m_secSvcVec) {
delete it;
}
delete m_pSecSvcDef;
}
for(auto &it : m_chrVec) { for(auto &it : m_chrVec) {
delete it; delete it;
} }
@ -223,6 +231,19 @@ bool NimBLEService::start() {
// end of services must indicate to api with type = 0 // end of services must indicate to api with type = 0
svc[1].type = 0; svc[1].type = 0;
m_pSvcDef = svc; m_pSvcDef = svc;
if(m_secSvcVec.size() > 0){
size_t numSecSvcs = m_secSvcVec.size();
ble_gatt_svc_def** m_pSecSvcDef = new ble_gatt_svc_def*[numSecSvcs + 1];
int i = 0;
for(auto& it : m_secSvcVec) {
it->start();
m_pSecSvcDef[i] = it->m_pSvcDef;
++i;
}
m_pSecSvcDef[numSecSvcs] = nullptr;
m_pSvcDef->includes = (const ble_gatt_svc_def**)m_pSecSvcDef;
}
} }
int rc = ble_gatts_count_cfg((const ble_gatt_svc_def*)m_pSvcDef); int rc = ble_gatts_count_cfg((const ble_gatt_svc_def*)m_pSvcDef);
@ -235,13 +256,6 @@ bool NimBLEService::start() {
if (rc != 0) { if (rc != 0) {
NIMBLE_LOGE(LOG_TAG, "ble_gatts_add_svcs, rc= %d, %s", rc, NimBLEUtils::returnCodeToString(rc)); NIMBLE_LOGE(LOG_TAG, "ble_gatts_add_svcs, rc= %d, %s", rc, NimBLEUtils::returnCodeToString(rc));
return false; return false;
}
if(m_secSvcVec.size() > 0){
for(auto& it : m_secSvcVec) {
it->start();
}
} }
NIMBLE_LOGD(LOG_TAG, "<< start()"); NIMBLE_LOGD(LOG_TAG, "<< start()");

View file

@ -83,6 +83,7 @@ private:
ble_gatt_svc_def* m_pSvcDef; ble_gatt_svc_def* m_pSvcDef;
uint8_t m_removed; uint8_t m_removed;
bool m_secondary; bool m_secondary;
ble_gatt_svc_def** m_pSecSvcDef;
std::vector<NimBLECharacteristic*> m_chrVec; std::vector<NimBLECharacteristic*> m_chrVec;
std::vector<NimBLEService*> m_secSvcVec; std::vector<NimBLEService*> m_secSvcVec;