Microchip® Advanced Software Framework

thirdparty/wireless/ble_sdk/ble_services/battery/battery.c File Reference

Battery service.

Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.

#include "battery.h"

Functions

at_ble_status_t bat_char_changed_event (bat_gatt_service_handler_t *battery_service, at_ble_characteristic_changed_t *characteristic_changed_param)
 function to check the client characteristic configuration value. More...
 
void bat_init_service (bat_gatt_service_handler_t *battery_serv, uint8_t *battery_value)
 Initialize the service with its included service, characteristics, and descriptors. More...
 
at_ble_status_t bat_primary_service_define (bat_gatt_service_handler_t *battery_service)
 defining a initialized service More...
 
at_ble_status_t bat_update_char_value (at_ble_handle_t conn_handle, bat_gatt_service_handler_t *battery_serv, uint8_t char_data, bool notify)
 Function used to update characteristic value. More...
 

Variables

uint8_t battery_init_value = 10
 Initial value of the battery level characteristic value. More...
 
at_ble_char_presentation_t presentation_format
 Presentation format of the battery level. More...
 

at_ble_status_t bat_char_changed_event ( bat_gatt_service_handler_t battery_service,
at_ble_characteristic_changed_t characteristic_changed_param 
)

function to check the client characteristic configuration value.

Parameters
[in]battery_servicebattery service instance
[in]characteristic_changed_paramcharacteristic changed at_ble_characteristic_changed_t
Returns
AT_BLE_SUCCESS when matches with BAS CCCD
AT_BLE_FAILURE when doesn't matches with BAS CCCD

References AT_BLE_FAILURE, AT_BLE_PRF_NTF_DISABLED, AT_BLE_SUCCESS, at_ble_characteristic_changed_t::char_handle, at_ble_characteristic_changed_t::char_new_value, at_ble_characteristic_t::client_config_handle, bat_gatt_service_handler::serv_chars, and status.

Referenced by ble_char_changed_app_event().

void bat_init_service ( bat_gatt_service_handler_t battery_serv,
uint8_t *  battery_value 
)

Initialize the service with its included service, characteristics, and descriptors.

Battery service and characteristic initialization(Called only once by user).

References ALL_UNUSED, AT_BLE_ATTR_NO_PERMISSIONS, AT_BLE_ATTR_READABLE_NO_AUTHN_NO_AUTHR, AT_BLE_ATTR_READABLE_REQ_AUTHN_NO_AUTHR, AT_BLE_ATTR_WRITABLE_NO_AUTHN_NO_AUTHR, AT_BLE_ATTR_WRITABLE_REQ_AUTHN_NO_AUTHR, AT_BLE_CHAR_NOTIFY, AT_BLE_CHAR_READ, AT_BLE_PRES_FORMAT_UINT8, AT_BLE_UUID_16, BAT_CHAR_BAT_LEVEL_UUID, BAT_CHAR_PRESENTATION_FORMAT_DESCRIPTOR, BAT_CHAR_PRESENTATION_FORMAT_EXPONENT, BAT_CHAR_PRESENTATION_FORMAT_NAMESPACE, BAT_CHAR_PRESENTATION_FORMAT_UNIT, BAT_SERVICE_UUID, at_ble_characteristic_t::char_val_handle, at_ble_characteristic_t::client_config_handle, at_ble_characteristic_t::client_config_permissions, at_ble_char_presentation_t::description, at_ble_char_presentation_t::exponent, at_ble_char_presentation_t::format, at_ble_characteristic_t::init_value, at_ble_char_presentation_t::name_space, NULL, presentation_format, at_ble_characteristic_t::presentation_format, at_ble_characteristic_t::properties, bat_gatt_service_handler::serv_chars, bat_gatt_service_handler::serv_handle, bat_gatt_service_handler::serv_uuid, at_ble_characteristic_t::server_config_handle, at_ble_characteristic_t::server_config_permissions, at_ble_uuid_t::type, at_ble_char_presentation_t::unit, at_ble_characteristic_t::user_desc, at_ble_characteristic_t::user_desc_handle, at_ble_characteristic_t::user_desc_len, at_ble_characteristic_t::user_desc_max_len, at_ble_characteristic_t::user_desc_permissions, at_ble_uuid_t::uuid, at_ble_characteristic_t::uuid, at_ble_characteristic_t::value_init_len, at_ble_characteristic_t::value_max_len, and at_ble_characteristic_t::value_permissions.

at_ble_status_t bat_primary_service_define ( bat_gatt_service_handler_t battery_service)

defining a initialized service

Register a battery service instance inside stack.

References at_ble_primary_service_define(), NULL, bat_gatt_service_handler::serv_chars, bat_gatt_service_handler::serv_handle, and bat_gatt_service_handler::serv_uuid.

at_ble_status_t bat_update_char_value ( at_ble_handle_t  conn_handle,
bat_gatt_service_handler_t battery_serv,
uint8_t  char_data,
bool  notify 
)

Function used to update characteristic value.

Update the battery characteristic value after defining the services using bat_primary_service_define.

References at_ble_characteristic_value_set(), at_ble_notification_send(), AT_BLE_SUCCESS, at_ble_characteristic_t::char_val_handle, DBG_LOG, DBG_LOG_DEV, bat_gatt_service_handler::serv_chars, and status.

uint8_t battery_init_value = 10

Initial value of the battery level characteristic value.

at_ble_char_presentation_t presentation_format

Presentation format of the battery level.