コード例 #1
0
ファイル: LKFlarm.cpp プロジェクト: AlphaLima/LK8000
void FLARM_RefreshSlots(NMEA_INFO *pGPS) {
  int i;
  double passed;
//  if (pGPS->FLARM_Available)
  {
	static unsigned short iTraceSpaceCnt = 0;
	if(iTraceSpaceCnt++ > GC_TRACE_TIME_SKIP) iTraceSpaceCnt =0;
	#ifdef DEBUG_LKT
	StartupStore(_T("... [CALC thread] RefreshSlots\n"));
	#endif

	for (i=0; i<FLARM_MAX_TRAFFIC; i++) {
		if (pGPS->FLARM_Traffic[i].ID>0) {

			if ( pGPS->Time< pGPS->FLARM_Traffic[i].Time_Fix) {
				// time gone back to to Replay mode?
				#ifdef DEBUG_LKT
				StartupStore(_T("...... Refresh Back in time! Removing:%s"),NEWLINE);
				FLARM_DumpSlot(pGPS,i);
				#endif
				if (pGPS->FLARM_Traffic[i].Locked) {
					#ifdef DEBUG_LKT
					StartupStore(_T("...... (it was a LOCKED target, unlocking)%s"),NEWLINE);
					#endif
					LKTargetIndex=-1;
					LKTargetType=LKT_TYPE_NONE;
					// reset Virtual waypoint in any case
					WayPointList[RESWP_FLARMTARGET].Latitude   = RESWP_INVALIDNUMBER;
					WayPointList[RESWP_FLARMTARGET].Longitude  = RESWP_INVALIDNUMBER;
					WayPointList[RESWP_FLARMTARGET].Altitude   = RESWP_INVALIDNUMBER;
				}
				FLARM_EmptySlot(pGPS,i);
				continue;
			}

			passed= pGPS->Time-pGPS->FLARM_Traffic[i].Time_Fix;

			// if time has passed > zombie, then we remove it
			if (passed > LKTime_Zombie) {
				if (pGPS->FLARM_Traffic[i].Locked) {
					#ifdef DEBUG_LKT
					StartupStore(_T("...... Zombie overtime index=%d is LOCKED, no remove\n"),i);
					#endif
					continue;
				}
				#ifdef DEBUG_LKT
				StartupStore(_T("... Refresh Removing old zombie (passed=%f Fix=%f Now=%f):%s"),
					passed,
					pGPS->FLARM_Traffic[i].Time_Fix,
					pGPS->Time,
					NEWLINE);
				FLARM_DumpSlot(pGPS,i);
				#endif
				FLARM_EmptySlot(pGPS,i);
				continue;
			}

			// if time has passed > ghost, then it is a zombie
			// Ghosts are not visible on map and radar, only in infopages
			if (passed > LKTime_Ghost) {
				if (pGPS->FLARM_Traffic[i].Status == LKT_ZOMBIE) continue;
				#ifdef DEBUG_LKT
				StartupStore(_T("... Refresh Change to zombie:%s"),NEWLINE);
				FLARM_DumpSlot(pGPS,i);
				#endif
				pGPS->FLARM_Traffic[i].Status = LKT_ZOMBIE;
				continue;
			}

			// if time has passed > real, than it is a ghost
			// Shadows are shown on map as reals.
			if (passed > LKTime_Real) {
				if (pGPS->FLARM_Traffic[i].Status == LKT_GHOST) continue;
				#ifdef DEBUG_LKT
				StartupStore(_T("... Refresh Change to ghost:%s"),NEWLINE);
				FLARM_DumpSlot(pGPS,i);
				#endif
				pGPS->FLARM_Traffic[i].Status = LKT_GHOST;
				continue;
			}

			// Then it is real traffic
			pGPS->FLARM_Traffic[i].Status = LKT_REAL; // 100325 BUGFIX missing

			if(iTraceSpaceCnt == 0) {

				LKASSERT(pGPS->FLARMTRACE_iLastPtr>=0 && pGPS->FLARMTRACE_iLastPtr<MAX_FLARM_TRACES);
				pGPS->FLARM_RingBuf[pGPS->FLARMTRACE_iLastPtr].fLat = pGPS->FLARM_Traffic[i].Latitude;
				pGPS->FLARM_RingBuf[pGPS->FLARMTRACE_iLastPtr].fLon = pGPS->FLARM_Traffic[i].Longitude;

				double Vario = pGPS->FLARM_Traffic[i].Average30s;
				int iColorIdx = (int)(2*Vario  -0.5)+NO_VARIO_COLORS/2;
				iColorIdx = max( iColorIdx, 0);
				iColorIdx = min( iColorIdx, NO_VARIO_COLORS-1);

				pGPS->FLARM_RingBuf[pGPS->FLARMTRACE_iLastPtr].iColorIdx = iColorIdx;
				pGPS->FLARMTRACE_iLastPtr++;

				if(pGPS->FLARMTRACE_iLastPtr >= MAX_FLARM_TRACES) {
					pGPS->FLARMTRACE_iLastPtr=0;
					pGPS->FLARMTRACE_bBuffFull = true;
				}
			}
		} // ID >0
	} // for all traffic

#ifdef OWN_FLARM_TRACES
	double Vario=0 ;

	if(iTraceSpaceCnt == 0) {

		LKASSERT(pGPS->FLARMTRACE_iLastPtr>=0 && pGPS->FLARMTRACE_iLastPtr<MAX_FLARM_TRACES);
		pGPS->FLARM_RingBuf[pGPS->FLARMTRACE_iLastPtr].fLat = pGPS->Latitude;
		pGPS->FLARM_RingBuf[pGPS->FLARMTRACE_iLastPtr].fLon = pGPS->Longitude;

        if(pGPS->NettoVarioAvailable)
		  Vario = pGPS->NettoVario;
        else
        {
          if(pGPS->VarioAvailable)
    		Vario = pGPS->Vario;
          else
          {
        	Vario =  CALCULATED_INFO.Vario;
          }
        }
		int iColorIdx = (int)(2*Vario  -0.5)+NO_VARIO_COLORS/2;
		iColorIdx = max( iColorIdx, 0);
		iColorIdx = min( iColorIdx, NO_VARIO_COLORS-1);

		pGPS->FLARM_RingBuf[pGPS->FLARMTRACE_iLastPtr].iColorIdx = iColorIdx;
		pGPS->FLARMTRACE_iLastPtr++;

		if(pGPS->FLARMTRACE_iLastPtr >= MAX_FLARM_TRACES) {
			pGPS->FLARMTRACE_iLastPtr=0;
			pGPS->FLARMTRACE_bBuffFull = true;
		}
	}
#endif
  } // if flarm available
}
コード例 #2
0
ファイル: LKFlarm.cpp プロジェクト: AlphaLima/LK8000
int FLARM_FindSlot(NMEA_INFO *pGPS, long Id)
{
  int i;
  for (i=0; i<FLARM_MAX_TRAFFIC; i++) {

	// find position in existing slot
	if (Id==pGPS->FLARM_Traffic[i].ID) {
		//#ifdef DEBUG_LKT
		//StartupStore(_T("... FindSlot ID=%lx found in slot %d\n"),Id,i);
		//#endif
		return i;
	}
	// find old empty slot
  }
  // not found, so try to find an empty slot
  for (i=0; i<FLARM_MAX_TRAFFIC; i++) {
	if (pGPS->FLARM_Traffic[i].ID<=0) { // 100327 <= was ==
		// this is a new target
		#ifdef DEBUG_LKT
		StartupStore(_T("... FLARM ID=%lx assigned NEW SLOT=%d\n"),Id,i);
		#endif
		return i;
	}
  }
  // remove a zombie to make place
  int toremove=-1;
  for (i=0; i<FLARM_MAX_TRAFFIC; i++) {
	if ( (pGPS->FLARM_Traffic[i].ID>0) && (pGPS->FLARM_Traffic[i].Status==LKT_ZOMBIE) &&
		(!pGPS->FLARM_Traffic[i].Locked) ) { 
		// if this is the first zombie, assign it and continue searching
		if (toremove==-1) {
			toremove=i;
		} else {
			// if this zombie is older than previous one
			if ( pGPS->FLARM_Traffic[i].Time_Fix < pGPS->FLARM_Traffic[toremove].Time_Fix ) {
				toremove=i;
			}
		}
	}
  }
  // did we find a zombie to remove?
  if (toremove>=0) {
	#ifdef DEBUG_LKT
	StartupStore(_T("... Removing OLDEST zombie:%s"),NEWLINE);
	FLARM_DumpSlot(pGPS,toremove);
	#endif
	FLARM_EmptySlot(pGPS,toremove);
	return toremove;
  }
  // remove a ghost to make place
  toremove=-1;
  for (i=0; i<FLARM_MAX_TRAFFIC; i++) {
	if ( (pGPS->FLARM_Traffic[i].ID>0) && (pGPS->FLARM_Traffic[i].Status==LKT_GHOST) &&
		(!pGPS->FLARM_Traffic[i].Locked) ) { 
		// if this is the first ghost, assign it and continue searching
		if (toremove==-1) {
			toremove=i;
		} else {
			// if this ghost is older than previous one
			if ( pGPS->FLARM_Traffic[i].Time_Fix < pGPS->FLARM_Traffic[toremove].Time_Fix ) {
				toremove=i;
			}
		}
	}
  }
  // did we find a ghost to remove?
  if (toremove>=0) {
	#ifdef DEBUG_LKT
	StartupStore(_T("... Removing OLDEST ghost:%s"),NEWLINE);
	FLARM_DumpSlot(pGPS,toremove);
	#endif
	FLARM_EmptySlot(pGPS,toremove);
	return toremove;
  }

  #ifdef DEBUG_LKT
  StartupStore(_T("... ID=<%lx> NO SPACE in slots!\n"),Id);
  #endif
  // still not found and no empty slots left, buffer is full
  return -1;
}
コード例 #3
0
ファイル: Parser.cpp プロジェクト: miza/LK8000
void FLARM_RefreshSlots(NMEA_INFO *GPS_INFO) {
  int i;
  bool present = false;
  double passed;
  if (GPS_INFO->FLARM_Available) {

	#ifdef DEBUG_LKT
	StartupStore(_T("... [CALC thread] RefreshSlots\n"));
	#endif

	for (i=0; i<FLARM_MAX_TRAFFIC; i++) {
		if (GPS_INFO->FLARM_Traffic[i].ID>0) {

			if ( GPS_INFO->Time< GPS_INFO->FLARM_Traffic[i].Time_Fix) {
				// time gone back to to Replay mode?
				#ifdef DEBUG_LKT
				StartupStore(_T("...... Refresh Back in time! Removing:%s"),NEWLINE);
				FLARM_DumpSlot(GPS_INFO,i);
				#endif
				if (GPS_INFO->FLARM_Traffic[i].Locked) {
					#ifdef DEBUG_LKT
					StartupStore(_T("...... (it was a LOCKED target, unlocking)%s"),NEWLINE);
					#endif
					LKTargetIndex=-1;
					LKTargetType=LKT_TYPE_NONE;
					// reset Virtual waypoint in any case
					WayPointList[RESWP_FLARMTARGET].Latitude   = RESWP_INVALIDNUMBER;
					WayPointList[RESWP_FLARMTARGET].Longitude  = RESWP_INVALIDNUMBER;
					WayPointList[RESWP_FLARMTARGET].Altitude   = RESWP_INVALIDNUMBER;
				}
				FLARM_EmptySlot(GPS_INFO,i);
				continue;
			}

			passed= GPS_INFO->Time-GPS_INFO->FLARM_Traffic[i].Time_Fix;

			// if time has passed > zombie, then we remove it
			if (passed > LKTime_Zombie) {
				if (GPS_INFO->FLARM_Traffic[i].Locked) {
					#ifdef DEBUG_LKT
					StartupStore(_T("...... Zombie overtime index=%d is LOCKED, no remove\n"),i);
					#endif
					continue;
				}
				#ifdef DEBUG_LKT
				StartupStore(_T("... Refresh Removing old zombie (passed=%f Fix=%f Now=%f):%s"),
					passed,
					GPS_INFO->FLARM_Traffic[i].Time_Fix,
					GPS_INFO->Time,
					NEWLINE);
				FLARM_DumpSlot(GPS_INFO,i);
				#endif
				FLARM_EmptySlot(GPS_INFO,i);
				continue;
			}

			// if time has passed > ghost, then it is a zombie
			// Ghosts are not visible on map and radar, only in infopages
			if (passed > LKTime_Ghost) {
				if (GPS_INFO->FLARM_Traffic[i].Status == LKT_ZOMBIE) continue;
				#ifdef DEBUG_LKT
				StartupStore(_T("... Refresh Change to zombie:%s"),NEWLINE);
				FLARM_DumpSlot(GPS_INFO,i);
				#endif
				GPS_INFO->FLARM_Traffic[i].Status = LKT_ZOMBIE;
				continue;
			}

			// if time has passed > real, than it is a ghost
			// Shadows are shown on map as reals.
			if (passed > LKTime_Real) {
				if (GPS_INFO->FLARM_Traffic[i].Status == LKT_GHOST) continue;
				#ifdef DEBUG_LKT
				StartupStore(_T("... Refresh Change to ghost:%s"),NEWLINE);
				FLARM_DumpSlot(GPS_INFO,i);
				#endif
				GPS_INFO->FLARM_Traffic[i].Status = LKT_GHOST;
				present = true;
				continue;
			}

			// Then it is real traffic
			present=true;
			GPS_INFO->FLARM_Traffic[i].Status = LKT_REAL; // 100325 BUGFIX missing

			/*
			} else {
				if (GPS_INFO->FLARM_Traffic[i].AlarmLevel>0) {
					GaugeFLARM::Suppress = false; // NO USE
				}
				present = true;
			}
			*/
		}
	}
  }
  #ifndef NOFLARMGAUGE
  GaugeFLARM::TrafficPresent(present);
  #endif
}