Beispiel #1
0
static void UpdateValuesTimes(void) {
  WndProperty *wp;
  TCHAR Temp[1000];
  double sunsettime;
  int sunsethours;
  int sunsetmins;

  sunsettime = DoSunEphemeris(GPS_INFO.Longitude,
                              GPS_INFO.Latitude);
  sunsethours = (int)sunsettime;
  sunsetmins = (int)((sunsettime-sunsethours)*60);

  wp = (WndProperty*)wf->FindByName(TEXT("prpSunset"));
  if (wp) {
    _stprintf(Temp, TEXT("%02d:%02d"), sunsethours,sunsetmins);
    wp->SetText(Temp);
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpLocalTime"));
  if (wp) {
    Units::TimeToText(Temp, (int)DetectCurrentTime());
    wp->SetText(Temp);
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpTakeoffTime"));
  if (wp) {
    if (CALCULATED_INFO.FlightTime>0) {
      Units::TimeToText(Temp, 
                        (int)TimeLocal((long)CALCULATED_INFO.TakeOffTime));
      wp->SetText(Temp);
    } else {
      wp->SetText(TEXT(""));
    }
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpLandingTime"));
  if (wp) {
    if (!CALCULATED_INFO.Flying) {
      Units::TimeToText(Temp, 
                        (int)TimeLocal((long)(CALCULATED_INFO.TakeOffTime
                                              +CALCULATED_INFO.FlightTime)));
      wp->SetText(Temp);
    } else {
      wp->SetText(TEXT(""));
    }
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpFlightTime"));
  if (wp) {
    if (CALCULATED_INFO.FlightTime > 0){
      Units::TimeToText(Temp, (int)CALCULATED_INFO.FlightTime);
      wp->SetText(Temp);
    } else {
      wp->SetText(TEXT(""));
    }
  }

}
Beispiel #2
0
void
InputEvents::eventTaskTransition(const TCHAR *misc)
{
  if (protected_task_manager == NULL)
    return;

  if (StringIsEqual(misc, _T("start"))) {
    AircraftState start_state = protected_task_manager->GetStartState();

    TCHAR TempTime[40];
    TCHAR TempAlt[40];
    TCHAR TempSpeed[40];
    
    FormatSignedTimeHHMM(TempTime, (int)TimeLocal((int)start_state.time));
    FormatUserAltitude(start_state.altitude, TempAlt, true);
    FormatUserSpeed(start_state.ground_speed,TempSpeed, true);
    
    TCHAR TempAll[120];
    _stprintf(TempAll, _T("\r\nAltitude: %s\r\nSpeed:%s\r\nTime: %s"),
              TempAlt, TempSpeed, TempTime);
    Message::AddMessage(_("Task start"), TempAll);
  } else if (StringIsEqual(misc, _T("tp"))) {
    Message::AddMessage(_("Next turnpoint"));
  } else if (StringIsEqual(misc, _T("finish"))) {
    Message::AddMessage(_("Task finished"));
  } else if (StringIsEqual(misc, _T("ready"))) {
    Message::AddMessage(_("In sector, arm advance when ready"));
  }
}
Beispiel #3
0
void TaskStartMessage(void) {

  TCHAR TempTime[40];
  TCHAR TempAlt[40];
  TCHAR TempSpeed[40];
  Units::TimeToText(TempTime, (int)TimeLocal((int)CALCULATED_INFO.TaskStartTime));
  _stprintf(TempAlt, TEXT("%.0f %s"), CALCULATED_INFO.TaskStartAltitude*ALTITUDEMODIFY, Units::GetAltitudeName());
  _stprintf(TempSpeed, TEXT("%.0f %s"), CALCULATED_INFO.TaskStartSpeed*TASKSPEEDMODIFY, Units::GetTaskSpeedName());

  TCHAR TempAll[300];
  _stprintf(TempAll, TEXT("\r\n%s: %s\r\n%s:%s\r\n%s: %s"),
  // Altitude
  gettext(TEXT("_@M89_")),
  TempAlt,
  // Speed
  gettext(TEXT("_@M632_")),
  TempSpeed,
  // Time
  gettext(TEXT("_@M720_")),
  TempTime);

  // ALWAYS issue DoStatusMessage BEFORE sounds, if possible.
  // LKTOKEN  _@M692_ = "Task Start"
  DoStatusMessage(gettext(TEXT("_@M692_")), TempAll);
}
void
MapItemListRenderer::Draw(Canvas &canvas, const PixelRect rc,
                          const MarkerMapItem &item,
                          const DialogLook &dialog_look,
                          const MarkerLook &look)
{
  const PixelScalar line_height = rc.bottom - rc.top;

  const Marker &marker = item.marker;

  const RasterPoint pt(rc.left + line_height / 2,
                       rc.top + line_height / 2);

  look.icon.Draw(canvas, pt);

  const Font &name_font = *dialog_look.list.font_bold;
  const Font &small_font = *dialog_look.small_font;

  PixelScalar left = rc.left + line_height + Layout::FastScale(2);

  StaticString<256> buffer;
  buffer.Format(_T("%s #%d"), _("Marker"), item.id + 1);
  canvas.Select(name_font);
  canvas.DrawClippedText(left, rc.top + Layout::FastScale(2), rc, buffer);

  TCHAR time_buffer[32], timespan_buffer[32];
  FormatSignedTimeHHMM(time_buffer, TimeLocal(marker.time.GetSecondOfDay()));
  FormatTimespanSmart(timespan_buffer, BrokenDateTime::NowUTC() - marker.time);
  buffer.Format(_("dropped %s ago"), timespan_buffer);
  buffer.AppendFormat(_T(" (%s)"), time_buffer);
  canvas.Select(small_font);
  canvas.DrawClippedText(left,
                         rc.top + name_font.GetHeight() + Layout::FastScale(4),
                         rc, buffer);
}
Beispiel #5
0
void TaskFinishMessage(void) {

  TCHAR TempTime[40];
  TCHAR TempAlt[40];
  TCHAR TempSpeed[40];
  TCHAR TempTskSpeed[40];

  Units::TimeToText(TempTime, (int)TimeLocal((int)GPS_INFO.Time));
  _stprintf(TempAlt, TEXT("%.0f %s"), CALCULATED_INFO.NavAltitude*ALTITUDEMODIFY, Units::GetAltitudeName());
  _stprintf(TempSpeed, TEXT("%.0f %s"), GPS_INFO.Speed*TASKSPEEDMODIFY, Units::GetTaskSpeedName());
  _stprintf(TempTskSpeed, TEXT("%.2f %s"), CALCULATED_INFO.TaskSpeedAchieved*TASKSPEEDMODIFY, Units::GetTaskSpeedName());

  TCHAR TempAll[300];

  _stprintf(TempAll, TEXT("\r\n%s: %s\r\n%s:%s\r\n%s: %s\r\n%s: %s"),
  // Altitude
  gettext(TEXT("_@M89_")),
  TempAlt,
  // Speed
  gettext(TEXT("_@M632_")),
  TempSpeed,
  // Time
  gettext(TEXT("_@M720_")),
  TempTime,
  // task speed
  gettext(TEXT("_@M697_")),
  TempTskSpeed);

  // LKTOKEN  _@M687_ = "Task Finish"
  DoStatusMessage(gettext(TEXT("_@M687_")), TempAll);

}
Beispiel #6
0
void
TimesStatusPanel::Refresh()
{
  const NMEAInfo &basic = CommonInterface::Basic();
  const DerivedInfo &calculated = CommonInterface::Calculated();
  const FlyingState &flight = calculated.flight;

  TCHAR Temp[64];
  fixed sunsettime;
  int sunsethours;
  int sunsetmins;

  sunsettime = XCSoarInterface::Calculated().sunset_time;
  sunsethours = (int)sunsettime;
  sunsetmins = (int)((sunsettime - fixed(sunsethours)) * 60);

  _stprintf(Temp, _T("%02d:%02d"), sunsethours, sunsetmins);
  SetFormValue(form, _T("prpSunset"), Temp);

  Units::TimeToTextHHMMSigned(Temp, DetectCurrentTime(basic));
  SetFormValue(form, _T("prpLocalTime"), Temp);

  if (positive(flight.flight_time)) {
    Units::TimeToTextHHMMSigned(Temp, TimeLocal((long)flight.takeoff_time));
    SetFormValue(form, _T("prpTakeoffTime"), Temp);
  } else {
    SetFormValue(form, _T("prpTakeoffTime"), _T(""));
  }

  if (!flight.flying && positive(flight.flight_time)) {
    Units::TimeToTextHHMMSigned(Temp,
                      TimeLocal((long)(flight.takeoff_time
                                       + flight.flight_time)));
    SetFormValue(form, _T("prpLandingTime"), Temp);
  } else {
    SetFormValue(form, _T("prpLandingTime"), _T(""));
  }

  if (positive(flight.flight_time)) {
    Units::TimeToTextHHMMSigned(Temp, (int)flight.flight_time);
    SetFormValue(form, _T("prpFlightTime"), Temp);
  } else {
    SetFormValue(form, _T("prpFlightTime"), _T(""));
  }
}
Beispiel #7
0
void
RasterWeather::Reload(int day_time)
{
  static unsigned last_weather_time;
  bool found = false;
  bool now = false;

  if (_parameter == 0)
    // will be drawing terrain
    return;

  Poco::ScopedRWLock protect(lock, true);
  if (_weather_time == 0) {
    // "Now" time, so find time in half hours
    unsigned half_hours = (TimeLocal(day_time) / 1800) % 48;
    _weather_time = max(_weather_time, half_hours);
    now = true;
  }

  // limit values, for safety
  _weather_time = min(MAX_WEATHER_TIMES - 1, _weather_time);
  if (_weather_time != last_weather_time)
    reload = true;

  if (!reload) {
    // no change, quick exit.
    if (now)
      // must return to 0 = Now time on exit
      _weather_time = 0;

    return;
  }

  reload = false;

  last_weather_time = _weather_time;

  // scan forward to next valid time
  while ((_weather_time < MAX_WEATHER_TIMES) && (!found)) {
    if (!weather_available[_weather_time]) {
      _weather_time++;
    } else {
      found = true;

      _Close();

      if (!LoadItem(WeatherDescriptors[_parameter].name, _weather_time) &&
          _parameter == 1)
        LoadItem(_T("wstar_bsratio"), _weather_time);
    }
  }

  // can't find valid time, so reset to zero
  if (!found || now)
    _weather_time = 0;
}
Beispiel #8
0
TCHAR *WhatTimeIsIt(void) {
  static TCHAR time_temp[60];
  TCHAR tlocal[20];
  TCHAR tutc[20];

  Units::TimeToTextS(tlocal, (int)TimeLocal((int)(GPS_INFO.Time))),
  Units::TimeToText(tutc, (int)GPS_INFO.Time);
  wsprintf(time_temp, _T("h%s (UTC %s)"), tlocal, tutc);

  return (time_temp);
}
Beispiel #9
0
void
TimeConfigPanel::SetLocalTime(int utc_offset)
{
  TCHAR temp[20];
  int time(XCSoarInterface::Basic().time);
  FormatSignedTimeHHMM(temp, TimeLocal(time, utc_offset));

  WndProperty &wp = GetControl(LocalTime);

  wp.SetText(temp);
  wp.RefreshDisplay();
}
Beispiel #10
0
void
TimeConfigPanel::SetLocalTime(int utc_offset)
{
  WndProperty* wp;
  TCHAR temp[20];
  int time(XCSoarInterface::Basic().time);
  Units::TimeToTextHHMMSigned(temp, TimeLocal(time, utc_offset));

  wp = (WndProperty*)form.FindByName(_T("prpLocalTime"));
  assert(wp != NULL);

  wp->SetText(temp);
  wp->RefreshDisplay();
}
Beispiel #11
0
TCHAR *WhatTimeIsIt(void) {
    static TCHAR time_temp[60];
    TCHAR tlocal[20];
    TCHAR tutc[20];

    Units::TimeToTextS(tlocal, (int)TimeLocal((int)(GPS_INFO.Time))),
          Units::TimeToText(tutc, (int)GPS_INFO.Time);
    _stprintf(time_temp, _T("h%s (UTC %s)"), tlocal, tutc);
    if (GPS_INFO.NAVWarning || (GPS_INFO.SatellitesUsed == 0))
        _stprintf(time_temp, _T("h%s (NO FIX)"), tlocal);
    else
        _stprintf(time_temp, _T("h%s (UTC %s)"), tlocal, tutc);

    return (time_temp);
}
Beispiel #12
0
void
MapItemListRenderer::Draw(Canvas &canvas, const PixelRect rc,
                          const ThermalMapItem &item,
                          const DialogLook &dialog_look,
                          const MapLook &look)
{
  const PixelScalar line_height = rc.bottom - rc.top;

  const ThermalSource &thermal = item.thermal;

  RasterPoint pt = { PixelScalar(rc.left + line_height / 2),
                     PixelScalar(rc.top + line_height / 2) };

  look.thermal_source_icon.Draw(canvas, pt);

  const Font &name_font = *dialog_look.list.font;
  const Font &small_font = *dialog_look.small_font;
  canvas.SetTextColor(COLOR_BLACK);

  PixelScalar left = rc.left + line_height + Layout::FastScale(2);

  canvas.Select(name_font);
  canvas.text_clipped(left, rc.top + Layout::FastScale(2), rc, _("Thermal"));

  StaticString<256> buffer;
  TCHAR lift_buffer[32], time_buffer[32], timespan_buffer[32];
  FormatUserVerticalSpeed(thermal.lift_rate, lift_buffer, 32);
  FormatSignedTimeHHMM(time_buffer, TimeLocal((int)thermal.time));

  int timespan = BrokenDateTime::NowUTC().GetSecondOfDay() - (int)thermal.time;
  if (timespan < 0)
    timespan += 24 * 60 * 60;

  FormatTimespanSmart(timespan_buffer, timespan);

  buffer.Format(_T("%s: %s"), _("Avg. lift"), lift_buffer);
  buffer.append(_T(" - "));
  buffer.AppendFormat(_("left %s ago"), timespan_buffer);
  buffer.AppendFormat(_T(" (%s)"), time_buffer);
  canvas.Select(small_font);
  canvas.text_clipped(left,
                      rc.top + name_font.GetHeight() + Layout::FastScale(4),
                      rc, buffer);
}
Beispiel #13
0
void dlgStartTaskShowModal(bool *validStart, double Time, double Speed, double Altitude){

  char filename[MAX_PATH];
  LocalPathS(filename, TEXT("dlgStartTask.xml"));
  wf = dlgLoadFromXML(CallBackTable, 
		      
                      filename, 
		      hWndMainWindow,
		      TEXT("IDR_XML_STARTTASK"));

  if (wf) {
    WndProperty* wp;

    TCHAR Temp[80];

    wp = (WndProperty*)wf->FindByName(TEXT("prpTime"));
    if (wp) {
      Units::TimeToText(Temp, (int)TimeLocal((int)Time));
      wp->SetText(Temp);
    }

    wp = (WndProperty*)wf->FindByName(TEXT("prpSpeed"));
    if (wp) {
      _stprintf(Temp, TEXT("%.0f %s"),
                (double) TASKSPEEDMODIFY * Speed, Units::GetTaskSpeedName());
      wp->SetText(Temp);
    }

    wp = (WndProperty*)wf->FindByName(TEXT("prpAltitude"));
    if (wp) {
      _stprintf(Temp, TEXT("%.0f %s"),
                (double) Altitude*ALTITUDEMODIFY, Units::GetAltitudeName());
      wp->SetText(Temp);
    }

    wf->ShowModal();
    
    delete wf;
  }
  wf = NULL;

  *validStart = startIsValid;
}
Beispiel #14
0
// This function is called upon exiting a thermal, just before input event to cruise mode is issued
// Functions using the ThermalHistory array should always check for Valid flag at each step,
// and in any case never use the array while Circling. Because anytime we may change a value, in case
// (very rare) the 100 limit is passed and we are reusing a value.
//
// When this function is called, the L> thermal is automatically selected as multitarget L
//
void InsertThermalHistory(double ThTime,  double ThLat, double ThLon, double ThBase,double ThTop, double ThAvg) {

  int i;

  for (i=0; i<MAX_THERMAL_HISTORY; i++) {
	if (ThermalHistory[i].Valid == false) break;
  }

  if (i==MAX_THERMAL_HISTORY) {
	#if DEBUG_THISTORY
	StartupStore(_T("... no more space in thermal history\n"));
	#endif
	int oldest=0; // lets assume the 0 is the oldest, to begin
  	for (i=1; i<MAX_THERMAL_HISTORY; i++) {
		if ( ThermalHistory[i].Time < ThermalHistory[oldest].Time ) {
			oldest=i;
			continue;
		}
	}
	#if DEBUG_THISTORY
	StartupStore(_T(".... oldest thermal in history is n.%d\n"),oldest);
	#endif
	i=oldest;
  }

  if (i<0 || i>=MAX_THERMAL_HISTORY) {
	#if DEBUG_THISTORY
	StartupStore(_T("..... Insert thermal history out of range: <%d>!\n"),i);
	#endif
	return;
  }

  ThermalHistory[i].Valid=false;

  TCHAR tstring[10];
  Units::TimeToTextSimple(tstring,TimeLocal((int)ThTime));
  
  _stprintf(ThermalHistory[i].Name,_T("th%s"),tstring);
  ThermalHistory[i].Time = ThTime;
  ThermalHistory[i].Latitude = ThLat;
  ThermalHistory[i].Longitude = ThLon;
  ThermalHistory[i].HBase = ThBase;
  ThermalHistory[i].HTop = ThTop;
  ThermalHistory[i].Lift = ThAvg;
  ThermalHistory[i].Valid=true;

  int j=FindNearestFarVisibleWayPoint(ThLon,ThLat,15000,WPT_UNKNOWN);
  if (j>0) {
	#if DEBUG_THISTORY
	StartupStore(_T("..... Thermal is near wp.%d <%s>\n"),j,WayPointList[j].Name);
	#endif
	TCHAR wpnear[NAME_SIZE+1];
	_tcscpy(wpnear,WayPointList[j].Name);
	wpnear[19]='\0'; // sized 20 chars
	_tcscpy(ThermalHistory[i].Near,wpnear);
  } else {
	_tcscpy(ThermalHistory[i].Near,_T(""));
  }

  LockTaskData();
  _tcscpy(WayPointList[RESWP_LASTTHERMAL].Name , ThermalHistory[i].Name);
  WayPointList[RESWP_LASTTHERMAL].Latitude  = CALCULATED_INFO.ClimbStartLat;
  WayPointList[RESWP_LASTTHERMAL].Longitude = CALCULATED_INFO.ClimbStartLong;
  WayPointList[RESWP_LASTTHERMAL].Altitude  = CALCULATED_INFO.ClimbStartAlt;
  LKASSERT(WayPointList[RESWP_LASTTHERMAL].Comment);
  if (j>0)
  	_tcscpy(WayPointList[RESWP_LASTTHERMAL].Comment,ThermalHistory[i].Name);
  else
	_tcscpy(WayPointList[RESWP_LASTTHERMAL].Comment, MsgToken(1320)); // last good thermal

  UnlockTaskData();

  // Update holder selected L> 
  SetThermalMultitarget(i);

  #if DEBUG_THISTORY
  StartupStore(_T("... Insert new thermal in history[%d]: <%s> Base=%.0f Top=%.0f Lift=%.1f\n"),
	i, ThermalHistory[i].Name, ThBase, ThTop, ThAvg);
  #endif

}
Beispiel #15
0
void MarkLocation(const double lon, const double lat, const double altitude)
#endif
{
  #if USETOPOMARKS
  LockTerrainDataGraphics();
  if (topo_marks) {
    topo_marks->addPoint(lon, lat);
    topo_marks->triggerUpdateCache = true;
  }
  UnlockTerrainDataGraphics();
  #endif

  char message[160];

  FILE *stream;
  TCHAR tstring[50];
  bool dopreambol=false;
  TCHAR fname[MAX_PATH];
  LocalPath(fname,TEXT(LKD_WAYPOINTS));
  _tcscat(fname,_T("\\")); 
  _stprintf(tstring,_T("LK%04d%02d%02d.cup"), GPS_INFO.Year,GPS_INFO.Month,GPS_INFO.Day);
  _tcscat(fname,tstring);

  stream = _tfopen(fname,TEXT("r"));
  if (stream == NULL)
	dopreambol=true;
  else
	fclose(stream);

  stream = _tfopen(fname,TEXT("a+"));
  if (stream != NULL){
	if (dopreambol) {
		// file was created empty, we need to add preambol header for CUP
		strcpy(message,"name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n");
		fwrite(message,strlen(message),1,stream);
	}

	char marktime[10], slat[20], slon[20], snear[50];
	Units::TimeToTextSimple(tstring,TimeLocal((int)GPS_INFO.Time));
	unicodetoascii(tstring,_tcslen(tstring),marktime);

	LatitudeToCUPString(lat,tstring);
	unicodetoascii(tstring,_tcslen(tstring),slat);
	LongitudeToCUPString(lon,tstring);
	unicodetoascii(tstring,_tcslen(tstring),slon);

	int j=FindNearestFarVisibleWayPoint(lon,lat,15000,WPT_UNKNOWN);
	if (j>0) {
        	_tcscpy(tstring,WayPointList[j].Name); // Name is sized NAME_SIZE, 30, so ok with tstring[50]
        	tstring[19]='\0'; // sized 20 chars
		unicodetoascii(tstring,_tcslen(tstring),snear);
	} else {
		strcpy(snear,"unknown");
	}

	sprintf(message,"MK%s%02d,LK8000,,%s,%s,%d.0m,1,,,,Created on %02d-%02d-%04d at h%s near: %s\r\n",
		marktime,GPS_INFO.Second,slat,slon, iround((int)altitude),
		GPS_INFO.Day,GPS_INFO.Month,GPS_INFO.Year, marktime, snear );

	fwrite(message,strlen(message),1,stream);
	fclose(stream);

extern int GetVirtualWaypointMarkerSlot(void);

	j=GetVirtualWaypointMarkerSlot();

	WayPointList[j].Latitude=lat;
	WayPointList[j].Longitude=lon;
	WayPointList[j].Altitude=altitude;
	WayPointList[j].Visible=TRUE;
	WayPointList[j].FarVisible=TRUE;

	wsprintf(WayPointList[j].Name,_T("MK%S%02d"),marktime,GPS_INFO.Second);
        #if BUGSTOP
        LKASSERT(WayPointList[j].Comment!=NULL);
        #endif
        if (WayPointList[j].Comment!=NULL)
	    wsprintf(WayPointList[j].Comment,_T("Near: %hs"),snear);

	WayPointCalc[j].WpType=WPT_TURNPOINT;

	// Force updating DoRange otherwise it will pass up to 3 minutes
	// before this marker appears in the 2.3 tps page
	LastDoRangeWaypointListTime=0; 
  }

}
Beispiel #16
0
int DetectCurrentTime() {
  int localtime = (int)GPS_INFO.Time;
  return TimeLocal(localtime);
}
Beispiel #17
0
void
TimesStatusPanel::Refresh()
{
  const NMEAInfo &basic = CommonInterface::Basic();
  const FlyingState &flight = CommonInterface::Calculated().flight;

  StaticString<64> temp;

  if (basic.location_available && basic.date_available) {
    SunEphemeris::Result sun = SunEphemeris::CalcSunTimes(
        basic.location, basic.date_time_utc, fixed(GetUTCOffset()) / 3600);

    const unsigned sunrisehours = (int)sun.time_of_sunrise;
    const unsigned sunrisemins = (int)((sun.time_of_sunrise - fixed(sunrisehours)) * 60);
    const unsigned sunsethours = (int)sun.time_of_sunset;
    const unsigned sunsetmins = (int)((sun.time_of_sunset - fixed(sunsethours)) * 60);

    temp.Format(_T("%02u:%02u - %02u:%02u"), sunrisehours, sunrisemins, sunsethours, sunsetmins);
    SetText(Daylight, temp);
  } else {
    SetText(Daylight, _T(""));
  }

  if (basic.time_available) {
    FormatSignedTimeHHMM(temp.buffer(), DetectCurrentTime(basic));
    SetText(LocalTime, temp);
    FormatSignedTimeHHMM(temp.buffer(), (int) basic.time);
    SetText(UTCTime, temp);
  } else {
    SetText(LocalTime, _T(""));
    SetText(UTCTime, _T(""));
  }

  if (basic.date_available) {
    temp.Format(_T("%04d-%02d-%02d"), basic.date_time_utc.year,
                basic.date_time_utc.month, basic.date_time_utc.day);
    SetText(UTCDate, temp);
  } else {
    SetText(UTCDate, _T(""));
  }

  if (positive(flight.flight_time)) {
    FormatSignedTimeHHMM(temp.buffer(), TimeLocal((int)flight.takeoff_time));
    SetText(TakeoffTime, temp);
  } else {
    SetText(TakeoffTime, _T(""));
  }

  if (!flight.flying && positive(flight.flight_time)) {
    FormatSignedTimeHHMM(temp.buffer(),
                      TimeLocal((long)(flight.takeoff_time
                                       + flight.flight_time)));
    SetText(LandingTime, temp);
  } else {
    SetText(LandingTime, _T(""));
  }

  if (positive(flight.flight_time)) {
    FormatSignedTimeHHMM(temp.buffer(), (int)flight.flight_time);
    SetText(FlightTime, temp);
  } else {
    SetText(FlightTime, _T(""));
  }
}
Beispiel #18
0
bool DetectFreeFlying(NMEA_INFO *Basic, DERIVED_INFO *Calculated) {

  static bool   ffDetected=false;
  static int    lastMaxAltitude=-1000;
  static double gndAltitude=0;
  static double vario[8];
  static bool   winchdetected=false;
  static short  wlaunch=0;
  static int    altLoss=0;
  static bool   safeTakeoffDetected=false;
  static bool   nowGearWarning = true; // init with true to prevent gear warning just after free flight detect
  static unsigned short noMessages =0;

  bool forcereset=LKSW_ForceFreeFlightRestart;

  if (DoInit[MDI_DETECTFREEFLYING]) {
    for (int i=0; i<8; i++) vario[i]=0;
    gndAltitude=0;
    winchdetected=false;
    wlaunch=0;
    altLoss=0;
    ffDetected=false;
    lastMaxAltitude=-1000;
    safeTakeoffDetected=false;
    nowGearWarning=true; // we are here before freeflight!
    noMessages=0;	// after a new takeoff we can give warnings again!
    DoInit[MDI_DETECTFREEFLYING]=false;
  }

  // reset on ground
  if (Calculated->Flying == false) {
    Calculated->FreeFlying=false;
    ffDetected=false;
    lastMaxAltitude=-1000;
    // For winch launches and also for quick taekoffs do not update gndAltitude when the plane
    // is already moving, probably towed or winched already. Threshold is at 4m/s, = 14kmh
    if (Basic->Speed<=4.0) gndAltitude=Basic->Altitude;
    winchdetected=false;
    wlaunch=0;
    altLoss=FF_TOWING_ALTLOSS;
    safeTakeoffDetected=false;
    LKSW_ForceFreeFlightRestart=false;
    return false;
  }

  if (forcereset) {
	LKSW_ForceFreeFlightRestart=false;
	#if TESTBENCH
	StartupStore(_T("... Forced FreeFlight Restart!\n"));
	#endif
	DoStatusMessage(MsgToken(1452),NULL,false);  // LKTOKEN  _@M1452_ = "Free flight detected"
	goto confirmbacktrue;
  }

  //  If we have a takeoff alarm, and  it is still pending!
  //  The AlarmTakeoffSafety is saved multiplied by 1000, so conversion between feet and meters will always be
  //  accurate and possible with no safety concerns about loosing accuracy on this issue!
  if ( (AlarmTakeoffSafety>0) && !safeTakeoffDetected ) {
	// Only if not in SIMMODE, or in SIM but replaying a flight
	if ( !(SIMMODE && !ReplayLogger::IsEnabled()) ) {
		if ( (Basic->Altitude - gndAltitude)>=(AlarmTakeoffSafety/1000)) {
			LKSound(_T("LK_SAFETAKEOFF.WAV"));
			safeTakeoffDetected=true;
		}
	}
  }

#ifdef  GEAR_WARNING
  if ( (GearWarningMode>0) && ffDetected) {
	// Only if not in SIMMODE, or in SIM but replaying a flight
//	if ( !(SIMMODE && !ReplayLogger::IsEnabled()) )
	  {

		double AltitudeAGL = Calculated->AltitudeAGL;

	    double dist = 0;
	    if(GearWarningMode ==1){
	      if( ValidWayPoint(BestAlternate))
	      {
	         AltitudeAGL = Basic->Altitude - WayPointList[BestAlternate].Altitude; // AGL = height above landable
	         if( AltitudeAGL <= (GearWarningAltitude/1000))
	            DistanceBearing(Basic->Latitude, Basic->Longitude, WayPointList[BestAlternate].Latitude, WayPointList[BestAlternate].Longitude, &dist, NULL);
	      }else{
	    	dist = 9999; // set to far away if best alternate  not valid
	      }
	    }

		if (( AltitudeAGL  <=(GearWarningAltitude/1000)) && (noMessages < MAX_NO_GEAR_WARN))
		{
		  if(!nowGearWarning)
		  {
		    if(dist < 3700) // show gear warning if 2Nautical Miles close to landable
		    {
			  LKSound(_T("LK_GEARWARNING.WAV"));
			  DoStatusMessage(gettext(TEXT("_@M1834_")),NULL,false);  // LKTOKEN _@M1834_ "Prepare for landing !"
			  nowGearWarning=true;
			  noMessages++;

#if TESTBENCH
			  if(GearWarningMode ==2)
			    StartupStore(_T("... %i. Gear warning at %im = %im [%im] AGL%s"),noMessages,(int)Basic->Altitude,(int)AltitudeAGL,(int)GearWarningAltitude/1000,NEWLINE);
			  else
				 StartupStore(_T("...%i. Gear warning at %im = %im [%im] over landable %s (%im)%s"),noMessages,(int)Basic->Altitude,(int)AltitudeAGL,(int)GearWarningAltitude/1000,WayPointList[BestAlternate].Name,(int)WayPointList[BestAlternate].Altitude,NEWLINE);
#endif

		    }
			if (noMessages==MAX_NO_GEAR_WARN) {
				StartupStore(_T("... GOING SILENT on too many Gear warnings.  %s%s"),WhatTimeIsIt(),NEWLINE);

				DoStatusMessage(MsgToken(2304)); // GOING SILENT ON GEAR REPORTING
				noMessages++;	// we go to 11, and never be back here		  }
			}
		  }
		}
		else
		{
		  if(( AltitudeAGL)> ((GearWarningAltitude/1000)+100))  // re-enable warning if higher that 100m above Gear altitude
		  {
            if( nowGearWarning )
            {
#if TESTBENCH
			  if(GearWarningMode ==2)
			    StartupStore(_T("...rearmed %i. Gear warning at %im = %im AGL %s"),noMessages,(int)Basic->Altitude,(int)AltitudeAGL,NEWLINE);
			  else
				 StartupStore(_T("..rearmed %i. Gear warning at %im = %im over landable %s (%im)%s"),noMessages,(int)Basic->Altitude,(int)AltitudeAGL,WayPointList[BestAlternate].Name,(int)WayPointList[BestAlternate].Altitude,NEWLINE);
#endif
	  		  nowGearWarning = false;
            }
		  }
		}
	}
  }
#endif

  if (ISPARAGLIDER) {
    Calculated->FreeFlying=true;
    return true; 
  }
  if (ISGAAIRCRAFT||ISCAR) {
    return false; 
  }

  // do something special for other situations
  if (SIMMODE && !ReplayLogger::IsEnabled()) {
    Calculated->FreeFlying=true;
    ffDetected=true;
    return true; 
  }

  // If flying, and start was already detected, assume valid freeflight.
  // Put here in the future the Engine Noise Detection for motorplanes
  if (ffDetected)
    return true;

  // Here we are flying, and the start of free flight must still be detected

  // In any case, after this time, force a start. This is to avoid that for any reason, no FF is ever detected.
  if ((int)Basic->Time > ( Calculated->TakeOffTime + FF_MAXTOWTIME)) {
    #if DEBUG_DFF
    DoStatusMessage(_T("DFF:  TIMEOUT"));
    #endif
    goto backtrue;	// unconditionally force start FF
  }

 
  // A loss of altitude will trigger FF 
  lastMaxAltitude = std::max(lastMaxAltitude, (int)Basic->Altitude);
  if ((int)Basic->Altitude <= ( lastMaxAltitude - altLoss)) {
    #if DEBUG_DFF
    if ( (winchdetected) || ((Basic->Altitude - gndAltitude)>=400) 
      && ((Basic->Time - Calculated->TakeOffTime) >= 150))
      DoStatusMessage(_T("DFF:  ALTITUDE LOSS"));
    #endif
    goto lastcheck;
  }

#ifdef TOW_CRUISE
  // If circling, we assume that we're in free flight and use the
  // start-of-circling time and position.  Turning.cpp makes sure
  // we aren't circling while on tow by imposing a 12 deg/sec turn
  // rate limit for on-tow turning.
#else
  // If circling we assume that we are in free flight already, using the start of circling time and position.
  // But we must be sure that we are not circling.. while towed. A 12 deg/sec turn rate will make it quite sure.
  // Of course nobody can circle while winchlaunched, so in this case FF is immediately detected.
#endif

#ifdef TOW_CRUISE
  // The 12 deg/sec check is now done in Turning.cpp, so there's no
  // need to do it here, too.  Doing it here, too, could allow the
  // possibility of climb mode engaging without FF detection, if the
  // climb rate goes above 12 deg/sec for just a split second.
  //if (Calculated->Circling && (winchdetected ||
  //   (fabs(Calculated->TurnRate) >= 12))) {

  if (Calculated->Circling) {
#else
  if (Calculated->Circling && ( winchdetected || ( fabs(Calculated->TurnRate) >=12 ) ) ) {
#endif

    if (UseContestEngine()) {
      CContestMgr::Instance().Add(new CPointGPS(static_cast<unsigned>(Calculated->ClimbStartTime),
	Calculated->ClimbStartLat, Calculated->ClimbStartLong,
	static_cast<unsigned>(Calculated->ClimbStartAlt)));
    }

    #if DEBUG_DFF
    DoStatusMessage(_T("DFF:  THERMALLING"));
    #endif
    goto backtrue;
  }

  vario[7]=vario[6];
  vario[6]=vario[5];
  vario[5]=vario[4];
  vario[4]=vario[3];
  vario[3]=vario[2];
  vario[2]=vario[1];
  vario[1]=Calculated->Vario;

  double newavervario;
  double oldavervario;

  newavervario=(vario[1]+vario[2]+vario[3])/3;

  if (newavervario>=10) {
    wlaunch++;
  } else {
    wlaunch=0;
  }
  // After (6+2) 8 seconds of consecutive fast climbing (AFTER TAKEOFF DETECTED!), winch launch is detected
  if (wlaunch==6) {
    #if DEBUG_DFF
    DoStatusMessage(_T("DFF:  WINCH LAUNCH"));
    #endif
    altLoss=FF_WINCHIN_ALTLOSS;
    winchdetected=true;
  }
    
  if (newavervario>0.3)
    return false;

  if (newavervario<=0) {
    #if DEBUG_DFF
    if ( (winchdetected) || ((Basic->Altitude - gndAltitude)>=400) 
      && ((Basic->Time - Calculated->TakeOffTime) >= 150))
      DoStatusMessage(_T("DFF:  VARIO SINK"));
    #endif
    goto lastcheck;
  }

  oldavervario=(vario[4]+vario[5]+vario[6]+vario[7])/4;
  // current avervario between 0.0 and 0.3: uncertain situation,  we check what we had in the previous time
  // Windy situations during towing may lead to false positives if delta is too low. This is the most
  // difficult part which could lead to false positives or negatives.
  if ( oldavervario >=4.5 ) {
    #if DEBUG_DFF
    StartupStore(_T("..... oldavervario=%.1f newavervario=%.1f current=%.1f\n"),oldavervario,newavervario,Calculated->Vario);
    if ( (winchdetected) || ((Basic->Altitude - gndAltitude)>=400) 
      && ((Basic->Time - Calculated->TakeOffTime) >= 150))
      DoStatusMessage(_T("DFF:  DELTA VARIO"));
    #endif
    goto lastcheck;
  }

  // No free flight detected
  return false;

  lastcheck: 

  // Unless under a winch launch, we shall not consider anything below 400m gain, 
  // and before 2.5minutes have passed since takeoff
  // Anybody releasing tow before 3 minutes will be below 500m QFE, and won't go much around
  // until a thermal is found. So no problems. 

  if (!winchdetected) {
    if ( (Basic->Altitude - gndAltitude)<400)
      return false;
    if ( (Basic->Time - Calculated->TakeOffTime) < 150)
      return false;
  }

  backtrue:
  // In real flight on a fly device (assuming a windowsPC is NOT a fly device)
  // give no messages during critical phases of flight
  #if ( !defined(WINDOWSPC) || WINDOWSPC==0 )
  if (SIMMODE)
  #endif
  DoStatusMessage(gettext(TEXT("_@M1452_")),NULL,false);  // LKTOKEN  _@M1452_ = "Free flight detected"

  confirmbacktrue:
  // Always sound
  if (EnableSoundModes) {
	LKSound(_T("LK_FREEFLIGHT.WAV"));
  }

  StartupStore(_T(". Free Flight started %s%s"), WhatTimeIsIt(),NEWLINE);

  ffDetected=true;
  Calculated->FreeFlying=true;
  Calculated->FreeFlightStartTime=Basic->Time;
  Calculated->FreeFlightStartQNH=Basic->Altitude;
  Calculated->FreeFlightStartQFE=gndAltitude;

  WayPointList[RESWP_FREEFLY].Latitude=Basic->Latitude;
  WayPointList[RESWP_FREEFLY].Longitude=Basic->Longitude;
  WayPointList[RESWP_FREEFLY].Altitude=Basic->Altitude;
  if (WayPointList[RESWP_FREEFLY].Altitude==0) WayPointList[RESWP_FREEFLY].Altitude=0.001;
  WayPointList[RESWP_FREEFLY].Reachable=TRUE;
  WayPointList[RESWP_FREEFLY].Visible=TRUE;
  WayPointList[RESWP_FREEFLY].Format = LKW_VIRTUAL;

  TCHAR Temp[30];
  Units::TimeToTextS(Temp, (int)TimeLocal((long)Calculated->FreeFlightStartTime));

  LKASSERT(WayPointList[RESWP_FREEFLY].Comment!=NULL);

  WayPointList[RESWP_FREEFLY].Comment[99]='\0'; // for safety
  _stprintf(WayPointList[RESWP_FREEFLY].Comment,_T("%s: %s  @%.0f%s QNH"),
	gettext(_T("_@M1754_")), 	// Free flight start
	Temp,
	ALTITUDEMODIFY*Calculated->FreeFlightStartQNH,
	Units::GetAltitudeName());

  ResetFreeFlightStats(Calculated);
  return true;

}




//
// Upon FF detection, we reset some calculations, ONLY SOME.
// Most things are pertinent to flying, not to freeflying.
//
// Notice 1:  we cannot do oldstyle reset, because it would reset also takeoff time.
//            For FF, we need new stuff doing new things.
// Notice 2:  GA and CAR mode will not ever use FF stuff
//
// Notice 3:  since FF is not (still) affecting tasks, we shall not reset task values now
//
void ResetFreeFlightStats(DERIVED_INFO *Calculated) {

  int i;

  CContestMgr::Instance().Reset(Handicap);
  flightstats.Reset();

  Calculated->timeCruising = 0;
  Calculated->timeCircling = 0;

  // Calculated->TotalHeightClimb = 0;
  // Calculated->CruiseStartTime = -1;
  // 
  // ClimbStartTime CANNOT be reset here: it is a loop! We use themal start to detect freeflight!
  // We have a conflict here!
  // Calculated->ClimbStartTime = -1;  
  // Calculated->AverageThermal = 0;

  for (i=0; i<200; i++) {
     Calculated->AverageClimbRate[i]= 0;
     Calculated->AverageClimbRateN[i]= 0;
  }
  Calculated->MaxThermalHeight = 0;
  for (i=0; i<NUMTHERMALBUCKETS; i++) {
    Calculated->ThermalProfileN[i]=0;
    Calculated->ThermalProfileW[i]=0;
  }

  // clear thermal sources for first time.
  for (i=0; i<MAX_THERMAL_SOURCES; i++) {
    Calculated->ThermalSources[i].LiftRate= -1.0;
  }

  // The MaxHeightGain function wait for FF in flight and will update
  // considering 0 as a no-altitude-set-yet .
  Calculated->MinAltitude = 0;
  Calculated->MaxAltitude = 0;
  Calculated->MaxHeightGain = 0;


}
Beispiel #19
0
// Returns false if something went wrong
bool UpdateLogBookTXT(bool welandedforsure) {

  TCHAR filename[MAX_PATH];
  TCHAR Temp[300], TUtc[20];
  TCHAR line[300];
  int ivalue;

  _stprintf(filename,_T("%s\\%S\\%S"), LKGetLocalPath(), LKD_LOGS,LKF_LOGBOOKTXT);

  #if TESTBENCH
  StartupStore(_T("... UpdateLogBookTXT <%s>\n"),filename);
  #endif

  bool dofirstline = !Utf8File::Exists(filename);

  Utf8File file;
  if (!file.Open(filename, Utf8File::io_append)) {
    StartupStore(_T(".... ERROR updating LogBookTXT, file open failure!%s"),NEWLINE);
    return false;
  }

  if (dofirstline) {
    file.WriteLn(_T("### AUTO-GENERATED LOGBOOK (ENCODED IN UTF-8)"));
    file.WriteLn(_T("###"));
  }
  
  //
  // Header line for new note
  //
  _stprintf(line,_T("[%04d-%02d-%02d  @%02d:%02d]"),
    GPS_INFO.Year,
    GPS_INFO.Month,
    GPS_INFO.Day,
    GPS_INFO.Hour,
    GPS_INFO.Minute);
  file.WriteLn(line);

  if (SIMMODE) {
    file.WriteLn(gettext(_T("_@M1211_")));
  }

  file.WriteLn(PilotName_Config);
  //
  // D-1234 (Ka6-CR)
  //
  _stprintf(line,_T("%s (%s)"), AircraftRego_Config,AircraftType_Config);
  file.WriteLn(line);
  file.WriteLn();

  //
  // Takeoff time
  //
  Units::TimeToTextS(Temp,(int)TimeLocal((long)CALCULATED_INFO.TakeOffTime));
  Units::TimeToText(TUtc, (int)CALCULATED_INFO.TakeOffTime);

  _stprintf(line,_T("%s:  %s  (UTC %s)"),gettext(_T("_@M680_")),Temp,TUtc);
  file.WriteLn(line);
  _stprintf(line,_T("%s:  %s"),gettext(_T("_@M930_")),TAKEOFFWP_Name);
  file.WriteLn(line);

  //
  // Landing time
  //
  if (!CALCULATED_INFO.Flying || welandedforsure ) {
    Units::TimeToTextS(Temp,(int)TimeLocal((long)(CALCULATED_INFO.TakeOffTime+CALCULATED_INFO.FlightTime)));
    Units::TimeToText(TUtc, (int)(CALCULATED_INFO.TakeOffTime+CALCULATED_INFO.FlightTime));
    _stprintf(line,_T("%s:  %s  (UTC %s)"),gettext(_T("_@M386_")),Temp,TUtc);
    file.WriteLn(line);

    _stprintf(line,_T("%s:  %s"),gettext(_T("_@M931_")),LANDINGWP_Name);
    file.WriteLn(line);
  } else {
    #if TESTBENCH
    StartupStore(_T(".... LogBookTXT, logging but still flying!%s"),NEWLINE);
    #endif
    _stprintf(line,_T("%s: ??:??:??"),gettext(_T("_@M386_")));
    file.WriteLn(line);
  }

  //
  // Flight time
  //
  Units::TimeToTextS(Temp, (int)CALCULATED_INFO.FlightTime);
  _stprintf(line,_T("%s: %s"),gettext(_T("_@M306_")),Temp);
  file.WriteLn(line);
  file.WriteLn();


  //
  // FREE FLIGHT DETECTION
  //
  if (ISGLIDER) {
    // Attention, FFStartTime is 0 for CAR,SIMMODE and other situations
    if ( CALCULATED_INFO.FreeFlightStartTime>0 ) {
        Units::TimeToTextS(Temp, (int)TimeLocal((long)CALCULATED_INFO.FreeFlightStartTime));
        _stprintf(line,_T("%s: %s  @%.0f%s QNH"),
            gettext(_T("_@M1754_")),
            Temp,
            ALTITUDEMODIFY*CALCULATED_INFO.FreeFlightStartQNH,
            Units::GetAltitudeName());
        file.WriteLn(line);

        Units::TimeToTextS(Temp, (int)(CALCULATED_INFO.FreeFlightStartTime-CALCULATED_INFO.TakeOffTime) );
        _stprintf(line,_T("%s: %s  @%.0f%s QFE"),
            gettext(_T("_@M1755_")),
            Temp,
            ALTITUDEMODIFY*(CALCULATED_INFO.FreeFlightStartQNH - CALCULATED_INFO.FreeFlightStartQFE),
            Units::GetAltitudeName());
        file.WriteLn(line);
        file.WriteLn();
    }
  }

  if (ISGLIDER || ISPARAGLIDER) {
    //
    // OLC Classic Dist
    //
    ivalue=CContestMgr::TYPE_OLC_CLASSIC;
    if (OlcResults[ivalue].Type()!=CContestMgr::TYPE_INVALID) {
        _stprintf(Temp, TEXT("%5.0f"),DISTANCEMODIFY*OlcResults[ivalue].Distance());
        _stprintf(line,_T("%s: %s %s"),
            gettext(_T("_@M1455_")),
            Temp,
            Units::GetDistanceName());
        file.WriteLn(line);
    }

    //
    // OLC FAI Dist
    //
    ivalue=CContestMgr::TYPE_OLC_FAI;
    if (OlcResults[ivalue].Type()!=CContestMgr::TYPE_INVALID) {
        _stprintf(Temp, TEXT("%5.0f"), DISTANCEMODIFY*OlcResults[ivalue].Distance());
        _stprintf(line,_T("%s: %s %s"),gettext(_T("_@M1457_")),
            Temp,
            Units::GetDistanceName());
        file.WriteLn(line);
    }

    //
    // Max Altitude gained
    //
    _stprintf(line,_T("%s: %.0f %s"),gettext(_T("_@M1769_")),
        ALTITUDEMODIFY*CALCULATED_INFO.MaxHeightGain,
        Units::GetAltitudeName());
    file.WriteLn(line);
  }
 
  //
  // Max Altitude reached
  //
  _stprintf(line,_T("%s: %.0f %s"),gettext(_T("_@M1767_")),ALTITUDEMODIFY*CALCULATED_INFO.MaxAltitude,Units::GetAltitudeName());
  file.WriteLn(line);

  //
  // Odometer, add a spare CR LF to separate next logfield
  //
  _stprintf(line,_T("%s: %.0f %s"),gettext(_T("_@M1167_")),DISTANCEMODIFY*CALCULATED_INFO.Odometer,Units::GetDistanceName());
  file.WriteLn(line);
  file.WriteLn();

  return true;
}
Beispiel #20
0
//
// This is a simple text list of the logbook
//
bool UpdateLogBookLST(bool welandedforsure) {

  TCHAR filename[MAX_PATH];
  TCHAR Temp[300];
  TCHAR line[300];
  TCHAR stakeoff[20],stakeoffutc[20],slanding[20],slandingutc[20],sflighttime[20];
  TCHAR pilotname[100];

  _stprintf(filename,_T("%s\\%S\\%S"), LKGetLocalPath(), LKD_LOGS,LKF_LOGBOOKLST);

  #if TESTBENCH
  StartupStore(_T("... UpdateLogBookLST <%s>\n"),filename);
  #endif

  bool dofirstline = !Utf8File::Exists(filename);

  Utf8File file;
  if (!file.Open(filename, Utf8File::io_append)) {
    StartupStore(_T(".... ERROR updating LogBookLST, file open failure!%s"),NEWLINE);
    return false;
  }

  if (dofirstline) {
    file.WriteLn(_T("### AUTO-GENERATED LOGBOOK (ENCODED IN UTF-8)"));
    file.WriteLn(_T("###"));
    _stprintf(line,_T("[%s]"),gettext(_T("_@M1753_"))); // List of flights
    file.WriteLn(line);
  }

  Units::TimeToTextS(stakeoff,(int)TimeLocal((long)CALCULATED_INFO.TakeOffTime));
  Units::TimeToText(Temp, (int)CALCULATED_INFO.TakeOffTime);
  _stprintf(stakeoffutc,_T("(UTC %s)"),Temp);

  if (!CALCULATED_INFO.Flying || welandedforsure) {
    Units::TimeToTextS(slanding,(int)TimeLocal((long)(CALCULATED_INFO.TakeOffTime+CALCULATED_INFO.FlightTime)));
    Units::TimeToText(Temp, (int)(CALCULATED_INFO.TakeOffTime+CALCULATED_INFO.FlightTime));
    _stprintf(slandingutc,_T("(UTC %s)"),Temp);
  } else {
    #if TESTBENCH
    StartupStore(_T(".... LogBookLST, logging but still flying!%s"),NEWLINE);
    #endif
    _tcscpy(slanding,_T("???"));
    _tcscpy(slandingutc,_T(""));
  }

  Units::TimeToTextS(sflighttime, (int)CALCULATED_INFO.FlightTime);

  if (_tcslen(PilotName_Config)>0) {
    _tcscpy(pilotname,PilotName_Config);
    pilotname[20]=0;
  } else
    _tcscpy(pilotname,_T(""));
    
  if (!dofirstline) {
    file.WriteLn(_T("________________________________________"));
  }

  if (SIMMODE) {
    file.WriteLn(gettext(_T("_@M1211_")));
  }

  _stprintf(line,_T("%04d/%02d/%02d   %s  %s %s"),
    GPS_INFO.Year, GPS_INFO.Month, GPS_INFO.Day,
    sflighttime,
    AircraftRego_Config,
    pilotname);

  file.WriteLn(line);

  _stprintf(line,_T("  %s  %s  %s"),stakeoff,stakeoffutc,TAKEOFFWP_Name);
  file.WriteLn(line);
  _stprintf(line,_T("  %s  %s  %s"),slanding,slandingutc,LANDINGWP_Name);
  file.WriteLn(line);

  return true;
}
Beispiel #21
0
//
// This is the comma separated value logbook, ready for excel and spreadsheets
//
bool UpdateLogBookCSV(bool welandedforsure) {

  TCHAR filename[MAX_PATH];
  TCHAR line[300];
  int ivalue;
  TCHAR stakeoff[20],stakeoffutc[20],slanding[20],slandingutc[20],sflighttime[20], solcdist[20];

  _stprintf(filename,_T("%s\\%S\\%S"), LKGetLocalPath(), LKD_LOGS,LKF_LOGBOOKCSV);

  #if TESTBENCH
  StartupStore(_T("... UpdateLogBookCSV <%s>\n"),filename);
  #endif

  bool dofirstline = !Utf8File::Exists(filename);

  Utf8File file;
  if (!file.Open(filename, Utf8File::io_append)) {
    StartupStore(_T(".... ERROR updating LogBookCSV, file open failure!%s"),NEWLINE);
    return false;
  }

  if (dofirstline) {
    file.WriteLn(_T("Year,Month,Day,Pilot,AircraftRego,AircraftType,TakeoffTime,TakeoffUTC,TakeOffLocation,LandingTime,LandingUTC,LandingLocation,TowingTime,TowingAltitude,AltUnits,TotalFlyTime,Odometer,OLCdist,DistUnits"));
  }


  Units::TimeToTextS(stakeoff,(int)TimeLocal((long)CALCULATED_INFO.TakeOffTime));
  Units::TimeToTextS(stakeoffutc, (int)CALCULATED_INFO.TakeOffTime);

  if (!CALCULATED_INFO.Flying || welandedforsure) {
    Units::TimeToTextS(slanding,(int)TimeLocal((long)(CALCULATED_INFO.TakeOffTime+CALCULATED_INFO.FlightTime)));
    Units::TimeToTextS(slandingutc, (int)(CALCULATED_INFO.TakeOffTime+CALCULATED_INFO.FlightTime));
  } else {
    #if TESTBENCH
    StartupStore(_T(".... LogBookCSV, logging but still flying!%s"),NEWLINE);
    #endif
    _tcscpy(slanding,_T("???"));
    _tcscpy(slandingutc,_T("???"));
  }

  ivalue=CContestMgr::TYPE_OLC_CLASSIC;
  if (OlcResults[ivalue].Type()!=CContestMgr::TYPE_INVALID) {
    _stprintf(solcdist, _T("%.0f"),DISTANCEMODIFY*OlcResults[ivalue].Distance());
  } else {
    _tcscpy(solcdist, _T("---"));
  }

  Units::TimeToTextS(sflighttime, (int)CALCULATED_INFO.FlightTime);

  TCHAR simmode[8];
  if (SIMMODE)
    _tcscpy(simmode,_T(",SIM"));
  else
    _tcscpy(simmode,_T(""));

  TCHAR towtime[20];
  _tcscpy(towtime,_T(""));
  int towaltitude=0;
  if (ISGLIDER && (CALCULATED_INFO.FreeFlightStartTime>0)) {
    Units::TimeToTextS(towtime, (int)(CALCULATED_INFO.FreeFlightStartTime-CALCULATED_INFO.TakeOffTime) );
    towaltitude=(int) (ALTITUDEMODIFY*(CALCULATED_INFO.FreeFlightStartQNH - CALCULATED_INFO.FreeFlightStartQFE));
  }

  _stprintf(line,_T("%04d,%02d,%02d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%d,%s,%s,%d,%s,%s%s"),
        GPS_INFO.Year,
        GPS_INFO.Month,
        GPS_INFO.Day,
    PilotName_Config,
    AircraftRego_Config,
    AircraftType_Config,
    stakeoff, stakeoffutc,TAKEOFFWP_Name,slanding, slandingutc,LANDINGWP_Name,
    towtime,
    towaltitude,
    Units::GetAltitudeName(),
    sflighttime,
    (int)(DISTANCEMODIFY*CALCULATED_INFO.Odometer),
    solcdist,
    Units::GetDistanceName(),
    simmode
  );

  file.WriteLn(line);

  return true;
}
Beispiel #22
0
static void UpdateValuesRules(void) {
  WndProperty *wp;
  TCHAR Temp[80];

  wp = (WndProperty*)wf->FindByName(TEXT("prpValidStart"));
  if (wp) {
    if (CALCULATED_INFO.ValidStart) {
	// LKTOKEN  _@M677_ = "TRUE" 
      wp->SetText(gettext(TEXT("_@M677_")));
    } else {
	// LKTOKEN  _@M278_ = "FALSE" 
      wp->SetText(gettext(TEXT("_@M278_")));
    }
  }
  wp = (WndProperty*)wf->FindByName(TEXT("prpValidFinish"));
  if (wp) {
    if (CALCULATED_INFO.ValidFinish) {
	// LKTOKEN  _@M677_ = "TRUE" 
      wp->SetText(gettext(TEXT("_@M677_")));
    } else {
	// LKTOKEN  _@M278_ = "FALSE" 
      wp->SetText(gettext(TEXT("_@M278_")));
    }
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpStartTime"));
  if (wp) {
    if (CALCULATED_INFO.TaskStartTime>0) {
      Units::TimeToText(Temp, (int)TimeLocal((int)(CALCULATED_INFO.TaskStartTime)));
      wp->SetText(Temp);
    } else {
      wp->SetText(TEXT(""));
    }
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpStartSpeed"));
  if (wp) {
    if (CALCULATED_INFO.TaskStartTime>0) {
      _stprintf(Temp, TEXT("%.0f %s"), 
                TASKSPEEDMODIFY*CALCULATED_INFO.TaskStartSpeed, 
                Units::GetTaskSpeedName());
      wp->SetText(Temp);
    } else {
      wp->SetText(TEXT(""));
    }
  }
  // StartMaxHeight, StartMaxSpeed;

  //  double start_h;
  LockTaskData();

  wp = (WndProperty*)wf->FindByName(TEXT("prpStartPoint"));

  if (ValidTaskPoint(0)) {
    //    start_h = WayPointList[Task[0].Index].Altitude;
    if (wp) {
      wp->SetText(WayPointList[Task[0].Index].Name);
    }
  } else {
    //    start_h = 0;
    if (wp) {
      wp->SetText(TEXT(""));
    }
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpStartHeight"));
  if (wp) {
    if (CALCULATED_INFO.TaskStartTime>0) {
      _stprintf(Temp, TEXT("%.0f %s"), 
                (CALCULATED_INFO.TaskStartAltitude)*ALTITUDEMODIFY, 
                Units::GetAltitudeName());
      wp->SetText(Temp);
    } else {
      wp->SetText(TEXT(""));
    }
  }

  wp = (WndProperty*)wf->FindByName(TEXT("prpFinishAlt"));
  if (wp) {
    double finish_min = FAIFinishHeight(&GPS_INFO, &CALCULATED_INFO, -1);
    _stprintf(Temp, TEXT("%.0f %s"), 
              finish_min*ALTITUDEMODIFY, 
              Units::GetAltitudeName());
    wp->SetText(Temp);
  }

  UnlockTaskData();
}