Return
– Execution Status
•
Characteristics –
–
Characteristics definition is done through specific array of following
“
at_ble_characteristic_t
” structure instances:
typedef struct
{
at_ble_handle_t char_val_handle; // Handler (returned during service initialisation)
at_ble_uuid_t uuid; // Characteristic UUID (type and value)
at_ble_char_properties_t properties;//Charac. Properties (read, write, notify)
uint8_t *init_value; // initial value
uint16_t value_init_len; // initial value length
uint16_t value_max_len; // value max length
at_ble_attr_permissions_t value_permissions; // access authorization and
authentication
uint8_t *user_desc; // User description
uint16_t user_desc_len; // User description length
uint16_t user_desc_max_len; // User description max length
at_ble_char_presentation_t *presentation_format; // Presentation format
at_ble_attr_permissions_t user_desc_permissions; // User description permission
at_ble_attr_permissions_t client_config_permissions;// client permission
at_ble_attr_permissions_t server_config_permissions;// server permission
at_ble_handle_t user_desc_handle;// description handler
at_ble_handle_t client_config_handle;// Client config handler
at_ble_handle_t server_config_handle;// Server config handler
} at_ble_characteristic_t;
5.1.1
Procedure to Configure and Load Custom Environment Service
1.
Define the following service UUID and characteristic UUID in
startup_template.c
file.
#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
2.
Define the following environment service handler and characteristics variable as global in
startup_template.c
file.
/* Services handlers */
at_ble_handle_t environment_service_handler;
at_ble_characteristic_t environment_service_characs[1];
3.
Add the following service initialization function
custom_environment_service_init
in
startup_template.c
.
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");
ATBTLC1000
Setting up and Handling Custom Service
©
2017 Microchip Technology Inc.
Training Manual
DS00002599A-page 39