7.
Appendix B: Software Solution - Custom Service
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"
volatile at_ble_status_t ble_status;
volatile bool timer_flag = false;
volatile bool connected_flag = false;
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”
};
#define ENVIRONMENT_SERVICE_UUID 0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xa6,0x87,\
0xe5,0x11,0x36,0x39,0xc0,0xba,0x5a,0xf0
#define TEMPERATURE_CHAR_UUID 0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xa6,0x87,\
0xe5,0x11,0x36,0x39,0xd8,0xba,0x5a,0xf0
/* Services handlers */
at_ble_handle_t environment_service_handler;
at_ble_characteristic_t environment_service_characs[1];
void custom_environment_service_init(void) {
at_ble_uuid_t environment_service_uuid;
uint8_t serv_uuid[] = {ENVIRONMENT_SERVICE_UUID};
uint8_t charac0_uuid[] = {TEMPERATURE_CHAR_UUID};
/* Set service UUID */
environment_service_uuid.type = AT_BLE_UUID_128;
memcpy(environment_service_uuid.uuid ,serv_uuid,16);
/* Define temperature characteristic */
environment_service_characs[0].user_desc = (uint8_t *)"Temperature";
environment_service_characs[0].user_desc_len = 10;
environment_service_characs[0].user_desc_max_len = 10;
environment_service_characs[0].uuid.type = AT_BLE_UUID_128;
memcpy(environment_service_characs[0].uuid.uuid,charac0_uuid,16);
environment_service_characs[0].properties = AT_BLE_CHAR_READ |\
AT_BLE_CHAR_NOTIFY;
environment_service_characs[0].value_max_len = sizeof(uint8_t);
// length of temperature value
environment_service_characs[0].value_permissions =\
(AT_BLE_ATTR_READABLE_NO_AUTHN_NO_AUTHR);
/* Push service configuration in ATBTLC1000 */
if(at_ble_primary_service_define(&environment_service_uuid,\
&environment_service_handler,NULL,0,\
environment_service_characs,1)!=AT_BLE_SUCCESS)
printf("\n*** Assignment 4.1: Failed to Initialize custom environment service");
else
printf("\n*** Assignment 4.1: Initialize custom environment service");
}
/* 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");
ATBTLC1000
Appendix B: Software Solution - Custom Service
©
2017 Microchip Technology Inc.
Training Manual
DS00002599A-page 49