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

how to get data length in bytes in notification only characteristics without enabling notification

hi,

i am working on generic ble central device which has nrf52832 as it's core.

my question is that i want to know the length of data in bytes which are being sent by notification only characteristic. without enabling notification.

so, for evaluation i am using pca10040 dev kit with sdk 14.2.0's blinkey central example with Nordic thingy 52 as peripheral device. i have modified it to connect with ble peripheral device according to device id entered via uart. after connection it will discover all the available service on peripheral and start allocation space in a register table (array of type uint16_t) to view by user via uart. so when it comes to read only, read/write, and write only characteristics i have no problem to get data length(for write only characteristics i don't have allocate memory space).but when it comes to notification i don't get data length until i enable notification and after that wait for that notification. that takes some time more time like thingy's button characteristic will only send notification when button is pressed. if button is never pressed my central device will always in wait to get notification from where it takes data length.

so is there any way to get data length in notification only characteristics without enabling notification. 

please reply.

thanks.

Parents Reply
  • hi andy,

    i am not using any memory allocation,

    basically i have a array of uint16_t type with length of 0xFF,

    i only want to reserve space in array for all the characteristics, and after that, that particuler array area will be used to store data from same characteristics.

    for example

    0x00 reserved
    0x01 char1 uuid
    0x02 char1 data1
    0x03 char1 data2
    0x04 char2 uuid
    0x05 char2 data1
    0x06 char2 data2

    so when i will receive data from char 1 i will store only on it's reserved location on array. 

      

Children
  • Ah, I understand. Is there any particular reason why you decided to implement it that way? That is a very bad, error prone architecture.

    May I suggest you use something like this?

    typedef struct {
    	uint16_t uuid;
    	uint8_t * p_data;
    } notification_data_t
    
    static notification_data_t notification[NUM_OF_CHARACTERISTICS];

  • hi andy,

    thanks for reply. so the array will be used as spi register table by user and will be accessed by used via spi interface. and array index will be register address.

    i like your idea but problem is that *p_data pointer is pointing to received data from ble and will be changed if another characteristic will send data to central device. so what i will do is that i will make p_data as array of size 20 because my ble data has maximum length of 20 bytes and copy ble data to it.

  • No, each characteristic has its own p_data, so it doesn't matter if you receive data from another characteristic. And yes, essentially you should have an array(per characteristic) big enough to hold the maximum amount of data that you can receive from a characteristic. Those things should be documented somewhere in the peripheral's API. If you don't have access to that, making each array size 20 will be the safest bet. You are already using 512 bytes in your previous implementation, so I guess RAM is not a limitation for you.

Related