This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Getting the new updated value of a write long in the event handler

I'm getting an event when a write long is completed (the line with BLE_GATTS_OP_EXEC_WRITE_REQ_NOW):

static void on_write(ble_mlbx_t * p_mlbx, ble_evt_t * p_ble_evt)
{
  ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

  switch (p_evt_write->op)
  {
    case BLE_GATTS_OP_WRITE_REQ:
      if (p_evt_write->handle == p_mlbx->inbox_char_handles.value_handle)
      {
        if (p_mlbx->evt_handler != NULL)
        {
          memcpy(p_mlbx->inbox_entry_last.p_data, p_ble_evt->evt.gatts_evt.params.write.data, p_ble_evt->evt.gatts_evt.params.write.len);
          p_mlbx->inbox_entry_last.size = p_ble_evt->evt.gatts_evt.params.write.len;
          p_mlbx->evt_handler(p_mlbx);
        }
      }
      break;
    case BLE_GATTS_OP_EXEC_WRITE_REQ_NOW:
      if (p_mlbx->evt_handler != NULL)
      {
        memcpy(p_mlbx->inbox_entry_last.p_data, p_evt_write->data, p_evt_write->len);
        p_mlbx->inbox_entry_last.size = p_evt_write->len;
        p_mlbx->evt_handler(p_mlbx);
      }            
      break;
    default:
      break;
  }

}

The problem I'm having is that p_evt_write->data is empty and p_evt_write->len is 0. The user memory block that I passed into sd_ble_user_mem_reply contains all the written data though. Should p_evt_write->data contain the new value or is it expected that someone needs to manually parse the memory block to get the new value?

  • Hi Robert,

    If you have a look at this case you can find the reply from Ole Morten would maybe answer your question.

    You could either parse the user memory or read the actual value of the characteristic to get the written value. Please be noted that handle ID need to be looked up in the user memory block since it's not included in the p_evt_write.

  • Hi Hung,

    Thanks for your help. I did see that case and it did help. My question is really this: should the write field in the ble_gatts_evt_write_t data structure contain the new value or is it expected that an application should parse the memory block directly? If it's expected that you should parse the memory block how do you know how many bytes the new data is?

  • Hi Robert, I believe the answer from Ole Morten is clear enough. Yes, you would need to parse the user memory and you can find the format for that user memory in the link Ole gave. There is a "length" field there.

Related