The number resulting from combining the above gives the flight level above the minimum datum.
The following C function can be used to carry out the decoding:
<source lang="c">
signed int32 GillhamToAltitude( int16 GillhamValue )
// Data must be in following order (MSB to LSB)
// D1 D2 D4 A1 A2 A4 B1 B2 B4 C1 C2 C4
{
signed int32 Result;
int16 FiveHundreds;
int16 OneHundreds;
// Convert Gillham value using gray code to binary conversion algorithm.
// Get rid of Hundreds (lower 3 bits).
FiveHundreds = GillhamValue >> 3;
// Strip off Five Hundreds leaving lower 3 bits.
OneHundreds = GillhamValue & 0x07;
FiveHundreds = GrayToBinary(FiveHundreds);
OneHundreds = GrayToBinary(OneHundreds);
// Check for invalid codes.
if (OneHundreds == 5 || OneHundreds == 6 || OneHundreds == 0)
{
Result = -9;
return Result;
}
// Remove 7s from OneHundreds.
if (OneHundreds == 7) OneHundreds = 5;
// Correct order of OneHundreds.
if (FiveHundreds % 2) OneHundreds = 6 - OneHundreds;
// Convert to feet and apply altitude datum offset.
Result = (signed int32)((FiveHundreds * 500) + (OneHundreds *100)) - 1300;
return Result;
}
unsigned int GrayToBinary(unsigned int num)
{
unsigned int temp;
temp = num ^ (num>>8);
temp ^= (temp>>4);
temp ^= (temp>>2);
temp ^= (temp>>1);
return temp;
}
</source>
[[Category:Data transmission]]
|