astuff / kvaser_interface

A Kvaser CAN interface ROS abstraction layer.
MIT License
83 stars 51 forks source link

numeric base:Hexadecimal #74

Closed nanyi98 closed 2 years ago

nanyi98 commented 2 years ago

Thank you very much for your work. I have a question. The data I accept is decimal. How can I modify the program file to accept hexadecimal data?

icolwell-as commented 2 years ago

Hi @nanyi98, can you be more specific? Do you mean the data in the can_msgs/Frame? The data is just data, how you interpret the data (decimal or hexadecimal) is up to you.

nanyi98 commented 2 years ago

HI @icolwell-as,Yes,I mean the data in can_msgs/Frame. the uint8[8] data I accept is decimal,but I want to accept hexadecimal.

header:
    seq:1033491
    stamp:
        secs: 1642148208
        nsecs: 260563749
    frame_id: "0”
id: 532
is rtr: False
is extended: Falseis error: False
dlc:8
data: [61,226,0,0,0,0,92,2]
icolwell-as commented 2 years ago

Hi @nanyi98, the data field in the Frame message is an 8 byte array of data, each of the 8 bytes is represented by the uint8 datatype. When you rostopic echo the topic, you will see the data presented in decimal form, simply because that is how the rostopic echo tool chooses to present the data. The data is just binary data, you can write your application to interpret the data however you choose to.

So when you see this printed: data: [61,226,0,0,0,0,92,2] it is equivalent to: data: [3D,E2,00,00,00,00,5C,02]

"Accepting hexadecimal" doesn't mean supporting a different datatype or something, it's just a software design choice, but the data is the same.

nanyi98 commented 2 years ago

Thank you !!!