else
printf("\n*** Assignment 4.1: Initialize custom environment service");
}
4.
Declare and implement the following GATT event callback function
custom_char_changed_app_event
in
startup_template.c
file. If a client (central) enables
notifications for a server, the server (peripheral) receives an
AT_BLE_CHARACTERISTIC_CHANGED
event and this event callback is called.
/* Callback registered for char changed event*/
static at_ble_status_t custom_char_changed_app_event (void *param)
{
at_ble_characteristic_changed_t *char_changed_param_handle =
(at_ble_characteristic_changed_t *)param;
if((environment_service_characs[0].client_config_handle == char_changed_param_handle-
>char_handle) && (char_changed_param_handle->char_new_value[0]))
{
printf("\n*** Assignment 4.1:Characteristic changed event");
}
return AT_BLE_SUCCESS;
}
5.
Declare and implement the following
custom_notification_confirmation_handler
function in
startup_template.c
file.
/* Callback registered for notification confirmed event*/
static at_ble_status_t custom_notification_confirmation_handler (void *param)
{
at_ble_cmd_complete_event_t *event_param = (at_ble_cmd_complete_event_t *)param;
if (event_param->status == AT_BLE_SUCCESS){
printf
("\n*** Assignment 4.1:Notification Successfully sent over the air");
} else {
printf("\n*** Assignment 4.1:Sending Notification over the air failed");
}
return AT_BLE_SUCCESS;
}
6.
Declare the following GATT server callback structure in
startup_template.c
file. This
assignment uses two GATT callbacks.
static const ble_gatt_server_event_cb_t app_gatt_server_handle = {
.notification_confirmed= custom_notification_confirmation_handler,
.characteristic_changed = custom_char_changed_app_event,
};
7.
Add the following
register_gatt_server_callbacks
function in
startup_template.c
to
register GATT server callback for notification confirmation event.
/* Register GATT callbacks at BLE manager level*/
void register_gatt_server_callbacks(void){
/* Register GAP Callbacks */
printf("\n*** Assignment 4.1: Register GATT Server callbacks");
ble_status = ble_mgr_events_callback_handler(REGISTER_CALL_BACK,\
BLE_GATT_SERVER_EVENT_TYPE,&app_gatt_server_handle);
if (ble_status != true)
printf("\n##Error when Registering ATBTLC1000 callbacks");
}
8.
Add
custom_environment_service_init
and
register_gatt_server_callbacks
function calls prior to start advertisement in the application main routine to initialize custom service
and to register the GATT server callbacks.
int main(void)
{
#if SAMG55 || SAM4S
/* Initialize the SAM system. */
sysclk_init();
board_init();
#elif SAM0
system_init();
ATBTLC1000
Setting up and Handling Custom Service
©
2017 Microchip Technology Inc.
Training Manual
DS00002599A-page 40