fixed altitude calculation as per GDL 90 data interface spec

pull/154/head
Joseph Poirier 2015-12-20 15:34:36 -06:00
rodzic b542ddc7ca
commit 373c0fa956
1 zmienionych plików z 18 dodań i 6 usunięć

Wyświetl plik

@ -138,12 +138,24 @@ func makeTrafficReport(ti TrafficInfo) {
msg[9] = tmp[1] // Longitude.
msg[10] = tmp[2] // Longitude.
//Altitude: OK
//TODO: 0xFFF "invalid altitude."
alt := int16(math.Max(float64(ti.Alt), float64(-1000.00)))
alt = (alt + 1000) / 25
alt = alt & 0xFFF // Should fit in 12 bits.
// Altitude: OK
// GDL 90 Data Interface Specification examples:
// where 1,000 foot offset and 25 foot resolution (1,000 / 25 = 40)
// -1,000 feet 0x000
// 0 feet 0x028
// +1000 feet 0x050
// +101,350 feet 0xFFE
// Invalid or unavailable 0xFFF
//
// Algo example at: https://play.golang.org/p/AQ0fpDudvi
//
var alt int32
if ti.Alt < -1000 || ti.Alt > 101350 {
alt = 0xFFF
} else {
// output guaranteed to be between 0x000 and 0xFFE
alt = int32((ti.Alt / 25) + 40)
}
msg[11] = byte((alt & 0xFF0) >> 4) // Altitude.
msg[12] = byte((alt & 0x00F) << 4)