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

Does a nus service data packet have to end with a NULL character

Hi,

Im trying to send data via the NUS service which is larger than 20 bytes. I understand that I have to break down the data into chunks in this case, which is what I'm trying to do. However, I see that if I send exactly 20bytes from the nRF UART v2.0 Android app to my nrf52823 application the data pointer (uint8_t * p_data) in the nus_data_handler function seems empty even though the length is showing 20. I tested my assumption with the following code:

 static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) {
     uint8_t buf[21];
     memcpy(buf, p_data, 20);
     buf[20] = 0;
     SEGGER_RTT_printf(0, "Data Received (buf): %s\n", buf);
     SEGGER_RTT_printf(0, "Data Received: %s; Length: %d\n", p_data, length);
     decode_nus_message(p_data, length); //my code
}

I see on the RTT Viewer:

 0>  Data Received (buf): 
 0>  Data Received: ; Length: 20

I'm thinking this might be a bug in the softdevice code copying the data to the pointer for the event handler. Maybe a strcpy was used instead of a memcpy?

Or is this expected behavior?

Related