Ejemplo n.º 1
0
bool
AltairProDevice::DeclareInternal(const struct Declaration &declaration)
{
  TCHAR Buffer[256];

  _stprintf(Buffer, _T("PDVSC,S,Pilot,%s"), declaration.pilot_name.c_str());
  if (!PropertySetGet(port, Buffer, ARRAY_SIZE(Buffer)))
    return false;

  _stprintf(Buffer, _T("PDVSC,S,GliderID,%s"), declaration.aircraft_registration.c_str());
  if (!PropertySetGet(port, Buffer, ARRAY_SIZE(Buffer)))
    return false;

  _stprintf(Buffer, _T("PDVSC,S,GliderType,%s"), declaration.aircraft_type.c_str());
  if (!PropertySetGet(port, Buffer, ARRAY_SIZE(Buffer)))
    return false;

  /* TODO currently not supported by XCSOAR
   * Pilot2
   * CompetitionID
   * CompetitionClass
   * ObserverID
   * DeclDescription
   * DeclFlightDate
   */

  if (declaration.Size() > 1) {
    PutTurnPoint(_T("DeclTakeoff"), NULL);
    PutTurnPoint(_T("DeclLanding"), NULL);

    PutTurnPoint(_T("DeclStart"), &declaration.GetFirstWaypoint());
    PutTurnPoint(_T("DeclFinish"), &declaration.GetLastWaypoint());

    for (unsigned int index=1; index <= 10; index++){
      TCHAR TurnPointPropertyName[32];
      _stprintf(TurnPointPropertyName, _T("DeclTurnPoint%d"), index);

      if (index < declaration.Size() - 1) {
        PutTurnPoint(TurnPointPropertyName, &declaration.GetWaypoint(index));
      } else {
        PutTurnPoint(TurnPointPropertyName, NULL);
      }
    }
  }

  _stprintf(Buffer, _T("PDVSC,S,DeclAction,DECLARE"));
  if (!PropertySetGet(port, Buffer, ARRAY_SIZE(Buffer)))
    return false;

  if (_tcscmp(&Buffer[9], _T("LOCKED")) == 0)
    // FAILED! try to declare a task on a airborn recorder
    return false;

  // Buffer holds the declaration ticket.
  // but no one is intresting in that
  // eg "2010-11-21 13:01:43 (1)"

  return true;
}
Ejemplo n.º 2
0
void
AltairProDevice::PutTurnPoint(const TCHAR *propertyName,
                              const Waypoint *waypoint,
                              OperationEnvironment &env)
{

    TCHAR Name[DECELWPNAMESIZE];
    TCHAR Buffer[DECELWPSIZE*2];

    int DegLat, DegLon;
    double tmp, MinLat, MinLon;
    char NoS, EoW;

    if (waypoint != NULL) {

        CopyString(Name, waypoint->name.c_str(), ARRAY_SIZE(Name));

        tmp = (double)waypoint->location.latitude.Degrees();

        if(tmp < 0) {
            NoS = 'S';
            tmp *= -1;
        } else NoS = 'N';

        DegLat = (int)tmp;
        MinLat = tmp - DegLat;
        MinLat *= 60;
        MinLat *= 1000;

        tmp = (double)waypoint->location.longitude.Degrees();

        if (tmp < 0) {
            EoW = 'W';
            tmp *= -1;
        } else EoW = 'E';

        DegLon = (int)tmp;
        MinLon = tmp  - DegLon;
        MinLon *= 60;
        MinLon *= 1000;

    } else {

        Name[0] = '\0';
        DegLat = 0;
        MinLat = 0;
        DegLon = 0;
        MinLon = 0;
        NoS = 'N';
        EoW = 'E';
    }

    _stprintf(Buffer, _T("PDVSC,S,%s,%02d%05.0f%c%03d%05.0f%c%s"),
              propertyName,
              DegLat, MinLat, NoS, DegLon, MinLon, EoW, Name
             );

    PropertySetGet(Buffer, ARRAY_SIZE(Buffer), env);

}
Ejemplo n.º 3
0
bool
AltairProDevice::PropertySetGet(TCHAR *s, size_t size)
{
  assert(s != NULL);

  char buffer[_tcslen(s) * 4 + 1];
  if (::WideCharToMultiByte(CP_ACP, 0, s, -1, buffer, sizeof(buffer),
                               NULL, NULL) <= 0)
    return false;

  if (!PropertySetGet(buffer, _tcslen(s) * 4 + 1))
    return false;

  if (::MultiByteToWideChar(CP_ACP, 0, buffer, -1, s, size) <= 0)
    return false;

  return true;

}
Ejemplo n.º 4
0
bool
AltairProDevice::PropertySetGet(TCHAR *s, size_t size,
                                OperationEnvironment &env)
{
    assert(s != nullptr);

    char buffer[_tcslen(s) * 4 + 1];
    if (::WideCharToMultiByte(CP_ACP, 0, s, -1, buffer, sizeof(buffer),
                              nullptr, nullptr) <= 0)
        return false;

    if (!PropertySetGet(buffer, _tcslen(s) * 4 + 1, env))
        return false;

    if (::MultiByteToWideChar(CP_ACP, 0, buffer, -1, s, size) <= 0)
        return false;

    return true;

}