# Custom message signature fail

**URL:** <https://forum.opencyphal.org/t/custom-message-signature-fail/372>\
**Category:** Libcanard\
**Created:** [February 25, 2019, 3:50pm UTC](https://forum.opencyphal.org/t/custom-message-signature-fail/372 "2019-02-25T15:50:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey\_Frolov](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@Sergey\_Frolov](https://forum.opencyphal.org/u/Sergey_Frolov)\
**Post date:** [February 25, 2019, 3:50pm UTC](https://forum.opencyphal.org/t/custom-message-signature-fail/372/1 "2019-02-25T15:50:25Z")

</div>

Hello. I use Libcanard with STM32F4. And I compiled my own custom message. GUI looks it fine.  
I have no troubles when I send messages less than 7 bytes, but when I try to send more bytes per 1 message, bus monitor print this:

 ![crcfail](https://forum.opencyphal.org/uploads/default/original/1X/c660630a658d24d51e8128ab18718f68ac68fd92.png)

“CRC mismatch: expected 697d, got 57b5…”

In canard core I see that crc calculated using ‘signature’-field (if size \> 7 bytes). It seems, that calculated signature (through dsdl) is wrong. How can I calculate it correct (manually)?? So GUI tool still send errors.

Thanks

---

<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:** [February 25, 2019, 4:05pm UTC](https://forum.opencyphal.org/t/custom-message-signature-fail/372/2 "2019-02-25T16:05:07Z")

</div>

The most likely reason is that the message definition used by the GUI tool differs from the one used by your libcanard-based system. Please ensure that the definitions are exactly identical.

Also, you can’t define vendor-specific messages inside the UAVCAN namespace. You should use a separate root namespace for your custom data types (although this is not directly related to your question).

---

<div class="post-metadata">

**Author:** ![Sergey\_Frolov](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@Sergey\_Frolov](https://forum.opencyphal.org/u/Sergey_Frolov)\
**Post date:** [February 25, 2019, 5:14pm UTC](https://forum.opencyphal.org/t/custom-message-signature-fail/372/3 "2019-02-25T17:14:52Z")

</div>

Thanks. But this works fine in another board with Nuttx and libuavcan. That says that signature-field is correct. And we able to include own message to uavcan-namespace… Hm… As for libcanard, troubles are still not solved.

---

<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:** [February 25, 2019, 7:27pm UTC](https://forum.opencyphal.org/t/custom-message-signature-fail/372/4 "2019-02-25T19:27:51Z")

</div>

> [@Sergey\_Frolov](#):
>
> As for libcanard, troubles are still not solved.

Let’s have a look at your code.

---

<div class="post-metadata">

**Author:** ![Sergey\_Frolov](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@Sergey\_Frolov](https://forum.opencyphal.org/u/Sergey_Frolov)\
**Post date:** [February 26, 2019, 7:00am UTC](https://forum.opencyphal.org/t/custom-message-signature-fail/372/5 "2019-02-26T07:00:37Z")

</div>

Ok. I hava a message template, described as:

```auto
uint8 id

void5
UvrValue value

```

where UveValue is:

```auto
@union # Tag is 3 bit long, so outer structure has 5-bit prefix to ensure proper alignment
uint8 bool_value
int8 byte_value # 8-bit value is used for alignment reasons
int16 short_value
int32 integer_value
int64 long_value

```

And function, where I try to send int64 value (tag=4 from union above)

```auto
	uint8_t n = 0;
        uint8_t tag=4;
	int offset = 0;
	uint8_t buffer[32];
	static uint8_t transferId = 0;
	uint8_t id=1;
	int64_t abs= 0x0000FF55;

	memset(buffer,0x00,32);		

	canardEncodeScalar(buffer, offset, 8, &id); //id
	offset += 8;
	canardEncodeScalar(buffer, offset, 5, &n); //void5 offset
	offset += 5;
	canardEncodeScalar(buffer, offset, 3, &tag); //tag to union member
	offset += 3;
	canardEncodeScalar(buffer, offset, 64, &abs); //int64 value
  canardBroadcast(&g_canard, 
                    UVR_ARRAY_SIGNATURE,
                    UVR_ARRAY_ID,
                    &transferId,
                    CANARD_TRANSFER_PRIORITY_HIGH,
		    buffer, 
                    10);	

```

I have doubts for last argument of canardBroadcast (length of packet), but I see - 8+5(void)+3+64=80 (10 bytes). But CRC is calculated with fail.  
If i try send for example int32 value (tag=3), length=6 (\<7) than the transmission is OK

---

<div class="post-metadata">

**Author:** ![Sergey\_Frolov](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@Sergey\_Frolov](https://forum.opencyphal.org/u/Sergey_Frolov)\
**Post date:** [February 26, 2019, 7:45am UTC](https://forum.opencyphal.org/t/custom-message-signature-fail/372/6 "2019-02-26T07:45:34Z")

</div>

So, it seems that signature is wrong. In libuavcan i cannot find using of signature-field in ‘add\_crc’-function (in contrast of libcanard). Libuavcan uses separate CRC-table (not Signature-field)  
That’s why libuavcan works fine… I’m clearly sure, that signature is wrong. And CRC-value also returns with fail

```auto
        if (payload_len > 7)
        {
            crc = crcAddSignature(crc, data_type_signature);
            crc = crcAdd(crc, payload, payload_len);
        }

```

---

<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:** [February 26, 2019, 9:17am UTC](https://forum.opencyphal.org/t/custom-message-signature-fail/372/7 "2019-02-26T09:17:59Z")

</div>

Yes, indeed, the serialization code seems correct; you need to check the value of `UVR_ARRAY_SIGNATURE`. You can use this script to compute and display the signature: [https://github.com/UAVCAN/libcanard/blob/master/show\_data\_type\_info.py](https://github.com/UAVCAN/libcanard/blob/master/show_data_type_info.py)

---

<div class="post-metadata">

**Author:** ![Sergey\_Frolov](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@Sergey\_Frolov](https://forum.opencyphal.org/u/Sergey_Frolov)\
**Post date:** [February 26, 2019, 10:54am UTC](https://forum.opencyphal.org/t/custom-message-signature-fail/372/8 "2019-02-26T10:54:27Z")

</div>

Good day!! O, great thanks.! I launched script and got a valid ‘signature’-field for my message. And now it works clearly fine.  
I want specify this moment (from replies below):

> “Also, you can’t define vendor-specific messages inside the UAVCAN namespace. You should use a separate root namespace for your custom data types.”

I little confused …how can I define my own namespace? I see extension of file like \*.uavcan. Is it means that i need use another extension (as own namespace) for custom messages?

---

<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:** [February 26, 2019, 11:27am UTC](https://forum.opencyphal.org/t/custom-message-signature-fail/372/9 "2019-02-26T11:27:12Z")

</div>

> [@Sergey\_Frolov](#):
>
> I see extension of file like \*.uavcan. Is it means that i need use another extension (as own namespace) for custom messages?

Nope, you still use the same `*.uavcan` extension but you put your files into a separate root namespace. This tutorial here should clarify things (ignore the fact that it’s written for libuavcan; same principles apply for any implementation): [Open technology for real-time intravehicular distributed computing and communication based on modern networking standards](https://uavcan.org/Implementations/Libuavcan/Tutorials/8._Custom_data_types/)
