Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lizzy_service.h Source File

lizzy_service.h

00001 #ifndef __LIZZY_SERVICE_H__
00002 #define __LIZZY_SERVICE_H__
00003 
00004 #include "mbed.h"
00005 #include "ble/BLE.h"
00006 #include "service_macros.h"
00007 #include "proj_config.h"
00008 
00009 #define NUM_LEDS        (3)
00010 #define NUM_AXIS        (3)
00011 
00012 
00013 typedef struct
00014 {
00015     bool buzz;
00016     bool leds[NUM_LEDS];
00017     uint16_t acc_lsb;
00018     int16_t acc_data[NUM_AXIS];
00019 } init_lizzy_t;
00020 
00021 
00022 class LizzyService{
00023     public:
00024         const static uint16_t LIZZY_SERVICE_UUID = 0xA000;
00025         const static uint16_t BUZZ_UUID = 0xA001;
00026         const static uint16_t MAC_RED_UUID = 0xA002;
00027         const static uint16_t GREEN_UUID = 0xA003;
00028         const static uint16_t BLUE_UUID = 0xA004;
00029         const static uint16_t ACC_LSB_UUID = 0xA005;
00030         const static uint16_t ACC_DATA_UUID = 0xA006;
00031 
00032         LizzyService(BLEDevice &_ble, init_lizzy_t *init) :
00033               ble(_ble),
00034 #if VODAFONE_COMPATIBILITY == 1
00035               buzz(BUZZ_UUID, (uint8_t*)&(init->buzz)),
00036               mac(MAC_RED_UUID, (uint8_t*)&(init->leds[0]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00037 #else
00038               buzz(BUZZ_UUID, &(init->buzz), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00039               redLed(MAC_RED_UUID, &(init->leds[0]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00040 #endif
00041               green_led(GREEN_UUID, &(init->leds[1]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00042               blue_led(BLUE_UUID, &(init->leds[2]), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00043               acc_lsb(ACC_LSB_UUID, &(init->acc_lsb), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00044               acc_data(ACC_DATA_UUID, init->acc_data, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
00045         {
00046             GattCharacteristic *charTable[] = {
00047 #if VODAFONE_COMPATIBILITY == 1
00048                 &buzz, &mac,
00049 #else
00050                 &buzz, &redLed,
00051 #endif
00052                 &green_led, &blue_led, &acc_lsb, &acc_data};     // Add characteristick in table
00053             GattService AckService(LIZZY_SERVICE_UUID, charTable, sizeof(charTable)/sizeof(GattCharacteristic *));   
00054             ble.gattServer().addService(AckService); // Add service in the BLE
00055         }
00056         
00057         inline BLEDevice *get_ble(){
00058             return &ble;
00059         }
00060         
00061         // Characteristic setters.
00062 /*
00063         inline void set_buzz_state(bool new_state){
00064             ble.gattServer().write(buzz.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state));
00065         }
00066         inline void set_red_state(bool new_state){
00067             ble.gattServer().write(red_led.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state));
00068         }*/
00069         inline void set_green_state(bool new_state){
00070             ble.gattServer().write(green_led.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state));
00071         }
00072         inline void set_blue_state(bool new_state){
00073             ble.gattServer().write(blue_led.getValueHandle(), (uint8_t*)&new_state, sizeof(new_state));
00074         }
00075         
00076         inline void set_acc_lsb(uint16_t new_value){
00077             ble.gattServer().write(acc_lsb.getValueHandle(), (uint8_t*)&new_value, sizeof(new_value));
00078         }
00079         inline void set_acc_data(int16_t *new_values){
00080             ble.gattServer().write(acc_data.getValueHandle(), (uint8_t*)new_values, sizeof(int16_t)*NUM_AXIS);
00081         }
00082         
00083         // Characteristic getters.
00084 /*
00085         inline bool get_buzz_state(){
00086             bool tmp;
00087             uint16_t size = sizeof(tmp);
00088             ble.gattServer().read(buzz.getValueHandle(), (uint8_t*)&tmp, &size);
00089             return tmp;
00090         }
00091         inline bool get_red_state(){
00092             bool tmp;
00093             uint16_t size = sizeof(tmp);
00094             ble.gattServer().read(red_led.getValueHandle(), (uint8_t*)&tmp, &size);
00095             return tmp;
00096         }*/
00097         inline bool get_green_state(){
00098             bool tmp;
00099             uint16_t size = sizeof(tmp);
00100             ble.gattServer().read(green_led.getValueHandle(), (uint8_t*)&tmp, &size);
00101             return tmp;
00102         }
00103         inline bool get_blue_state(){
00104             bool tmp;
00105             uint16_t size = sizeof(tmp);
00106             ble.gattServer().read(blue_led.getValueHandle(), (uint8_t*)&tmp, &size);
00107             return tmp;
00108         }
00109 
00110 /*
00111         inline GattAttribute::Handle_t get_buzz_handle(){
00112             return buzz.getValueHandle();
00113         }
00114         inline GattAttribute::Handle_t get_red_handle(){
00115             return red_led.getValueHandle();
00116         }*/
00117         inline GattAttribute::Handle_t get_green_handle(){
00118             return green_led.getValueHandle();
00119         }
00120         inline GattAttribute::Handle_t get_blue_handle(){
00121             return blue_led.getValueHandle();
00122         }
00123         
00124         inline GattAttribute::Handle_t get_acc_lsb_handle(){
00125             return acc_lsb.getValueHandle();
00126         }inline GattAttribute::Handle_t get_acc_data_handle(){
00127             return acc_data.getValueHandle();
00128         }
00129 
00130 #if VODAFONE_COMPATIBILITY == 1
00131         CHARACTERISTIC_A(WriteOnly, uint8_t, 4, buzz, Buzz);
00132         CHARACTERISTIC_A(ReadOnly, uint8_t, 6, mac, Mac);
00133 #else
00134         CHARACTERISTIC_W(ReadWrite, bool, buzz, Buzz);
00135         CHARACTERISTIC_W(ReadWrite, bool, redLed, RedLed);
00136 #endif
00137         
00138     private:
00139         BLEDevice &ble;
00140         // Create new characteristics
00141 /*
00142         ReadWriteGattCharacteristic<bool> buzz;
00143         ReadWriteGattCharacteristic<bool> red_led;*/
00144         ReadWriteGattCharacteristic<bool> green_led;
00145         ReadWriteGattCharacteristic<bool> blue_led;
00146         
00147         ReadOnlyGattCharacteristic<uint16_t> acc_lsb;
00148         ReadOnlyArrayGattCharacteristic<int16_t, NUM_AXIS> acc_data;
00149 };
00150 
00151 #endif //__LIZZY_SERVICE_H__