hsp docu, documented event types in hci_cmds.h

This commit is contained in:
Milanka Ringwald 2016-02-17 12:07:24 +01:00
parent 6c63e7d47b
commit 0ebf25ba54
8 changed files with 79 additions and 27 deletions

View File

@ -35,7 +35,7 @@ apis = [
["include/btstack/sdp_util.h","SDP Utils", "sdpUtil"]
["src/hsp_hf.h","HSP Headset","hspHF"],
["src/hsp_ag.h","HSP Audio Gateway","hspAG"],
["src/hsp_hf.h","HFP Headset","hfpHF"],
["src/hsp_hf.h","HFP Hands-Free","hfpHF"],
["src/hsp_ag.h","HFP Audio Gateway","hfpAG"]
]

View File

@ -203,8 +203,8 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
break;
case HSP_SUBEVENT_AG_INDICATION:
memset(hs_cmd_buffer, 0, sizeof(hs_cmd_buffer));
int size = event_size <= sizeof(hs_cmd_buffer)? event_size : sizeof(hs_cmd_buffer);
memcpy(hs_cmd_buffer, &event[3], size - 1);
int size = event[3] <= sizeof(hs_cmd_buffer)? event[3] : sizeof(hs_cmd_buffer);
memcpy(hs_cmd_buffer, &event[4], size - 1);
printf("Received custom indication: \"%s\". \nExit code or call hsp_hs_send_result.\n", hs_cmd_buffer);
break;
default:

View File

@ -617,14 +617,57 @@ extern "C" {
#define HCI_EVENT_HSP_META 0xE8
#define HSP_SUBEVENT_ERROR 0x01
#define HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE 0x02
#define HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE 0x03
#define HSP_SUBEVENT_RING 0x04
#define HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED 0x05
#define HSP_SUBEVENT_SPEAKER_GAIN_CHANGED 0x06
#define HSP_SUBEVENT_HS_COMMAND 0x07
#define HSP_SUBEVENT_AG_INDICATION 0x08
// data: event(8), len(8), subevent(8), status(8)
/**
* @format 11
* @param subevent_code
* @param status 0 == OK
*/
#define HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE 0x01
/**
* @format 11
* @param subevent_code
* @param status 0 == OK
*/
#define HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE 0x02
/**
* @format 1
* @param subevent_code
*/
#define HSP_SUBEVENT_RING 0x03
/**
* @format 11
* @param subevent_code
* @param gain Valid range: [0,15]
*/
#define HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED 0x04
/**
* @format 11
* @param subevent_code
* @param gain Valid range: [0,15]
*/
#define HSP_SUBEVENT_SPEAKER_GAIN_CHANGED 0x05
/**
* @format 1JV
* @param subevent_code
* @param value_length
* @param value
*/
#define HSP_SUBEVENT_HS_COMMAND 0x06
/**
* @format 1JV
* @param subevent_code
* @param value_length
* @param value
*/
#define HSP_SUBEVENT_AG_INDICATION 0x07
#define HCI_EVENT_HFP_META 0xE9

View File

@ -470,11 +470,12 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha
ag_send_error = 1;
if (!hsp_ag_callback) return;
// re-use incoming buffer to avoid reserving large buffers - ugly but efficient
uint8_t * event = packet - 3;
uint8_t * event = packet - 4;
event[0] = HCI_EVENT_HSP_META;
event[1] = size + 1;
event[1] = size + 2;
event[2] = HSP_SUBEVENT_HS_COMMAND;
(*hsp_ag_callback)(event, size+3);
event[3] = size;
(*hsp_ag_callback)(event, size+4);
}
hsp_run();

View File

@ -57,8 +57,7 @@ extern "C" {
/**
* @brief Packet handler for HSP Audio Gateway (AG) events.
*
* The HSP AG event has type HCI_EVENT_HSP_META with following subtypes:
* - HSP_SUBEVENT_ERROR
* The HSP AG event has type HCI_EVENT_HSP_META with following subtypes:
* - HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE
* - HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE
* - HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED

View File

@ -132,6 +132,15 @@ static void emit_event(uint8_t event_subtype, uint8_t value){
(*hsp_hs_callback)(event, sizeof(event));
}
static void emit_ring_event(void){
if (!hsp_hs_callback) return;
uint8_t event[3];
event[0] = HCI_EVENT_HSP_META;
event[1] = sizeof(event) - 2;
event[2] = HSP_SUBEVENT_RING;
(*hsp_hs_callback)(event, sizeof(event));
}
static void emit_event_audio_connected(uint8_t status, uint16_t handle){
if (!hsp_hs_callback) return;
uint8_t event[6];
@ -380,7 +389,7 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha
packet++;
}
if (strncmp((char *)packet, HSP_AG_RING, strlen(HSP_AG_RING)) == 0){
emit_event(HSP_SUBEVENT_RING, 0);
emit_ring_event();
} else if (strncmp((char *)packet, HSP_AG_OK, strlen(HSP_AG_OK)) == 0){
printf("OK RECEIVED\n");
switch (hsp_state){
@ -409,11 +418,12 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha
// add trailing \0
packet[size] = 0;
// re-use incoming buffer to avoid reserving large buffers - ugly but efficient
uint8_t * event = packet - 3;
uint8_t * event = packet - 4;
event[0] = HCI_EVENT_HSP_META;
event[1] = size + 1;
event[1] = size + 2;
event[2] = HSP_SUBEVENT_AG_INDICATION;
(*hsp_hs_callback)(event, size+3);
event[3] = size;
(*hsp_hs_callback)(event, size+4);
}
hsp_run();
return;

View File

@ -57,8 +57,7 @@ extern "C" {
/**
* @brief Packet handler for HSP Headset (HS) events.
*
* The HSP HS event has type HCI_EVENT_HSP_META with following subtypes:
* - HSP_SUBEVENT_ERROR
* The HSP HS event has type HCI_EVENT_HSP_META with following subtypes:
* - HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE
* - HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE
* - HSP_SUBEVENT_RING
@ -93,7 +92,7 @@ void hsp_hs_create_sdp_record(uint8_t * service, int rfcomm_channel_nr, const ch
void hsp_hs_register_packet_handler(hsp_hs_callback_t callback);
/**
* @brief Connect to HSP Audio Gateway
* @brief Connect to HSP Audio Gateway.
*
* Perform SDP query for an RFCOMM service on a remote device,
* and establish an RFCOMM connection if such service is found. The reception of the
@ -138,7 +137,7 @@ void hsp_hs_set_speaker_gain(uint8_t gain);
void hsp_hs_send_button_press(void);
/**
* @brief Enable custom indications
* @brief Enable custom indications.
*
* Custom indications are disabled by default.
* When enabled, custom indications are received via the HSP_SUBEVENT_AG_INDICATION.
@ -147,7 +146,7 @@ void hsp_hs_send_button_press(void);
void hsp_hs_enable_custom_indications(int enable);
/**
* @brief Send answer to custom indication
* @brief Send answer to custom indication.
*
* On HSP_SUBEVENT_AG_INDICATION, the client needs to respond
* with this function with the result to the custom indication

View File

@ -172,8 +172,8 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
break;
case HSP_SUBEVENT_HS_COMMAND:{
memset(hs_cmd_buffer, 0, sizeof(hs_cmd_buffer));
int size = event_size <= sizeof(hs_cmd_buffer)? event_size : sizeof(hs_cmd_buffer);
memcpy(hs_cmd_buffer, &event[3], size - 1);
int size = event[3] <= sizeof(hs_cmd_buffer)? event[3] : sizeof(hs_cmd_buffer);
memcpy(hs_cmd_buffer, &event[4], size - 1);
printf("Received custom command: \"%s\". \nExit code or call hsp_ag_send_result.\n", hs_cmd_buffer);
break;
}