Sign in to follow this  
Guest ChrisD

Anyone know how MS code ICAO in the BGL files?

Recommended Posts

After the recently release of the BGLCOMP SDK I started my 'GA AI Traffic generator' project. Part of this project is to examine every airport BGL file (Stock and usermade) and count the numbers/types of GA parking places. The programm should be able to manipulate the GA traffic at airport level up to global world settings. For showing airport data I tried to read the ICAO (called identifier in the SDK) of the airport BGL. But there is a problem, MS used 4 Bytes to store the 5 charcters you could use for the identifier. I found that they use only capatials and numbers, so they could use a 7 Bit code. But if I loock with a hexeditor I couldn't identify the coding MS did. I know the place where the 4 Bytes are stored, I tried several alphanumerical identifiers, but I didn't find the algorithm It loock like they use 3 Bit fileds for coding, but I didn't see the formular.So is anyone know how to get the ICAO string back out of the BGL file?Please help

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Greetings.Regrettably I do not know how to do the required task, however I have an idea for You to try out. (No guarantee though :))Using say Ground 2K4 or a similar program, make Yourself a single runway in a remote area and name this with an ICAO-code of Your chice.Now go check the bgl-file..Tell me if this helps.ChrisD

Share this post


Link to post
Share on other sites

Hi ChrisD,maybe I'm didn't see it, but how can Ground2k4 make airports?I thought only AFCAD2 and the MS BGL Compiler can do that.I used AFCAD2 and the MS BGL Compiler, but didn't found the algorithm they use. I put an ICAO of 'AAAA' in and got this binary back in the BGL10000001 00110100 01001010 00000001 AAAAI didn't see any repeating pattern for 'A'I got this if I set the ICAO to 'A'/'AA'/'AAA'/'AAAA':10000001 00000001 00000000 00000000 A10000001 00111010 00000000 00000000 AA10000001 10110000 00001000 00000000 AAA10000001 00110100 01001010 00000001 AAAAI didn' found the pattern in this.

Share this post


Link to post
Share on other sites

>I used AFCAD2 and the MS BGL Compiler, but didn't found the>algorithm they use. I put an ICAO of 'AAAA' in and got this>binary back in the BGL>10000001 00110100 01001010 00000001 AAAA>I didn't see any repeating pattern for 'A'>I got this if I set the ICAO to 'A'/'AA'/'AAA'/'AAAA':>10000001 00000001 00000000 00000000 A>10000001 00111010 00000000 00000000 AA>10000001 10110000 00001000 00000000 AAA>10000001 00110100 01001010 00000001 AAAA>You just found the solution Yourself :) Here is a suggestion. If the work is not too time-consuming, then try the whole alphabet.Start with a single letter A - ZThen AA - AB - AC - AD etcThen AAB- AAC - AAD etc.Put the whole lot into a table. If You still cannot figure out how they code the thing, just make a matrix to convert from 'gibberish' to ICAO.However, whith a few more examples, say: 'B - BB - BBB - BBBB', I am sure You will see the pattern emerge.Let's have a few more results posted here. Maybe one of the other readers of this forum may be able to figure out the 'key-code'.Good Luck.ChrisD

Share this post


Link to post
Share on other sites

Hi ChrisD,after the last post I downloaded the TTools Source and found a hint for the solution there.MS use the ICAO in backorder, means EDFL is stored as LFDE.With this it was easy to get the solution.Each character is stored as value in the range 2-38. Starting with 2='0' and 38='Z' (don't know what the value 0 and 1 represent). So the last character of EDFL is stored first as 23. The next one 'F' is stored as 38*17 and so on.MS used a special format where the first three bits of the first byte is used as lastsignificant bits. The following 5 Bits are alway '00001' and the next three bytes represent the rest of the value.Didn't have any clue why they made it so complicated.

Share this post


Link to post
Share on other sites

Greetings again :)I just stumbled over this msg somewhere else.This should remove the last ambiguity of the matter:Quote: It's definitely an interesting data scheme. It took quite afew sample BGLs and some time in Excel to figure this out. Basically, each letter is a digit in a base 38 number scheme.There are 38 possible values for each position. 0 seems tosignify an empty space, I'm not sure what 1 means, 2-11 are"0"-"9", and 12 is the first letter("A").Start by shifting the 32 bit value right by 5. Only the top3 bits of the lowest byte are used. After that eachcharacter can be pulled off by dividing and mod'ing the27-bit value with 38.So for a 27-bit value X, char n = ( X / 38^(n - 1) ) mod 38As an example, here's KPDX (0x0260c721): 0x0260c721 >> 5 = 0x130639 = 1246777 ( 1246777 / 1 ) mod 38 = 35 ("X") ( 1246777 / 38 ) mod 38 = 15 ("D") ( 1246777 / 1444 ) mod 38 = 27 ("P") ( 1246777 / 54872 ) mod 38 = 22 ("K") ( 1246777 / 2085136 ) mod 38 = 0 ("")So, I have a question for you as well. I can't figure outhow to find the location of the ICAO, airport name, etc.within the BGL. I assume that there is an offset of somesort in the BGL header that points to it. Do you know whatthat would be and how to find it?Thanks,EliotEndquote:Maybe You can enlighten Eliot on this :)Good luckChrisD

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this