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

ble_nus_c possible bug

Hi

we are working on ble_nus_c multilink implementation and had problems when more than 1 server is connected: we've noticed that data get mixed between servers.

when I tried to debug, I noticed that sometimes, under on_hvx function, I get 2 calls: one is OK and on the second one p_ble_evt->evt.gap_evt.conn_handle is invalid, while p_ble_nus_c->conn_handle stays the same as the previous call.

diving a bit into the ble_nus_c.c code, I found the following lines under ble_nus_c_on_ble_evt:

    if ( (p_ble_nus_c->conn_handle != BLE_CONN_HANDLE_INVALID) 
       &&(p_ble_nus_c->conn_handle != p_ble_evt->evt.gap_evt.conn_handle)
       )
    {
        return;
    }

my question is: shouldn't it be:

    if ( (p_ble_nus_c->conn_handle == BLE_CONN_HANDLE_INVALID) 
       || (p_ble_nus_c->conn_handle != p_ble_evt->evt.gap_evt.conn_handle)
       )
    {
        return;
    }

changing to the second solved our problems...

thanks

Parents
  • Hi Lolek, 

    My understanding is the developer want to catch the event even when the connection handle is BLE_CONN_HANDLE_INVALID.

    I'm not sure why we need to do that, but could you tell when do you receive  p_ble_evt->evt.gap_evt.conn_handle = BLE_CONN_HANDLE_INVALID

    I think your code is fine, if you want to completely clear out any event with conn_handle = BLE_CONN_HANDLE_INVALID.

  • Thank you for the quick reply.

    I can't think of a reason for catching the event when p_ble_evt->evt.gap_evt.conn_handle is BLE_CONN_HANDLE_INVALID. Especially when p_ble_nus_c->conn_handle is valid. It just shoots the event handler with wrong parameters.

    I can say that when there are several connections active, every valid handle event is followed up with an invalid handle event. This definitely seems like a bug.

    Anyway, I'm happy to know I solved it correctly.

    Thanks again

Reply
  • Thank you for the quick reply.

    I can't think of a reason for catching the event when p_ble_evt->evt.gap_evt.conn_handle is BLE_CONN_HANDLE_INVALID. Especially when p_ble_nus_c->conn_handle is valid. It just shoots the event handler with wrong parameters.

    I can say that when there are several connections active, every valid handle event is followed up with an invalid handle event. This definitely seems like a bug.

    Anyway, I'm happy to know I solved it correctly.

    Thanks again

Children
Related