Kris Scholte Lubberink
/
SSS_Ble
Ble for smart sOlutions
Diff: source/BleDevicePeripheral.cpp
- Revision:
- 7:9cda1b0f25ae
- Parent:
- 6:ee9c86f06eae
- Child:
- 10:d845189d146e
diff -r ee9c86f06eae -r 9cda1b0f25ae source/BleDevicePeripheral.cpp --- a/source/BleDevicePeripheral.cpp Mon May 20 09:55:38 2019 +0200 +++ b/source/BleDevicePeripheral.cpp Mon May 20 13:20:35 2019 +0200 @@ -1,5 +1,6 @@ #include "BleDevicePeripheral.h" + void BleDevicePeripheral::onConnectionComplete(const ble::ConnectionCompleteEvent &event) { // ble_error_t error; @@ -25,48 +26,52 @@ } } +BleDevicePeripheral::~BleDevicePeripheral() { + printf("[PERIPHERAL]\t Destructing the peripheral\r\n"); +} + void BleDevicePeripheral::start() { - printf("[PERIPHERAL]\t Starting advertising \r\n"); - /* Set up and start advertising */ - uint8_t adv_buffer[ble::LEGACY_ADVERTISING_MAX_SIZE]; - /* use the helper to build the payload */ - ble::AdvertisingDataBuilder adv_data_builder( - adv_buffer - ); - adv_data_builder.setFlags(); - adv_data_builder.setName("SSS BLE", true); - ble::AdvertisingParameters adv_parameters( - ble::advertising_type_t::CONNECTABLE_UNDIRECTED, - ble::adv_interval_t(ble::millisecond_t(50)) - ); + ble_error_t error; + /* Set up and start advertising */ + uint8_t adv_buffer[ble::LEGACY_ADVERTISING_MAX_SIZE]; + /* use the helper to build the payload */ + ble::AdvertisingDataBuilder adv_data_builder( + adv_buffer + ); - ble_error_t error = _ble.gap().setAdvertisingParameters( - ble::LEGACY_ADVERTISING_HANDLE, - adv_parameters - ); - if (error) { - print_error(error, "[PERIPHERAL]\t Gap::setAdvertisingParameters() failed"); - return; - } - /* Set payload for the set */ - error = _ble.gap().setAdvertisingPayload( - ble::LEGACY_ADVERTISING_HANDLE, - adv_data_builder.getAdvertisingData() - ); + adv_data_builder.setFlags(); + adv_data_builder.setName("SSS BLE", true); + ble::AdvertisingParameters adv_parameters( + ble::advertising_type_t::CONNECTABLE_UNDIRECTED, + ble::adv_interval_t(ble::millisecond_t(50)) + ); - if (error) { - print_error(error, "Gap::setAdvertisingPayload() failed"); - _event_queue.break_dispatch(); - return; - } + error = _ble.gap().setAdvertisingParameters( + ble::LEGACY_ADVERTISING_HANDLE, + adv_parameters + ); + if (error) { + print_error(error, "[PERIPHERAL]\t Gap::setAdvertisingParameters() failed"); + return; + } + /* Set payload for the set */ + error = _ble.gap().setAdvertisingPayload( + ble::LEGACY_ADVERTISING_HANDLE, + adv_data_builder.getAdvertisingData() + ); + + if (error) { + print_error(error, "Gap::setAdvertisingPayload() failed"); + _event_queue.break_dispatch(); + return; + } - cs = new ColorService(_ble); - is = new InterestService(_ble); - - + cs = new ColorService(_ble); + is = new InterestService(_ble); + printf("[PERIPHERAL]\t Starting advertising \r\n"); error = _ble.gap().startAdvertising(ble::LEGACY_ADVERTISING_HANDLE);