Characteristic of variable-length write

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello,

SDK:2.1.1

Hardware:Tag board + iPhone

I want to send 1-22 bytes from iPhone to the Tag board. The length is not fixed, variable.

I have studied the SDK's samples but couldn't the sample for variable length write.

Now, the characteristic setting is like this,

CHARACTERISTIC_UUID128_WRITABLE (HDLC_VSP_VSP_TX,

  HDLC_VSP_VSP_TX_VALUE,

__UUID_VSP_VSP_TX,

LEGATTDB_CHAR_PROP_WRITE_NO_RESPONSE,

LEGATTDB_PERM_WRITE_CMD,

22),

    0x00,...0x00,     //22 of 0x00

And I can get the data in the handler,

int test3_write_handler(LEGATTDB_ENTRY_HDR *p)

{

    UINT8  writtenbyte;

    UINT16 handle   = legattdb_getHandle(p);

    int    len      = legattdb_getAttrValueLen(p);

    UINT8  *attrPtr = legattdb_getAttrValue(p);

    BOOL changed;

...etc...

then I could get the data. But the length is always 22, so there is no length infomation of each packet.

For example, when iPhone send one byte

0x00

then send two bytes

0x00 0x00

then I can not to know what was the second packet.

I found the setting of "LEGATTDB_PERM_VARIABLE_LENGTH" in MMP920732SW-AN103-R application note, P12, table2.

So I think there is a way to get variable length write data, isn't there?

0 Likes
1 Solution
Anonymous
Not applicable

I changed the 5th parameter as " LEGATTDB_PERM_WRITE_CMD | LEGATTDB_PERM_VARIABLE_LENGTH" then I could get the actual length information of the data.

View solution in original post

0 Likes
7 Replies
Anonymous
Not applicable

If you have access to process the received data, then you can add one byte(say byte0) which carries the size of the rest payload. From my experience, once you declare the size of the characteristic value in the gattdb, the stack sends the PDU of that size.

Anonymous
Not applicable

I think LEGATTDB_PERM_VARIABLE_LENGTH can solve your issue, I had same issue with yours ever.

0 Likes
Anonymous
Not applicable

Thank you for the reply.

I am making a kind of UART dongle via BLE, so I can not to add the length byte.

I think LEGATTDB_PERM_VARIABLE_LENGTH can solve too, but there is no infomation to use the setting.

I set it in my cord, but I doesn't work.

I set LEGATTDB_PERM_VARIABLE_LENGTH like this.

CHARACTERISTIC_UUID128_WRITABLE (HDLC_VSP_VSP_TX,

                           HDLC_VSP_VSP_TX_VALUE,

                           __UUID_VSP_VSP_TX,

                           LEGATTDB_CHAR_PROP_WRITE_NO_RESPONSE,

                           //LEGATTDB_PERM_WRITE_CMD,

                           LEGATTDB_PERM_VARIABLE_LENGTH,

                           16),

CHARACTERISTIC_UUID128_WRITABLE needs 6 auguments so I have to add some length number like "16".

If I set like this, the write will not fire at all. If I change from LEGATTDB_PERM_VARIABLE_LENGTH to LEGATTDB_PERM_VARIABLE_LENGTH, I can get the write data.


Is there a document for LEGATTDB_PERM_VARIABLE_LENGTH?


0 Likes

From the new thread you added here: How to use "LEGATTDB_PERM_VARIABLE_LENGTH"

Hello,

SDK:2.1.1

Hardware:Tag board + iPhone

I want to send variable data from client(iPhone) to the tag-board.

I have checked some samples and documents, and I found a description of setting "LEGATTDB_PERM_VARIABLE_LENGTH" in MMP920732SW-AN103-R application note, P12, table2.

Does any body know how to set this setting?

The samples just have the setting function CHARACTERISTIC_UUID128_WRITABLE () for write characteristic, and it need the length information like this.


CHARACTERISTIC_UUID128_WRITABLE (HDLC_VSP_VSP_TX,

  HDLC_VSP_VSP_TX_VALUE,

__UUID_VSP_VSP_TX,

LEGATTDB_CHAR_PROP_WRITE_NO_RESPONSE,

LEGATTDB_PERM_WRITE_CMD,

16), ect...

It sets the data length, so the length is always 16 or something even iPhone sent other length data.

I want to like this,

When I sent data

0x00 0x00

then I want to get two byte of 0x00.

When I sent

0x00 0x00 0x00

then I want to get three byte of 0x00.

I changed the setting LEGATTDB_PERM_WRITE_CMD to LEGATTDB_PERM_VARIABLE_LENGTH.


I want to get 16byte data paket, so I can not add a length data in the data.

0 Likes
Anonymous
Not applicable

Hi,

I think the 5th parameter requires LEGATTDB_PERM_WRITE_CMD to be written.

So please try "LEGATTDB_PERM_WRITE_CMD | LEGATTDB_PERM_WRITE_REQ".

I didn't test this, but hope it works.

Anonymous
Not applicable

dmiya, thank you for reply, but it doesn't work.

The problem is the "length". The Broadcom firmware seems to have no infomation of the length when WRTTE was ocurred.

You mentioned the 5th parameter but the "CHARACTERISTIC_UUID128_WRITABLE (" have 6th parameter.

I want to send a "variable" data. Not fixed length data.

I have to say again.

I want to send,

0x00

or

0x00 0x00

these are different packet length. Variable.

"CHARACTERISTIC_UUID128_WRITABLE ()" has 6th parameter and it's the length of the received data structure.

Because the length is fixed, I couldn't get the infomation of the data length.


For example, I set the 5th and 6th parameter as

1) LEGATTDB_PERM_WRITE_CMD,16

or

2) LEGATTDB_PERM_VARIABLE_LENGTH,16

or

3) LEGATTDB_PERM_WRITE_CMD | LEGATTDB_PERM_WRITE_REQ,16


"16" is the max hardware buffer length of the BCM20737S. And i sent some data from iPhone.


2) doesn't work at all. If I set this and do "write", nothing happened.


1) and 2) can get data but can't get the length at all.

When I send two byte of 0xFF 0xFF, then the result is


0xFF 0xFF 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00


then I send one byte of 0xAA then the result is


0xAA 0xFF 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00



The previous data is remained and just the first byte is overwritten.
I want to receive the data when I send 0xFF 0xFF, it's just 0xFF 0xFF.


When I make the project that include Write characteristic, the SDK make xx_db.c automatically, and it has the write call-back. I checked it and it's like this,


BOOL __write_handler(UINT16 handle, int len, UINT8 *attrPtr)

{...

the "int len" is always 16 when I set the 6th parameter as 16, so the "len" is not the received length.

0 Likes
Anonymous
Not applicable

I changed the 5th parameter as " LEGATTDB_PERM_WRITE_CMD | LEGATTDB_PERM_VARIABLE_LENGTH" then I could get the actual length information of the data.

0 Likes