Don't mark undecodable altitudes as ALTITUDE_VALID when decoding.

This commit is contained in:
Oliver Jowett 2015-02-09 22:53:18 +00:00
parent 54677f3ae0
commit 474fe45256

View file

@ -101,6 +101,9 @@ static int decodeID13Field(int ID13Field) {
return (hexGillham); return (hexGillham);
} }
#define INVALID_ALTITUDE (-9999)
// //
//========================================================================= //=========================================================================
// //
@ -123,15 +126,17 @@ static int decodeAC13Field(int AC13Field, int *unit) {
} else { } else {
// N is an 11 bit Gillham coded altitude // N is an 11 bit Gillham coded altitude
int n = ModeAToModeC(decodeID13Field(AC13Field)); int n = ModeAToModeC(decodeID13Field(AC13Field));
if (n < -12) {n = 0;} if (n < -12) {
return INVALID_ALTITUDE;
}
return (100 * n); return (100 * n);
} }
} else { } else {
*unit = MODES_UNIT_METERS; *unit = MODES_UNIT_METERS;
// TODO: Implement altitude when meter unit is selected // TODO: Implement altitude when meter unit is selected
return INVALID_ALTITUDE;
} }
return 0;
} }
// //
//========================================================================= //=========================================================================
@ -153,7 +158,9 @@ static int decodeAC12Field(int AC12Field, int *unit) {
int n = ((AC12Field & 0x0FC0) << 1) | int n = ((AC12Field & 0x0FC0) << 1) |
(AC12Field & 0x003F); (AC12Field & 0x003F);
n = ModeAToModeC(decodeID13Field(n)); n = ModeAToModeC(decodeID13Field(n));
if (n < -12) {n = 0;} if (n < -12) {
return INVALID_ALTITUDE;
}
return (100 * n); return (100 * n);
} }
@ -561,8 +568,9 @@ int decodeModesMessage(struct modesMessage *mm, unsigned char *msg)
if (mm->msgtype == 0 || mm->msgtype == 4 || mm->msgtype == 16 || mm->msgtype == 20) { if (mm->msgtype == 0 || mm->msgtype == 4 || mm->msgtype == 16 || mm->msgtype == 20) {
int AC13Field = ((msg[2] << 8) | msg[3]) & 0x1FFF; int AC13Field = ((msg[2] << 8) | msg[3]) & 0x1FFF;
if (AC13Field) { // Only attempt to decode if a valid (non zero) altitude is present if (AC13Field) { // Only attempt to decode if a valid (non zero) altitude is present
mm->bFlags |= MODES_ACFLAGS_ALTITUDE_VALID;
mm->altitude = decodeAC13Field(AC13Field, &mm->unit); mm->altitude = decodeAC13Field(AC13Field, &mm->unit);
if (mm->altitude != INVALID_ALTITUDE)
mm->bFlags |= MODES_ACFLAGS_ALTITUDE_VALID;
} }
} }
@ -883,8 +891,9 @@ static void decodeExtendedSquitter(struct modesMessage *mm)
} }
if (AC12Field) {// Only attempt to decode if a valid (non zero) altitude is present if (AC12Field) {// Only attempt to decode if a valid (non zero) altitude is present
mm->bFlags |= MODES_ACFLAGS_ALTITUDE_VALID;
mm->altitude = decodeAC12Field(AC12Field, &mm->unit); mm->altitude = decodeAC12Field(AC12Field, &mm->unit);
if (mm->altitude != INVALID_ALTITUDE)
mm->bFlags |= MODES_ACFLAGS_ALTITUDE_VALID;
} }
if (metype == 0 || metype == 18 || metype == 22) if (metype == 0 || metype == 18 || metype == 22)