Decode Little Endian

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
hrcap
Posts: 131
Joined: Mon Jan 14, 2019 5:20 pm

Decode Little Endian

Post by hrcap » Tue Jul 11, 2023 9:51 pm

Hi All

I am receiving data from a GPS receiver which comes out as the below:

µbˇP–±Á17h~N-˙¶·ù€vÅ˚Œ+
$H∆oê_@ÉPωˇºˇÎˇo


The user manual for the GPS reads:

Packets are sent and received in U-Blox UBX binary format, consisting of a header, optional payload, and a checksum. The header is used to identify the packet start, contents, and payload length. The checksum is used to verify the packet transmission.

Data in the packet is encoded in Little-Endian and uses only integer fields - all double values are multiplied with some value and rounded to the nearest integer. Up to 32-bit values are used.



the link to the user manual is here
https://www.racebox.pro/products/racebo ... 1856094c08

... and the relevant info starts on Page 2



Can anybody assist as to how I might go about decoding this into readable data please?


Many Thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Decode Little Endian

Post by dunbarx » Wed Jul 12, 2023 2:57 pm

Hi.

Little Endian only specifies whether byte order is most-to-least significant or least-to-most.

The string you have returned looks rather more foreign. I tried to find some sort of guide to the U-Blox thing, but could not really get a handle on it.

Craig

hrcap
Posts: 131
Joined: Mon Jan 14, 2019 5:20 pm

Re: Decode Little Endian

Post by hrcap » Wed Jul 12, 2023 3:08 pm

Hi Craig

Thanks for your reply... im starting to make a little bit of progress. I have decoded the original data into:

Code: Select all

 put urlencode(t_endian) into t
   replace "%" with " " in t
...gives:

B5b FF 01P 00 90 88 00 00 E4 07 08 02 00 00 22 F0 FF FF FF FF 00p89 00 00 24 00 00 00 00 00 00 00 00 00 00 00 00 00 98 BD FF FF FF FF FF FF 00v 84 DF 00 00 00 00 00 00 00 00+N 00 00 80 A8 12 01 0F 27 00I 11 00 2C 00 E9 03 E3 FF B9 FF E9 FFk FD


This looks a little bit more like it should... however in trying to convert the relevant parts of the above into what it should be I'm stuck again... for example the manual states:

E6 07 should equal 2022

I've tried all of the following but can't find a way to get it to come out to 2022..:

Code: Select all

put baseConvert("E607" ,16,10) into t
... this comes out as 58887

Code: Select all

put baseConvert("E6" ,16,10) into t
... this comes out as 230

Code: Select all

put baseConvert("07" ,16,10) into t
... this comes out as 7





where the manual gives a shorter example of e.g. :

0A should equal 10

Code: Select all

put baseConvert("0A" ,16,10) into t
... gives the correct result of 10




.... so my knowledge is too limited here to know how to convert any more than one pair of digits

... any ideas?



Many Thanks

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Decode Little Endian

Post by Thierry » Wed Jul 12, 2023 3:20 pm


I've tried all of the following but can't find a way to get it to come out to 2022..:

Code: Select all

put baseConvert("E607" ,16,10) into t
... this comes out as 58887
Hi,

As said in the subject: little Endian.

Have you tried reversing the 2 bytes, as:

Code: Select all

put baseConvert("07E6" ,16,10) into t
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Decode Little Endian

Post by FourthWorld » Wed Jul 12, 2023 3:59 pm

Look into the binaryDecode function. I believe you'll want the options specifying host byte order.

https://livecode.fandom.com/wiki/BinaryDecode
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

hrcap
Posts: 131
Joined: Mon Jan 14, 2019 5:20 pm

Re: Decode Little Endian

Post by hrcap » Thu Jul 13, 2023 9:08 am

Ok thank you very much for the replies guys.

• Thierry: your suggestion of reversing the order worked, thank you.

• FourthWorld: I am still trying to get my head around binaryDecode

...however I think my stumbling block may be in my first steps

the raw data received from the device is e.g:

µbˇP†dIÁ
3Ûˇˇˇˇ˜ß%&‰òΩˇˇˇˇˇˇvÑfl NÄ®'d·˝Î˝i˝[˚àc[


when I convert that raw using:

Code: Select all

put urlencode(t_raw_data) into t_data_in_pairs
   replace "%" with " " in t_data_in_pairs 

it comes out as:

B5b FF 01P 00 A0dI 16 E7 07 07 0D 073 1E F3 FF FF FF FF F7 A7 25 26 00 00 E4 00 00 00 00 00 00 00 00 00 00 00 00 00 98 BD FF FF FF FF FF FF 00v 84 DF 00 00 00 00 00 00 00 00+N 00 00 80 A8 12 01 0F 27 00d E1 FD EB FDi 02 1D FD 5B FB 88 06c 5B


Now this is mostly correct but not perfect... for example:

• the user manual says the:
- 1st 4 digits should be: B5 62
- 2nd 4 digits should be: FF 01


• you will also notice that some of the data isn't pairs of numbers, for example:
- 01P
- A0dl
- 00v
- 00+N
- 00d
- FDi
- 06c


any ideas on why this might be please?

hrcap
Posts: 131
Joined: Mon Jan 14, 2019 5:20 pm

Re: Decode Little Endian

Post by hrcap » Thu Jul 13, 2023 12:22 pm

... and there we go after spending all day on this yesterday and deciding I need to ask the question on here, I end up working out the answer 5 minutes after asking the question

this should have been the initial decode from little endian:

Code: Select all

put the c_endian of me into t_data_raw --raw data in little endian
   
   ---
   --decode the endian into hexadecimal
   put binarydecode("H*", t_data_raw, t_data_hex) into theNumConversions
   ---
   

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7239
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Decode Little Endian

Post by jacque » Thu Jul 13, 2023 9:10 pm

hrcap wrote:
Thu Jul 13, 2023 12:22 pm
... and there we go after spending all day on this yesterday and deciding I need to ask the question on here, I end up working out the answer 5 minutes after asking the question
It's always like that. All you need to do is ask.

This is a story my father told. He said both men in the conversation swore it was true. Names have been changed to protect the innocent.
Two men in the office elevator:

Man 1: What is Joe's last name?
Man 2: Joe who?
Man 1: Joe Smith.
Man 2: I don't know.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”