Exemple #1
0
/**
 * Saves the calculated values to the persistent memory file
 * @param gps_info The basic data
 * @param Calculated The calculated data
 */
void
SaveCalculationsPersist(const NMEA_INFO &gps_info,
                        const DERIVED_INFO &Calculated,
                        const ProtectedTaskManager &protected_task_manager,
                        const GlideComputer &glide_computer,
                        Logger &logger)
{
  unsigned size;

  logger.LoggerClearFreeSpace(gps_info);

  if (FindFreeSpace(szCalculationsPersistDirectory) < MINFREESTORAGE) {
    if (!logger.LoggerClearFreeSpace(gps_info)) {
      LogStartUp(_T("SaveCalculationsPersist insufficient storage"));
      return;
    } else {
      LogStartUp(_T("SaveCalculationsPersist cleared logs to free storage"));
    }
  }

  LogStartUp(_T("SaveCalculationsPersist"));

  FILE *file = _tfopen(szCalculationsPersistFileName, _T("wb"));

  if (file == NULL) {
    LogStartUp(_T("SaveCalculationsPersist can't create file"));
    return;
  }

  size = sizeof(DERIVED_INFO);
  fwrite(&size, sizeof(size), 1, file);
  fwrite(&Calculated, size, 1, file);

  size = sizeof(FlightStatistics);
  fwrite(&size, sizeof(size), 1, file);
  fwrite(&glide_computer.GetFlightStats(), size, 1, file);

  /// @todo persistence for OLC data

  GlidePolar polar = glide_computer.SettingsComputer().glide_polar_task;
  double MACCREADY = polar.get_mc();
  double BUGS = polar.get_bugs();
  double BALLAST = polar.get_ballast();

  size = sizeof(double)*4;
  fwrite(&size, sizeof(size), 1, file);
  fwrite(&MACCREADY, sizeof(MACCREADY), 1, file);
  fwrite(&BUGS, sizeof(BUGS), 1, file);
  fwrite(&BALLAST, sizeof(BALLAST), 1, file);
  fwrite(&CuSonde::maxGroundTemperature,
      sizeof(CuSonde::maxGroundTemperature), 1, file);

  //    WriteFile(hFile,&CRUISE_EFFICIENCY,
  //              size,&dwBytesWritten,(OVERLAPPED*)NULL);

  LogStartUp(_T("SaveCalculationsPersist ok"));

  fclose(file);
}