How to decode Binary serial?

Hi, I am just starting to look at this nice library: http://www.billporter.info/easytransfer-arduino-library which makes it easy to build a data packets for transmitting to another Arduino. All works well - I am now looking to see if I can understand the structure of the message sent but cannot figure it out, wondering if anyone might have a few pointers on how to do it? I'm picking up the packet sent over serial and displaying it as hex (below), I understand that this is a binary encoded packet but when I try and unravel it I cannot see the intended data leaping out at me :-) ... should be 3 float values all being well.... about 19.00, 53.00 & 10.00 (actual values will not be nice round numbers). HEX

06 85 0C AE 47 99 41 65 D4 6E 42 D3 2d 32 41 AA

Binary

00000110 10000101 00001100 10101110 01000111 10011001 01000001 01100101 11010100 01101110 01000010 11010011 00101101 00110010 01000001 10101010

ASCII

…®G™AeÔnBÓ-2Aª

All works well

What does? I don't see any code for constructing the packets.

I am now looking to see if I can understand the structure of the message sent

Why? You didn't seem concerned about the packet that was sent. Apparently, you are confident the the library did the float to packet contents conversion correctly.

So, why are you suspicious of the library's ability to convert the packet to values correctly?

The same methods (well, the get version of the set methods, that is) should be used to extract the packet information.

Without knowing what this library does, or how it does it, it is impossible to decode the data as provided.

However, one starting point I would recommend would be to first understand how a floating point number is stored in binary form.

For that, you need to read and understand this: http://en.wikipedia.org/wiki/Single_precision_floating-point_format

You'll quickly see that it's not just stored as simple numbers.

I am wondering if you actually have the values 11.136188, 59.707417 and 19.160000 there.

All works well

I have good comms between to arduinos - values are to 2 decimal places.

I am now looking to see if I can understand the structure of the message sent

I hope to have a third part of the system being able to read the packets - ie a PC using serial.... also keen to learn :-)

majenko:
I am wondering if you actually have the values 11.136188, 59.707417 and 19.160000 there.

By the way, I took the numbers 10.00, 59.00 and 19.00, put them into some float variables, extracted the hexadecimal representation, flipped it over (big endian → little endian) and looked for similarities.

From that I then determined which bits of the message are the float values, took those hexadecimal values, flipped them over again, and fed them into my program backwards, to get the float representation of the binary data. That’s the values I came up with.

Out of interest, the packet looks like:

{06 85 0C} {AE 47 99 41} {65 D4 6E 42} {D3 2d 32 41} {AA}

The first chunk {06 85 0C} is some form of packet header - probably telling the other end what the data in the packet is.

The next three chunks are little endian IEEE single-precision floating point numbers.

The final {AA} will be an end of packet marker.

I’ll leave it to you to discover the format of the header chunk.

I have good comms between to arduinos - values are printed to 2 decimal places.

I fixed that for you.

Thanks for your help majenko, that gets me quite a long way there and I have learnt a bit about Binary encoding too - much appreciated.

For now I can ignore the header and terminating byte and extract the 3 values.... will come back to the header later.

Cheers :-)

Hi, this is the author of the EasyTransfer library you are using.

It might help if you read the readme:

  • The protocol is as follows:
  • Header(0x06,0x85),SizeofPayload,Payload,Checksum

And maybe I didn't make it crystal clear on my blog post, but the library doesn't encode the values in any special way. It simply copies the raw binary out of memory and transmits it. So the binary you are seeing has the numbers 'encoded' the same way the AVR (Arduino) stores them in RAM. It looks like majenko figured that out and sent you in the right direction.

Bill