mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-25 16:43:28 +00:00
ancs_client: drop ancs_client_event_t
This commit is contained in:
parent
36f83f4111
commit
a481587475
@ -55,6 +55,7 @@
|
|||||||
#include "btstack_run_loop.h"
|
#include "btstack_run_loop.h"
|
||||||
|
|
||||||
#include "btstack_debug.h"
|
#include "btstack_debug.h"
|
||||||
|
#include "btstack_event.h"
|
||||||
#include "btstack_memory.h"
|
#include "btstack_memory.h"
|
||||||
#include "gap.h"
|
#include "gap.h"
|
||||||
#include "hci.h"
|
#include "hci.h"
|
||||||
@ -95,9 +96,9 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ancs_callback(ancs_event_t * event){
|
static void ancs_callback(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
const char * attribute_name;
|
const char * attribute_name;
|
||||||
switch (event->type){
|
switch (packet[0]){
|
||||||
case ANCS_CLIENT_CONNECTED:
|
case ANCS_CLIENT_CONNECTED:
|
||||||
printf("ANCS Client: Connected\n");
|
printf("ANCS Client: Connected\n");
|
||||||
break;
|
break;
|
||||||
@ -105,9 +106,9 @@ static void ancs_callback(ancs_event_t * event){
|
|||||||
printf("ANCS Client: Disconnected\n");
|
printf("ANCS Client: Disconnected\n");
|
||||||
break;
|
break;
|
||||||
case ANCS_CLIENT_NOTIFICATION:
|
case ANCS_CLIENT_NOTIFICATION:
|
||||||
attribute_name = ancs_client_attribute_name_for_id(event->attribute_id);
|
attribute_name = ancs_client_attribute_name_for_id(ancs_client_notification_event_get_attribute_id(packet));
|
||||||
if (!attribute_name) break;
|
if (!attribute_name) break;
|
||||||
printf("Notification: %s - %s\n", attribute_name, event->text);
|
printf("Notification: %s - %s\n", attribute_name, ancs_client_notification_event_get_text(packet));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "ble/att_server.h"
|
#include "ble/att_server.h"
|
||||||
#include "ble/gatt_client.h"
|
#include "ble/gatt_client.h"
|
||||||
#include "ancs_client.h"
|
#include "ancs_client.h"
|
||||||
|
#include "btstack_event.h"
|
||||||
#include "ble/sm.h"
|
#include "ble/sm.h"
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
|
||||||
@ -69,10 +70,11 @@ void loop(void){
|
|||||||
* the GATT Client needs to be used direclty.
|
* the GATT Client needs to be used direclty.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* LISTING_START(ANCSCallback): ANCS Callback */
|
/* LISTING_START(ANCSCallback): ANCS Callback */
|
||||||
void ancs_callback(ancs_event_t * event){
|
void ancs_callback(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
const char * attribute_name;
|
const char * attribute_name;
|
||||||
switch (event->type){
|
switch (packet[0]){
|
||||||
case ANCS_CLIENT_CONNECTED:
|
case ANCS_CLIENT_CONNECTED:
|
||||||
Serial.println("ANCS Client: Connected");
|
Serial.println("ANCS Client: Connected");
|
||||||
break;
|
break;
|
||||||
@ -80,12 +82,12 @@ void ancs_callback(ancs_event_t * event){
|
|||||||
Serial.println("ANCS Client: Disconnected");
|
Serial.println("ANCS Client: Disconnected");
|
||||||
break;
|
break;
|
||||||
case ANCS_CLIENT_NOTIFICATION:
|
case ANCS_CLIENT_NOTIFICATION:
|
||||||
attribute_name = ancs_client_attribute_name_for_id(event->attribute_id);
|
attribute_name = ancs_client_attribute_name_for_id(ancs_client_notification_event_get_attribute_id(packet));
|
||||||
if (!attribute_name) break;
|
if (!attribute_name) break;
|
||||||
Serial.print("Notification: ");
|
Serial.print("Notification: ");
|
||||||
Serial.print(attribute_name);
|
Serial.print(attribute_name);
|
||||||
Serial.print(" - ");
|
Serial.print(" - ");
|
||||||
Serial.println(event->text);
|
Serial.println(ancs_client_notification_event_get_text(packet));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -102,20 +102,32 @@ 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)(ancs_event_t * event);
|
static void (*client_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
|
|
||||||
void ancs_client_register_callback(void (*handler)(ancs_event_t * event)){
|
void ancs_client_register_callback(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
|
||||||
client_handler = handler;
|
client_handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void notify_client(int event_type){
|
static void notify_client_text(int event_type){
|
||||||
if (!client_handler) return;
|
if (!client_handler) return;
|
||||||
ancs_event_t event;
|
uint8_t event[6 + sizeof(ancs_notification_buffer) + 1];
|
||||||
event.type = event_type;
|
event[0] = event_type;
|
||||||
event.handle = gc_handle;
|
event[1] = 6 + ancs_attribute_len;
|
||||||
event.attribute_id = ancs_attribute_id;
|
bt_store_16(event, 2, gc_handle);
|
||||||
event.text = ancs_notification_buffer;
|
bt_store_16(event, 4, ancs_attribute_id);
|
||||||
(*client_handler)(&event);
|
memcpy(&event[6], ancs_notification_buffer, ancs_attribute_len);
|
||||||
|
// we're nice
|
||||||
|
event[6+ancs_attribute_len] = 0;
|
||||||
|
(*client_handler)(HCI_EVENT_PACKET, event, event[1] + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void notify_client_simple(int event_type){
|
||||||
|
if (!client_handler) return;
|
||||||
|
uint8_t event[4];
|
||||||
|
event[0] = event_type;
|
||||||
|
event[1] = 2;
|
||||||
|
bt_store_16(event, 2, gc_handle);
|
||||||
|
(*client_handler)(HCI_EVENT_PACKET, event, sizeof(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ancs_chunk_parser_init(void){
|
static void ancs_chunk_parser_init(void){
|
||||||
@ -152,7 +164,7 @@ static void ancs_chunk_parser_handle_byte(uint8_t data){
|
|||||||
break;
|
break;
|
||||||
case W4_ATTRIBUTE_COMPLETE:
|
case W4_ATTRIBUTE_COMPLETE:
|
||||||
ancs_notification_buffer[ancs_bytes_received] = 0;
|
ancs_notification_buffer[ancs_bytes_received] = 0;
|
||||||
notify_client(ANCS_CLIENT_NOTIFICATION);
|
notify_client_text(ANCS_CLIENT_NOTIFICATION);
|
||||||
ancs_bytes_received = 0;
|
ancs_bytes_received = 0;
|
||||||
ancs_bytes_needed = 1;
|
ancs_bytes_needed = 1;
|
||||||
chunk_parser_state = W4_ATTRIBUTE_ID;
|
chunk_parser_state = W4_ATTRIBUTE_ID;
|
||||||
@ -217,7 +229,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint1
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||||
notify_client(ANCS_CLIENT_DISCONNECTED);
|
notify_client_simple(ANCS_CLIENT_DISCONNECTED);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -301,7 +313,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint1
|
|||||||
case GATT_QUERY_COMPLETE:
|
case GATT_QUERY_COMPLETE:
|
||||||
printf("ANCS Data Source subscribed\n");
|
printf("ANCS Data Source subscribed\n");
|
||||||
tc_state = TC_SUBSCRIBED;
|
tc_state = TC_SUBSCRIBED;
|
||||||
notify_client(ANCS_CLIENT_CONNECTED);
|
notify_client_simple(ANCS_CLIENT_CONNECTED);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -46,15 +46,8 @@ extern "C" {
|
|||||||
|
|
||||||
/* API_START */
|
/* API_START */
|
||||||
|
|
||||||
typedef struct ancs_event{
|
|
||||||
uint8_t type;
|
|
||||||
uint16_t handle;
|
|
||||||
uint16_t attribute_id;
|
|
||||||
const char * text;
|
|
||||||
} ancs_event_t;
|
|
||||||
|
|
||||||
void ancs_client_init(void);
|
void ancs_client_init(void);
|
||||||
void ancs_client_register_callback(void (*handler)(ancs_event_t * event));
|
void ancs_client_register_callback(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
|
||||||
const char * ancs_client_attribute_name_for_id(int id);
|
const char * ancs_client_attribute_name_for_id(int id);
|
||||||
|
|
||||||
/* API_END */
|
/* API_END */
|
||||||
|
@ -708,8 +708,25 @@
|
|||||||
#define HFP_SUBEVENT_MICROPHONE_VOLUME 0x17
|
#define HFP_SUBEVENT_MICROPHONE_VOLUME 0x17
|
||||||
|
|
||||||
// ANCS Client
|
// ANCS Client
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @format H
|
||||||
|
* @param handle
|
||||||
|
*/
|
||||||
#define ANCS_CLIENT_CONNECTED 0xF0
|
#define ANCS_CLIENT_CONNECTED 0xF0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @format H2T
|
||||||
|
* @param handle
|
||||||
|
* @param attribute_id
|
||||||
|
* @param text
|
||||||
|
*/
|
||||||
#define ANCS_CLIENT_NOTIFICATION 0xF1
|
#define ANCS_CLIENT_NOTIFICATION 0xF1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @format H
|
||||||
|
* @param handle
|
||||||
|
*/
|
||||||
#define ANCS_CLIENT_DISCONNECTED 0xF2
|
#define ANCS_CLIENT_DISCONNECTED 0xF2
|
||||||
|
|
||||||
// #define HCI_EVENT_HFP_META 0xxx
|
// #define HCI_EVENT_HFP_META 0xxx
|
||||||
|
@ -167,6 +167,56 @@ static inline uint32_t sdp_query_service_record_handle_event_get_record_handle(c
|
|||||||
return READ_BT_32(event, 6);
|
return READ_BT_32(event, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get field handle from event ancs_client_connected_event
|
||||||
|
* @param Event packet
|
||||||
|
* @return handle
|
||||||
|
* @note: btstack_type H
|
||||||
|
*/
|
||||||
|
static inline hci_con_handle_t ancs_client_connected_event_get_handle(const uint8_t * event){
|
||||||
|
return READ_BT_16(event, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get field handle from event ancs_client_notification_event
|
||||||
|
* @param Event packet
|
||||||
|
* @return handle
|
||||||
|
* @note: btstack_type H
|
||||||
|
*/
|
||||||
|
static inline hci_con_handle_t ancs_client_notification_event_get_handle(const uint8_t * event){
|
||||||
|
return READ_BT_16(event, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get field attribute_id from event ancs_client_notification_event
|
||||||
|
* @param Event packet
|
||||||
|
* @return attribute_id
|
||||||
|
* @note: btstack_type 2
|
||||||
|
*/
|
||||||
|
static inline uint16_t ancs_client_notification_event_get_attribute_id(const uint8_t * event){
|
||||||
|
return READ_BT_16(event, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get field text from event ancs_client_notification_event
|
||||||
|
* @param Event packet
|
||||||
|
* @return text
|
||||||
|
* @note: btstack_type T
|
||||||
|
*/
|
||||||
|
static inline const char * ancs_client_notification_event_get_text(const uint8_t * event){
|
||||||
|
return (const char *) &event[6];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get field handle from event ancs_client_disconnected_event
|
||||||
|
* @param Event packet
|
||||||
|
* @return handle
|
||||||
|
* @note: btstack_type H
|
||||||
|
*/
|
||||||
|
static inline hci_con_handle_t ancs_client_disconnected_event_get_handle(const uint8_t * event){
|
||||||
|
return READ_BT_16(event, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* API_END */
|
/* API_END */
|
||||||
|
|
||||||
|
@ -207,7 +207,10 @@ def create_events(events):
|
|||||||
'SDP_QUERY_COMPLETE',
|
'SDP_QUERY_COMPLETE',
|
||||||
'SDP_QUERY_RFCOMM_SERVICE',
|
'SDP_QUERY_RFCOMM_SERVICE',
|
||||||
'SDP_QUERY_ATTRIBUTE_BYTE',
|
'SDP_QUERY_ATTRIBUTE_BYTE',
|
||||||
'SDP_QUERY_SERVICE_RECORD_HANDLE']:
|
'SDP_QUERY_SERVICE_RECORD_HANDLE',
|
||||||
|
'ANCS_CLIENT_CONNECTED',
|
||||||
|
'ANCS_CLIENT_NOTIFICATION',
|
||||||
|
'ANCS_CLIENT_DISCONNECTED']:
|
||||||
continue
|
continue
|
||||||
event_name = format_function_name(event_name)
|
event_name = format_function_name(event_name)
|
||||||
length_name = ''
|
length_name = ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user