First programBLE

Dependents:   Nucleo_BLE_UART

Fork of Nucleo_BLE_API by ST Americas mbed Team

Committer:
sjallouli
Date:
Fri Dec 19 19:52:49 2014 +0000
Revision:
1:79e5c08cbcc7
Parent:
0:289fd2dae405
change the USARTService->write() method access permission to public

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sjallouli 0:289fd2dae405 1 /* mbed Microcontroller Library
sjallouli 0:289fd2dae405 2 * Copyright (c) 2006-2013 ARM Limited
sjallouli 0:289fd2dae405 3 *
sjallouli 0:289fd2dae405 4 * Licensed under the Apache License, Version 2.0 (the "License");
sjallouli 0:289fd2dae405 5 * you may not use this file except in compliance with the License.
sjallouli 0:289fd2dae405 6 * You may obtain a copy of the License at
sjallouli 0:289fd2dae405 7 *
sjallouli 0:289fd2dae405 8 * http://www.apache.org/licenses/LICENSE-2.0
sjallouli 0:289fd2dae405 9 *
sjallouli 0:289fd2dae405 10 * Unless required by applicable law or agreed to in writing, software
sjallouli 0:289fd2dae405 11 * distributed under the License is distributed on an "AS IS" BASIS,
sjallouli 0:289fd2dae405 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sjallouli 0:289fd2dae405 13 * See the License for the specific language governing permissions and
sjallouli 0:289fd2dae405 14 * limitations under the License.
sjallouli 0:289fd2dae405 15 */
sjallouli 0:289fd2dae405 16
sjallouli 0:289fd2dae405 17 #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__
sjallouli 0:289fd2dae405 18 #define __BLE_DEVICE_INFORMATION_SERVICE_H__
sjallouli 0:289fd2dae405 19
sjallouli 0:289fd2dae405 20 #include "BLEDevice.h"
sjallouli 0:289fd2dae405 21
sjallouli 0:289fd2dae405 22 /* Device Information Service */
sjallouli 0:289fd2dae405 23 /* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml */
sjallouli 0:289fd2dae405 24 /* Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml */
sjallouli 0:289fd2dae405 25 class DeviceInformationService {
sjallouli 0:289fd2dae405 26 public:
sjallouli 0:289fd2dae405 27 /**
sjallouli 0:289fd2dae405 28 * Constructor.
sjallouli 0:289fd2dae405 29 *
sjallouli 0:289fd2dae405 30 * @param[in] _ble
sjallouli 0:289fd2dae405 31 * Reference to the BLEDevice.
sjallouli 0:289fd2dae405 32 * @param[in] manufacturersName
sjallouli 0:289fd2dae405 33 * This characteristic represents the name of the
sjallouli 0:289fd2dae405 34 * manufacturer of the device. The name is copied into the
sjallouli 0:289fd2dae405 35 * BLE stack during this constructor.
sjallouli 0:289fd2dae405 36 * @param[in] modelNumber
sjallouli 0:289fd2dae405 37 * This characteristic represents the model number that is
sjallouli 0:289fd2dae405 38 * assigned by the device vendor. The value is copied into
sjallouli 0:289fd2dae405 39 * the BLE stack during this constructor.
sjallouli 0:289fd2dae405 40 * @param[in] serialNumber
sjallouli 0:289fd2dae405 41 * This characteristic represents the serial number for a
sjallouli 0:289fd2dae405 42 * particular instance of the device. The value is copied
sjallouli 0:289fd2dae405 43 * into the BLE stack during this constructor.
sjallouli 0:289fd2dae405 44 * @param[in] hardwareRevision
sjallouli 0:289fd2dae405 45 * This characteristic represents the hardware revision for
sjallouli 0:289fd2dae405 46 * the hardware within the device. The value is copied
sjallouli 0:289fd2dae405 47 * into the BLE stack during this constructor.
sjallouli 0:289fd2dae405 48 * @param[in] firmwareRevision
sjallouli 0:289fd2dae405 49 * This characteristic represents the firmware revision for
sjallouli 0:289fd2dae405 50 * the firmware within the device. The value is copied
sjallouli 0:289fd2dae405 51 * into the BLE stack during this constructor.
sjallouli 0:289fd2dae405 52 * @param[in] softwareRevision
sjallouli 0:289fd2dae405 53 * This characteristic represents the software revision for
sjallouli 0:289fd2dae405 54 * the software within the device. The value is copied
sjallouli 0:289fd2dae405 55 * into the BLE stack during this constructor.
sjallouli 0:289fd2dae405 56 */
sjallouli 0:289fd2dae405 57 DeviceInformationService(BLEDevice &_ble,
sjallouli 0:289fd2dae405 58 const char *manufacturersName = NULL,
sjallouli 0:289fd2dae405 59 const char *modelNumber = NULL,
sjallouli 0:289fd2dae405 60 const char *serialNumber = NULL,
sjallouli 0:289fd2dae405 61 const char *hardwareRevision = NULL,
sjallouli 0:289fd2dae405 62 const char *firmwareRevision = NULL,
sjallouli 0:289fd2dae405 63 const char *softwareRevision = NULL) :
sjallouli 0:289fd2dae405 64 ble(_ble),
sjallouli 0:289fd2dae405 65 manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR,
sjallouli 0:289fd2dae405 66 (uint8_t *)manufacturersName,
sjallouli 0:289fd2dae405 67 (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* minLength */
sjallouli 0:289fd2dae405 68 (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* maxLength */
sjallouli 0:289fd2dae405 69 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
sjallouli 0:289fd2dae405 70 modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR,
sjallouli 0:289fd2dae405 71 (uint8_t *)modelNumber,
sjallouli 0:289fd2dae405 72 (modelNumber != NULL) ? strlen(modelNumber) : 0, /* minLength */
sjallouli 0:289fd2dae405 73 (modelNumber != NULL) ? strlen(modelNumber) : 0, /* maxLength */
sjallouli 0:289fd2dae405 74 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
sjallouli 0:289fd2dae405 75 serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR,
sjallouli 0:289fd2dae405 76 (uint8_t *)serialNumber,
sjallouli 0:289fd2dae405 77 (serialNumber != NULL) ? strlen(serialNumber) : 0, /* minLength */
sjallouli 0:289fd2dae405 78 (serialNumber != NULL) ? strlen(serialNumber) : 0, /* maxLength */
sjallouli 0:289fd2dae405 79 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
sjallouli 0:289fd2dae405 80 hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR,
sjallouli 0:289fd2dae405 81 (uint8_t *)hardwareRevision,
sjallouli 0:289fd2dae405 82 (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* minLength */
sjallouli 0:289fd2dae405 83 (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* maxLength */
sjallouli 0:289fd2dae405 84 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
sjallouli 0:289fd2dae405 85 firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR,
sjallouli 0:289fd2dae405 86 (uint8_t *)firmwareRevision,
sjallouli 0:289fd2dae405 87 (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* minLength */
sjallouli 0:289fd2dae405 88 (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* maxLength */
sjallouli 0:289fd2dae405 89 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
sjallouli 0:289fd2dae405 90 softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR,
sjallouli 0:289fd2dae405 91 (uint8_t *)softwareRevision,
sjallouli 0:289fd2dae405 92 (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* minLength */
sjallouli 0:289fd2dae405 93 (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* maxLength */
sjallouli 0:289fd2dae405 94 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)
sjallouli 0:289fd2dae405 95 {
sjallouli 0:289fd2dae405 96 static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */
sjallouli 0:289fd2dae405 97 if (serviceAdded) {
sjallouli 0:289fd2dae405 98 return;
sjallouli 0:289fd2dae405 99 }
sjallouli 0:289fd2dae405 100
sjallouli 0:289fd2dae405 101 GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic,
sjallouli 0:289fd2dae405 102 &modelNumberStringCharacteristic,
sjallouli 0:289fd2dae405 103 &serialNumberStringCharacteristic,
sjallouli 0:289fd2dae405 104 &hardwareRevisionStringCharacteristic,
sjallouli 0:289fd2dae405 105 &firmwareRevisionStringCharacteristic,
sjallouli 0:289fd2dae405 106 &softwareRevisionStringCharacteristic};
sjallouli 0:289fd2dae405 107 GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable,
sjallouli 0:289fd2dae405 108 sizeof(charTable) / sizeof(GattCharacteristic *));
sjallouli 0:289fd2dae405 109
sjallouli 0:289fd2dae405 110 ble.addService(deviceInformationService);
sjallouli 0:289fd2dae405 111 serviceAdded = true;
sjallouli 0:289fd2dae405 112 }
sjallouli 0:289fd2dae405 113
sjallouli 0:289fd2dae405 114 private:
sjallouli 0:289fd2dae405 115 BLEDevice &ble;
sjallouli 0:289fd2dae405 116 GattCharacteristic manufacturersNameStringCharacteristic;
sjallouli 0:289fd2dae405 117 GattCharacteristic modelNumberStringCharacteristic;
sjallouli 0:289fd2dae405 118 GattCharacteristic serialNumberStringCharacteristic;
sjallouli 0:289fd2dae405 119 GattCharacteristic hardwareRevisionStringCharacteristic;
sjallouli 0:289fd2dae405 120 GattCharacteristic firmwareRevisionStringCharacteristic;
sjallouli 0:289fd2dae405 121 GattCharacteristic softwareRevisionStringCharacteristic;
sjallouli 0:289fd2dae405 122 };
sjallouli 0:289fd2dae405 123
sjallouli 0:289fd2dae405 124 #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/