Skip to content

Commit

Permalink
Add new ForeFlight AHRS and ID GDL90 messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyoung committed Apr 6, 2018
1 parent 14a21ea commit 54ab7df
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
34 changes: 34 additions & 0 deletions main/gen_gdl90.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,39 @@ func makeStratuxHeartbeat() []byte {
return prepareMessage(msg)
}

/*
ForeFlight "ID Message".
Sends device information to ForeFlight.
*/
func makeFFIDMessage() []byte {
msg := make([]byte, 39)
msg[0] = 0x65 // Message type "ForeFlight".
msg[1] = 0 // ID message identifier.
msg[2] = 1 // Message version.
// Serial number. Set to "invalid" for now.
for i := 3; i <= 10; i++ {
msg[i] = 0xFF
}
devShortName := "Stratux" // Temporary. Will be populated in the future with other names.
if len(devShortName) > 8 {
devShortName = devShortName[:8] // 8 chars.
}
copy(msg[11:], devShortName)

devLongName := fmt.Sprintf("%s-%s", stratuxVersion, stratuxBuild)
if len(devLongName) > 16 {
devLongName = devLongName[:16] // 16 chars.
}
copy(msg[19:], devLongName)

msg[38] = 0x01 // Capabilities mask. MSL altitude for Ownship Geometric report.

return prepareMessage(msg)
}

func makeHeartbeat() []byte {
msg := make([]byte, 7)
// See p.10.
Expand Down Expand Up @@ -727,6 +760,7 @@ func heartBeatSender() {
sendGDL90(makeHeartbeat(), false)
sendGDL90(makeStratuxHeartbeat(), false)
sendGDL90(makeStratuxStatus(), false)
sendGDL90(makeFFIDMessage(), false)
makeOwnshipReport()
makeOwnshipGeometricAltitudeReport()

Expand Down
66 changes: 66 additions & 0 deletions main/gps.go
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,71 @@ func makeFFAHRSSimReport() {
sendMsg([]byte(s), NETWORK_AHRS_FFSIM, false)
}

/*
ForeFlight "AHRS Message".
Sends AHRS information to ForeFlight.
*/

func makeFFAHRSMessage() {
msg := make([]byte, 12)
msg[0] = 0x65 // Message type "ForeFlight".
msg[1] = 0x01 // AHRS message identifier.

// Values if invalid
pitch := int16(0x7FFF)
roll := int16(0x7FFF)
hdg := uint16(0xFFFF)
ias := uint16(0xFFFF)
tas := uint16(0xFFFF)

if isAHRSValid() {
if !isAHRSInvalidValue(mySituation.AHRSPitch) {
pitch = roundToInt16(mySituation.AHRSPitch * 10)
}
if !isAHRSInvalidValue(mySituation.AHRSRoll) {
roll = roundToInt16(mySituation.AHRSRoll * 10)
}
}

// Roll.
msg[2] = byte((roll >> 8) & 0xFF)
msg[3] = byte(roll & 0xFF)

// Pitch.
msg[4] = byte((pitch >> 8) & 0xFF)
msg[5] = byte(pitch & 0xFF)

// Heading.
msg[6] = byte((hdg >> 8) & 0xFF)
msg[7] = byte(hdg & 0xFF)

// Indicated Airspeed.
msg[8] = byte((ias >> 8) & 0xFF)
msg[9] = byte(ias & 0xFF)

// True Airspeed.
msg[10] = byte((tas >> 8) & 0xFF)
msg[11] = byte(tas & 0xFF)

sendMsg(prepareMessage(msg), NETWORK_AHRS_GDL90, false)
}

/*
ffAttitudeSender()
Send AHRS message in FF format every 200ms.
*/

func ffAttitudeSender() {
ticker := time.NewTicker(200 * time.Millisecond)
for {
<-ticker.C
makeFFAHRSMessage()
}
}

func makeAHRSGDL90Report() {
msg := make([]byte, 24)
msg[0] = 0x4c
Expand Down Expand Up @@ -2049,6 +2114,7 @@ func pollGPS() {
readyToInitGPS = true //TODO: Implement more robust method (channel control) to kill zombie serial readers
timer := time.NewTicker(4 * time.Second)
go gpsAttitudeSender()
go ffAttitudeSender()
for {
<-timer.C
// GPS enabled, was not connected previously?
Expand Down
2 changes: 1 addition & 1 deletion main/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func sensorAttitudeSender() {
mySituation.AHRSPitch = pitch / ahrs.Deg
mySituation.AHRSGyroHeading = heading / ahrs.Deg

// TODO westphae: until magnetometer calibration is performed, no mag heading
//TODO westphae: until magnetometer calibration is performed, no mag heading
mySituation.AHRSMagHeading = ahrs.Invalid
mySituation.AHRSSlipSkid = s.SlipSkid()
mySituation.AHRSTurnRate = s.RateOfTurn()
Expand Down

0 comments on commit 54ab7df

Please sign in to comment.