Example #1
0
bool
WPASupplicant::SelectNetwork(unsigned id)
{
  NarrowString<64> cmd;
  cmd.Format("SELECT_NETWORK %u", id);
  return SendCommand(cmd) && ExpectOK();
}
Example #2
0
bool
WPASupplicant::DisableNetwork(unsigned id)
{
  NarrowString<64> cmd;
  cmd.Format("DISABLE_NETWORK %u", id);
  return SendCommand(cmd) && ExpectOK();
}
Example #3
0
bool
WPASupplicant::RemoveNetwork(unsigned id)
{
  NarrowString<64> cmd;
  cmd.Format("REMOVE_NETWORK %u", id);
  return SendCommand(cmd) && ExpectOK();
}
Example #4
0
bool
FlarmDevice::SetBaudRate(unsigned baud_id, OperationEnvironment &env)
{
  NarrowString<32> buffer;
  buffer.Format("%u", baud_id);
  return SetConfig("BAUD", buffer, env);
}
Example #5
0
bool
LiveTrack24::StartTracking(SessionID session, const TCHAR *username,
                           const TCHAR *password, unsigned tracking_interval,
                           VehicleType vtype, const TCHAR *vname,
                           OperationEnvironment &env)
{
  // http://www.livetrack24.com/track.php?leolive=2&sid=42664778&pid=1&
  //   client=YourProgramName&v=1&user=yourusername&pass=yourpass&
  //   phone=Nokia 2600c&gps=BT GPS&trk1=4&vtype=16388&
  //   vname=vehicle name and model

  const WideToUTF8Converter username2(username);
  const WideToUTF8Converter password2(password);
  const WideToUTF8Converter vname2(vname);
  if (!username2.IsValid() || !password2.IsValid() || !vname2.IsValid())
    return false;

#ifdef _UNICODE
  NarrowString<32> version;
  version.SetASCII(XCSoar_VersionLong);
#else
  const char *version = XCSoar_VersionLong;
#endif

  NarrowString<2048> url;
  url.Format("http://%s/track.php?leolive=2&sid=%u&pid=%u&"
             "client=%s&v=%s&user=%s&pass=%s&vtype=%u&vname=%s",
             GetServer(), session, 1, "XCSoar", version,
             (const char *)username2, (const char *)password, vtype, vname);

  return SendRequest(url, env);
}
Example #6
0
bool
FlarmDevice::SetRange(unsigned range, OperationEnvironment &env)
{
  NarrowString<32> buffer;
  buffer.Format("%d", range);
  return SetConfig("RANGE", buffer, env);
}
Example #7
0
bool
WPASupplicant::SetNetworkID(unsigned id,
                                const char *name, const char *value)
{
  NarrowString<512> cmd;
  cmd.Format("SET_NETWORK %u %s %s", id, name, value);
  return SendCommand(cmd) && ExpectOK();
}
Example #8
0
void
PlaneGlue::Write(const Plane &plane, KeyValueFileWriter &writer)
{
  NarrowString<255> tmp;

  writer.Write("Registration", plane.registration);
  writer.Write("CompetitionID", plane.competition_id);
  writer.Write("Type", plane.type);

  tmp.Format("%u", plane.handicap);
  writer.Write("Handicap", tmp);

  writer.Write("PolarName", plane.polar_name);

  FormatPolarShape(plane.polar_shape, tmp.buffer(), tmp.MAX_SIZE);
  writer.Write("PolarInformation", tmp);

  tmp.Format("%f", (double)plane.reference_mass);
  writer.Write("PolarReferenceMass", tmp);
  tmp.Format("%f", (double)plane.dry_mass);
  writer.Write("PolarDryMass", tmp);
  tmp.Format("%f", (double)plane.max_ballast);
  writer.Write("MaxBallast", tmp);
  tmp.Format("%f", (double)plane.dump_time);
  writer.Write("DumpTime", tmp);
  tmp.Format("%f", (double)plane.max_speed);
  writer.Write("MaxSpeed", tmp);
  tmp.Format("%f", (double)plane.wing_area);
  writer.Write("WingArea", tmp);
}
Example #9
0
bool
LiveTrack24::Client::EndTracking(OperationEnvironment &env)
{
  // http://www.livetrack24.com/track.php?leolive=3&sid=42664778&pid=453&prid=0

  NarrowString<1024> url;
  url.Format("http://%s/track.php?leolive=3&sid=%u&pid=%u&prid=0",
             (const char *)server, session_id, packet_id);

  return SendRequest(url, env);
}
Example #10
0
bool
LiveTrack24::EndTracking(SessionID session, unsigned packet_id,
                         OperationEnvironment &env)
{
  // http://www.livetrack24.com/track.php?leolive=3&sid=42664778&pid=453&prid=0

  NarrowString<1024> url;
  url.Format("http://%s/track.php?leolive=3&sid=%u&pid=%u&prid=0",
             GetServer(), session, packet_id);

  return SendRequest(url, env);
}
Example #11
0
bool
FlarmDevice::SetConfig(const char *setting, const char *value,
                       OperationEnvironment &env)
{
  NarrowString<256> buffer;
  buffer.Format("PFLAC,S,%s,%s", setting, value);

  NarrowString<256> expected_answer(buffer);
  expected_answer[6u] = 'A';

  Send(buffer, env);
  return port.ExpectString(expected_answer, env, 2000) &&
    ExpectChecksum(port, NMEAChecksum(expected_answer), env);
}
Example #12
0
bool
FlarmDevice::GetConfig(const char *setting, char *buffer, size_t length,
                       OperationEnvironment &env)
{
  NarrowString<256> request;
  request.Format("PFLAC,R,%s", setting);

  NarrowString<256> expected_answer(request);
  expected_answer[6u] = 'A';
  expected_answer += ',';

  Send(request, env);
  return Receive(expected_answer, buffer, length, env, 2000);
}
Example #13
0
bool
FlarmDevice::GetConfig(const char *setting, char *buffer, size_t length,
                       OperationEnvironment &env)
{
  NarrowString<90> request;
  request.Format("PFLAC,R,%s", setting);

  NarrowString<90> expected_answer(request);
  expected_answer[6u] = 'A';
  expected_answer.push_back(',');

  Send(request, env);
  return Receive(expected_answer, buffer, length,
                 env, std::chrono::seconds(2));
}
Example #14
0
bool
FlarmDevice::SetConfig(const char *setting, const TCHAR *value)
{
  NarrowPathName narrow_value(value);

  NarrowString<256> buffer;
  buffer.Format("PFLAC,S,%s,", setting);
  buffer.append(narrow_value);

  NarrowString<256> expected_answer(buffer);
  expected_answer[6u] = 'A';

  Send(buffer);
  return port.ExpectString(expected_answer);
}
Example #15
0
bool
LiveTrack24::Client::GenerateSessionID(const TCHAR *_username, const TCHAR *_password,
                                       OperationEnvironment &env)
{
  // http://www.livetrack24.com/client.php?op=login&user=<username>&pass=<pass>

  assert(_username != NULL);
  assert(!StringIsEmpty(_username));
  assert(_password != NULL);
  assert(!StringIsEmpty(_password));

  const WideToUTF8Converter username2(_username);
  const WideToUTF8Converter password2(_password);
  if (!username2.IsValid() || !password2.IsValid())
    return false;

  NarrowString<1024> url;
  url.Format("http://%s/client.php?op=login&user=%s&pass=%s",
             (const char *)server, (const char *)username2, (const char *)_password);

  // Open download session
  Net::Session session;

  // Request the file
  char buffer[1024];
  size_t size = Net::DownloadToBuffer(session, url, buffer, sizeof(buffer) - 1,
                                      env);
  if (size == 0 || size == size_t(-1))
    return false;

  buffer[size] = 0;

  char *p_end;
  UserID user_id = strtoul(buffer, &p_end, 10);
  if (buffer == p_end) {
      return false;
  }

  username.SetASCII(_username);
  password.SetASCII(_password);
  session_id = RandomSessionID();
  session_id |= (user_id & 0x00ffffff);
  return true;
}
Example #16
0
bool
FlarmDevice::GetConfig(const char *setting, TCHAR *buffer, size_t length)
{
  NarrowString<256> request;
  request.Format("PFLAC,R,%s", setting);

  NarrowString<256> expected_answer(request);
  expected_answer[6u] = 'A';
  expected_answer += ',';

  char narrow_buffer[length];

  Send(request);
  if (!Receive(expected_answer, narrow_buffer, length, 1000))
    return false;

  _tcscpy(buffer, PathName(narrow_buffer));
  return true;
}
Example #17
0
bool
LiveTrack24::SendPosition(SessionID session, unsigned packet_id,
                          GeoPoint position, unsigned altitude,
                          unsigned ground_speed, Angle track,
                          int64_t timestamp_utc,
                          OperationEnvironment &env)
{
  // http://www.livetrack24.com/track.php?leolive=4&sid=42664778&pid=321&
  //   lat=22.3&lon=40.2&alt=23&sog=40&cog=160&tm=1241422845

  NarrowString<2048> url;
  url.Format("http://%s/track.php?leolive=4&sid=%u&pid=%u&"
             "lat=%f&lon=%f&alt=%d&sog=%d&cog=%d&tm=%lld",
             GetServer(), session, packet_id,
             (double)position.latitude.Degrees(),
             (double)position.longitude.Degrees(),
             altitude, ground_speed,
             (unsigned)track.AsBearing().Degrees(),
             (long long int)timestamp_utc);

  return SendRequest(url, env);
}
Example #18
0
LiveTrack24::UserID
LiveTrack24::GetUserID(const TCHAR *username, const TCHAR *password,
                       OperationEnvironment &env)
{
  // http://www.livetrack24.com/client.php?op=login&user=<username>&pass=<pass>

  assert(username != NULL);
  assert(!StringIsEmpty(username));
  assert(password != NULL);
  assert(!StringIsEmpty(password));

  const WideToUTF8Converter username2(username);
  const WideToUTF8Converter password2(password);
  if (!username2.IsValid() || !password2.IsValid())
    return 0;

  NarrowString<1024> url;
  url.Format("http://%s/client.php?op=login&user=%s&pass=%s",
             GetServer(), (const char *)username2, (const char *)password);

  // Open download session
  Net::Session session;

  // Request the file
  char buffer[1024];
  size_t size = Net::DownloadToBuffer(session, url, buffer, sizeof(buffer) - 1,
                                      env);
  if (size == 0 || size == size_t(-1))
    return 0;

  buffer[size] = 0;

  char *p_end;
  UserID user_id = strtoul(buffer, &p_end, 10);
  if (buffer == p_end)
    return 0;

  return user_id;
}
Example #19
0
void
Profile::SetFont(const char *key, LOGFONT &logfont)
{
  assert(key != NULL);
  assert(key[0] != '\0');

#ifdef _UNICODE
  char face[256];
  WideCharToMultiByte(CP_UTF8, 0, logfont.lfFaceName, -1,
                      face, ARRAY_SIZE(face),
                      nullptr, nullptr);
#else
  const char *face = logfont.lfFaceName;
#endif

  NarrowString<256> buffer;
  buffer.Format("%d,%d,0,0,%d,%d,0,0,0,0,0,%d,%d,%s", logfont.lfHeight,
                logfont.lfWidth, logfont.lfWeight, logfont.lfItalic,
                logfont.lfQuality, logfont.lfPitchAndFamily,
                face);

  Profile::Set(key, buffer);
}
Example #20
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;
}