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

Differentiate between different writes

I have a few characteristics under a service, and I'm trying to store the value if any of these characteristics is written to. However I run into an issue where if I enable services on the Master Control Panel, my code thinks that the value of the characteristic is being written.

How do I differentiate between a write to the actual data value of my characteristic and whatever the master control panel is doing when I enable services?

static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
{
    dm_ble_evt_handler(p_ble_evt);
    on_ble_evt(p_ble_evt);
    check_status(p_ble_evt);
}

static void check_status(ble_evt_t * p_ble_evt){	
    
    ble_gatts_evt_write_t *p_evt_write = &p_ble_evt -> evt.gatts_evt.params.write;
    
    switch (p_ble_evt -> header.evt_id)
        {
        case BLE_GATTS_EVT_WRITE:
            if (p_evt_write -> context.srvc_uuid.uuid == DEVICE_STATUS_SERVICE_UUID){
                /* If mode characteristic was written to update the status value */
                if (p_evt_write -> context.char_uuid.uuid == DEVICE_STATUS_MODE_UUID){
                    m_status.mode = p_evt_write -> data[0];
                }
                /* If datarate characteristic was written to update the status value */
                else if (p_evt_write -> context.char_uuid.uuid == DEVICE_STATUS_DATARATE_UUID){
                    m_status.datarate = p_evt_write -> data[0];
                }
                advertising_init();     /* Update advertising data with new mode and datarate */
            }
        break;
    }
}

Once I enable services, both m_status.mode and m_status.datarate are set to 0x03. If I write to both of these characteristics after enabling services the correct values are written to them. But for example if I only modify one, the other one will have 0x03 stored in it still (even though the attribute is storing 0x0).

Related