コード例 #1
0
ファイル: LoggerImpl.cpp プロジェクト: ThomasXBMC/XCSoar
// TODO: fix scope so only gui things can start it
void
LoggerImpl::StartLogger(const NMEAInfo &gps_info,
                        const LoggerSettings &settings,
                        const TCHAR *asset_number, const Declaration &decl)
{
  if (!settings.logger_id.empty())
    asset_number = settings.logger_id.c_str();

  // chars must be legal in file names
  char logger_id[4];
  unsigned asset_length = _tcslen(asset_number);
  for (unsigned i = 0; i < 3; i++)
    logger_id[i] = i < asset_length && IsAlphaNumericASCII(asset_number[i]) ?
                   asset_number[i] : _T('A');
  logger_id[3] = _T('\0');

  if (!StartLogger(gps_info, settings, logger_id))
    return;

  simulator = gps_info.location_available && !gps_info.gps.real;
  writer->WriteHeader(gps_info.date_time_utc, decl.pilot_name,
                      decl.aircraft_type, decl.aircraft_registration,
                      decl.competition_id,
                      logger_id, GetGPSDeviceName(), simulator);

  if (decl.Size()) {
    BrokenDateTime FirstDateTime = !pre_takeoff_buffer.empty()
      ? pre_takeoff_buffer.peek().date_time_utc
      : gps_info.date_time_utc;
    writer->StartDeclaration(FirstDateTime, decl.Size());

    for (unsigned i = 0; i< decl.Size(); ++i)
      writer->AddDeclaration(decl.GetLocation(i), decl.GetName(i));

    writer->EndDeclaration();
  }
}
コード例 #2
0
ファイル: Declare.cpp プロジェクト: pascaltempez/xcsoar
/**
 * Loads LX task structure from XCSoar task structure
 * @param decl  The declaration
 */
static bool
LoadTask(LX::Declaration &lxDevice_Declaration, const Declaration &declaration)
{
    if (declaration.Size() > 10)
        return false;

    if (declaration.Size() < 2)
        return false;

    memset((void*)lxDevice_Declaration.unknown1, 0,
           sizeof(lxDevice_Declaration.unknown1));

    BrokenDate DeclDate;
    DeclDate.day = 1;
    DeclDate.month = 1;
    DeclDate.year = 2010;

    if (DeclDate.day > 0 && DeclDate.day < 32
            && DeclDate.month > 0 && DeclDate.month < 13) {
        lxDevice_Declaration.dayinput = (unsigned char)DeclDate.day;
        lxDevice_Declaration.monthinput = (unsigned char)DeclDate.month;
        int iCentury = DeclDate.year / 100; // Todo: if no gps fix, use system time
        iCentury *= 100;
        lxDevice_Declaration.yearinput = (unsigned char)(DeclDate.year - iCentury);
    }
    else {
        lxDevice_Declaration.dayinput = (unsigned char)1;
        lxDevice_Declaration.monthinput = (unsigned char)1;
        lxDevice_Declaration.yearinput = (unsigned char)10;
    }
    lxDevice_Declaration.dayuser = lxDevice_Declaration.dayinput;
    lxDevice_Declaration.monthuser = lxDevice_Declaration.monthinput;
    lxDevice_Declaration.yearuser = lxDevice_Declaration.yearinput;
    lxDevice_Declaration.taskid = 0;
    lxDevice_Declaration.numtps = declaration.Size();

    for (unsigned i = 0; i < LX::NUMTPS; i++) {
        if (i == 0) { // takeoff
            lxDevice_Declaration.tptypes[i] = 3;
            lxDevice_Declaration.Latitudes[i] = 0;
            lxDevice_Declaration.Longitudes[i] = 0;
            copy_space_padded(lxDevice_Declaration.WaypointNames[i], _T("TAKEOFF"),
                              sizeof(lxDevice_Declaration.WaypointNames[i]));


        } else if (i <= declaration.Size()) {
            lxDevice_Declaration.tptypes[i] = 1;
            lxDevice_Declaration.Longitudes[i] =
                AngleToLX(declaration.GetLocation(i - 1).longitude);
            lxDevice_Declaration.Latitudes[i] =
                AngleToLX(declaration.GetLocation(i - 1).latitude);
            copy_space_padded(lxDevice_Declaration.WaypointNames[i],
                              declaration.GetName(i - 1),
                              sizeof(lxDevice_Declaration.WaypointNames[i]));

        } else if (i == declaration.Size() + 1) { // landing
            lxDevice_Declaration.tptypes[i] = 2;
            lxDevice_Declaration.Longitudes[i] = 0;
            lxDevice_Declaration.Latitudes[i] = 0;
            copy_space_padded(lxDevice_Declaration.WaypointNames[i], _T("LANDING"),
                              sizeof(lxDevice_Declaration.WaypointNames[i]));

        } else { // unused
            lxDevice_Declaration.tptypes[i] = 0;
            lxDevice_Declaration.Longitudes[i] = 0;
            lxDevice_Declaration.Latitudes[i] = 0;
            memset((void*)lxDevice_Declaration.WaypointNames[i], 0, 9);
        }
    }

    return true;
}
コード例 #3
0
ファイル: Declare.cpp プロジェクト: kwtskran/XCSoar
bool
FlarmDevice::DeclareInternal(const Declaration &declaration,
                             OperationEnvironment &env)
{
  unsigned size = declaration.Size();

  env.SetProgressRange(6 + size);
  env.SetProgressPosition(0);

  if (!SetPilot(declaration.pilot_name.c_str(), env))
    return false;

  env.SetProgressPosition(1);

  if (!SetPlaneRegistration(declaration.aircraft_registration.c_str(), env))
    return false;

  env.SetProgressPosition(2);

  if (!SetPlaneType(declaration.aircraft_type.c_str(), env))
    return false;

  env.SetProgressPosition(3);

  if (!SetConfig("NEWTASK", "Task", env))
    return false;

  env.SetProgressPosition(4);

  if (!SetConfig("ADDWP", "0000000N,00000000E,T", env))
    return false;

  env.SetProgressPosition(5);

  for (unsigned i = 0; i < size; ++i) {
    int DegLat, DegLon;
    fixed tmp, MinLat, MinLon;
    char NoS, EoW;

    tmp = declaration.GetLocation(i).latitude.Degrees();
    if (negative(tmp)) {
      NoS = 'S';
      tmp = -tmp;
    } else {
      NoS = 'N';
    }
    DegLat = (int)tmp;
    MinLat = (tmp - fixed(DegLat)) * 60 * 1000;

    tmp = declaration.GetLocation(i).longitude.Degrees();
    if (negative(tmp)) {
      EoW = 'W';
      tmp = -tmp;
    } else {
      EoW = 'E';
    }
    DegLon = (int)tmp;
    MinLon = (tmp - fixed(DegLon)) * 60 * 1000;

    /*
     * We use the waypoint index here as name to get around the 192 byte
     * task size limit of the FLARM devices.
     *
     * see Flarm DataPort Manual:
     * "The total data size entered through this command may not surpass
     * 192 bytes when calculated as follows: 7+(Number of Waypoints * 9) +
     * (sum of length of all task and waypoint descriptions)"
     */
    NarrowString<90> buffer;
    buffer.Format("%02d%05.0f%c,%03d%05.0f%c,%d",
                  DegLat, (double)MinLat, NoS,
                  DegLon, (double)MinLon, EoW, i + 1);

    if (!SetConfig("ADDWP", buffer, env))
      return false;

    env.SetProgressPosition(6 + i);
  }

  if (!SetConfig("ADDWP", "0000000N,00000000E,L", env))
    return false;

  env.SetProgressPosition(6 + size);

  // PFLAC,S,KEY,VALUE
  // Expect
  // PFLAC,A,blah
  // PFLAC,,COPIL:
  // PFLAC,,COMPID:
  // PFLAC,,COMPCLASS:

  // PFLAC,,NEWTASK:
  // PFLAC,,ADDWP:

  // Reset the FLARM to activate the declaration
  Restart(env);

  return true;
}