Move Mode C altitude calc into mode A/C message decoding.

If SPI is set, it cannot be mode C.
This commit is contained in:
Oliver Jowett 2016-03-20 19:47:27 +00:00
parent 85aa200947
commit 7a58e3cdc5
2 changed files with 27 additions and 22 deletions

View file

@ -75,7 +75,7 @@ int ModeAToModeC(unsigned int ModeA)
//========================================================================= //=========================================================================
// //
void decodeModeAMessage(struct modesMessage *mm, int ModeA) void decodeModeAMessage(struct modesMessage *mm, int ModeA)
{ {
mm->msgtype = 32; // Valid Mode S DF's are DF-00 to DF-31. mm->msgtype = 32; // Valid Mode S DF's are DF-00 to DF-31.
// so use 32 to indicate Mode A/C // so use 32 to indicate Mode A/C
@ -93,10 +93,19 @@ void decodeModeAMessage(struct modesMessage *mm, int ModeA)
// Flag ident in flight status // Flag ident in flight status
mm->fs = ModeA & 0x0080; mm->fs = ModeA & 0x0080;
// Decode an altitude if this looks like a possible mode C
if (!mm->fs) {
int modeC = ModeAToModeC(ModeA);
if (modeC >= -12) {
mm->altitude = modeC * 100;
mm->bFlags |= MODES_ACFLAGS_ALTITUDE_VALID;
}
}
// Not much else we can tell from a Mode A/C reply. // Not much else we can tell from a Mode A/C reply.
// Just fudge up a few bits to keep other code happy // Just fudge up a few bits to keep other code happy
mm->correctedbits = 0; mm->correctedbits = 0;
} }
// //
// ===================== Mode A/C detection and decoding =================== // ===================== Mode A/C detection and decoding ===================
// //

View file

@ -73,13 +73,9 @@ struct aircraft *trackCreateAircraft(struct modesMessage *mm) {
// set them once here during initialisation, and don't bother to set them every // set them once here during initialisation, and don't bother to set them every
// time this ModeA/C is received again in the future // time this ModeA/C is received again in the future
if (mm->msgtype == 32) { if (mm->msgtype == 32) {
int modeC = ModeAToModeC(mm->modeA | mm->fs);
a->modeACflags = MODEAC_MSG_FLAG; a->modeACflags = MODEAC_MSG_FLAG;
if (modeC < -12) { if (!(mm->bFlags & MODES_ACFLAGS_ALTITUDE_VALID)) {
a->modeACflags |= MODEAC_MSG_MODEA_ONLY; a->modeACflags |= MODEAC_MSG_MODEA_ONLY;
} else {
mm->altitude = modeC * 100;
mm->bFlags |= MODES_ACFLAGS_ALTITUDE_VALID;
} }
} }