Skip to content

Commit

Permalink
Merge remote-tracking branch '0x74/devel/x_plane_feed' into xp11out
Browse files Browse the repository at this point in the history
  • Loading branch information
b3nn0 committed Jul 22, 2019
2 parents 97d6f04 + 3a9509d commit 94824f2
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ all:

xgen_gdl90:
go get -t -d -v ./main ./godump978 ./uatparse ./sensors
export CGO_CFLAGS_ALLOW="-L/root/stratux" && go build $(BUILDINFO) -p 4 main/gen_gdl90.go main/traffic.go main/gps.go main/network.go main/managementinterface.go main/sdr.go main/ping.go main/uibroadcast.go main/monotonic.go main/datalog.go main/equations.go main/sensors.go main/cputemp.go main/lowpower_uat.go main/flarm.go main/flarm-nmea.go main/networksettings.go
export CGO_CFLAGS_ALLOW="-L/root/stratux" && go build $(BUILDINFO) -p 4 main/gen_gdl90.go main/traffic.go main/gps.go main/network.go main/managementinterface.go main/sdr.go main/ping.go main/uibroadcast.go main/monotonic.go main/datalog.go main/equations.go main/sensors.go main/cputemp.go main/lowpower_uat.go main/flarm.go main/flarm-nmea.go main/networksettings.go main/xplane.go

fancontrol:
go get -t -d -v ./main
Expand Down
37 changes: 19 additions & 18 deletions main/gen_gdl90.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,27 +310,26 @@ func makeOwnshipReport() bool {
msg[4] = code[2] // Mode S address.
}

var tmp []byte
var lat float32
var lon float32
if selfOwnshipValid {
tmp = makeLatLng(curOwnship.Lat)
msg[5] = tmp[0] // Latitude.
msg[6] = tmp[1] // Latitude.
msg[7] = tmp[2] // Latitude.
tmp = makeLatLng(curOwnship.Lng)
msg[8] = tmp[0] // Longitude.
msg[9] = tmp[1] // Longitude.
msg[10] = tmp[2] // Longitude.
lat = curOwnship.Lat
lon = curOwnship.Lng
} else {
tmp = makeLatLng(mySituation.GPSLatitude)
msg[5] = tmp[0] // Latitude.
msg[6] = tmp[1] // Latitude.
msg[7] = tmp[2] // Latitude.
tmp = makeLatLng(mySituation.GPSLongitude)
msg[8] = tmp[0] // Longitude.
msg[9] = tmp[1] // Longitude.
msg[10] = tmp[2] // Longitude.
lat = mySituation.GPSLatitude
lon = mySituation.GPSLongitude
}

var tmp []byte
tmp = makeLatLng(lat)
msg[5] = tmp[0] // Latitude.
msg[6] = tmp[1] // Latitude.
msg[7] = tmp[2] // Latitude.
tmp = makeLatLng(lon)
msg[8] = tmp[0] // Longitude.
msg[9] = tmp[1] // Longitude.
msg[10] = tmp[2] // Longitude.

// This is **PRESSURE ALTITUDE**
alt := uint16(0xFFF) // 0xFFF "invalid altitude."
validAltf := false
Expand Down Expand Up @@ -437,6 +436,8 @@ func makeOwnshipReport() bool {
}

sendGDL90(prepareMessage(msg), false)
sendXPlane(createXPlaneGpsMsg(lat, lon, mySituation.GPSAltitudeMSL, groundTrack, float32(gdSpeed)), false)

return true
}

Expand Down Expand Up @@ -1239,7 +1240,7 @@ func defaultSettings() {
globalSettings.NetworkOutputs = []networkConnection{
{Conn: nil, Ip: "", Port: 4000, Capability: NETWORK_GDL90_STANDARD | NETWORK_AHRS_GDL90},
{Conn: nil, Ip: "", Port: 2000, Capability: NETWORK_FLARM_NMEA},
// {Conn: nil, Ip: "", Port: 49002, Capability: NETWORK_AHRS_FFSIM},
{Conn: nil, Ip: "", Port: 49002, Capability: NETWORK_POSITION_FFSIM | NETWORK_AHRS_FFSIM},
}
globalSettings.DEBUG = false
globalSettings.DisplayTrafficSource = false
Expand Down
7 changes: 3 additions & 4 deletions main/gps.go
Original file line number Diff line number Diff line change
Expand Up @@ -1873,10 +1873,8 @@ func gpsSerialReader() {
return
}

func makeFFAHRSSimReport() {
s := fmt.Sprintf("XATTStratux,%f,%f,%f", mySituation.AHRSGyroHeading, mySituation.AHRSPitch, mySituation.AHRSRoll)

sendMsg([]byte(s), NETWORK_AHRS_FFSIM, false)
func makeAHRSSimReport() {
sendXPlane(createXPlaneAttitudeMsg(float32(mySituation.AHRSGyroHeading), float32(mySituation.AHRSPitch), float32(mySituation.AHRSRoll)), false)
}

/*
Expand Down Expand Up @@ -2051,6 +2049,7 @@ func gpsAttitudeSender() {
mySituation.AHRSLastAttitudeTime = stratuxClock.Time

makeAHRSGDL90Report()
makeAHRSSimReport()
}
mySituation.muGPSPerformance.Unlock()
}
Expand Down
12 changes: 9 additions & 3 deletions main/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
package main

import (
"github.com/tarm/serial"
"golang.org/x/net/icmp"
"golang.org/x/net/ipv4"
"io/ioutil"
"log"
"math"
Expand All @@ -23,6 +20,10 @@ import (
"strings"
"sync"
"time"

"github.com/tarm/serial"
"golang.org/x/net/icmp"
"golang.org/x/net/ipv4"
)

type networkMessage struct {
Expand Down Expand Up @@ -70,6 +71,7 @@ const (
NETWORK_AHRS_FFSIM = 2
NETWORK_AHRS_GDL90 = 4
NETWORK_FLARM_NMEA = 8
NETWORK_POSITION_FFSIM = 16
dhcp_lease_file = "/var/lib/dhcp/dhcpd.leases"
dhcp_lease_dir = "/var/lib/dhcp"
extra_hosts_file = "/etc/stratux-static-hosts.conf"
Expand Down Expand Up @@ -465,6 +467,10 @@ func sendGDL90(msg []byte, queueable bool) {
sendMsg(msg, NETWORK_GDL90_STANDARD, queueable)
}

func sendXPlane(msg []byte, queueable bool) {
sendMsg(msg, NETWORK_POSITION_FFSIM, queueable)
}

func monitorDHCPLeases() {
timer := time.NewTicker(30 * time.Second)
for {
Expand Down
1 change: 1 addition & 0 deletions main/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func sensorAttitudeSender() {
mySituation.muAttitude.Unlock()

makeAHRSGDL90Report() // Send whether or not valid - the function will invalidate the values as appropriate
makeAHRSSimReport()

// Send to AHRS debugging server.
if ahrswebListener != nil {
Expand Down
10 changes: 10 additions & 0 deletions main/traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ func sendTrafficUpdates() {
} else {
//log.Printf("FLARM output: Traffic %X couldn't be translated\n", ti.Icao_addr)
}

var trafficCallsign string
if len(ti.Tail) > 0 {
trafficCallsign = ti.Tail
} else {
trafficCallsign = fmt.Sprintf("%X_%d", ti.Icao_addr, ti.Squawk)
}

// send traffic message to X-Plane
sendXPlane(createXPlaneTrafficMsg(ti.Icao_addr, ti.Lat, ti.Lng, ti.Alt, uint32(ti.Speed), int32(ti.Vvel), ti.OnGround, uint32(ti.Track), trafficCallsign), false)
}
}
}
Expand Down
48 changes: 48 additions & 0 deletions main/xplane.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright (c) 2018 Thorsten Biermann
Distributable under the terms of The "BSD New" License
that can be found in the LICENSE file, herein included
as part of this header.
xplane.go: Routines for generating X-Plane data feed
*/

package main

import (
"fmt"
"regexp"
)

func convertKnotsToXPlaneSpeed(knots float32) float32 {
return knots / 1.945
}

func createXPlaneGpsMsg(latDeg float32, lonDeg float32, altMslFt float32, trackDeg float32, speedKt float32) []byte {
// example: XGPS1,-122.298432,47.450756,420.9961,349.7547,57.9145
return []byte(fmt.Sprintf("XGPS1,%.6f,%.6f,%.4f,%.4f,%.4f\n", lonDeg, latDeg, convertFeetToMeters(altMslFt), trackDeg, convertKnotsToXPlaneSpeed(speedKt)))
}

func createXPlaneAttitudeMsg(headingDeg float32, pitchDeg float32, rollDeg float32) []byte {
// example: XATT1,345.1,-1.1,-12.5,0.1374,0.0954,-0.0444,-17.0,-1.2,-65.0,-0.01,1.63,0.02
// TODO find out what the remaining parameters are for
return []byte(fmt.Sprintf("XATT1,%.1f,%.1f,%.1f,%.4f,%.4f,%.4f,%.1f,%.1f,%.1f,%.2f,%.2f,%.2f\n", headingDeg, pitchDeg, rollDeg, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0))
}

func createXPlaneTrafficMsg(targetId uint32, latDeg float32, lonDeg float32, altFt int32, hSpeedKt uint32, vSpeedFpm int32, onGround bool, trackDeg uint32, callSign string) []byte {
// example: XTRA1,1,47.435484,-122.304048,351,1,0,62,0,N172SP

// prepare airborne/ground information
airborneValue := uint8(0)
if onGround {
airborneValue = 0
} else {
airborneValue = 1
}

// prepare callsign (remove all non-alphanumeric characters)
regEx, _ := regexp.Compile("[^a-zA-Z0-9]+")
cleanCallSign := regEx.ReplaceAllString(callSign, "")

return []byte(fmt.Sprintf("XTRA1,%d,%.6f,%.6f,%d,%d,%d,%d,%d,%s\n", targetId, latDeg, lonDeg, altFt, vSpeedFpm, airborneValue, trackDeg, hSpeedKt, cleanCallSign))
}

0 comments on commit 94824f2

Please sign in to comment.