ancs_client: use btstack_packet_handler_t

This commit is contained in:
Matthias Ringwald 2016-02-19 14:05:39 +01:00
parent e628322d35
commit 591e55515a
5 changed files with 12 additions and 11 deletions

View File

@ -105,7 +105,7 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
} }
} }
static void ancs_callback(uint8_t packet_type, uint8_t *packet, uint16_t size){ static void ancs_callback(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
const char * attribute_name; const char * attribute_name;
if (packet[0] != HCI_EVENT_ANCS_META) return; if (packet[0] != HCI_EVENT_ANCS_META) return;
switch (packet[2]){ switch (packet[2]){

View File

@ -106,11 +106,11 @@ public:
class BLEDevice { class BLEDevice {
private: private:
uint16_t handle; hci_con_handle_t handle;
public: public:
BLEDevice(); BLEDevice();
BLEDevice(uint16_t handle); BLEDevice(hci_con_handle_t handle);
uint16_t getHandle(); hci_con_handle_t getHandle();
// discovery of services and characteristics // discovery of services and characteristics
int discoverGATTServices(); int discoverGATTServices();

View File

@ -72,7 +72,7 @@ void loop(void){
/* LISTING_START(ANCSCallback): ANCS Callback */ /* LISTING_START(ANCSCallback): ANCS Callback */
void ancs_callback(uint8_t packet_type, uint8_t *packet, uint16_t size){ void ancs_callback(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
const char * attribute_name; const char * attribute_name;
if (packet[0] != HCI_EVENT_ANCS_META) return; if (packet[0] != HCI_EVENT_ANCS_META) return;
switch (packet[0]){ switch (packet[0]){

View File

@ -103,11 +103,11 @@ static uint16_t ancs_bytes_received;
static uint16_t ancs_bytes_needed; static uint16_t ancs_bytes_needed;
static uint8_t ancs_attribute_id; static uint8_t ancs_attribute_id;
static uint16_t ancs_attribute_len; static uint16_t ancs_attribute_len;
static void (*client_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
static btstack_packet_handler_t client_handler;
static btstack_packet_callback_registration_t hci_event_callback_registration; static btstack_packet_callback_registration_t hci_event_callback_registration;
void ancs_client_register_callback(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){ void ancs_client_register_callback(btstack_packet_handler_t handler){
client_handler = handler; client_handler = handler;
} }
@ -122,7 +122,7 @@ static void notify_client_text(int event_type){
memcpy(&event[7], ancs_notification_buffer, ancs_attribute_len); memcpy(&event[7], ancs_notification_buffer, ancs_attribute_len);
// we're nice // we're nice
event[7+ancs_attribute_len] = 0; event[7+ancs_attribute_len] = 0;
(*client_handler)(HCI_EVENT_PACKET, event, event[1] + 2); (*client_handler)(HCI_EVENT_PACKET, 0, event, event[1] + 2);
} }
static void notify_client_simple(int event_type){ static void notify_client_simple(int event_type){
@ -132,7 +132,7 @@ static void notify_client_simple(int event_type){
event[1] = 3; event[1] = 3;
event[2] = event_type; event[2] = event_type;
little_endian_store_16(event, 3, gc_handle); little_endian_store_16(event, 3, gc_handle);
(*client_handler)(HCI_EVENT_PACKET, event, sizeof(event)); (*client_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
} }
static void ancs_chunk_parser_init(void){ static void ancs_chunk_parser_init(void){

View File

@ -43,11 +43,12 @@ extern "C" {
#endif #endif
#include <stdint.h> #include <stdint.h>
#include "btstack_defines.h"
/* API_START */ /* API_START */
void ancs_client_init(void); void ancs_client_init(void);
void ancs_client_register_callback(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)); void ancs_client_register_callback(btstack_packet_handler_t callback);
const char * ancs_client_attribute_name_for_id(int id); const char * ancs_client_attribute_name_for_id(int id);
/* API_END */ /* API_END */