Basic message sending over an ad hoc ble network

Fork of mbed-os-example-ble-LEDBlinker by mbed-os-examples

Committer:
wijtse
Date:
Tue Dec 12 10:59:54 2017 +0000
Revision:
53:520683d4f1d2
Parent:
50:7dcc6a0d9c95
reverted to start adv on disconnect

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wijtse 50:7dcc6a0d9c95 1 /* mbed Microcontroller Library
wijtse 50:7dcc6a0d9c95 2 * Copyright (c) 2006-2013 ARM Limited
wijtse 50:7dcc6a0d9c95 3 *
wijtse 50:7dcc6a0d9c95 4 * Licensed under the Apache License, Version 2.0 (the "License");
wijtse 50:7dcc6a0d9c95 5 * you may not use this file except in compliance with the License.
wijtse 50:7dcc6a0d9c95 6 * You may obtain a copy of the License at
wijtse 50:7dcc6a0d9c95 7 *
wijtse 50:7dcc6a0d9c95 8 * http://www.apache.org/licenses/LICENSE-2.0
wijtse 50:7dcc6a0d9c95 9 *
wijtse 50:7dcc6a0d9c95 10 * Unless required by applicable law or agreed to in writing, software
wijtse 50:7dcc6a0d9c95 11 * distributed under the License is distributed on an "AS IS" BASIS,
wijtse 50:7dcc6a0d9c95 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
wijtse 50:7dcc6a0d9c95 13 * See the License for the specific language governing permissions and
wijtse 50:7dcc6a0d9c95 14 * limitations under the License.
wijtse 50:7dcc6a0d9c95 15 */
wijtse 50:7dcc6a0d9c95 16
wijtse 50:7dcc6a0d9c95 17 #ifndef __BLE_LED_SERVICE_H__
wijtse 50:7dcc6a0d9c95 18 #define __BLE_LED_SERVICE_H__
wijtse 50:7dcc6a0d9c95 19
wijtse 50:7dcc6a0d9c95 20 class LEDService {
wijtse 50:7dcc6a0d9c95 21 public:
wijtse 50:7dcc6a0d9c95 22 const static uint16_t LED_SERVICE_UUID = 0xA000;
wijtse 50:7dcc6a0d9c95 23 const static uint16_t LED_STATE_CHARACTERISTIC_UUID = 0xA001;
wijtse 50:7dcc6a0d9c95 24
wijtse 50:7dcc6a0d9c95 25 LEDService(BLEDevice &_ble, bool initialValueForLEDCharacteristic) :
wijtse 50:7dcc6a0d9c95 26 ble(_ble), ledState(LED_STATE_CHARACTERISTIC_UUID, &initialValueForLEDCharacteristic)
wijtse 50:7dcc6a0d9c95 27 {
wijtse 50:7dcc6a0d9c95 28 GattCharacteristic *charTable[] = {&ledState};
wijtse 50:7dcc6a0d9c95 29 GattService ledService(LED_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
wijtse 50:7dcc6a0d9c95 30 ble.addService(ledService);
wijtse 50:7dcc6a0d9c95 31 }
wijtse 50:7dcc6a0d9c95 32
wijtse 50:7dcc6a0d9c95 33 GattAttribute::Handle_t getValueHandle() const
wijtse 50:7dcc6a0d9c95 34 {
wijtse 50:7dcc6a0d9c95 35 return ledState.getValueHandle();
wijtse 50:7dcc6a0d9c95 36 }
wijtse 50:7dcc6a0d9c95 37
wijtse 50:7dcc6a0d9c95 38 private:
wijtse 50:7dcc6a0d9c95 39 BLEDevice &ble;
wijtse 50:7dcc6a0d9c95 40 ReadWriteGattCharacteristic<bool> ledState;
wijtse 50:7dcc6a0d9c95 41 };
wijtse 50:7dcc6a0d9c95 42
wijtse 50:7dcc6a0d9c95 43 #endif /* #ifndef __BLE_LED_SERVICE_H__ */