Minor cleanup (better comments, etc.)

master
ktownsend 2014-01-08 18:49:39 +00:00
parent b9cf8e2cee
commit 07e679bea3
2 changed files with 17 additions and 36 deletions

View File

@ -219,18 +219,6 @@ typedef struct PresentationFormat
uint16_t gatt_nsdesc; /**< Namespace description from Bluetooth Assigned Numbers, normally '0', see @ref BLE_GATT_CPF_NAMESPACES. */
} presentation_format_t;
struct UTF8String
{
uint16_t length; /**< String length. */
uint8_t str[32]; /**< String data. */
};
struct UTF16String
{
uint16_t length; /**< String length. */
uint16_t str[32]; /**< String data. */
};
struct SecurityMode
{
uint8_t mode; /**< Security Mode (1 or 2), 0 for no permissions at all. */

View File

@ -2,61 +2,53 @@
#include "uuid.h"
#include "hw/nrf51822.h"
DigitalOut myled ( LED1 );
/* Radio HW */
nRF51822 radio;
void startBeacon(void)
{
ble_error_t error;
GapAdvertisingParams advParams ( GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED );
GapAdvertisingData advData;
GapAdvertisingData scanResponse;
/* Define an iBeacon payload
--------------------------------------------------------------
128-Bit UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
Major/Minor = 0000 / 0000
Tx Power = C8
*/
uint8_t iBeaconPayload[25] = { 0x4C, 0x00, 0x02, 0x15, 0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61, 0x00, 0x00, 0x00, 0x00, 0xC8 };
/* iBeacon includes the FLAG and MSD fields */
error = advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
error = advData.addData(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, iBeaconPayload, 25);
advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
advData.addData(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, iBeaconPayload, sizeof(iBeaconPayload));
error = radio.reset();
error = radio.setAdvertising(advParams, advData, scanResponse);
error = radio.start();
/* Hang around here for a while */
while(1)
{
}
radio.reset();
radio.setAdvertising(advParams, advData, scanResponse);
radio.start();
}
void startBatteryService(void)
{
ble_error_t error;
GattService battService ( 0x180F );
GattCharacteristic battLevel ( 0x2A19, 1, 1, BLE_GATT_CHAR_PROPERTIES_NOTIFY | BLE_GATT_CHAR_PROPERTIES_READ);
/* Make sure we get a clean start */
error = radio.reset();
radio.reset();
/* Add the characteristic to our service */
error = battService.addCharacteristic(battLevel);
battService.addCharacteristic(battLevel);
/* Pass the service into the radio */
error = radio.addService(battService);
radio.addService(battService);
/* Configure the radio and start advertising with default values */
/* Make sure you've added all of your services before calling this function! */
error = radio.start();
radio.start();
/* Now that we're live, update the battery level characteristic */
uint8_t batt = 72;
error = radio.writeCharacteristic(battLevel.handle, (uint8_t*)&batt, sizeof(batt));
/* Hang around here for a while */
while(1)
{
}
radio.writeCharacteristic(battLevel.handle, (uint8_t*)&batt, sizeof(batt));
}
int main()
@ -64,6 +56,7 @@ int main()
/* Give the radio some time to boot up and settle */
wait(2);
/* Select one of the options below depending on the demo you want to see */
// startBeacon();
startBatteryService();