ANCS done first draft, Central and Peripheral titles set

This commit is contained in:
Matthias Ringwald 2015-06-03 20:02:40 +02:00
parent 1af481c201
commit 35697e8afc
3 changed files with 64 additions and 24 deletions

View File

@ -6,6 +6,17 @@
#include "sm.h"
#include <SPI.h>
/*
* EXAMPLE_START(ANCS): ANCS Client
*/
/*
* @section Advertisement
* @text An ANCS Client needs to include the ANCS UUID in its advertisement to
* get recognized by iOS
*/
/* LISTING_START(ANCSAdvertisement): ANCS Advertisement */
const uint8_t adv_data[] = {
// Flags general discoverable
0x02, 0x01, 0x02,
@ -14,7 +25,51 @@ const uint8_t adv_data[] = {
// Service Solicitation, 128-bit UUIDs - ANCS (little endian)
0x11,0x15,0xD0,0x00,0x2D,0x12,0x1E,0x4B,0x0F,0xA4,0x99,0x4E,0xCE,0xB5,0x31,0xF4,0x05,0x79
};
/* LISTING_END(ANCSAdvertisement): ANCS Advertisement */
/*
* @section Setup
*
* @text In the setup, the LE Security Manager is configured to accept pairing requests.
* Then, the ANCS Client library is initialized and and ancs_callback registered.
* Finally, the Advertisement data is set and Advertisements are started.
*/
/* LISTING_START(ANCSSetup): ANCS Setup */
void setup(void){
Serial.begin(9600);
Serial.println("BTstack ANCS Client starting up...");
// startup BTstack and configure log_info/log_error
BTstack.setup();
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
sm_set_authentication_requirements( SM_AUTHREQ_BONDING );
// setup ANCS Client
ancs_client_init();
ancs_client_register_callback(&ancs_callback);
// enable advertisements
BTstack.setAdvData(sizeof(adv_data), adv_data);
BTstack.startAdvertising();
}
/* LISTING_END(ANCSSetup): ANCS Setup */
void loop(void){
BTstack.loop();
}
/*
* @section ANCS Callback
* @text In the ANCS Callback, connect and disconnect events are received.
* For actual notifications, ancs_client_attribute_name_for_id allows to
* look up the name. To get the notification body, e.g., the actual message,
* the GATT Client needs to be used direclty.
*/
/* LISTING_START(ANCSCallback): ANCS Callback */
void ancs_callback(ancs_event_t * event){
const char * attribute_name;
switch (event->type){
@ -36,27 +91,5 @@ void ancs_callback(ancs_event_t * event){
break;
}
}
/* LISTING_END(ANCSCallback): ANCS Callback */
void setup(void){
Serial.begin(9600);
Serial.println("BTstack ANCS Client starting up...");
// startup BTstack and configure log_info/log_error
BTstack.setup();
sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
sm_set_authentication_requirements( SM_AUTHREQ_BONDING );
// setup ANCS Client
ancs_client_init();
ancs_client_register_callback(&ancs_callback);
// enable advertisements
BTstack.setAdvData(sizeof(adv_data), adv_data);
BTstack.startAdvertising();
}
void loop(void){
BTstack.loop();
}

View File

@ -2,7 +2,10 @@
#include <BTstack.h>
#include <SPI.h>
//
/*
* EXAMPLE_START(LECentral): LE Central
*/
typedef struct characteristic_summary {
UUID uuid;
const char * name;

View File

@ -2,6 +2,10 @@
#include <BTstack.h>
#include <SPI.h>
/*
* EXAMPLE_START(LEPeripheral): LE Peripheral
*/
static char characteristic_data = 'H';
void setup(void){