gatt_service: move gatt_microphone_control_mute_t to bluetooth.h

This commit is contained in:
Milanka Ringwald 2021-09-23 15:06:39 +02:00
parent 0dfa621783
commit f229ad0a0f
5 changed files with 24 additions and 21 deletions

View File

@ -55,7 +55,7 @@
static btstack_context_callback_registration_t mc_mute_callback;
static att_service_handler_t microphone_control;
static microphone_control_mute_t mc_mute_value;
static gatt_microphone_control_mute_t mc_mute_value;
static uint16_t mc_mute_value_client_configuration;
static hci_con_handle_t mc_mute_value_client_configuration_connection;
@ -85,11 +85,11 @@ static int microphone_control_service_write_callback(hci_con_handle_t con_handle
if (buffer_size != 1){
return ATT_ERROR_VALUE_NOT_ALLOWED;
}
microphone_control_mute_t mute_value = (microphone_control_mute_t)buffer[0];
gatt_microphone_control_mute_t mute_value = (gatt_microphone_control_mute_t)buffer[0];
switch (mute_value){
case MICROPHONE_CONTROL_MUTE_OFF:
case MICROPHONE_CONTROL_MUTE_ON:
if (mc_mute_value == MICROPHONE_CONTROL_MUTE_DISABLED){
case GATT_MICROPHONE_CONTROL_MUTE_OFF:
case GATT_MICROPHONE_CONTROL_MUTE_ON:
if (mc_mute_value == GATT_MICROPHONE_CONTROL_MUTE_DISABLED){
return ATT_ERROR_RESPONSE_MICROPHONE_CONTROL_MUTE_DISABLED;
}
mc_mute_value = mute_value;
@ -115,7 +115,7 @@ static void microphone_control_service_can_send_now(void * context){
att_server_notify(con_handle, mc_mute_value_handle, &value, 1);
}
void microphone_control_service_server_init(microphone_control_mute_t mute_value){
void microphone_control_service_server_init(gatt_microphone_control_mute_t mute_value){
mc_mute_value = mute_value;
// get service handle range
@ -137,7 +137,7 @@ void microphone_control_service_server_init(microphone_control_mute_t mute_value
att_server_register_service_handler(&microphone_control);
}
void microphone_control_service_server_set_mute(microphone_control_mute_t mute_value){
void microphone_control_service_server_set_mute(gatt_microphone_control_mute_t mute_value){
if (mc_mute_value == mute_value){
return;
}

View File

@ -51,12 +51,6 @@ extern "C" {
#define ATT_ERROR_RESPONSE_MICROPHONE_CONTROL_MUTE_DISABLED 0x80
typedef enum {
MICROPHONE_CONTROL_MUTE_OFF = 0x00,
MICROPHONE_CONTROL_MUTE_ON,
MICROPHONE_CONTROL_MUTE_DISABLED
} microphone_control_mute_t;
/**
* @text The Microphone Control Service enables a device to expose the mute control and state of one or more microphones.
* Only server can disable and enable mute. Currently one one client supported.
@ -70,13 +64,13 @@ typedef enum {
* @brief Init Microphone Control Service Server with ATT DB
* @param mute_value
*/
void microphone_control_service_server_init(microphone_control_mute_t mute_value);
void microphone_control_service_server_init(gatt_microphone_control_mute_t mute_value);
/**
* @brief Set mute value.
* @param mute_value
*/
void microphone_control_service_server_set_mute(microphone_control_mute_t mute_value);
void microphone_control_service_server_set_mute(gatt_microphone_control_mute_t mute_value);
/* API_END */

View File

@ -704,6 +704,12 @@ typedef struct {
uint8_t seconds; // [0,59]
} gatt_date_time_t;
typedef enum {
GATT_MICROPHONE_CONTROL_MUTE_OFF = 0x00,
GATT_MICROPHONE_CONTROL_MUTE_ON,
GATT_MICROPHONE_CONTROL_MUTE_DISABLED
} gatt_microphone_control_mute_t;
/**
* SM - LE Security Manager
*/

View File

@ -85,6 +85,7 @@
#include "ble/gatt-service/ancs_client.h"
#include "ble/gatt-service/battery_service_client.h"
#include "ble/gatt-service/battery_service_server.h"
#include "ble/gatt-service/bond_management_service_server.h"
#include "ble/gatt-service/cycling_power_service_server.h"
#include "ble/gatt-service/cycling_speed_and_cadence_service_server.h"
#include "ble/gatt-service/device_information_service_client.h"
@ -92,8 +93,10 @@
#include "ble/gatt-service/heart_rate_service_server.h"
#include "ble/gatt-service/hids_client.h"
#include "ble/gatt-service/hids_device.h"
#include "ble/gatt-service/microphone_control_service_server.h"
#include "ble/gatt-service/scan_parameters_service_client.h"
#include "ble/gatt-service/scan_parameters_service_server.h"
#include "ble/gatt-service/tx_power_service_server.h"
#ifdef ENABLE_MESH
#include "ble/gatt-service/mesh_provisioning_service_server.h"
#include "ble/gatt-service/mesh_proxy_service_server.h"

View File

@ -38,7 +38,7 @@ TEST_GROUP(MICROPHONE_CONTROL_SERVICE_SERVER){
mute_value_handle_client_configuration = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(0, 0xffff, ORG_BLUETOOTH_CHARACTERISTIC_MUTE);
// setup battery service
microphone_control_service_server_init(MICROPHONE_CONTROL_MUTE_OFF);
microphone_control_service_server_init(GATT_MICROPHONE_CONTROL_MUTE_OFF);
service = mock_att_server_get_service();
con_handle = 0x00;
@ -56,7 +56,7 @@ TEST(MICROPHONE_CONTROL_SERVICE_SERVER, set_mute_value_trigger_can_send_now){
// set battery to trigger notification
mock().expectOneCall("att_server_register_can_send_now_callback");
microphone_control_service_server_set_mute(MICROPHONE_CONTROL_MUTE_ON);
microphone_control_service_server_set_mute(GATT_MICROPHONE_CONTROL_MUTE_ON);
mock().checkExpectations();
mock().expectOneCall("att_server_notify");
mock_att_service_trigger_can_send_now();
@ -71,28 +71,28 @@ TEST(MICROPHONE_CONTROL_SERVICE_SERVER, lookup_attribute_handles){
TEST(MICROPHONE_CONTROL_SERVICE_SERVER, set_mute_value){
// mute_value_handle_client_configuration not set
mock().expectNCalls(con_handle, "att_server_register_can_send_now_callback");
microphone_control_service_server_set_mute(MICROPHONE_CONTROL_MUTE_ON);
microphone_control_service_server_set_mute(GATT_MICROPHONE_CONTROL_MUTE_ON);
mock().checkExpectations();
// mute_value_handle_client_configuration set
mock().expectOneCall("att_server_register_can_send_now_callback");
const uint8_t enable_notify[]= { 0x1, 0x0 };
mock_att_service_write_callback(con_handle, mute_value_handle_client_configuration, ATT_TRANSACTION_MODE_NONE, 0, enable_notify, sizeof(enable_notify));
microphone_control_service_server_set_mute(MICROPHONE_CONTROL_MUTE_OFF);
microphone_control_service_server_set_mute(GATT_MICROPHONE_CONTROL_MUTE_OFF);
mock().checkExpectations();
}
TEST(MICROPHONE_CONTROL_SERVICE_SERVER, set_wrong_handle_mute_value){
// mute_value_handle_client_configuration not set
mock().expectNCalls(con_handle, "att_server_register_can_send_now_callback");
microphone_control_service_server_set_mute(MICROPHONE_CONTROL_MUTE_ON);
microphone_control_service_server_set_mute(GATT_MICROPHONE_CONTROL_MUTE_ON);
mock().checkExpectations();
// // mute_value_handle_client_configuration set
mock().expectNoCall("att_server_register_can_send_now_callback");
const uint8_t enable_notify[]= { 0x1, 0x0 };
mock_att_service_write_callback(con_handle, mute_value_handle_client_configuration + 10, ATT_TRANSACTION_MODE_NONE, 0, enable_notify, sizeof(enable_notify));
microphone_control_service_server_set_mute(MICROPHONE_CONTROL_MUTE_OFF);
microphone_control_service_server_set_mute(GATT_MICROPHONE_CONTROL_MUTE_OFF);
mock().checkExpectations();
}