Skip to content

Instantly share code, notes, and snippets.

@zdennis
Last active January 3, 2017 17:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdennis/9822900 to your computer and use it in GitHub Desktop.
Save zdennis/9822900 to your computer and use it in GitHub Desktop.
Bluetooth Low Energy C macros for use with the Texas Instruments BTLE Stack 1.4.x.
#ifndef BLE_MACROS
#define BLE_MACROS
#include "att.h"
#include "gatt_uuid.h"
#define BLE_PRIMARY_SERVICE(permissions, valuePtr) \
{ \
{ ATT_BT_UUID_SIZE, primaryServiceUUID }, \
permissions, \
0, \
valuePtr \
}
#define BLE_START_CHARACTERISTIC(description, permissions, valuePtr) \
/* description is unused intentionally, it's for code-readability at the call-site */ \
{ { ATT_BT_UUID_SIZE, characterUUID }, \
permissions, \
0, \
valuePtr \
}
#define BLE_CHARACTERISTIC_VALUE(permissions, uuid, valuePtr) \
{ \
{ ATT_UUID_SIZE, uuid }, \
permissions, \
0, \
valuePtr \
}
#define BLE_CHARACTERISTIC_CLIENT_CONFIG(permissions, valuePtr) \
{ \
{ ATT_BT_UUID_SIZE, clientCharCfgUUID }, \
permissions, \
0, \
valuePtr \
}
#define BLE_CHARACTERISTIC_USER_DESCRIPTION(permissions, valuePtr) \
{ \
{ ATT_BT_UUID_SIZE, charUserDescUUID }, \
permissions, \
0, \
valuePtr \
}
#endif /* BLE_MACROS */
static gattAttribute_t attrTbl[] =
{
/* START OF SERVICE */
{
{ ATT_BT_UUID_SIZE, primaryServiceUUID },
GATT_PERMIT_READ,
0,
(uint8 *)&service
},
/* ADVERTISTING INTERVAL CHARACTERISTIC DECLARATION */
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&charProps
},
/* ADVERTISTING INTERVAL CHARACTERISTIC DESCRIPTOR */
{
{ ATT_UUID_SIZE, advIntervalUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
&config.advIntervalValue
},
{
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
GATT_PERMIT_READ,
0,
(uint8 *)advIntervalConfig
},
{ \
{ ATT_BT_UUID_SIZE, charUserDescUUID }, \
GATT_PERMIT_READ,
0,
advIntervalDescription
},
/* ADVERTISTING INTERVAL CHARACTERISTIC DECLARATION */
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&charProps
},
{
{ ATT_UUID_SIZE, txPowerUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
&config.txPowerValue
},
{
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
GATT_PERMIT_READ,
0,
(uint8 *)txPowerConfig
},
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
txPowerDescription
}
};
static gattAttribute_t attrTbl[] =
{
BLE_PRIMARY_SERVICE(GATT_PERMIT_READ, (uint8 *)&service),
BLE_START_CHARACTERISTIC("Adv. Interval", GATT_PERMIT_READ, &charProps),
BLE_CHARACTERISTIC_VALUE(GATT_PERMIT_READ | GATT_PERMIT_WRITE, advIntervalUUID, &config.adv),
BLE_CHARACTERISTIC_CLIENT_CONFIG(GATT_PERMIT_READ, (uint8 *)advIntervalConfig),
BLE_CHARACTERISTIC_USER_DESCRIPTION(GATT_PERMIT_READ, advIntervalDescription),
BLE_START_CHARACTERISTIC("TxPower", GATT_PERMIT_READ, &charProps),
BLE_CHARACTERISTIC_VALUE(GATT_PERMIT_READ | GATT_PERMIT_WRITE, txPowerUUID, &config.adv),
BLE_CHARACTERISTIC_CLIENT_CONFIG(GATT_PERMIT_READ, (uint8 *)txPowerConfig),
BLE_CHARACTERISTIC_USER_DESCRIPTION(GATT_PERMIT_READ, txPowerDescription)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment