UART Tests

This commit is contained in:
ktownsend 2013-12-10 07:32:12 +00:00
parent 7cbe25810b
commit 7094c665cd
14 changed files with 270 additions and 87 deletions

28
GapAdvertisingData.cpp Normal file
View file

@ -0,0 +1,28 @@
#include <stdio.h>
#include <string.h>
#include "GapAdvertisingData.h"
/**************************************************************************/
/*!
@brief Creates a new GapAdvertisingData instance
@section EXAMPLE
@code
@endcode
*/
/**************************************************************************/
GapAdvertisingData::GapAdvertisingData(void)
{
}
/**************************************************************************/
/*!
Destructor
*/
/**************************************************************************/
GapAdvertisingData::~GapAdvertisingData(void)
{
}

15
GapAdvertisingData.h Normal file
View file

@ -0,0 +1,15 @@
#ifndef __GAP_ADVERTISING_DATA_H__
#define __GAP_ADVERTISING_DATA_H__
#include "blecommon.h"
class GapAdvertisingData
{
public:
GapAdvertisingData(void);
virtual ~GapAdvertisingData(void);
private:
};
#endif

31
GapAdvertisingParams.cpp Normal file
View file

@ -0,0 +1,31 @@
#include <stdio.h>
#include <string.h>
#include "GapAdvertisingParams.h"
/**************************************************************************/
/*!
@brief Creates a new GapAdvertisingParams
@section EXAMPLE
@code
@endcode
*/
/**************************************************************************/
GapAdvertisingParams::GapAdvertisingParams(uint8_t advType, uint16_t interval, uint16_t timeout)
{
_advType = advType;
_interval = interval;
_timeout = timeout;
}
/**************************************************************************/
/*!
Destructor
*/
/**************************************************************************/
GapAdvertisingParams::~GapAdvertisingParams(void)
{
}

18
GapAdvertisingParams.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef __GAP_ADVERTISING_PARAMS_H__
#define __GAP_ADVERTISING_PARAMS_H__
#include "blecommon.h"
class GapAdvertisingParams
{
public:
GapAdvertisingParams(uint8_t advType, uint16_t interval, uint16_t timeout);
virtual ~GapAdvertisingParams(void);
private:
uint8_t _advType;
uint16_t _interval;
uint16_t _timeout;
};
#endif

View file

@ -1,11 +1,11 @@
#include <stdio.h>
#include <string.h>
#include "blecharacteristic.h"
#include "GattCharacteristic.h"
/**************************************************************************/
/*!
@brief Creates a new BLECharacteristic using the specified 16-bit
@brief Creates a new GattCharacteristic using the specified 16-bit
UUID, value length, and properties
@note The UUID value must be unique in the service and is normally >1
@ -25,12 +25,12 @@
@code
// UUID = 0x2A19, Min length 2, Max len = 2, Properties = write
BLECharacteristic c = BLECharacteristic( 0x2A19, 2, 2, 0x08 );
GattCharacteristic c = GattCharacteristic( 0x2A19, 2, 2, 0x08 );
@endcode
*/
/**************************************************************************/
BLECharacteristic::BLECharacteristic(uint16_t id, uint16_t minLen, uint16_t maxLen, uint8_t props)
GattCharacteristic::GattCharacteristic(uint16_t id, uint16_t minLen, uint16_t maxLen, uint8_t props)
{
uuid = id;
memcpy(&properties, &props, 1);
@ -43,6 +43,6 @@ BLECharacteristic::BLECharacteristic(uint16_t id, uint16_t minLen, uint16_t maxL
Destructor
*/
/**************************************************************************/
BLECharacteristic::~BLECharacteristic(void)
GattCharacteristic::~GattCharacteristic(void)
{
}

View file

@ -1,16 +1,16 @@
#ifndef __BLE_CHARACTERISTIC_H__
#define __BLE_CHARACTERISTIC_H__
#ifndef __GATT_CHARACTERISTIC_H__
#define __GATT_CHARACTERISTIC_H__
#include "blecommon.h"
#include "uuid.h"
class BLECharacteristic
class GattCharacteristic
{
private:
public:
BLECharacteristic(uint16_t uuid, uint16_t minLen, uint16_t maxLen, uint8_t properties);
virtual ~BLECharacteristic(void);
GattCharacteristic(uint16_t uuid, uint16_t minLen, uint16_t maxLen, uint8_t properties);
virtual ~GattCharacteristic(void);
uint16_t uuid; /* Characteristic UUID */
uint16_t lenMin; /* Minimum length of the value */

View file

@ -1,11 +1,11 @@
#include <stdio.h>
#include <string.h>
#include "bleservice.h"
#include "GattService.h"
/**************************************************************************/
/*!
@brief Creates a new BLEService using the specified 16 byte UUID
@brief Creates a new GattService using the specified 128-bit UUID
@note The UUID value must be unique on the device
@ -19,7 +19,7 @@
@endcode
*/
/**************************************************************************/
BLEService::BLEService(uint8_t base_uuid[16])
GattService::GattService(uint8_t base_uuid[16])
{
primaryServiceID.update(base_uuid);
characteristicCount = 0;
@ -29,7 +29,7 @@ BLEService::BLEService(uint8_t base_uuid[16])
/**************************************************************************/
/*!
@brief Creates a new BLEService using the specified 2 byte BLE UUID
@brief Creates a new GattService using the specified 16-bit BLE UUID
@param[in] ble_uuid
The standardised 16-bit (2 byte) BLE UUID to use for this
@ -42,7 +42,7 @@ BLEService::BLEService(uint8_t base_uuid[16])
@endcode
*/
/**************************************************************************/
BLEService::BLEService(uint16_t ble_uuid)
GattService::GattService(uint16_t ble_uuid)
{
primaryServiceID.update( ble_uuid );
characteristicCount = 0;
@ -55,26 +55,26 @@ BLEService::BLEService(uint16_t ble_uuid)
@brief Destructor
*/
/**************************************************************************/
BLEService::~BLEService(void)
GattService::~GattService(void)
{
}
/**************************************************************************/
/*!
@brief Adds a BLECharacterisic to the service, serialising the
@brief Adds a GattCharacterisic to the service, serialising the
essential data for the characteristic.
@note The BLEService does not store a reference to the source
BLECharacteristic, only a serialised version of the key
@note The GattService does not store a reference to the source
GattCharacteristic, only a serialised version of the key
properties required to create the characteristic on the
target radio board.
@note This function will update the .index field in the
BLECharacteristic to indicate where this characteristic was
stored in the BLEService's characteristic array.
GattCharacteristic to indicate where this characteristic was
stored in the GattService's characteristic array.
@param[in] characteristic
The BLECharacteristic object describing the characteristic
The GattCharacteristic object describing the characteristic
to add to this service
@returns BLE_ERROR_NONE (0) if everything executed correctly, or an
@ -89,7 +89,7 @@ BLEService::~BLEService(void)
@endcode
*/
/**************************************************************************/
ble_error_t BLEService::addCharacteristic(BLECharacteristic & characteristic)
ble_error_t GattService::addCharacteristic(GattCharacteristic & characteristic)
{
/* ToDo: Make sure we don't overflow the array, etc. */
/* ToDo: Make sure this characteristic UUID doesn't already exist */
@ -97,7 +97,7 @@ ble_error_t BLEService::addCharacteristic(BLECharacteristic & characteristic)
serialisedChar_t c;
/* Serialise the source BLECharacteristic */
/* Serialise the source GattCharacteristic */
memcpy(&c.id, &characteristic.uuid, 2);
memcpy(&c.lenMin, &characteristic.lenMin, 2);
memcpy(&c.lenMax, &characteristic.lenMax, 2);

View file

@ -1,13 +1,13 @@
#ifndef __BLE_SERVICE_H__
#define __BLE_SERVICE_H__
#ifndef __GATT_SERVICE_H__
#define __GATT_SERVICE_H__
#include "blecommon.h"
#include "uuid.h"
#include "blecharacteristic.h"
#include "GattCharacteristic.h"
#define BLE_SERVICE_MAX_CHARACTERISTICS (5)
class BLEService
class GattService
{
private:
@ -21,16 +21,16 @@ public:
uint8_t reserved;
} serialisedChar_t;
BLEService(uint8_t[16]); /* 128-bit Base UUID */
BLEService(uint16_t); /* 16-bit BLE UUID */
virtual ~BLEService(void);
GattService(uint8_t[16]); /* 128-bit Base UUID */
GattService(uint16_t); /* 16-bit BLE UUID */
virtual ~GattService(void);
UUID primaryServiceID;
uint8_t characteristicCount;
serialisedChar_t characteristics[BLE_SERVICE_MAX_CHARACTERISTICS];
uint8_t index;
ble_error_t addCharacteristic(BLECharacteristic &);
ble_error_t addCharacteristic(GattCharacteristic &);
};
#endif

View file

@ -8,6 +8,32 @@ typedef enum ble_error_e
BLE_ERROR_NONE = 0
} ble_error_t;
typedef enum ble_gap_adv_flags_e
{
BLE_GAP_ADV_FLAGS_
} ble_gap_adv_flags_t;
// https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
typedef enum ble_gap_adv_datatype_e
{
BLE_GAP_ADV_DATATYPE_FLAGS = 0x01,
BLE_GAP_ADV_DATATYPE_INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02,
BLE_GAP_ADV_DATATYPE_COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03,
BLE_GAP_ADV_DATATYPE_INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04,
BLE_GAP_ADV_DATATYPE_COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05,
BLE_GAP_ADV_DATATYPE_INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06,
BLE_GAP_ADV_DATATYPE_COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07,
BLE_GAP_ADV_DATATYPE_SHORTENED_LOCAL_NAME = 0x08,
BLE_GAP_ADV_DATATYPE_COMPLETE_LOCAL_NAME = 0x09,
BLE_GAP_ADV_DATATYPE_TX_POWER_LEVEL = 0x0A,
BLE_GAP_ADV_DATATYPE_DEVICE_ID = 0x10,
BLE_GAP_ADV_DATATYPE_SLAVE_CONNECTION_INTERVAL_RANGE = 0x12,
BLE_GAP_ADV_DATATYPE_SERVICE_DATA = 0x16,
BLE_GAP_ADV_DATATYPE_APPEARANCE = 0x19,
BLE_GAP_ADV_DATATYPE_ADVERTISING_INTERVAL = 0x1A,
BLE_GAP_ADV_DATATYPE_MANUFACTURER_SPECIFIC_DATA = 0xFF
} ble_gap_adv_datatype_t;
// https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
typedef enum ble_gap_char_appearance_e
{
@ -52,8 +78,8 @@ typedef enum ble_gap_char_appearance_e
BLE_GAP_CHAR_APPEARANCE_CYCLING_POWER_SENSOR = 1156,
BLE_GAP_CHAR_APPEARANCE_CYCLING_SPEED_AND_CADENCE_SENSOR = 1157,
BLE_GAP_CHAR_APPEARANCE_PULSE_OXIMETER_GENERIC = 3136,
BLE_GAP_CHAR_APPEARANCE_PULSE_OXIMETERFINGERTIP = 3137,
BLE_GAP_CHAR_APPEARANCE_PULSE_OXIMETERWRIST_WORN = 3138,
BLE_GAP_CHAR_APPEARANCE_PULSE_OXIMETER_FINGERTIP = 3137,
BLE_GAP_CHAR_APPEARANCE_PULSE_OXIMETER_WRIST_WORN = 3138,
BLE_GAP_CHAR_APPEARANCE_OUTDOOR_GENERIC = 5184,
BLE_GAP_CHAR_APPEARANCE_OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185,
BLE_GAP_CHAR_APPEARANCE_OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186,
@ -205,13 +231,13 @@ typedef enum ble_gatt_format_e
BLE_GATT_FORMAT_DUINT16 = 0x18, /**< IEEE-20601 format. */
BLE_GATT_FORMAT_UTF8S = 0x19, /**< UTF-8 string. */
BLE_GATT_FORMAT_UTF16S = 0x1A, /**< UTF-16 string. */
BLE_GATT_FORMAT_STRUCT = 0x1B /**< Opaque Structure. */
BLE_GATT_FORMAT_STRUCT = 0x1B /**< Opaque Structure. */
} ble_gatt_format_t;
struct UTF8String
{
uint16_t length; /**< String length. */
uint8_t str[32]; /**< String data. */
uint8_t str[32]; /**< String data. */
};
struct UTF16String
@ -227,13 +253,13 @@ struct SecurityMode
};
// See https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
struct PresentationFormat
typedef struct PresentationFormat
{
uint8_t format; /**< Format of the value, see @ref ble_gatt_format_t. */
uint8_t gatt_format; /**< Format of the value, see @ref ble_gatt_format_t. */
int8_t exponent; /**< Exponent for integer data types. */
uint16_t unit; /**< UUID from Bluetooth Assigned Numbers, see @ref ble_gatt_unit_t. */
uint8_t name_space; /**< Namespace from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
uint16_t desc; /**< Namespace description from Bluetooth Assigned Numbers, see @ref BLE_GATT_CPF_NAMESPACES. */
};
uint16_t gatt_unit; /**< UUID from Bluetooth Assigned Numbers, see @ref ble_gatt_unit_t. */
uint8_t gatt_namespace; /**< Namespace from Bluetooth Assigned Numbers, normally '1', see @ref BLE_GATT_CPF_NAMESPACES. */
uint16_t gatt_nsdesc; /**< Namespace description from Bluetooth Assigned Numbers, normally '0', see @ref BLE_GATT_CPF_NAMESPACES. */
} presentation_format_t;
#endif

View file

@ -2,10 +2,15 @@
#define __BLE_RADIO_H__
#include "blecommon.h"
#include "bleservice.h"
#include "GattService.h"
#include "GapAdvertisingData.h"
#include "GapAdvertisingParams.h"
class BLERadio
{
protected:
FunctionPointer _callback_event;
public:
typedef enum radio_event_e
{
@ -20,12 +25,23 @@ class BLERadio
/* ToDo: Force constructor with event handler callback */
/* These functions must be defined in the sub-class */
//virtual ble_error_t attach(void (*fptr)(void));
virtual ble_error_t addService(BLEService &) = 0;
virtual ble_error_t updateValue(uint8_t, uint8_t, uint8_t[], uint16_t) = 0;
virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &) = 0;
virtual ble_error_t addService(GattService &) = 0;
virtual ble_error_t readCharacteristic(GattService &, GattCharacteristic &, uint8_t[], uint16_t) = 0;
virtual ble_error_t writeCharacteristic(GattService &, GattCharacteristic &, uint8_t[], uint16_t) = 0;
virtual ble_error_t start(void) = 0;
virtual ble_error_t stop(void) = 0;
virtual ble_error_t reset(void) = 0;
/* BLE event callback (connect, disconnect, etc.) */
void attach(void (*function)(void)) {
_callback_event.attach( function );
}
template<typename T>
void attach(T *object, void (T::*member)(void)) {
_callback_event.attach( object, member );
}
};
#endif

View file

@ -17,9 +17,6 @@ void nRF51822::uartCallback(void)
/**************************************************************************/
/*!
@brief Constructor
@args fptr[in] Pointer to the callback function when any radio
event is raised by the radio HW.
*/
/**************************************************************************/
//nRF51822::nRF51822() : uart(P0_4, P0_0) /* LPC812 */
@ -27,14 +24,14 @@ nRF51822::nRF51822() : uart(p9, p10) /* LPC1768 using apps board */
{
/* Setup the nRF UART interface */
uart.baud(9600);
/* Echo data on the debug CDC port */
uart.attach(this, &nRF51822::uartCallback);
/* Add flow control for UART (required by the nRF51822) */
//uart.set_flow_control(Serial::RTSCTS, P0_6, P0_8); /* LPC812 */
uart.set_flow_control(Serial::RTSCTS, p30, p29); /* LPC1768 */
/* Reset the service counter */
serviceCount = 0;
}
@ -53,17 +50,40 @@ nRF51822::~nRF51822(void)
*/
/**************************************************************************/
//ble_error_t nRF51822::attach(void (*fptr)(void))
//{
// return BLE_ERROR_NONE;
//}
void nRF51822::test(void)
{
/* Send iBeacon data as a test */
uint8_t response[4];
uart.printf("10 0a 00 1e 02 01 04 1A FF 4C 00 02 15 E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 00 00 00 00 C8\r\n");
response[0] = uart.getc();
response[1] = uart.getc();
response[2] = uart.getc();
response[3] = uart.getc();
wait(0.1);
/* Start the radio */
uart.printf("10 03 00 00\r\n");
response[0] = uart.getc();
response[1] = uart.getc();
response[2] = uart.getc();
response[3] = uart.getc();
}
/**************************************************************************/
/*!
*/
/**************************************************************************/
ble_error_t nRF51822::addService(BLEService & service)
ble_error_t nRF51822::setAdvertising(GapAdvertisingParams &, GapAdvertisingData &)
{
return BLE_ERROR_NONE;
}
/**************************************************************************/
/*!
*/
/**************************************************************************/
ble_error_t nRF51822::addService(GattService & service)
{
/* ToDo: Make sure we don't overflow the array, etc. */
/* ToDo: Make sure this service UUID doesn't already exist (?) */
@ -126,15 +146,38 @@ ble_error_t nRF51822::addService(BLEService & service)
return BLE_ERROR_NONE;
}
/**************************************************************************/
/*!
@brief Reads the value of a characteristic, based on the service
and characteristic index fields
@param[in] service
The GattService to read from
@param[in] characteristic
The GattCharacteristic to read from
@param[in] buffer
Buffer to hold the the characteristic's value
(raw byte array in LSB format)
@param[in] len
The number of bytes read into the buffer
*/
/**************************************************************************/
ble_error_t nRF51822::readCharacteristic(GattService &service, GattCharacteristic &characteristic, uint8_t buffer[], uint16_t len)
{
/* ToDo */
return BLE_ERROR_NONE;
}
/**************************************************************************/
/*!
@brief Updates the value of a characteristic, based on the service
and characteristic index fields
@param[in] sIndex
The BLEService's index value (.index)
@param[in] cIndex
The BLECharacteristic's index value (.index)
@param[in] service
The GattService to write to
@param[in] characteristic
The GattCharacteristic to write to
@param[in] buffer
Data to use when updating the characteristic's value
(raw byte array in LSB format)
@ -142,10 +185,10 @@ ble_error_t nRF51822::addService(BLEService & service)
The number of bytes in buffer
*/
/**************************************************************************/
ble_error_t nRF51822::updateValue(uint8_t sIndex, uint8_t cIndex, uint8_t buffer[], uint16_t len)
ble_error_t nRF51822::writeCharacteristic(GattService &service, GattCharacteristic &characteristic, uint8_t buffer[], uint16_t len)
{
/* Command ID = 0x0006, Payload = Service ID, Characteristic ID, Value */
uart.printf("10 06 00 %02X %02X %02X", len + 2, cIndex, sIndex);
uart.printf("10 06 00 %02X %02X %02X", len + 2, characteristic.index, service.index);
for (uint16_t i = 0; i<len; i++)
{
uart.printf(" %02X", buffer[i]);

View file

@ -3,8 +3,8 @@
#include "mbed.h"
#include "blecommon.h"
#include "bleservice.h"
#include "bleradio.h"
#include "GattService.h"
class nRF51822 : public BLERadio
{
@ -13,18 +13,21 @@ class nRF51822 : public BLERadio
virtual ~nRF51822(void);
/* Functions that mus be implemented from NRFRadio */
//virtual ble_error_t attach(void (*fptr)(void));
virtual ble_error_t addService(BLEService &);
virtual ble_error_t updateValue(uint8_t, uint8_t, uint8_t[], uint16_t);
virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &);
virtual ble_error_t addService(GattService &);
virtual ble_error_t readCharacteristic(GattService &, GattCharacteristic &, uint8_t[], uint16_t);
virtual ble_error_t writeCharacteristic(GattService &, GattCharacteristic &, uint8_t[], uint16_t);
virtual ble_error_t start(void);
virtual ble_error_t stop(void);
virtual ble_error_t reset(void);
/* nRF51 Functions */
void uartCallback(void);
void test(void);
private:
Serial uart;
Serial uart;
/* nRF51 Functions */
void uartCallback(void);
};
#endif

View file

@ -1,8 +1,8 @@
#include "mbed.h"
#include "uuid.h"
#include "bleservice.h"
#include "blecharacteristic.h"
#include "GattService.h"
#include "GattCharacteristic.h"
#include "hw/nrf51822.h"
DigitalOut myled ( LED1 );
@ -12,27 +12,30 @@ nRF51822 radio;
/* Battery Level Service */
/* See --> https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.battery_service.xml */
BLEService battService ( 0x180F );
BLECharacteristic battLevel ( 0x2A19, 1, 1, 0x10 | 0x02); /* Read + Notify */
GattService battService ( 0x180F );
GattCharacteristic battLevel ( 0x2A19, 1, 1, 0x10 | 0x02); /* Read + Notify */
/* Heart Rate Monitor Service */
/* See --> https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.heart_rate.xml */
BLEService hrmService ( 0x180D );
BLECharacteristic hrmRate ( 0x2A37, 2, 3, 0x10 ); /* Notify */
BLECharacteristic hrmLocation ( 0x2A39, 1, 1, 0x02 ); /* Read */
GattService hrmService ( 0x180D );
GattCharacteristic hrmRate ( 0x2A37, 2, 3, 0x10 ); /* Notify */
GattCharacteristic hrmLocation ( 0x2A39, 1, 1, 0x02 ); /* Read */
/* Health Thermometer Service */
/* See --> https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.health_thermometer.xml */
BLEService thermService ( 0x1809 );
BLECharacteristic thermTemp ( 0x2A1C, 5, 13, 0x20 ); /* Indicate */
BLECharacteristic thermType ( 0x2A1D, 1, 1, 0x02 ); /* Read */
BLECharacteristic thermInterval ( 0x2A21, 2, 2, 0x02 ); /* Read */
GattService thermService ( 0x1809 );
GattCharacteristic thermTemp ( 0x2A1C, 5, 13, 0x20 ); /* Indicate */
GattCharacteristic thermType ( 0x2A1D, 1, 1, 0x02 ); /* Read */
GattCharacteristic thermInterval ( 0x2A21, 2, 2, 0x02 ); /* Read */
/* Notify = device (server) sends data when it changes */
/* Indicate = device (server) sends data when it changes and client confirms reception */
int main()
{
radio.test();
while(1);
/* Add the battery level characteristic to the battery service */
/* Note: This will also update the characteristic's .index field */
/* so that we know where it's stored in the BLEService.characteristics */
@ -63,20 +66,20 @@ int main()
/* Set the heart rate monitor location (one time only) */
/* See --> https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.body_sensor_location.xml */
uint8_t location = 0x01; /* Chest */
radio.updateValue(hrmService.index, hrmLocation.index, (uint8_t*)&location, sizeof(location));
radio.writeCharacteristic(hrmService, hrmLocation, (uint8_t*)&location, sizeof(location));
/* Update the battery level */
/* See --> https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.battery_level.xml */
uint8_t batt = 72; /* Percentage (0..100) */
radio.updateValue(battService.index, battLevel.index, (uint8_t*)&batt, sizeof(batt));
radio.writeCharacteristic(battService, battLevel, (uint8_t*)&batt, sizeof(batt));
/* Update the fixed health thermometer characteristics */
/* See --> https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_type.xml */
uint8_t thermLocation = 6; /* Location = mouth */
radio.updateValue(thermService.index, thermType.index, (uint8_t*)&thermLocation, sizeof(thermLocation));
radio.writeCharacteristic(thermService, thermType, (uint8_t*)&thermLocation, sizeof(thermLocation));
/* See --> https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.measurement_interval.xml */
uint16_t thermDelay = 5;
radio.updateValue(thermService.index, thermInterval.index, (uint8_t*)&thermDelay, sizeof(thermDelay));
radio.writeCharacteristic(thermService, thermInterval, (uint8_t*)&thermDelay, sizeof(thermDelay));
/* Blinky + value updates */
uint8_t hrmCounter = 100;
@ -94,7 +97,7 @@ int main()
hrmCounter++;
if (hrmCounter == 175) hrmCounter = 100;
uint8_t bpm[2] = { 0x00, hrmCounter };
radio.updateValue(hrmService.index, hrmRate.index, bpm, 2);
radio.writeCharacteristic(hrmService, hrmRate, bpm, 2);
/* Update the Health Thermometer measurement */
@ -109,6 +112,6 @@ int main()
uint8_t temperature[5] = { 0x00, 0x00, 0x00, 0x00, 0xFF };
// Use the hrm counter to provide a shifting temperature value (175 = 17.5C, etc.)
memcpy (temperature+1, &hrmCounter, 1);
radio.updateValue(thermService.index, thermTemp.index, temperature, 5);
radio.writeCharacteristic(thermService, thermTemp, temperature, 5);
}
}

View file

@ -1 +1 @@
http://mbed.org/users/bogdanm/code/mbed-src-flowcontrol/#d8b836b18f9c
http://mbed.org/users/bogdanm/code/mbed-src-flowcontrol/#5b5370bf691e