Data type signature

402 views
Skip to first unread message

yangyu...@gmail.com

unread,
Feb 10, 2017, 4:39:09 AM2/10/17
to UAVCAN
Can anyone provide some example for  the Data type signature that implement by C langue,and shown the process for get  signature resule.

Pavel Kirienko

unread,
Feb 10, 2017, 1:41:55 PM2/10/17
to yangyu...@gmail.com, UAVCAN
Hello,

The data type computation algorithm is implemented in Libuavcan (C++) and Pyuavcan (Python). Libcanard currently does not have such implementation, since it doesn't work with source-level DSDL definitions yet.

In Libuavcan, the algorithm that derives the Data Type Signature from DSDL signatures is implemented by means of code generation. The template is provided here (it's a bit hard to read): https://github.com/UAVCAN/libuavcan/blob/master/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl#L400-L420

Here's an example expanded for the data type NodeStatus:

template <int _tmpl>
::uavcan::DataTypeSignature NodeStatus_<_tmpl>::getDataTypeSignature()
{
    ::uavcan::DataTypeSignature signature(0xF0868D0C1A7C6F1ULL);

    FieldTypes::uptime_sec::extendDataTypeSignature(signature);
    FieldTypes::health::extendDataTypeSignature(signature);
    FieldTypes::mode::extendDataTypeSignature(signature);
    FieldTypes::sub_mode::extendDataTypeSignature(signature);
    FieldTypes::vendor_specific_status_code::extendDataTypeSignature(signature);

    return signature;
}

In Pyuavcan, the implementation is available here: https://github.com/UAVCAN/pyuavcan/blob/master/uavcan/dsdl/parser.py#L304-L318

Both implementations are trivially convertible to C.

Hope this helps!

Pavel.

On Fri, Feb 10, 2017 at 12:39 PM, <yangyu...@gmail.com> wrote:
Can anyone provide some example for  the Data type signature that implement by C langue,and shown the process for get  signature resule.

--
You received this message because you are subscribed to the Google Groups "UAVCAN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+unsubscribe@googlegroups.com.
To post to this group, send email to uav...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/uavcan/a3c1aba0-e48d-4020-bf15-4ac6522911e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yangyu...@gmail.com

unread,
Feb 11, 2017, 2:45:45 AM2/11/17
to UAVCAN
Dear Pavel:
 Thanks for your answer.
 There is some problem after refer you answer. Now I can get the right result for the data type signature that does not contain nested data structures. But the signature contain nested data structures,is alway  different  with the libcanard demo.
There has define  in demo 
#define UAVCAN_GET_NODE_INFO_DATA_TYPE_SIGNATURE                    0xee468a8121c46a9e.
This is my test code process for this data type by below:

My result is 0x9d1d79a965b4c3e4. Where is my fault?

在 2017年2月10日星期五 UTC+8下午5:39:09,yangyu...@gmail.com写道:

Pavel Kirienko

unread,
Feb 12, 2017, 5:28:48 PM2/12/17
to yangyu...@gmail.com, UAVCAN
The algorithm you attached is implemented incorrectly. To quote the specification:

The following is a data type signature computation algorithm for a given data type, where hash is the signature hash function described earlier:
  1. Initialize the hash value with the DSDL signature of the given type.
  2. Starting from the top of the DSDL definition, do the following for each nested data structure:
  3. Extend the current hash value with the data type signature of the nested data structure.
The resulting hash value will be the data type signature.
The hash extension algorithm:
  1. Save the current hash value.
  2. Feed the value the hash needs to be extended with to the hash function, byte by byte, LSB first.
  3. Feed the saved hash value to the hash function, byte by byte, LSB first.
The data type signature computation algorithm has the following properties:
  • Data type signature and DSDL signature of the same type are equal if the data type does not contain nested data structures.
  • Data type signature is guaranteed to match only if all nested data structures are compatible.
You're supposed to extend the DSDL signature of the outer type with LSB-first representation of the DSDL signatures of each nested type, rather than extending it directly with the normalized definitions of the nested types.

Pavel.

--
You received this message because you are subscribed to the Google Groups "UAVCAN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+unsubscribe@googlegroups.com.
To post to this group, send email to uav...@googlegroups.com.
Message has been deleted

yangyu...@gmail.com

unread,
Feb 12, 2017, 8:51:12 PM2/12/17
to UAVCAN
Hello Pavel:
 Thank for your answer.But maybe my comment or code structure are misguide you.I was get the data type signature first,then use them to going on the extend calculate. I have rebuild my code by following:
import struct
def bytes_from_crc64(crc64):
    # Cast to str explicitly for Python 2.7 compatibility when
    # unicode_literals is enabled
    return bytes(struct.pack(str("<Q"), crc64))

        

#get DSDL signature nodeinfo
nodeinfo_str = "uavcan.protocol.GetNodeInfo\nNodeStatus status\nSoftwareVersion software_version\nHardwareVersion hardware_version\nsaturated uint8[<=80] name";
sing = Signature();
sing.add(nodeinfo_str);
nodeinfo_sig = sing.get_value();

#get data type signature of nodestatus,there no nested data type,so equal to DSDL signature;the following below are  same case.
nodestatus_str = "uavcan.protocol.NodeStatus\nsaturated uint32 uptime_sec\nsaturated uint2 health\nsaturated uint3 mode\nsaturated uint3 sub_mode\nsaturated uint16 vendor_specific_status_code";
sing = Signature();
sing.add(nodestatus_str);
nodestatus_sig = sing.get_value();

#get data type signature of software
software_str = "uavcan.protocol.SoftwareVersion\nsaturated uint8 major\nsaturated uint8 minor\nsaturated uint8 optional_field_flags\nsaturated uint32 vcs_commit\nsaturated uint64 image_crc";
sing = Signature();
sing.add(software_str);
software_sig = sing.get_value();

#get data type signature of hardware 
hardware_str = "uavcan.protocol.HardwareVersion\nsaturated uint8 major\nsaturated uint8 minor\nsaturated uint8[16] unique_id\nsaturated uint8[<=255] certificate_of_authenticity";
sing = Signature();
sing.add(hardware_str);
hardware_sig = sing.get_value();

#init the signature with the DSDL signature of the nodeinfo
sing = Signature(nodeinfo_sig);

#extend nodestatus signature
sig_vl = sing.get_value();
sing.add(bytes_from_crc64(nodestatus_sig));
sing.add(bytes_from_crc64(sig_vl));

#extern software signature
sig_vl = sing.get_value();
sing.add(bytes_from_crc64(software_sig));
sing.add(bytes_from_crc64(sig_vl));

#extern hardware signature
sig_vl = sing.get_value();
sing.add(bytes_from_crc64(hardware_sig));
sing.add(bytes_from_crc64(sig_vl));

print("The CRC64 is 0x%016x"%(sing.get_value()));
I hope I have make clear my means oneself. I was extend the signature with the data type signature;not the normalized definitions of the nested types. If the DSDL signatures are not calculated,how to get it?  There are some concept of error with me?



在 2017年2月10日星期五 UTC+8下午5:39:09,yangyu...@gmail.com写道:
Can anyone provide some example for  the Data type signature that implement by C langue,and shown the process for get  signature resule.

Pavel Kirienko

unread,
Feb 14, 2017, 10:09:31 AM2/14/17
to yangyu...@gmail.com, UAVCAN
Indeed, I misunderstood your intention. Please observe that in the first step, you're supposed to initialize the signature with the DSDL signature of the outer type. You can refer to https://github.com/UAVCAN/pyuavcan/blob/master/uavcan/dsdl/parser.py#L304-L318 for reference.

Pavel.

--
You received this message because you are subscribed to the Google Groups "UAVCAN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+unsubscribe@googlegroups.com.
To post to this group, send email to uav...@googlegroups.com.

yangyu...@gmail.com

unread,
Feb 14, 2017, 10:36:06 PM2/14/17
to UAVCAN, yangyu...@gmail.com
Hello Pavel:
  Thanks for your help,I have understood how to calulate the data signature.I not used fullname of the nested data type in the normalized definition.
  Thanks so much.

在 2017年2月14日星期二 UTC+8下午11:09:31,Pavel Kirienko写道:
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+un...@googlegroups.com.

To post to this group, send email to uav...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages