summaryrefslogtreecommitdiff
path: root/src/BLEService.cpp
diff options
context:
space:
mode:
authorkolban <kolban1@kolban.com>2017-10-13 10:52:17 -0500
committerkolban <kolban1@kolban.com>2017-10-13 10:52:17 -0500
commit34902f4e7fc6926a005a5ccfd4e530d6a6321613 (patch)
tree512593068ed656012ee31fced9526bff80ecad55 /src/BLEService.cpp
parentMerge pull request #5 from sebastiankliem/master (diff)
downloadthermostat-34902f4e7fc6926a005a5ccfd4e530d6a6321613.tar.gz
thermostat-34902f4e7fc6926a005a5ccfd4e530d6a6321613.tar.bz2
thermostat-34902f4e7fc6926a005a5ccfd4e530d6a6321613.zip
Sync update for 0.4.3 take 2
Diffstat (limited to 'src/BLEService.cpp')
-rw-r--r--src/BLEService.cpp50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/BLEService.cpp b/src/BLEService.cpp
index ec16db8..9e7fa28 100644
--- a/src/BLEService.cpp
+++ b/src/BLEService.cpp
@@ -29,21 +29,24 @@ static const char* LOG_TAG = "BLEService"; // Tag for logging.
/**
* @brief Construct an instance of the BLEService
* @param [in] uuid The UUID of the service.
+ * @param [in] numHandles The maximum number of handles associated with the service.
*/
-BLEService::BLEService(const char* uuid) : BLEService(BLEUUID(uuid)) {
+BLEService::BLEService(const char* uuid, uint32_t numHandles) : BLEService(BLEUUID(uuid), numHandles) {
}
/**
* @brief Construct an instance of the BLEService
* @param [in] uuid The UUID of the service.
+ * @param [in] numHandles The maximum number of handles associated with the service.
*/
-BLEService::BLEService(BLEUUID uuid) {
- m_uuid = uuid;
- m_handle = NULL_HANDLE;
- m_pServer = nullptr;
+BLEService::BLEService(BLEUUID uuid, uint32_t numHandles) {
+ m_uuid = uuid;
+ m_handle = NULL_HANDLE;
+ m_pServer = nullptr;
//m_serializeMutex.setName("BLEService");
m_lastCreatedCharacteristic = nullptr;
+ m_numHandles = numHandles;
} // BLEService
@@ -54,16 +57,19 @@ BLEService::BLEService(BLEUUID uuid) {
* @return N/A.
*/
void BLEService::executeCreate(BLEServer *pServer) {
- ESP_LOGD(LOG_TAG, ">> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: %s", getUUID().toString().c_str());
-
+ //ESP_LOGD(LOG_TAG, ">> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: %s", getUUID().toString().c_str());
+ getUUID(); // Needed for a weird bug fix
m_pServer = pServer;
+ m_semaphoreCreateEvt.take("executeCreate"); // Take the mutex and release at event ESP_GATTS_CREATE_EVT
+
esp_gatt_srvc_id_t srvc_id;
srvc_id.id.inst_id = 0;
srvc_id.id.uuid = *m_uuid.getNative();
-
- m_semaphoreCreateEvt.take("executeCreate"); // Take the mutex and release at event ESP_GATTS_CREATE_EVT
-
- esp_err_t errRc = ::esp_ble_gatts_create_service(getServer()->getGattsIf(), &srvc_id, 10);
+ esp_err_t errRc = ::esp_ble_gatts_create_service(
+ getServer()->getGattsIf(),
+ &srvc_id,
+ m_numHandles // The maximum number of handles associated with the service.
+ );
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gatts_create_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
@@ -71,7 +77,6 @@ void BLEService::executeCreate(BLEServer *pServer) {
}
m_semaphoreCreateEvt.wait("executeCreate");
-
ESP_LOGD(LOG_TAG, "<< executeCreate");
} // executeCreate
@@ -87,18 +92,6 @@ void BLEService::dump() {
ESP_LOGD(LOG_TAG, "Characteristics:\n%s", m_characteristicMap.toString().c_str());
} // dump
-/*
-void BLEService::setService(esp_gatt_srvc_id_t srvc_id) {
- m_srvc_id = srvc_id;
-}
-*/
-
-/*
-esp_gatt_srvc_id_t BLEService::getService() {
- return m_srvc_id;
-}
-*/
-
/**
* @brief Get the UUID of the service.
@@ -184,7 +177,7 @@ void BLEService::addCharacteristic(BLECharacteristic* pCharacteristic) {
// to the map and then ask the service to add the characteristic at the BLE level (ESP-IDF).
//
ESP_LOGD(LOG_TAG, ">> addCharacteristic()");
- ESP_LOGD(LOG_TAG, "Adding characteristic (esp_ble_gatts_add_char): uuid=%s to service: %s",
+ ESP_LOGD(LOG_TAG, "Adding characteristic: uuid=%s to service: %s",
pCharacteristic->getUUID().toString().c_str(),
toString().c_str());
@@ -212,6 +205,7 @@ BLECharacteristic* BLEService::createCharacteristic(const char* uuid, uint32_t p
return createCharacteristic(BLEUUID(uuid), properties);
}
+
/**
* @brief Create a new BLE Characteristic associated with this service.
* @param [in] uuid - The UUID of the characteristic.
@@ -235,7 +229,7 @@ void BLEService::handleGATTServerEvent(
switch(event) {
- // ESP_GATTS_ADD_CHAR_EVT - Indicate that a characteristic was added to the service.
+ // ESP_GATTS_ADD_CHAR_EVT - Indicate that a characteristic was added to the service.
// add_char:
// - esp_gatt_status_t status
// - uint16_t attr_handle
@@ -251,18 +245,17 @@ void BLEService::handleGATTServerEvent(
ESP_LOGE(LOG_TAG, "Expected to find characteristic with UUID: %s, but didnt!",
BLEUUID(param->add_char.char_uuid).toString().c_str());
dump();
- m_semaphoreAddCharEvt.give();
break;
}
pCharacteristic->setHandle(param->add_char.attr_handle);
m_characteristicMap.setByHandle(param->add_char.attr_handle, pCharacteristic);
//ESP_LOGD(tag, "Characteristic map: %s", m_characteristicMap.toString().c_str());
- m_semaphoreAddCharEvt.give();
break;
} // Reached the correct service.
break;
} // ESP_GATTS_ADD_CHAR_EVT
+
// ESP_GATTS_START_EVT
//
// start:
@@ -301,6 +294,7 @@ void BLEService::handleGATTServerEvent(
} // Default
} // Switch
+ // Invoke the GATTS handler in each of the associated characteristics.
m_characteristicMap.handleGATTServerEvent(event, gatts_if, param);
} // handleGATTServerEvent