6.
Appendix A: Software Solution - Pre-Defined Svc
The following is the code implementation for handling of pre-defined service done in
.
/*- Includes ---------------------------------------------------------------*/
#include <asf.h>
#include "platform.h"
#include "at_ble_api.h"
#include "profiles.h"
#include "console_serial.h"
#include "timer_hw.h"
#include "conf_extint.h"
#include "ble_manager.h"
#include "ble_utils.h"
#include "conf_serialdrv.h"
#include "startup_template.h"
#include "device_info.h"
volatile at_ble_status_t ble_status;
volatile bool timer_flag = false;
volatile bool connected_flag = false;
/* Services handlers */
dis_gatt_service_handler_t dis_service_handler;
static uint8_t adv_data[] = {
0x08, // AD2 Length = 8 (A AD)
0x09, // AD2 Type = Complete local Name
'M','y','_','S','E','N','S' // AD2 = “My_SENS”
};
void start_advertisement (void){
printf("\n*** Assignment 2.1: Start Advertisement");
/*Set advertisement data*/
ble_status = at_ble_adv_data_set(adv_data,sizeof(adv_data), NULL, 0);
/*Start Advertisement*/
ble_status = at_ble_adv_start(AT_BLE_ADV_TYPE_UNDIRECTED,\
AT_BLE_ADV_GEN_DISCOVERABLE,NULL,AT_BLE_ADV_FP_ANY,1600,655,0);
if(ble_status != AT_BLE_SUCCESS)
printf("\n*** Failed to start advertisement");
}
/* Callback registered for AT_BLE_CONNECTED event*/
static at_ble_status_t ble_connected_cb (void *param)
{
printf("\n*** Assignment 2.2: Application connected ");
connected_flag = true;
ALL_UNUSED(param);
return AT_BLE_SUCCESS;
}
/* Callback registered for AT_BLE_DISCONNECTED event */
static at_ble_status_t ble_disconnected_cb (void *param)
{
printf("\n*** Assignment 2.2: Application disconnected ");
connected_flag = false;
start_advertisement();
ALL_UNUSED(param);return AT_BLE_SUCCESS;
}
static const ble_gap_event_cb_t app_gap_handle = {
.connected = ble_connected_cb, // AT_BLE_CONNECTED
.disconnected = ble_disconnected_cb, // AT_BLE_DISCONNECTED
};
/* Register GAP callbacks at BLE manager level*/
void register_btlc1000_callbacks(void){
/* Register GAP Callbacks */
printf("\n*** Assignment 2.2: Register ATBTLC1000 callbacks");
ATBTLC1000
Appendix A: Software Solution - Pre-Defined Svc
©
2017 Microchip Technology Inc.
Training Manual
DS00002599A-page 47