Skip to content

Commit

Permalink
-Set true/magnetic heading correctly for ForeFlight.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-gomez-windhover committed Feb 29, 2024
1 parent 40e4fb3 commit f24edfc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Logs
**/.classpath
.classpath
logs
*.log
npm-debug.log*
Expand Down
36 changes: 21 additions & 15 deletions src/main/java/com/windhoverlabs/yamcs/gdl90/AHRS.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,36 @@ public byte[] toBytes() throws Exception {
messageStream.write(packedPitchBytes[3]);

// Heading = -80;
// Heading = 147;
// Heading = 0b10110111110;
int packedHeading = packDegrees(FFB_PackForeFlightHeading((Heading)));

// packedHeading = packedHeading | 0b00000101101111100000000000000000;

// packedHeading = packedHeading | 0b00000000000000000000000000000001;

// packedHeading = packedHeading | 1 << 31;

// packedHeading = 0xffffffff;

// 0x01C2 = 450
// int packedHeading = packDegrees(45);

byte[] packedHeadingBytes = ByteBuffer.allocate(4).putInt(packedHeading).array();

byte iaByte = packedHeadingBytes[2];
switch (HeadingType) {
case TRUE_HEADING:
iaByte = (byte) (iaByte | (0 << 7));

// NOTE:It seems that the ForeFlight Docs have these definitions flipped
// switch (HeadingType) {
// case TRUE_HEADING:
// // packedHeading = packedHeading | (1 << 15);
// iaByte = (byte) setNibble(packedHeadingBytes[2], 0x01, 1);
//
// break;
// case MAGNETIC:
// // packedHeading = packedHeading | ~(1 << 15);
// iaByte = (byte) setNibble(packedHeadingBytes[2], 0x00, 1);
//
// break;
// default:
// break;
// }
break;
case MAGNETIC:
iaByte = (byte) (iaByte | (1 << 7));

break;
default:
break;
}
messageStream.write(iaByte);
messageStream.write(packedHeadingBytes[3]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public byte[] toBytes() throws Exception {
byte dmByte = (byte) AltitudeBytes[2];

if (TrueHeading) {
// dmByte = (byte) (dmByte | (1 << 0));
dmByte = (byte) (dmByte | (1 << 0));
dmByte = (byte) (dmByte | (1 << 1));
dmByte = (byte) (dmByte | (1 << 3));
}
Expand Down

0 comments on commit f24edfc

Please sign in to comment.