This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Timer implementation

Hi,

I was referring the timer example code for PCA10040. I wanted to include the timer code in my ble peripheral code which uses custom GATT service. Can you help me with this? What I was trying - Once I receive a message from the host, I start the timer. If the next message is not received within a certain timeout, then I quit.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static void cus_on_write(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt)
{
int i;
ble_gatts_evt_write_t const * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
// Custom Value Characteristic Written to.
if (p_evt_write->handle == p_cus->custom_value_handles.value_handle)
{
NRF_LOG_INFO("Data Length:::::::::::::: %d", p_evt_write->len);
if((p_evt_write->data[0] == 0x0A) && (p_evt_write->data[1] == 0x0B) && (p_evt_write->data[2] == 0x0C) && (p_evt_write->data[3] == 0x0D) && (p_evt_write->data[4] == 0x0E))
{
NRF_LOG_INFO("Received message from host");
//IF THIS MESSAGE IS NOT RECEIVED WITHIN 2 SECONDS, THEN CALL delete_bonds()
}
}
// Check if the Custom value CCCD is written to and that the value is the appropriate length, i.e 2 bytes.
if ((p_evt_write->handle == p_cus->custom_value_handles.cccd_handle) && (p_evt_write->len == 2))
{
// CCCD written, call application event handler
if (p_cus->evt_handler != NULL)
{
ble_cus_evt_t evt;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX