Example #1
0
/** This function writes the header of the IGC file into the logfile. */
void IgcLogger::writeHeader()
{
  GeneralConfig *conf = GeneralConfig::instance();

  QString pilot = conf->getSurname();
  QString date  = formatDate( GpsNmea::gps->getLastDate() );
  QString time  = formatTime( GpsNmea::gps->getLastTime() );

  QString coPilot            = "UNKNOWN";
  Glider::seat gliderSeats   = Glider::singleSeater;
  QString gliderType         = "UNKNOWN";
  QString gliderRegistration = "UNKNOWN";
  QString gliderCallSign     = "UNKNOWN";

  if( calculator->glider() )
    {
      // access glider items only if glider is defined
      coPilot            = calculator->glider()->coPilot();
      gliderSeats        = calculator->glider()->seats();
      gliderType         = calculator->glider()->type();
      gliderRegistration = calculator->glider()->registration();
      gliderCallSign     = calculator->glider()->callSign();
    }

  _stream << "AXXXCUM Cumulus soaring flight computer, Flight: " << flightNumber << "\r\n" ;
  _stream << "HFDTE" << date << "\r\n";
  _stream << "HFFXA500" << "\r\n";
  _stream << "HFPLTPILOTINCHARGE: " << (pilot.isEmpty() ? "Unknown" : pilot) << "\r\n";

  if( gliderSeats == Glider::doubleSeater )
    {
      if( coPilot == "" )
        {
          coPilot = tr( "Unknown" );
        }

      _stream << "HFCM2CREW2: " << coPilot << "\r\n";
    }

  QString os;

#ifdef MAEMO4
  os = "Maemo 4";
#elif MAEMO5
  os = "Maemo 5";
#elif ANDROID
  os = "Android";
#else
  os = "Linux";
#endif

  QString hwv;

#ifndef ANDROID
  hwv = HwInfo::instance()->getTypeString();
#else
  QHash<QString, QString> hwh = jniGetBuildData();

  hwv = hwh.value("MANUFACTURER", "Unknown") + ", " +
        hwh.value("HARDWARE", "Unknown") + ", " +
        hwh.value("MODEL", "Unknown");
#endif

  _stream << "HFGTYGLIDERTYPE: " << gliderType << "\r\n";
  _stream << "HFGIDGLIDERID: " << gliderRegistration << "\r\n";
  _stream << "HFDTM100GPSDATUM: WSG-1984\r\n";
  _stream << "HFRFWFIRMWAREVERION: " << QCoreApplication::applicationVersion() << "\r\n";
  _stream << "HFRHWHARDWAREVERSION: " << hwv << "\r\n" ;
  _stream << "HFFTYFRTYPE: Cumulus: " << QCoreApplication::applicationVersion()
          << ", Qt: " << qVersion()
          << ", OS: " << os
          << "\r\n";
  _stream << "HFGPS: Unknown\r\n";
  _stream << "HFPRSPRESSALTSENSOR: Unknown\r\n";
  _stream << "HSCIDCOMPETITIONID: " << gliderCallSign << "\r\n";

  // GSP info lines committed for now
  _stream << "I023638FXA3940SIU\r\n"; // Fix accuracy and sat count as add ons

  // Write J Record definitions, if extended logging is activated by the user.
  if( conf->getKRecordInterval() > 0 )
    {
      // Set extended logging flag used for writing of K record.
      _kRecordLogging = true;
      _stream << "J050810HDT1116TAS1719WDI2022WSP2329VAT" << "\r\n";
    }
  else
    {
      _kRecordLogging = false;
    }

  // Task support: C-Records
  extern MapContents* _globalMapContents;

  FlightTask* task = _globalMapContents->getCurrentTask();

  if ( ! task )
    {
      return; // no task active
    }

  QList<TaskPoint *> tpList = task->getTpList();

  if ( tpList.count() < 2 )
    {
      return; // too less task points
    }

  QString taskDate = formatDate( task->getDeclarationDateTime().date() );
  QString taskTime = formatTime( task->getDeclarationDateTime().time() );
  QString fnr; fnr = fnr.sprintf( "%04d", flightNumber );
  QString tpnr; tpnr = tpnr.sprintf( "%02d ", tpList.count() - 4 );
  QString taskId = task->getTaskTypeString();

  // date, time UTC is expected at first and second position
  _stream << "C"
          << taskDate
          << taskTime
          << QDate::currentDate().toString("ddMMyy")
          << fnr
          << tpnr
          << task->getTaskDistanceString() << " "
          << taskId
          << "\r\n";

  // Takeoff point as dummy entry
  _stream << "C0000000N00000000E\r\n";

  for( int i=0; i < tpList.count(); i++ )
    {
      TaskPoint *tp = tpList.at(i);

      _stream << "C"
              << formatPosition( tp->getWGSPosition() )
              << tp->getWPName() << "\r\n";
    }

  // Landing point as dummy entry
  _stream << "C0000000N00000000E\r\n";
}
bool TaskFileManagerOld::saveTaskList( QList<FlightTask*>& flightTaskList,
                                    QString fileName )
{
  QString fn;

  if( fileName.isEmpty() )
    {
      // Use task default file name
      fn = m_taskFileName;
    }

  QFile f( fn );

  if ( ! f.open( QIODevice::WriteOnly ) )
    {
      qWarning() << __PRETTY_FUNCTION__ << "Could not write to task-file:" << fn;
      return false;
    }

  QTextStream stream( &f );

  // writing file-header
  QDateTime dt = QDateTime::currentDateTime();
  QString dtStr = dt.toString("yyyy-MM-dd hh:mm:ss");

  stream << "# Cumulus-Task-File V4.0, created at "
         << dtStr << " by Cumulus "
         << QCoreApplication::applicationVersion() << endl << endl;

  for ( int i=0; i < flightTaskList.count(); i++ )
    {
      FlightTask *task = flightTaskList.at(i);
      QList<TaskPoint *> tpList = task->getTpList();

      stream << "TS," << task->getTaskName() << "," << tpList.count() << endl;

      for ( int j=0; j < tpList.count(); j++ )
        {
          // saving each task point ...
          TaskPoint* tp = tpList.at(j);
          stream << "TW,"
                 << tp->getWGSPosition().x() << ","
                 << tp->getWGSPosition().y() << ","
                 << tp->getElevation() << ","
                 << tp->getWPName() << ","
                 << tp->getName() << ","
                 << tp->getTypeID() << ","
                 << tp->getActiveTaskPointFigureScheme() << ","
                 << tp->getTaskLineLength().getMeters() << ","
                 << tp->getTaskCircleRadius().getMeters() << ","
                 << tp->getTaskSectorInnerRadius().getMeters() << ","
                 << tp->getTaskSectorOuterRadius().getMeters() << ","
                 << tp->getTaskSectorAngle() << ","
                 << tp->getAutoZoom() << ","
                 << tp->getUserEditFlag()
                 << endl;
        }

      stream << "TE" << endl;
    }

  f.close();

  qDebug() << "TFM:" << flightTaskList.size()
           << "task objects saved to file"
           << fn;

  return true;
}