From 206531d881a31e67469eaa79c00d057841eddbbe Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 1 Apr 2016 15:24:22 +0200 Subject: [PATCH] use getters in hsp examples --- example/hsp_ag_demo.c | 39 ++++++++++++++++++++------------------- example/hsp_hs_demo.c | 32 ++++++++++++++++---------------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/example/hsp_ag_demo.c b/example/hsp_ag_demo.c index 024e72aee..f20b10ea8 100644 --- a/example/hsp_ag_demo.c +++ b/example/hsp_ag_demo.c @@ -241,47 +241,48 @@ static void packet_handler(uint8_t * event, uint16_t event_size){ case HCI_EVENT_HSP_META: switch (event[2]) { case HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE: - if (event[3] == 0){ - printf("RFCOMM connection established.\n"); + if (hsp_subevent_rfcomm_connection_complete_get_status(event)){ + printf("RFCOMM connection establishement failed with status %u\n", hsp_subevent_audio_connection_complete_get_handle(event)); } else { - printf("RFCOMM connection establishement failed.\n"); - } + printf("RFCOMM connection established.\n"); + } break; case HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE: - if (event[3] == 0){ - printf("RFCOMM disconnected.\n"); + if (hsp_subevent_rfcomm_disconnection_complete_get_status(event)){ + printf("RFCOMM disconnection failed with status %u.\n", hsp_subevent_rfcomm_disconnection_complete_get_status(event)); } else { - printf("RFCOMM disconnection failed.\n"); + printf("RFCOMM disconnected.\n"); } break; case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE: - if (event[3] == 0){ - sco_handle = little_endian_read_16(event, 4); + if (hsp_subevent_audio_connection_complete_get_status(event)){ + printf("Audio connection establishment failed with status %u\n", hsp_subevent_audio_connection_complete_get_status(event)); + sco_handle = 0; + } else { + sco_handle = hsp_subevent_audio_connection_complete_get_handle(event); printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); try_send_sco(); - } else { - printf("Audio connection establishment failed with status %u\n", event[3]); - sco_handle = 0; } break; case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE: - if (event[3] == 0){ + if (hsp_subevent_audio_disconnection_complete_get_status(event)){ + printf("Audio connection releasing failed with status %u\n", hsp_subevent_audio_disconnection_complete_get_status(event)); + } else { printf("Audio connection released.\n\n"); sco_handle = 0; - } else { - printf("Audio connection releasing failed with status %u\n", event[3]); } break; case HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED: - printf("Received microphone gain change %d\n", event[3]); + printf("Received microphone gain change %d\n", hsp_subevent_microphone_gain_changed_get_gain(event)); break; case HSP_SUBEVENT_SPEAKER_GAIN_CHANGED: - printf("Received speaker gain change %d\n", event[3]); + printf("Received speaker gain change %d\n", hsp_subevent_speaker_gain_changed_get_gain(event)); break; case HSP_SUBEVENT_HS_COMMAND:{ memset(hs_cmd_buffer, 0, sizeof(hs_cmd_buffer)); - int size = event[3] <= sizeof(hs_cmd_buffer)? event[3] : sizeof(hs_cmd_buffer); - memcpy(hs_cmd_buffer, &event[4], size - 1); + int cmd_length = hsp_subevent_hs_command_get_value_length(event); + int size = cmd_length <= sizeof(hs_cmd_buffer)? cmd_length : sizeof(hs_cmd_buffer); + memcpy(hs_cmd_buffer, hsp_subevent_hs_command_get_value(event), size - 1); printf("Received custom command: \"%s\". \nExit code or call hsp_ag_send_result.\n", hs_cmd_buffer); break; } diff --git a/example/hsp_hs_demo.c b/example/hsp_hs_demo.c index a9b80660d..cc4a3060e 100644 --- a/example/hsp_hs_demo.c +++ b/example/hsp_hs_demo.c @@ -238,35 +238,35 @@ static void packet_handler(uint8_t * event, uint16_t event_size){ case HCI_EVENT_HSP_META: switch (event[2]) { case HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE: - if (hsp_subevent_audio_connection_complete_get_handle(event) == 0){ - printf("RFCOMM connection established.\n"); + if (hsp_subevent_rfcomm_connection_complete_get_status(event)){ + printf("RFCOMM connection establishement failed with status %u\n", hsp_subevent_audio_connection_complete_get_handle(event)); } else { - printf("RFCOMM connection establishement failed.\n"); - } + printf("RFCOMM connection established.\n"); + } break; case HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE: - if (hsp_subevent_audio_connection_complete_get_handle(event) == 0){ - printf("RFCOMM disconnected.\n"); + if (hsp_subevent_rfcomm_disconnection_complete_get_status(event)){ + printf("RFCOMM disconnection failed with status %u.\n", hsp_subevent_rfcomm_disconnection_complete_get_status(event)); } else { - printf("RFCOMM disconnection failed.\n"); + printf("RFCOMM disconnected.\n"); } break; case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE: - if (hsp_subevent_audio_connection_complete_get_handle(event) == 0){ - sco_handle = little_endian_read_16(event, 4); - printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); - try_send_sco(); - } else { + if (hsp_subevent_audio_connection_complete_get_status(event)){ printf("Audio connection establishment failed with status %u\n", hsp_subevent_audio_connection_complete_get_status(event)); sco_handle = 0; - } + } else { + sco_handle = hsp_subevent_audio_connection_complete_get_handle(event); + printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); + try_send_sco(); + } break; case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE: - if (event[3] == 0){ + if (hsp_subevent_audio_disconnection_complete_get_status(event)){ + printf("Audio connection releasing failed with status %u\n", hsp_subevent_audio_disconnection_complete_get_status(event)); + } else { printf("Audio connection released.\n\n"); sco_handle = 0; - } else { - printf("Audio connection releasing failed with status %u\n", event[3]); } break; case HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED: