Skip to content

Commit e0b6904

Browse files
committed
Fix time for adsb list
1 parent 9fa5c2a commit e0b6904

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

src/main/io/adsb.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,6 @@ adsbVehicle_t *findVehicleClosest(void) {
9898
* @return
9999
*/
100100
adsbVehicle_t *findVehicleClosestLimit(int32_t maxVerticalDistance) {
101-
102-
/* static int32_t lat = 492551325;
103-
adsbVehicle_t *v1 = &adsbVehiclesList[0];
104-
105-
v1->vehicleValues.gps.lat = lat;
106-
v1->vehicleValues.gps.lon = 165428489;
107-
v1->vehicleValues.alt = 1000 * 100;
108-
v1->vehicleValues.tslc = 0;
109-
v1->vehicleValues.emitterType = 5;
110-
v1->vehicleValues.horVelocity = 55277;
111-
v1->ttl = 10;
112-
memcpy(v1->vehicleValues.callsign, "DUMMY ", 9);
113-
114-
lat += 1000;
115-
116-
recalculateVehicle(v1);*/
117-
118101
adsbVehicle_t *adsbLocal = NULL;
119102
for (uint8_t i = 0; i < MAX_ADSB_VEHICLES; i++) {
120103
if(adsbVehiclesList[i].ttl > 0 && adsbVehiclesList[i].calculatedVehicleValues.valid){
@@ -187,14 +170,15 @@ void adsbNewVehicle(adsbVehicleValues_t* vehicleValuesLocal) {
187170
adsbVehicle_t *vehicle = NULL;
188171

189172
vehicle = findVehicleByIcao(vehicleValuesLocal->icao);
190-
if(vehicle != NULL && vehicleValuesLocal->tslc > ADSB_MAX_SECONDS_KEEP_INACTIVE_PLANE_IN_LIST){
191-
vehicle->ttl = 0;
173+
if(vehicleValuesLocal->tslc > ADSB_MAX_SECONDS_KEEP_INACTIVE_PLANE_IN_LIST){
174+
if(vehicle != NULL){
175+
vehicle->ttl = 0;
176+
}
192177
return;
193178
}
194179

195180
// non GPS mode, GPS is not fix, just find free space in list or by icao and save vehicle without calculated values
196181
if (!enviromentOkForCalculatingDistaceBearing()) {
197-
198182
if(vehicle == NULL){
199183
vehicle = findFreeSpaceInList();
200184
}
@@ -217,6 +201,16 @@ void adsbNewVehicle(adsbVehicleValues_t* vehicleValuesLocal) {
217201

218202
if(vehicle == NULL){
219203
vehicle = findVehicleFarthest();
204+
if(vehicle != NULL)
205+
{
206+
//calculate distance to new vehicle, we need to compare if new vehicle is closer than the farthest plane
207+
fpVector3_t vehicleVector;
208+
geoConvertGeodeticToLocal(&vehicleVector, &posControl.gpsOrigin, &vehicleValuesLocal->gps, GEO_ALT_RELATIVE);
209+
if(calculateDistanceToDestination(&vehicleVector) > vehicle->calculatedVehicleValues.dist){
210+
//saved vehicle in list is closer, no need to update vehicle in list
211+
vehicle = NULL;
212+
}
213+
}
220214
}
221215

222216
if (vehicle != NULL) {

0 commit comments

Comments
 (0)