Bluetooth Low Energy enabled device with "Analog" feature, compatible with BlueST Protocol.

Dependencies:   X_NUCLEO_LED61A1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CustomService.h Source File

CustomService.h

Go to the documentation of this file.
00001 /**
00002  *******************************************************************************
00003  * @file    CustomService.h
00004  * @author  Davide Aliprandi, STMicroelectronics
00005  * @version V1.0.0
00006  * @date    October 31st, 2017
00007  * @brief   mbed test application for the STMicroelectronics X-NUCLEO-IHM01A1
00008  *          Motor Control Expansion Board and the X-NUCLEO-IDB05A1 Bluetooth
00009  *          Low energy Expansion Board.
00010  *******************************************************************************
00011  * @attention
00012  *
00013  * <h2><center>&copy; COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions are met:
00017  *   1. Redistributions of source code must retain the above copyright notice,
00018  *      this list of conditions and the following disclaimer.
00019  *   2. Redistributions in binary form must reproduce the above copyright
00020  *      notice, this list of conditions and the following disclaimer in the
00021  *      documentation and/or other materials provided with the distribution.
00022  *   3. Neither the name of STMicroelectronics nor the names of its
00023  *      contributors may be used to endorse or promote products derived from
00024  *      this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  *******************************************************************************
00039  */
00040  
00041 
00042 #ifndef __BLE_CUSTOM_SERVICE_H__
00043 #define __BLE_CUSTOM_SERVICE_H__
00044 
00045 #include "ble_utils.h"
00046 
00047 #define COMMAND_DATA_LENGTH (sizeof(uint8_t))
00048 #define MAX_DATA_LENGTH     (COMMAND_DATA_LENGTH)
00049 
00050 const UUID::LongUUIDBytes_t CUSTOM_SERVICE_UUID            = {0x00,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0x9a,0xb4,0x00,0x02,0xa5,0xd5,0xc5,0x1b};
00051 const UUID::LongUUIDBytes_t CUSTOM_LED_CHARACTERISTIC_UUID = {0x80,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b};
00052 
00053 class CustomService {
00054 public:
00055 
00056     /* Led commands. */
00057     typedef enum
00058     {
00059         LED_POWER_OFF = 0,  // Led Off.
00060         LED_POWER_ON        // Led On.
00061     } led_commands_t;
00062 
00063     CustomService(BLEDevice &_ble) :
00064         ble(_ble),
00065         command(CUSTOM_LED_CHARACTERISTIC_UUID, packed_command, MAX_DATA_LENGTH, MAX_DATA_LENGTH,
00066             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)
00067     {
00068         GattCharacteristic *char_table[] = {&command};
00069         GattService led_service(CUSTOM_SERVICE_UUID, char_table, sizeof(char_table) / sizeof(GattCharacteristic *));
00070         ble.addService(led_service);
00071         memset (packed_command, 0, MAX_DATA_LENGTH);
00072     }
00073 
00074     GattAttribute::Handle_t getValueHandle() const
00075     {
00076         return command.getValueAttribute().getHandle();
00077     }
00078 
00079 private:
00080     BLEDevice &ble;
00081     GattCharacteristic command;
00082     uint8_t packed_command[MAX_DATA_LENGTH];
00083 };
00084 
00085 #endif /* #ifndef __BLE_CUSTOM_SERVICE_H__ */