テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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