Fix Issue 88, Wrong Longitude in ADSB RX (#242)

This commit is contained in:
Tyler Roussos 2019-05-21 11:44:14 -04:00 committed by Furrtek
parent aa77657092
commit 9f587e6085
3 changed files with 18 additions and 9 deletions

View File

@ -220,7 +220,7 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
callsign = decode_frame_id(frame); callsign = decode_frame_id(frame);
entry.set_callsign(callsign); entry.set_callsign(callsign);
logentry+=callsign+" "; logentry+=callsign+" ";
} else if ((msg_type >= 9) && (msg_type <= 18)) { } else if (((msg_type >= 9) && (msg_type <= 18)) || ((msg_type >= 20) && (msg_type <= 22))) {
entry.set_frame_pos(frame, raw_data[6] & 4); entry.set_frame_pos(frame, raw_data[6] & 4);
if (entry.pos.valid) { if (entry.pos.valid) {

View File

@ -211,7 +211,7 @@ void encode_frame_pos(ADSBFrame& frame, const uint32_t ICAO_address, const int32
adsb_pos decode_frame_pos(ADSBFrame& frame_even, ADSBFrame& frame_odd) { adsb_pos decode_frame_pos(ADSBFrame& frame_even, ADSBFrame& frame_odd) {
uint8_t * raw_data; uint8_t * raw_data;
uint32_t latcprE, latcprO, loncprE, loncprO; uint32_t latcprE, latcprO, loncprE, loncprO;
float latE, latO, m, Dlon; float latE, latO, m, Dlon, cpr_lon_odd, cpr_lon_even, cpr_lat_odd, cpr_lat_even;
int ni; int ni;
adsb_pos position { false, 0, 0, 0 }; adsb_pos position { false, 0, 0, 0 };
@ -237,10 +237,17 @@ adsb_pos decode_frame_pos(ADSBFrame& frame_even, ADSBFrame& frame_odd) {
latcprO = ((frame_data_odd[6] & 3) << 15) | (frame_data_odd[7] << 7) | (frame_data_odd[8] >> 1); latcprO = ((frame_data_odd[6] & 3) << 15) | (frame_data_odd[7] << 7) | (frame_data_odd[8] >> 1);
loncprO = ((frame_data_odd[8] & 1) << 16) | (frame_data_odd[9] << 8) | frame_data_odd[10]; loncprO = ((frame_data_odd[8] & 1) << 16) | (frame_data_odd[9] << 8) | frame_data_odd[10];
// Calculate the coefficients
cpr_lon_even = loncprE / CPR_MAX_VALUE;
cpr_lon_odd = loncprO / CPR_MAX_VALUE;
cpr_lat_odd = latcprO / CPR_MAX_VALUE;
cpr_lat_even = latcprE / CPR_MAX_VALUE;
// Compute latitude index // Compute latitude index
float j = floor((((59.0 * latcprE) - (60.0 * latcprO)) / 131072.0) + 0.5); float j = floor(((59.0 * cpr_lat_even) - (60.0 * cpr_lat_odd)) + 0.5);
latE = (360.0 / 60.0) * (cpr_mod(j, 60) + (latcprE / 131072.0)); latE = (360.0 / 60.0) * (cpr_mod(j, 60) + cpr_lat_even);
latO = (360.0 / 59.0) * (cpr_mod(j, 59) + (latcprO / 131072.0)); latO = (360.0 / 59.0) * (cpr_mod(j, 59) + cpr_lat_odd);
if (latE >= 270) latE -= 360; if (latE >= 270) latE -= 360;
if (latO >= 270) latO -= 360; if (latO >= 270) latO -= 360;
@ -255,9 +262,9 @@ adsb_pos decode_frame_pos(ADSBFrame& frame_even, ADSBFrame& frame_odd) {
ni = cpr_N(latE, 0); ni = cpr_N(latE, 0);
Dlon = 360.0 / ni; Dlon = 360.0 / ni;
m = floor((((loncprE * (cpr_NL(latE) - 1)) - (loncprO * cpr_NL(latE))) / 131072.0) + 0.5); m = floor((cpr_lon_even * (cpr_NL(latE) - 1)) - (cpr_lon_odd * cpr_NL(latE)) + 0.5);
position.longitude = Dlon * (cpr_mod(m, ni) + loncprE / 131072.0); position.longitude = Dlon * (cpr_mod(m, ni) + cpr_lon_even);
position.latitude = latE; position.latitude = latE;
} else { } else {
@ -265,9 +272,9 @@ adsb_pos decode_frame_pos(ADSBFrame& frame_even, ADSBFrame& frame_odd) {
ni = cpr_N(latO, 1); ni = cpr_N(latO, 1);
Dlon = 360.0 / ni; Dlon = 360.0 / ni;
m = floor((((loncprE * (cpr_NL(latO) - 1)) - (loncprO * cpr_NL(latO))) / 131072.0) + 0.5); m = floor((cpr_lon_even * (cpr_NL(latO) - 1)) - (cpr_lon_odd * cpr_NL(latO)) + 0.5);
position.longitude = Dlon * (cpr_mod(m, ni) + loncprO / 131072.0); position.longitude = Dlon * (cpr_mod(m, ni) + cpr_lon_odd);
position.latitude = latO; position.latitude = latO;
} }

View File

@ -56,6 +56,8 @@ struct adsb_pos {
int32_t altitude; int32_t altitude;
}; };
const float CPR_MAX_VALUE = 131072.0;
const float adsb_lat_lut[58] = { const float adsb_lat_lut[58] = {
10.47047130, 14.82817437, 18.18626357, 21.02939493, 10.47047130, 14.82817437, 18.18626357, 21.02939493,
23.54504487, 25.82924707, 27.93898710, 29.91135686, 23.54504487, 25.82924707, 27.93898710, 29.91135686,