Hugo Pristauz / Mbed 2 deprecated S14_TOF_Detector

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers detection.cpp Source File

detection.cpp

00001 // detection.cpp - setup and handle DETECTION services
00002 
00003 #include "detection.h"
00004 
00005 
00006 // declare a CharacteristicDataInitializer which can be used to initialize
00007 // all our characteristics
00008 
00009    CharacteristicInitializer ini;
00010    
00011 // Detection Service
00012 
00013    Service detection(0xA010,"Detection"); // Detection Service
00014    Characteristic<Bool>        chrPresence(detection,0xA011, "n", "Presence"); 
00015 
00016 // Address Service
00017 
00018    Service address(0xA020,"Address");   // Address Service
00019    Characteristic<ObjectId>    chrId     (address, 0xA021, "na", "ID"); 
00020    //Characteristic<ObjectName>  chrName   (address, 0xA022, "na", "Name"); 
00021    //Characteristic<ObjectName>   chrLayout (address, 0xA023, "na", "Layout"); 
00022 
00023       // here is the issue: if above declaration of the characteristic chrName
00024       // is being uncommented the GATT database will be corrupted. It has been 
00025       // found out by trial & error that below 'tedious' code is a fix.
00026 /*      
00027    UserDescriptor(nameLayout,attLayout,dscLayout,"Layout")
00028    static ReadOnlyGattCharacteristic<ObjectName> _chrLayout(0xA023,ini.pObjectName(),0,dscLayout,1);   
00029 
00030    static GattCharacteristic *addressList[] = {&chrId,&chrName,&_chrLayout};
00031    static GattService _address(0xA020, addressList, GattListLength(addressList));
00032 */
00033 // Debug Service
00034 
00035    Service debug(0xA030,"Debug");      // Debug Service
00036    Characteristic<Bool>        chrTest      (debug, 0xA031, "w", "Test"); 
00037    Characteristic<DateTime>    chrTimestamp (debug, 0xA032, "r", "Timestamp"); 
00038 
00039 //==============================================================================
00040 // Update Callback
00041 //==============================================================================
00042 
00043    static void cbWritten(Blob &o)            // handle updates
00044    {
00045       Bool value;  
00046       
00047       if (updated(o,chrTest))          // has chrTest been updated?
00048       {
00049          get(o,chrTest,value);         // get value of chrTest
00050          set(o,chrPresence,value);     // and store this value to chrPresence 
00051 
00052          print(o,value,"test");
00053          if (value == 0)
00054             blinkConnected(o,"x x          ");
00055          else if (value == 1)
00056             blinkConnected(o,"xxx xxx          ");
00057          else
00058             blinkConnected(o,"x xxx x xxx          ");
00059       }
00060       else if (updated(o,chrPresence)) // has chrPresence been updated?
00061       {  
00062          get(o,chrPresence,value);      
00063          print(o,value,"test");
00064       }
00065    }
00066 
00067 //==============================================================================
00068 // Register Services and Callbacks
00069 //==============================================================================
00070 
00071    void services(Blob &o)              // enroll all services & characteristics
00072    {
00073       enroll(o,detection);             // enroll Detection Service
00074       enroll(o,address);               // enroll Address Service
00075       enroll(o,debug);                 // enroll Debug Service
00076       
00077       onWritten(o,cbWritten);          // setup 'data written' callback
00078    }
00079 
00080 //eof