mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-01 09:08:06 +00:00
ublox_spp_service_server: use events instead of callback
This commit is contained in:
parent
257f2b0068
commit
694f87bfcd
@ -51,6 +51,8 @@ HCI Dump: replace monolithic `hci_dump.c` (with many #ifdefs) into dispatcher wi
|
||||
- `embedded/hci_dump_segger_stdout` - log to RTT console using `SEGGER_printf`
|
||||
- `embedded/hci_dump_segger_binary` - writes binary log over RTT to host
|
||||
|
||||
u-blox SPP Service Server: use `GATTSERVICE_SUBEVENT_SPP_SERVICE_CONNECTED` and `GATTSERVICE_SUBEVENT_SPP_SERVICE_CONNECTED`
|
||||
events instead of callback, and `RFCOMM_DATA_PACKET` for received data
|
||||
|
||||
## Release v1.3.2
|
||||
|
||||
|
@ -126,24 +126,32 @@ static void heartbeat_handler(struct btstack_timer_source *ts){
|
||||
}
|
||||
/* LISTING_END */
|
||||
|
||||
static void ublox_data(hci_con_handle_t handle, const uint8_t * data, uint16_t size){
|
||||
if (size == 0 && con_handle == HCI_CON_HANDLE_INVALID ){
|
||||
con_handle = handle;
|
||||
printf("Connected with handle 0x%04x\n", con_handle);
|
||||
} else {
|
||||
printf("RECV: ");
|
||||
printf_hexdump(data, size);
|
||||
static void ublox_spp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
switch (packet_type){
|
||||
case HCI_EVENT_PACKET:
|
||||
if (hci_event_packet_get_type(packet) != HCI_EVENT_GATTSERVICE_META) break;
|
||||
switch (hci_event_gattservice_meta_get_subevent_code(packet)){
|
||||
case GATTSERVICE_SUBEVENT_SPP_SERVICE_CONNECTED:
|
||||
con_handle = gattservice_subevent_spp_service_connected_get_con_handle(packet);
|
||||
printf("Connected with handle 0x%04x\n", con_handle);
|
||||
break;
|
||||
case GATTSERVICE_SUBEVENT_SPP_SERVICE_DISCONNECTED:
|
||||
con_handle = HCI_CON_HANDLE_INVALID;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RFCOMM_DATA_PACKET:
|
||||
printf("RECV: ");
|
||||
printf_hexdump(packet, size);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ublox_flow_control(hci_con_handle_t handle, uint16_t credits){
|
||||
if (con_handle == HCI_CON_HANDLE_INVALID ){
|
||||
con_handle = handle;
|
||||
printf("Connected with handle 0x%04x\n", handle);
|
||||
}
|
||||
printf("credits %d\n", credits);
|
||||
}
|
||||
/*
|
||||
/*
|
||||
* @section Packet Handler
|
||||
*
|
||||
* @text The packet handler is used to:
|
||||
@ -192,7 +200,7 @@ int btstack_main(void)
|
||||
// setup device information service
|
||||
device_information_service_server_init();
|
||||
// setup Nordic SPP service
|
||||
ublox_spp_service_server_init(&ublox_data, &ublox_flow_control);
|
||||
ublox_spp_service_server_init(&ublox_spp_packet_handler);
|
||||
|
||||
// setup advertisements
|
||||
uint16_t adv_int_min = 0x0030;
|
||||
|
@ -83,8 +83,7 @@ typedef struct {
|
||||
|
||||
btstack_context_callback_registration_t credits_callback;
|
||||
|
||||
void (*client_data_callback)(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size);
|
||||
void (*client_credits_callback)(hci_con_handle_t con_handle, uint16_t credits);
|
||||
btstack_packet_handler_t client_packet_handler;
|
||||
|
||||
// flow control
|
||||
btstack_context_callback_registration_t * request;
|
||||
@ -93,6 +92,17 @@ typedef struct {
|
||||
static att_service_handler_t ublox_spp_service;
|
||||
static ublox_spp_service_t ublox_spp;
|
||||
|
||||
static void ublox_spp_service_emit_state(ublox_spp_service_t * instance, bool enabled){
|
||||
uint8_t event[5];
|
||||
uint8_t pos = 0;
|
||||
event[pos++] = HCI_EVENT_GATTSERVICE_META;
|
||||
event[pos++] = sizeof(event) - 2;
|
||||
event[pos++] = enabled ? GATTSERVICE_SUBEVENT_SPP_SERVICE_CONNECTED : GATTSERVICE_SUBEVENT_SPP_SERVICE_DISCONNECTED;
|
||||
little_endian_store_16(event,pos, instance->con_handle);
|
||||
pos += 2;
|
||||
(*instance->client_packet_handler)(HCI_EVENT_PACKET, 0, event, pos);
|
||||
}
|
||||
|
||||
static int ublox_spp_service_flow_control_enabled(ublox_spp_service_t * instance){
|
||||
return instance->credits_client_configuration_descriptor_value;
|
||||
}
|
||||
@ -140,7 +150,7 @@ static int ublox_spp_service_write_callback(hci_con_handle_t con_handle, uint16_
|
||||
if (!instance) return 0;
|
||||
|
||||
if (attribute_handle == instance->fifo_value_handle){
|
||||
instance->client_data_callback(con_handle, &buffer[0], buffer_size);
|
||||
instance->client_packet_handler(RFCOMM_DATA_PACKET, (uint16_t) con_handle, &buffer[0], buffer_size);
|
||||
if (!ublox_spp_service_flow_control_enabled(instance)) return 0;
|
||||
if (!instance->incoming_credits) return 0;
|
||||
instance->incoming_credits--;
|
||||
@ -155,7 +165,7 @@ static int ublox_spp_service_write_callback(hci_con_handle_t con_handle, uint16_
|
||||
}
|
||||
instance->fifo_client_configuration_descriptor_value = little_endian_read_16(buffer, 0);
|
||||
log_info("ublox spp service FIFO control: %d", instance->fifo_client_configuration_descriptor_value);
|
||||
instance->client_data_callback(con_handle, NULL, 0);
|
||||
ublox_spp_service_emit_state(instance, instance->fifo_client_configuration_descriptor_value != 0);
|
||||
}
|
||||
|
||||
if (attribute_handle == instance->credits_value_handle){
|
||||
@ -201,16 +211,14 @@ static void ublox_spp_credits_callback(void * context){
|
||||
* @brief Init ublox SPP Service Server with ATT DB
|
||||
* @param callback for tx data from peer
|
||||
*/
|
||||
void ublox_spp_service_server_init(void (*client_data_callback)(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size),
|
||||
void (*client_credits_callback)(hci_con_handle_t con_handle, uint16_t credits)){
|
||||
void ublox_spp_service_server_init(btstack_packet_handler_t packet_handler){
|
||||
|
||||
static const uint8_t ublox_spp_profile_uuid128[] = { 0x24, 0x56, 0xE1, 0xB9, 0x26, 0xE2, 0x8F, 0x83, 0xE7, 0x44, 0xF3, 0x4F, 0x01, 0xE9, 0xD7, 0x01 };
|
||||
static const uint8_t ublox_spp_fifo_uuid128[] = { 0x24, 0x56, 0xE1, 0xB9, 0x26, 0xE2, 0x8F, 0x83, 0xE7, 0x44, 0xF3, 0x4F, 0x01, 0xE9, 0xD7, 0x03 };
|
||||
static const uint8_t ublox_spp_credits_uuid128[] = { 0x24, 0x56, 0xE1, 0xB9, 0x26, 0xE2, 0x8F, 0x83, 0xE7, 0x44, 0xF3, 0x4F, 0x01, 0xE9, 0xD7, 0x04 };
|
||||
|
||||
ublox_spp_service_t * instance = &ublox_spp;
|
||||
instance->client_data_callback = client_data_callback;
|
||||
instance->client_credits_callback = client_credits_callback;
|
||||
instance->client_packet_handler = packet_handler;
|
||||
|
||||
instance->credits_callback.callback = ublox_spp_credits_callback;
|
||||
instance->credits_callback.context = instance;
|
||||
|
@ -56,11 +56,9 @@ extern "C" {
|
||||
|
||||
/**
|
||||
* @brief Init ublox SPP Service Server with ATT DB
|
||||
* @param client_data_callback
|
||||
* @param client_flow_control_callback
|
||||
* @param packet_handler for events and tx data from peer as RFCOMM_DATA_PACKET
|
||||
*/
|
||||
void ublox_spp_service_server_init(void (*client_data_callback)(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size),
|
||||
void (*client_flow_control_callback)(hci_con_handle_t con_handle, uint16_t credits));
|
||||
void ublox_spp_service_server_init(btstack_packet_handler_t packet_handler);
|
||||
|
||||
/**
|
||||
* @brief Queue send request. When called, one packet can be send via ublox_spp_service_send below
|
||||
|
Loading…
Reference in New Issue
Block a user