# Various questions about libcanard

**URL:** <https://forum.opencyphal.org/t/various-questions-about-libcanard/928>\
**Category:** Libcanard\
**Created:** [August 25, 2020, 6:52am UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928 "2020-08-25T06:52:13Z")\
**Posts on this page:** 11\
**Page:** 3

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [September 19, 2020, 5:40pm UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/45 "2020-09-19T17:40:06Z")

</div>

Because you are converting DLC to length incorrectly. You need a mapping function similar to what I posted above, but inverse.

---

<div class="post-metadata">

**Author:** ![newcomer](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/n/e5b9ba/32.png) [@newcomer](https://forum.opencyphal.org/u/newcomer)\
**Post date:** [September 19, 2020, 5:47pm UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/47 "2020-09-19T17:47:51Z")

</div>

Is the actual length of the data being sent, or can only be the following value  
0  
1  
2  
3  
4  
5  
6  
7  
8  
12  
16  
20  
24  
32  
48  
64

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [September 19, 2020, 8:54pm UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/48 "2020-09-19T20:54:14Z")

</div>

What you listed are the only valid payload lengths of a CAN FD data frame. For example, one can’t send a CAN FD data frame with 35 bytes of payload; one would have to pad it out to 48 bytes. In your specific case, the library does the padding for you, so you don’t have to bother.

---

<div class="post-metadata">

**Author:** ![newcomer](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/n/e5b9ba/32.png) [@newcomer](https://forum.opencyphal.org/u/newcomer)\
**Post date:** [September 21, 2020, 8:59am UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/50 "2020-09-21T08:59:17Z")

</div>

I found that when I transmitted more than eight bytes(7bytes data + 1 tail byte) of data, I could not receive it successfully.  
I have done this:

```auto
received_frame.payload_size = CanardCANLengthToDLC[RxHeader.DataLength >> 16];

```

```auto
// --------------------------------------------- PUBLIC API---------------------------------------------

const uint8_t CanardCANDLCToLength[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64};
const uint8_t CanardCANLengthToDLC[65] = {
    0, 1, 2, 3, 4, 5, 6, 7, 8, // 0-8
    9, 9, 9, 9, // 9-12
    10, 10, 10, 10, // 13-16
    11, 11, 11, 11, // 17-20
    12, 12, 12, 12, // 21-24
    13, 13, 13, 13, 13, 13, 13, 13, // 25-32
    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, // 33-48
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, // 49-64
};

```

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [September 21, 2020, 9:08am UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/51 "2020-09-21T09:08:07Z")

</div>

The conversion between DLC and length is incorrect. Please do it as I suggested above.

---

<div class="post-metadata">

**Author:** ![newcomer](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/n/e5b9ba/32.png) [@newcomer](https://forum.opencyphal.org/u/newcomer)\
**Post date:** [September 21, 2020, 11:13am UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/52 "2020-09-21T11:13:46Z")

</div>

Thanks a lot ,but I still don’t know what parameter to pass in. 😖

```auto
received_frame.payload_size =xxxxx;

```

xxxxx: I don’t konw what is this length going to be?  
RxHeader.DataLength \>\> 16 or CanardCANLengthToDLC[RxHeader.DataLength \>\> 16] or the size of the data i send ,for example ：the flowing , 4 ?

```auto
uint8_t my_msg[4] = {0};
	canardDSDLSetUxx(&my_msg[0], 0, 10, 8); // msg1
	canardDSDLSetUxx(&my_msg[0], 8, 110, 8); // msg2
	canardDSDLSetUxx(&my_msg[0], 16, 120, 8); // msg3
	canardDSDLSetUxx(&my_msg[0], 24, 0xff, 8); // msg4

```

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [September 21, 2020, 11:21am UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/53 "2020-09-21T11:21:02Z")

</div>

> [@newcomer](#):
>
> I don’t konw what is this length going to be?  
> RxHeader.DataLength \>\> 16 or CanardCANLengthToDLC[RxHeader.DataLength \>\> 16] or the size of the data i send ,for example ：the flowing , 4 ?

The last option is correct. As the name of the field suggests (`payload_size`), it is the size of the payload, in bytes. Not DLC.

---

<div class="post-metadata">

**Author:** ![newcomer](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/n/e5b9ba/32.png) [@newcomer](https://forum.opencyphal.org/u/newcomer)\
**Post date:** [September 21, 2020, 11:23am UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/54 "2020-09-21T11:23:51Z")

</div>

Thank you very much. I will try it again.

---

<div class="post-metadata">

**Author:** ![newcomer](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/n/e5b9ba/32.png) [@newcomer](https://forum.opencyphal.org/u/newcomer)\
**Post date:** [September 22, 2020, 7:02am UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/55 "2020-09-22T07:02:59Z")

</div>

> [@newcomer](#):
>
> I found that when I transmitted more than eight bytes(7bytes data + 1 tail byte) of data, I could not receive it successfully.  
> I have done this:

Still can not receive success 😑  
Didn’t I set the FDCAN for Uavcan

---

<div class="post-metadata">

**Author:** ![hugo](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/h/b38774/32.png) [@hugo](https://forum.opencyphal.org/u/hugo)\
**Post date:** [September 23, 2020, 10:36am UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/56 "2020-09-23T10:36:16Z")

</div>

Maybe this example can help you?

> [@Libcanard: Examples, Starters, Tutorials](https://forum.opencyphal.org/t/libcanard-examples-starters-tutorials/935/5):
>
> Raspberry Pi with ultrasound example in C The code is meant to be run using two Raspberry Pi. Each Pi is connected to a MCP2515 module. One Pi is connected to a HC-SR04 ultrasound sensor. The sensor calculated distance to an obstacle is transmitted as a 32bit float. The float is serialized using canard\_dsdl.h. At the reciving end the float is deserialized and the distance is printed to the console. The code can be found at: [raspberry-can-HC-SR04](https://github.com/bluecorn/raspberry-can-HC-SR04)[raspberry-can-master-ultrasound](https://github.com/bluecorn/raspberry-can-master-ultrasound)

---

<div class="post-metadata">

**Author:** ![newcomer](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/n/e5b9ba/32.png) [@newcomer](https://forum.opencyphal.org/u/newcomer)\
**Post date:** [September 23, 2020, 10:50am UTC](https://forum.opencyphal.org/t/various-questions-about-libcanard/928/57 "2020-09-23T10:50:12Z")

</div>

ok,thanks a lot

[Previous page](https://forum.opencyphal.org/t/various-questions-about-libcanard/928.md?page=2)
