test1
Diff: source/BlueNRGDevice.cpp
- Revision:
- 242:058b2e731adc
- Parent:
- 191:d22cc4715b0c
- Parent:
- 229:9981f62cdb1a
- Child:
- 247:932a44bdff4f
--- a/source/BlueNRGDevice.cpp Fri Mar 18 12:10:20 2016 +0100 +++ b/source/BlueNRGDevice.cpp Mon Jun 20 14:59:06 2016 +0200 @@ -142,7 +142,7 @@ /* ToDo: Clear memory contents, reset the SD, etc. */ // By default, we set the device GAP role to PERIPHERAL - btle_init(BlueNRGGap::getInstance().getIsSetAddress(), GAP_PERIPHERAL_ROLE_IDB04A1); + btleInit(BlueNRGGap::getInstance().getIsSetAddress(), GAP_PERIPHERAL_ROLE_IDB04A1); isInitialized = true; BLE::InitializationCompleteCallbackContext context = { @@ -159,9 +159,9 @@ @brief Resets the BLE HW, removing any existing services and characteristics @param[in] void - @returns ble_error_t + @returns void */ -ble_error_t BlueNRGDevice::reset(void) +void BlueNRGDevice::reset(void) { wait_us(500); @@ -173,10 +173,7 @@ /* Wait for the radio to come back up */ wait_us(500); - - isInitialized = false; - return BLE_ERROR_NONE; } /*! @@ -205,14 +202,14 @@ /*! @brief get GAP version + @brief Get the BLE stack version information @param[in] void @returns char * + @returns char * */ const char *BlueNRGDevice::getVersion(void) { - char *version = new char[6]; - memcpy((void *)version, "1.0.0", 5); - return version; + return getVersionString(); } /**************************************************************************/ @@ -251,12 +248,43 @@ /**************************************************************************/ /*! - @brief shut down the the BLE device + @brief shut down the BLE device @param[out] error if any */ /**************************************************************************/ ble_error_t BlueNRGDevice::shutdown(void) { - return reset(); + if (!isInitialized) { + return BLE_ERROR_INITIALIZATION_INCOMPLETE; + } + + /* Reset the BlueNRG device first */ + reset(); + + /* Shutdown the BLE API and BlueNRG glue code */ + ble_error_t error; + + /* GattServer instance */ + error = BlueNRGGattServer::getInstance().reset(); + if (error != BLE_ERROR_NONE) { + return error; + } + + /* GattClient instance */ + error = BlueNRGGattClient::getInstance().reset(); + if (error != BLE_ERROR_NONE) { + return error; + } + + /* Gap instance */ + error = BlueNRGGap::getInstance().reset(); + if (error != BLE_ERROR_NONE) { + return error; + } + + isInitialized = false; + + return BLE_ERROR_NONE; + } /**