# Uavcan v0 found data transfer reversal

**URL:** <https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476>\
**Category:** LibCyphal\
**Created:** [October 9, 2021, 3:29am UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476 "2021-10-09T03:29:50Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cherish-forever](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/cherish-forever/32/802_2.png) [@Cherish-forever](https://forum.opencyphal.org/u/Cherish-forever)\
**Post date:** [October 9, 2021, 3:29am UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/1 "2021-10-09T03:29:51Z")

</div>

![img_v2_402a9248-7ad3-4103-9765-4bb9fa0dc13g](https://forum.opencyphal.org/uploads/default/original/1X/9c280c999a39522adfaf3aff7ccd0fc2f706a3eb.png)

In this case we found that

data: 21 50 21 8d f8 05 10  
data: 4f f0 03 02 14 bf 44

transfer reversal, then data decode error.  
how can I process this case?  
I think protocol stack need consider data order.

---

<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:** [October 9, 2021, 9:14am UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/2 "2021-10-09T09:14:50Z")

</div>

Of course the protocol is aware of basic things like frame transmission ordering. Your case looks like a typical priority inversion problem. Please tell us how do you manage the transmission queue in your CAN driver? Can you share the code here?

Related: [UAVCAN/CAN: tx buffer management in CAN (FD) controllers](https://forum.opencyphal.org/t/uavcan-can-tx-buffer-management-in-can-fd-controllers/1215)

---

<div class="post-metadata">

**Author:** ![Cherish-forever](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/cherish-forever/32/802_2.png) [@Cherish-forever](https://forum.opencyphal.org/u/Cherish-forever)\
**Post date:** [October 11, 2021, 3:30am UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/3 "2021-10-11T03:30:59Z")

</div>

We use like this:

```auto
      clock_(std::make_shared<uavcan_linux::SystemClock>()),
      can_driver_(std::make_shared<uavcan_linux::SocketCanDriver>(*clock_)),

```

---

<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:** [October 11, 2021, 7:52am UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/4 "2021-10-11T07:52:27Z")

</div>

What CAN controller are you using? Perhaps the inversion is happening within it. Try also to reduce the number of frames enqueued inside the socket from the default 2 to 1 (see `max_frames_in_socket_tx_queue`):

> <https://github.com/UAVCAN/platform_specific_components/blob/22132baf133593cd9a5619b1ec333f8a03d2bd45/linux/libuavcan/include/uavcan_linux/socketcan.hpp#L372>

---

<div class="post-metadata">

**Author:** ![Cherish-forever](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/cherish-forever/32/802_2.png) [@Cherish-forever](https://forum.opencyphal.org/u/Cherish-forever)\
**Post date:** [October 11, 2021, 8:04am UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/5 "2021-10-11T08:04:22Z")

</div>

mttcan:

[https://docs.nvidia.com/drive/drive\_os\_5.1.6.1L/nvvib\_docs/index.html#page/DRIVE\_OS\_Linux\_SDK\_Development\_Guide/System%20Programming/sys\_components\_tegra\_can.html](https://docs.nvidia.com/drive/drive_os_5.1.6.1L/nvvib_docs/index.html#page/DRIVE_OS_Linux_SDK_Development_Guide/System%20Programming/sys_components_tegra_can.html)

---

<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:** [October 11, 2021, 8:10am UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/6 "2021-10-11T08:10:57Z")

</div>

I doubt there are issues in the M\_CAN driver but then again, you never know.

You are dealing with an inner priority inversion problem. It is not really specific to UAVCAN. There are two things to try:

- Reduce the number of enqueued frames to 1 as suggested above. The default should actually be updated in the sources; if you could submit a pull request that would be appreciated.

- Inspect the sources of the M\_CAN driver (which are rather massive) to see if the TX queue management is implemented correctly. Maybe reach out to the maintainers.

---

<div class="post-metadata">

**Author:** ![Cherish-forever](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/cherish-forever/32/802_2.png) [@Cherish-forever](https://forum.opencyphal.org/u/Cherish-forever)\
**Post date:** [October 11, 2021, 8:17am UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/7 "2021-10-11T08:17:01Z")

</div>

Is that means make change

```auto
SocketCanIface(const SystemClock& clock, int socket_fd, int max_frames_in_socket_tx_queue = 1)

```

as a PR?

---

<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:** [October 11, 2021, 8:34am UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/8 "2021-10-11T08:34:23Z")

</div>

Yes.

---

<div class="post-metadata">

**Author:** ![Cherish-forever](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/cherish-forever/32/802_2.png) [@Cherish-forever](https://forum.opencyphal.org/u/Cherish-forever)\
**Post date:** [October 11, 2021, 12:04pm UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/9 "2021-10-11T12:04:32Z")

</div>

Here：

> <https://github.com/UAVCAN/platform_specific_components/pull/31>
>
> for more details: https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-rever…sal/1476

---

<div class="post-metadata">

**Author:** ![gribov42](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/gribov42/32/1520_2.png) [@gribov42](https://forum.opencyphal.org/u/gribov42)\
**Post date:** [December 5, 2023, 7:09pm UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/10 "2023-12-05T19:09:40Z")

</div>

Not sure if there’s any remedy here, since this driver is deprecated, but at the very least I thought I’d leave this comment for someone going down the same rabbit hole as me -  
In the original V2 drivers [this max variable was set to “2”](https://github.com/OpenCyphal-Garage/libcyphal/pull/298) - It was changed to “10” in February of 2020 because of [this bug](https://github.com/OpenCyphal-Garage/libcyphal/issues/279) showing the buffer was not large enough for SocketCAN requirements.

After that, in March 2020, the platform\_specific\_software repo was moved to OpenCyphal, and it seems that move _did not include_ this change to size 10 for whatever reason. Then this was posted and the above PR was put up in Oct 21 to set it to “1”, but seemingly that’s only needed for the MTCAN controller mentioned above?

Would be nice if this was broken out into something settable by the API if different values are needed for different systems, but given that it’s legacy code it’s probably not worth it 🤷

---

<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:** [December 5, 2023, 7:25pm UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/11 "2023-12-05T19:25:22Z")

</div>

A merge request adding a setter method would be accepted.

---

<div class="post-metadata">

**Author:** ![deekay](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@deekay](https://forum.opencyphal.org/u/deekay)\
**Post date:** [December 18, 2023, 7:37am UTC](https://forum.opencyphal.org/t/uavcan-v0-found-data-transfer-reversal/1476/12 "2023-12-18T07:37:50Z")

</div>

@Cherish-forever Did the `SocketCanIface(const SystemClock& clock, int socket_fd, int max_frames_in_socket_tx_queue = 1)` solve your issue?
