Esempio n. 1
0
bool
LXDevice::Declare(const Declaration &declaration,
                  gcc_unused const Waypoint *home,
                  OperationEnvironment &env)
{
  if (declaration.Size() < 2 || declaration.Size() > 12)
    return false;

  if (!EnableCommandMode(env))
    return false;

  unsigned old_baud_rate = 0;
  if (bulk_baud_rate != 0) {
    old_baud_rate = port.GetBaudrate();
    if (old_baud_rate == bulk_baud_rate)
      old_baud_rate = 0;
    else if (!port.SetBaudrate(bulk_baud_rate))
      return false;
  }

  bool success = DeclareInner(port, declaration, env);

  LX::CommandModeQuick(port, env);

  return success;
}
Esempio n. 2
0
static bool
DeclareInner(Port &port, const Declaration &declaration, const Waypoint *home,
             OperationEnvironment &env)
{
  assert(declaration.Size() >= 2);

  VLAPI vl(port, 38400L, env);

  if (vl.connect(20) != VLA_ERR_NOERR)
    return false;

  memset(&vl.database, 0, sizeof(vl.database));
  memset(&vl.declaration, 0, sizeof(vl.declaration));

  CopyToNarrowBuffer(vl.declaration.flightinfo.pilot,
		     sizeof(vl.declaration.flightinfo.pilot),
                     declaration.pilot_name);

  CopyToNarrowBuffer(vl.declaration.flightinfo.gliderid,
                     sizeof(vl.declaration.flightinfo.gliderid),
                     declaration.aircraft_registration);

  CopyToNarrowBuffer(vl.declaration.flightinfo.glidertype,
                     sizeof(vl.declaration.flightinfo.glidertype),
                     declaration.aircraft_type);

  if (home != NULL)
    CopyWaypoint(vl.declaration.flightinfo.homepoint, *home);

  // start..
  CopyTurnPoint(vl.declaration.task.startpoint,
                declaration.turnpoints.front());

  // rest of task...
  const unsigned n = std::min(declaration.Size() - 2, 12u);
  for (unsigned i = 0; i < n; ++i)
    CopyTurnPoint(vl.declaration.task.turnpoints[i],
                  declaration.turnpoints[i + 1]);

  // Finish
  CopyTurnPoint(vl.declaration.task.finishpoint,
                declaration.turnpoints.back());

  vl.declaration.task.nturnpoints = n;

  bool success = vl.write_db_and_declaration() == VLA_ERR_NOERR;
  Volkslogger::Reset(port, env);
  return success;
}
Esempio n. 3
0
bool
VolksloggerDevice::Declare(const Declaration &declaration,
                           const Waypoint *home,
                           OperationEnvironment &env)
{
  if (declaration.Size() < 2)
    return false;

  port.StopRxThread();

  // change to IO mode baud rate
  unsigned old_baud_rate = port.GetBaudrate();
  if (old_baud_rate == 9600)
    old_baud_rate = 0;
  else if (old_baud_rate != 0 && !port.SetBaudrate(9600))
    return false;

  bool success = DeclareInner(port, declaration, home, env);

  // restore baudrate
  if (old_baud_rate != 0)
    port.SetBaudrate(old_baud_rate);

  return success;
}
Esempio n. 4
0
bool
VolksloggerDevice::Declare(const Declaration &declaration,
                           const Waypoint *home,
                           OperationEnvironment &env)
{
  if (declaration.Size() < 2)
    return false;

  env.SetText(_T("Comms with Volkslogger"));

  port.SetRxTimeout(500);

  // change to IO mode baud rate
  unsigned lLastBaudrate = port.SetBaudrate(9600L);

  VLAPI vl(port, env);

  bool success = DeclareInner(vl, declaration, home);

  vl.close(1);

  port.SetBaudrate(lLastBaudrate); // restore baudrate

  return success;
}
Esempio n. 5
0
void
Logger::GUIStartLogger(const NMEAInfo& gps_info,
                    const ComputerSettings& settings,
                       const ProtectedTaskManager *protected_task_manager,
                    bool noAsk)
{
  if (IsLoggerActive() || gps_info.gps.replay)
    return;

  OrderedTask* task = protected_task_manager != nullptr
    ? protected_task_manager->TaskClone()
    : nullptr;
  const Declaration decl(settings.logger, settings.plane, task);

  if (task) {
    delete task;

    if (!noAsk) {
      TCHAR TaskMessage[1024];
      _tcscpy(TaskMessage, _T("Start Logger With Declaration\r\n"));
      
      if (decl.Size()) {
        for (unsigned i = 0; i< decl.Size(); ++i) {
          _tcscat(TaskMessage, decl.GetName(i));
          _tcscat(TaskMessage, _T("\r\n"));
        }
      } else {
        _tcscat(TaskMessage, _T("None"));
      }
      
      if (ShowMessageBox(TaskMessage, _("Start Logger"),
                      MB_YESNO | MB_ICONQUESTION) != IDYES)
        return;
    }
  }

  if (!LoggerClearFreeSpace(gps_info.date_time_utc.year)) {
    ShowMessageBox(_("Logger inactive, insufficient storage!"),
                _("Logger Error"), MB_OK| MB_ICONERROR);
    LogFormat("Logger not started: Insufficient Storage");
    return;
  }

  const ScopeExclusiveLock protect(lock);
  logger.StartLogger(gps_info, settings.logger, asset_number, decl);
}
Esempio n. 6
0
bool
LXDevice::Declare(const Declaration &declaration,
                  gcc_unused const Waypoint *home,
                  OperationEnvironment &env)
{
  if (declaration.Size() < 2 || declaration.Size() > 12)
    return false;

  if (!EnableCommandMode(env))
    return false;

  bool success = DeclareInner(port, declaration, env);

  LX::CommandModeQuick(port, env);

  return success;
}
Esempio n. 7
0
static bool
DeclareInner(VLAPI &vl, const Declaration &declaration, const Waypoint *home)
{
  assert(declaration.Size() >= 2);

  if (vl.open(20, 38400L) != VLA_ERR_NOERR ||
      vl.read_info() != VLA_ERR_NOERR)
    return false;

  memset(&vl.database, 0, sizeof(vl.database));
  memset(&vl.declaration, 0, sizeof(vl.declaration));

  CopyToNarrowBuffer(vl.declaration.flightinfo.pilot,
		     sizeof(vl.declaration.flightinfo.pilot),
                     declaration.pilot_name);

  CopyToNarrowBuffer(vl.declaration.flightinfo.gliderid,
                     sizeof(vl.declaration.flightinfo.gliderid),
                     declaration.aircraft_registration);

  CopyToNarrowBuffer(vl.declaration.flightinfo.glidertype,
                     sizeof(vl.declaration.flightinfo.glidertype),
                     declaration.aircraft_type);

  if (home != NULL)
    CopyWaypoint(vl.declaration.flightinfo.homepoint, *home);

  // start..
  CopyTurnPoint(vl.declaration.task.startpoint,
                declaration.turnpoints.front());

  // rest of task...
  const unsigned n = std::min(declaration.Size() - 2, 12u);
  for (unsigned i = 0; i < n; ++i)
    CopyTurnPoint(vl.declaration.task.turnpoints[i],
                  declaration.turnpoints[i + 1]);

  // Finish
  CopyTurnPoint(vl.declaration.task.finishpoint,
                declaration.turnpoints.back());

  vl.declaration.task.nturnpoints = n;

  return vl.write_db_and_declaration() == VLA_ERR_NOERR;
}
Esempio n. 8
0
bool
EWMicroRecorderDevice::Declare(const Declaration &declaration,
                               const Waypoint *home,
                               OperationEnvironment &env)
{
  // Must have at least two, max 12 waypoints
  if (declaration.Size() < 2 || declaration.Size() > 12)
    return false;

  port.StopRxThread();

  bool success = DeclareInner(port, declaration, env);

  // go back to NMEA mode
  port.FullWrite("!!\r\n", 4, env, 500);

  return success;
}
Esempio n. 9
0
bool
EWMicroRecorderDevice::Declare(const Declaration &declaration,
                               const Waypoint *home,
                               OperationEnvironment &env)
{
    // Must have at least two, max 12 waypoints
    if (declaration.Size() < 2 || declaration.Size() > 12)
        return false;

    /* during tests, the EW has taken up to one second to respond to
       the command \x18 */
    port.SetRxTimeout(2500);

    bool success = DeclareInner(port, declaration, env);

    // go back to NMEA mode
    port.FullWrite("!!\r\n", 4, 500);

    return success;
}
Esempio n. 10
0
bool
LXDevice::Declare(const Declaration &declaration,
                  gcc_unused const Waypoint *home,
                  OperationEnvironment &env)
{
    if (declaration.Size() < 2 || declaration.Size() > 12)
        return false;

    const unsigned old_baud_rate = bulk_baud_rate != 0
                                   ? port.SetBaudrate(bulk_baud_rate)
                                   : 0;

    bool success = DeclareInner(port, declaration, env);

    LX::CommandModeQuick(port, env);

    if (old_baud_rate != 0)
        port.SetBaudrate(old_baud_rate);

    return success;
}
Esempio n. 11
0
// 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();
  }
}
Esempio n. 12
0
bool
IMIDevice::Declare(const Declaration &declaration,
                   gcc_unused const Waypoint *home,
                   OperationEnvironment &env)
{
  // verify WP number
  unsigned size = declaration.Size();
  if (size < 2 || size > 13)
    return false;

  bool success = Connect(env) && !env.IsCancelled();
  success = success && IMI::DeclarationWrite(port, declaration);

  // disconnect
  Disconnect();

  return success;
}
Esempio n. 13
0
bool
IMI::DeclarationWrite(Port &port, const Declaration &decl,
                      OperationEnvironment &env)
{
  if (!_connected)
    return false;

  TDeclaration imiDecl;
  memset(&imiDecl, 0, sizeof(imiDecl));

  // idecl.date ignored - will be set by FR
  ConvertToChar(decl.pilot_name, imiDecl.header.plt,
                  sizeof(imiDecl.header.plt));
  ConvertToChar(decl.aircraft_type, imiDecl.header.gty,
                  sizeof(imiDecl.header.gty));
  ConvertToChar(decl.aircraft_registration, imiDecl.header.gid,
                  sizeof(imiDecl.header.gid));
  ConvertToChar(decl.competition_id, imiDecl.header.cid,
                  sizeof(imiDecl.header.cid));
  ConvertToChar(_T("XCSOARTASK"), imiDecl.header.tskName,
                  sizeof(imiDecl.header.tskName));

  ConvertWaypoint(decl.turnpoints[0].waypoint, imiDecl.wp[0]);

  unsigned size = decl.Size();
  for (unsigned i = 0; i < size; i++) {
    ConvertWaypoint(decl.turnpoints[i].waypoint, imiDecl.wp[i + 1]);
    ConvertOZ(decl.turnpoints[i], i == 0, i == size - 1,
              imiDecl.wp[i + 1]);
  }

  ConvertWaypoint(decl.turnpoints[size - 1].waypoint,
              imiDecl.wp[size + 1]);

  // send declaration for current task
  return SendRet(port, env, MSG_DECLARATION, &imiDecl, sizeof(imiDecl),
                 MSG_ACK_SUCCESS, 0, -1) != nullptr;
}
Esempio n. 14
0
/**
 * 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;
}
Esempio n. 15
0
static bool
DeclareInner(Port &port, const Declaration &declaration,
             OperationEnvironment &env)
{
  assert(declaration.Size() >= 2);
  assert(declaration.Size() <= 12);

  char user_data[2500];

  if (!TryConnectRetry(port, user_data, sizeof(user_data), env))
    return false;

  char *p = strstr(user_data, "USER DETAILS");
  if (p != NULL)
    *p = 0;

  port.Write('\x18');         // start to upload file

  if (!port.FullWriteString(user_data, env, 5000) ||
      !port.FullWriteString("USER DETAILS\r\n--------------\r\n\r\n",
                            env, 1000))
    return false;

  WritePair(port, "Pilot Name", declaration.pilot_name.c_str(), env);
  WritePair(port, "Competition ID", declaration.competition_id.c_str(), env);
  WritePair(port,  "Aircraft Type", declaration.aircraft_type.c_str(), env);
  WritePair(port,  "Aircraft ID",
            declaration.aircraft_registration.c_str(), env);

  if (!port.FullWriteString("\r\nFLIGHT DECLARATION\r\n-------------------\r\n\r\n",
                            env, 1000))
    return false;

  WritePair(port, "Description", _T("XCSoar task declaration"), env);

  for (unsigned i = 0; i < 11; i++) {
    if (env.IsCancelled())
      return false;

    if (i+1>= declaration.Size()) {
      port.FullWriteString("TP LatLon: 0000000N00000000E TURN POINT\r\n",
                           env, 1000);
    } else {
      const Waypoint &wp = declaration.GetWaypoint(i);
      if (i == 0) {
        if (!EWMicroRecorderWriteWaypoint(port, "Take Off LatLong", wp, env) ||
            !EWMicroRecorderWriteWaypoint(port, "Start LatLon", wp, env))
          return false;
      } else if (i + 1 < declaration.Size()) {
        if (!EWMicroRecorderWriteWaypoint(port, "TP LatLon", wp, env))
          return false;
      }
    }
  }

  const Waypoint &wp = declaration.GetLastWaypoint();
  if (!EWMicroRecorderWriteWaypoint(port, "Finish LatLon", wp, env) ||
      !EWMicroRecorderWriteWaypoint(port, "Land LatLon", wp, env) ||
      env.IsCancelled())
      return false;

  port.Write('\x03');         // finish sending user file

  return port.ExpectString("uploaded successfully", env, 5000);
}
Esempio n. 16
0
static bool
DeclareInner(Port &port, const Declaration &declaration,
             gcc_unused OperationEnvironment &env)
{
  using CAI302::UploadShort;
  unsigned size = declaration.Size();

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

  CAI302::PilotMeta pilot_meta;
  if (!CAI302::UploadPilotMeta(port, pilot_meta, env))
    return false;

  env.SetProgressPosition(1);

  CAI302::Pilot pilot;
  if (!CAI302::UploadPilot(port, 0, pilot, env))
    return false;

  env.SetProgressPosition(2);

  CAI302::PolarMeta polar_meta;
  if (!CAI302::UploadPolarMeta(port, polar_meta, env))
    return false;

  env.SetProgressPosition(3);

  CAI302::Polar polar;
  if (!CAI302::UploadPolar(port, polar, env))
    return false;

  env.SetProgressPosition(4);

  if (!CAI302::DownloadMode(port, env))
    return false;

  char GliderType[13], GliderID[13];
  convert_string(GliderType, sizeof(GliderType), declaration.aircraft_type);
  convert_string(GliderID, sizeof(GliderID), declaration.aircraft_registration);

  convert_string(pilot.name, sizeof(pilot.name), declaration.pilot_name);
  if (!CAI302::DownloadPilot(port, pilot, 0, env))
    return false;

  env.SetProgressPosition(5);

  convert_string(polar.glider_type, sizeof(polar.glider_type),
                 declaration.aircraft_type);
  convert_string(polar.glider_id, sizeof(polar.glider_id),
                 declaration.aircraft_registration);
  if (!CAI302::DownloadPolar(port, polar, env))
    return false;

  env.SetProgressPosition(6);

  for (unsigned i = 0; i < size; ++i) {
    if (!cai302DeclAddWaypoint(port, i, declaration.GetWaypoint(i), env))
      return false;

    env.SetProgressPosition(7 + i);
  }

  return CAI302::DeclareSave(port, env);
}
Esempio n. 17
0
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;
}