From 373c0fa9567792e50f1a22721d8712736b3806ad Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Sun, 20 Dec 2015 15:34:36 -0600 Subject: [PATCH 1/3] fixed altitude calculation as per GDL 90 data interface spec --- main/traffic.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/main/traffic.go b/main/traffic.go index c51025bc..75b6c87c 100644 --- a/main/traffic.go +++ b/main/traffic.go @@ -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) From 227f4f5571f9fc343362f8ddb3ae6364494858e4 Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Sun, 20 Dec 2015 16:16:52 -0600 Subject: [PATCH 2/3] use smallest possible var size --- main/traffic.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main/traffic.go b/main/traffic.go index 75b6c87c..5ca46270 100644 --- a/main/traffic.go +++ b/main/traffic.go @@ -149,12 +149,12 @@ func makeTrafficReport(ti TrafficInfo) { // // Algo example at: https://play.golang.org/p/AQ0fpDudvi // - var alt int32 + var alt int16 if ti.Alt < -1000 || ti.Alt > 101350 { - alt = 0xFFF + alt = 0x0FFF } else { - // output guaranteed to be between 0x000 and 0xFFE - alt = int32((ti.Alt / 25) + 40) + // output guaranteed to be between 0x0000 and 0x0FFE + alt = int16((ti.Alt / 25) + 40) } msg[11] = byte((alt & 0xFF0) >> 4) // Altitude. msg[12] = byte((alt & 0x00F) << 4) From b765d55f7c5035593297a317fab7f52fcbe81cce Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Sun, 20 Dec 2015 18:20:38 -0600 Subject: [PATCH 3/3] updated example link --- main/traffic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/traffic.go b/main/traffic.go index 5ca46270..05765cb8 100644 --- a/main/traffic.go +++ b/main/traffic.go @@ -147,7 +147,7 @@ func makeTrafficReport(ti TrafficInfo) { // +101,350 feet 0xFFE // Invalid or unavailable 0xFFF // - // Algo example at: https://play.golang.org/p/AQ0fpDudvi + // Algo example at: https://play.golang.org/p/VXCckSdsvT // var alt int16 if ti.Alt < -1000 || ti.Alt > 101350 {