Example #1
0
bool
InfoBoxesConfigWidget::Save(bool &changed_r)
{
  if (allow_name_change) {
    const auto *new_name = GetValueString(InfoBoxesConfigWidget::NAME);
    if (!StringIsEqual(new_name, data.name)) {
      data.name = new_name;
      changed = true;
    }
  }

  changed_r = changed;
  return true;
}
Example #2
0
gcc_pure
static const BuiltinLanguage *
FindLanguage(const TCHAR *resource)
{
  assert(resource != NULL);

  // Search for supported languages matching the MO file name
  for (unsigned i = 0; language_table[i].resource != NULL; ++i)
    if (StringIsEqual(language_table[i].resource, resource))
      // .. and return the language code
      return &language_table[i];

  return nullptr;
}
Example #3
0
void
ParsePFLAE(NMEAInputLine &line, FlarmError &error, double clock)
{
    char type[2];
    line.Read(type, ARRAY_SIZE(type));
    if (!StringIsEqual(type, "A"))
        return;

    error.severity = (FlarmError::Severity)
                     line.Read((int)FlarmError::Severity::NO_ERROR);
    error.code = (FlarmError::Code)line.ReadHex(0);

    error.available.Update(clock);
}
Example #4
0
const char *
StringAfterPrefix(const char *string, const char *prefix)
{
#if !CLANG_CHECK_VERSION(3,6)
  /* disabled on clang due to -Wtautological-pointer-compare */
  assert(string != nullptr);
  assert(prefix != nullptr);
#endif

  size_t prefix_length = strlen(prefix);
  return StringIsEqual(string, prefix, prefix_length)
    ? string + prefix_length
    : nullptr;
}
Example #5
0
bool
PGDevice::ParseNMEA(const char *String, NMEAInfo &info)
{
  NMEAInputLine line(String);
  char type[16];
  line.Read(type, 16);

  // $GPWIN ... Winpilot proprietary sentance includinh baro altitude
  // $GPWIN ,01900 , 0 , 5159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 * 6 B , 0 7 * 6 0 E
  if (StringIsEqual(type, "$GPWIN"))
    return GPWIN(line, info);
  else
    return LXDevice::ParseNMEA(String, info);
}
Example #6
0
unsigned
ParseKeyCode(const TCHAR *data)
{
  for (const struct string_to_key *p = &string_to_key[0]; p->name != NULL; ++p)
    if (StringIsEqual(data, p->name))
      return p->key;

  if (StringLength(data) == 1)
    return ToUpperASCII(data[0]);

  else
    return 0;

}
Example #7
0
void
InputEvents::eventSounds(const TCHAR *misc)
{
  SoundSettings &settings = CommonInterface::SetUISettings().sound;
 // bool OldEnableSoundVario = EnableSoundVario;

  if (StringIsEqual(misc, _T("toggle")))
    settings.vario.enabled = !settings.vario.enabled;
  else if (StringIsEqual(misc, _T("on")))
    settings.vario.enabled = true;
  else if (StringIsEqual(misc, _T("off")))
    settings.vario.enabled = false;
  else if (StringIsEqual(misc, _T("show"))) {
    if (settings.vario.enabled)
      Message::AddMessage(_("Vario sounds on"));
    else
      Message::AddMessage(_("Vario sounds off"));
    return;
  }

  AudioVarioGlue::Configure(settings.vario);
  Profile::Set(ProfileKeys::SoundAudioVario, settings.vario.enabled);
}
Example #8
0
static int
l_airspace_index(lua_State *L)
{
  const char *name = lua_tostring(L, 2);
  if (name == nullptr)
    return 0;
  else if (StringIsEqual(name, "nearest_vertical_distance")) {
    NearestAirspace nearest = NearestAirspace::FindVertical(CommonInterface::Basic(),
                                                            CommonInterface::Calculated(),
                                                            glide_computer->GetAirspaceWarnings(),
                                                            airspace_database);
    if (!nearest.IsDefined()) return 0;
    Lua::Push(L, nearest.distance);
  } else if (StringIsEqual(name, "nearest_vertical_name")) {
    NearestAirspace nearest = NearestAirspace::FindVertical(CommonInterface::Basic(),
                                                            CommonInterface::Calculated(),
                                                            glide_computer->GetAirspaceWarnings(),
                                                            airspace_database);
    if (!nearest.IsDefined()) return 0;
    Lua::Push(L, nearest.airspace->GetName());
  } else if (StringIsEqual(name, "nearest_horizontal_distance")) {
    NearestAirspace nearest = NearestAirspace::FindHorizontal(CommonInterface::Basic(),
                                                              glide_computer->GetAirspaceWarnings(),
                                                              airspace_database);
    if (!nearest.IsDefined()) return 0;
    Lua::Push(L, nearest.distance);
  } else if (StringIsEqual(name, "nearest_horizontal_name")) {
    NearestAirspace nearest = NearestAirspace::FindHorizontal(CommonInterface::Basic(),
                                                              glide_computer->GetAirspaceWarnings(),
                                                              airspace_database);
    if (!nearest.IsDefined()) return 0;
    Lua::Push(L, nearest.airspace->GetName());
  } else
    return 0;

  return 1;
}
Example #9
0
void
InputEvents::eventOrientation(const TCHAR *misc)
{
  MapSettings &settings_map = CommonInterface::SetMapSettings();

  if (StringIsEqual(misc, _T("northup"))) {
    settings_map.cruise_orientation = NORTHUP;
    settings_map.circling_orientation = NORTHUP;
  } else if (StringIsEqual(misc, _T("northcircle"))) {
    settings_map.cruise_orientation = TRACKUP;
    settings_map.circling_orientation = NORTHUP;
  } else if (StringIsEqual(misc, _T("trackcircle"))) {
    settings_map.cruise_orientation = NORTHUP;
    settings_map.circling_orientation = TRACKUP;
  } else if (StringIsEqual(misc, _T("trackup"))) {
    settings_map.cruise_orientation = TRACKUP;
    settings_map.circling_orientation = TRACKUP;
  } else if (StringIsEqual(misc, _T("northtrack"))) {
    settings_map.cruise_orientation = TRACKUP;
    settings_map.circling_orientation = TARGETUP;
  }

  ActionInterface::SendMapSettings(true);
}
Example #10
0
bool
VolksloggerDevice::ParseNMEA(const char *String, NMEAInfo &info)
{
  if (!VerifyNMEAChecksum(String))
    return false;

  NMEAInputLine line(String);
  char type[16];
  line.Read(type, 16);

  if (StringIsEqual(type, "$PGCS"))
    return vl_PGCS1(line, info);
  else
    return false;
}
Example #11
0
static void *
CallBackLookup(const CallBackTableEntry *lookup_table, const TCHAR *name)
{
  assert(name != NULL);
  assert(!StringIsEmpty(name));
  assert(lookup_table != NULL);

  for (const CallBackTableEntry *p = lookup_table;; ++p) {
    assert(p->name != NULL);
    assert(p->callback != NULL);

    if (StringIsEqual(p->name, name))
      return p->callback;
  }
}
Example #12
0
bool
IsWidcommDevice(const TCHAR *name)
{
  TCHAR key[64];
  if (!FindDevice(name, key, 64))
    return false;

  RegistryKey registry(HKEY_LOCAL_MACHINE, key, true);
  if (registry.error())
    return false;

  TCHAR dll[64];
  return registry.GetValue(_T("Dll"), dll, 64) &&
    StringIsEqual(dll, _T("btcedrivers.dll"));
}
Example #13
0
bool
FlymasterF1Device::ParseNMEA(const char *String, NMEAInfo &info)
{
  if (!VerifyNMEAChecksum(String))
    return false;

  NMEAInputLine line(String);
  char type[16];
  line.Read(type, 16);

  if (StringIsEqual(type, "$VARIO"))
    return VARIO(line, info);
  else
    return false;
}
Example #14
0
void
Profile::Load(const ProfileMap &map, LiveTrack24Settings &settings)
{
  map.Get(ProfileKeys::LiveTrack24Enabled, settings.enabled);

  if (!map.Get(ProfileKeys::LiveTrack24Server, settings.server))
    settings.server = _T("www.livetrack24.com");
  else if (StringIsEqual(settings.server, _T("livexc.dhv1.de"))) {
    // DHV tracking server moved to new host (#3208)
    settings.server = _T("livexc.dhv.de");
  }

  map.Get(ProfileKeys::LiveTrack24Username, settings.username);
  map.Get(ProfileKeys::LiveTrack24Password, settings.password);
}
Example #15
0
bool
CondorDevice::ParseNMEA(const char *String, NMEAInfo &info)
{
  if (!VerifyNMEAChecksum(String))
    return false;

  NMEAInputLine line(String);
  char type[16];
  line.Read(type, 16);

  if (StringIsEqual(type, "$LXWP0"))
    return cLXWP0(line, info);

  return false;
}
Example #16
0
bool
GTAltimeterDevice::ParseNMEA(const char *_line, NMEAInfo &info)
{
  if (!VerifyNMEAChecksum(_line))
    return false;

  NMEAInputLine line(_line);
  char type[16];
  line.Read(type, 16);

  if (StringIsEqual(type, "$LK8EX1"))
    return LK8EX1(line, info);

  return false;
}
Example #17
0
bool
DeviceDescriptor::IsManageable() const
{
  if (driver != nullptr) {
    if (driver->IsManageable())
      return true;

    if (StringIsEqual(driver->name, _T("LX")) && device != nullptr) {
      const LXDevice &lx = *(const LXDevice *)device;
      return lx.IsV7() || lx.IsNano() || lx.IsLX16xx();
    }
  }

  return false;
}
Example #18
0
bool
AltairProDevice::ParseNMEA(const char *String, NMEAInfo &info)
{
    if (!VerifyNMEAChecksum(String))
        return false;

    NMEAInputLine line(String);
    char type[16];
    line.Read(type, 16);

    // no propriatary sentence

    if (StringIsEqual(type, "$PGRMZ")) {
        fixed value;
        if (ReadAltitude(line, value))
            info.ProvidePressureAltitude(value);

        return true;
    } else if (StringIsEqual(type, "$PTFRS")) {
        return PTFRS(line, info);
    }

    return false;
}
Example #19
0
void
WifiListWidget::OnPaintItem(Canvas &canvas, const PixelRect rc,
                            unsigned idx)
{
  const auto &info = networks[idx];

  static char wifi_security[][20] = {
    "WPA",
    "WEP",
    "Open",
  };

  row_renderer.DrawFirstRow(canvas, rc, info.ssid);
  row_renderer.DrawSecondRow(canvas, rc, info.bssid);

  const TCHAR *state = nullptr;
  StaticString<40> state_buffer;

  /* found the currently connected wifi network? */
  if (StringIsEqual(info.bssid, status.bssid)) {
    state = _("Connected");

    /* look up ip address for eth0 */
    const auto addr = IPv4Address::GetDeviceAddress("eth0");
    if (addr.IsDefined()) { /* valid address? */
      StaticString<40> addr_str;
      if (addr.ToString(addr_str.buffer(), addr_str.capacity()) != nullptr) {
        state_buffer.Format(_T("%s (%s)"), state, addr_str.c_str());
        state = state_buffer;
      }
    }
  }
  else if (info.id >= 0)
    state = info.signal_level >= 0
      ? _("Saved and visible")
      : _("Saved, but not visible");
  else if (info.signal_level >= 0)
    state = _("Visible");

  if (state != nullptr)
    row_renderer.DrawRightFirstRow(canvas, rc, state);

  if (info.signal_level >= 0) {
    StaticString<20> text;
    text.UnsafeFormat(_T("%s %u"), wifi_security[info.security], info.signal_level);
    row_renderer.DrawRightSecondRow(canvas, rc, text);
  }
}
Example #20
0
static int
l_wind_index(lua_State *L)
{
  const char *name = lua_tostring(L, 2);
  if (name == nullptr)
    return 0;
  else if (StringIsEqual(name, "wind_mode")) {
    /* Wind mode
       0: Manual, When the algorithm is switched off, the pilot is 
          responsible for setting the wind estimate.
       1: Circling, Requires only a GPS source.
       2: ZigZag, Requires GPS and an intelligent vario with airspeed output.
       3: Both, Uses ZigZag and circling. */
    const WindSettings &settings = CommonInterface::GetComputerSettings().wind;
    Lua::Push(L, (int)settings.GetLegacyAutoWindMode());
  } else if (StringIsEqual(name, "manual_wind_bearing")) {
      SpeedVector manual_wind = CommonInterface::Calculated().GetWindOrZero();
      Lua::Push(L, manual_wind.bearing);
  } else if (StringIsEqual(name, "manual_wind_speed")) {
      SpeedVector manual_wind = CommonInterface::Calculated().GetWindOrZero();
      Lua::Push(L, manual_wind.norm);
  } else if (StringIsEqual(name, "tail_drift")) {
      /* Determines whether the snail trail is drifted with the wind 
         when displayed in circling mode. Switched Off, "
         the snail trail stays uncompensated for wind drift. */
      MapSettings &map_settings = CommonInterface::SetMapSettings();
      if (map_settings.trail.wind_drift_enabled) Lua::Push(L, 1);
      else Lua::Push(L, 0);
  } else if (StringIsEqual(name, "wind_source")) {
      /* The Source of the current wind
         0: None
         1: Manual
         2: Circling
         3: ZigZag
         4: External */
      const DerivedInfo &calculated = CommonInterface::Calculated();
      Lua::Push(L, (int)calculated.wind_source);
  } else if (StringIsEqual(name, "wind_speed")) {
      // The current wind speed [m/s] 
      const DerivedInfo &info = CommonInterface::Calculated();
      Lua::Push(L, info.wind.norm);
  } else if (StringIsEqual(name, "wind_bearing")) {
      // The current wind bearing [degrees]
      const DerivedInfo &info = CommonInterface::Calculated();
      Lua::Push(L, info.wind.bearing);
  } else
    return 0;

  return 1;
}
Example #21
0
unsigned
FlarmDatabase::FindIdsByCallSign(const TCHAR *cn, FlarmId array[],
                                 unsigned size) const
{
  unsigned count = 0;

  for (const auto &i : map) {
    assert(i.first.IsDefined());

    const FlarmRecord &record = i.second;
    if (StringIsEqual(record.callsign, cn))
      array[count++] = i.first;
  }

  return count;
}
Example #22
0
static bool
FindDevice(const TCHAR *name, TCHAR *result, size_t result_size)
{
  RegistryKey drivers_active(HKEY_LOCAL_MACHINE, _T("Drivers\\Active"), true);
  if (drivers_active.error())
    return false;

  TCHAR key_name[64], value[64];
  for (unsigned i = 0; drivers_active.EnumKey(i, key_name, 64); ++i) {
    RegistryKey device(drivers_active, key_name, true);
    if (!device.error() && device.GetValue(_T("Name"), value, 64) &&
        StringIsEqual(name, value))
      return device.GetValue(_T("Key"), result, result_size);
  }

  return false;
}
Example #23
0
bool
Profile::LoadFile(ProfileMap &map, const TCHAR *path, Error &error)
{
  FileLineReaderA reader(path, error);
  if (reader.error())
    return false;

  KeyValueFileReader kvreader(reader);
  KeyValuePair pair;
  while (kvreader.Read(pair))
    /* ignore the "Vega*" values; the Vega driver used to abuse the
       profile to pass messages between the driver and the user
       interface */
    if (!StringIsEqual(pair.key, "Vega", 4))
      map.Set(pair.key, pair.value);

  return true;
}
Example #24
0
void
InputEvents::eventAutoLogger(const TCHAR *misc)
{
  if (is_simulator())
    return;

  LoggerSettings::AutoLogger auto_logger =
    CommonInterface::GetComputerSettings().logger.auto_logger;

  if (auto_logger == LoggerSettings::AutoLogger::OFF)
    return;

  if (auto_logger == LoggerSettings::AutoLogger::START_ONLY &&
      !StringIsEqual(misc, _T("start")))
    return;

  eventLogger(misc);
}
Example #25
0
static int
l_map_index(lua_State *L)
{
  const char *name = lua_tostring(L, 2);
  if (name == nullptr)
    return 0;

  auto *map = UIGlobals::GetMap();
  if (map == nullptr)
    return 0;

  if (StringIsEqual(name, "location"))
    Lua::Push(L, map->GetLocation());
  else
    return 0;

  return 1;
}
Example #26
0
ComboList
FileDataField::CreateComboList(const TCHAR *reference) const
{
  /* sorry for the const_cast .. this method keeps the promise of not
     modifying the object, given that one does not count filling the
     (cached) file list as "modification" */
  EnsureLoadedDeconst();

  ComboList combo_list;

  TCHAR buffer[MAX_PATH];

  for (unsigned i = 0; i < files.size(); i++) {
    const TCHAR *path = files[i].filename;
    assert(path != nullptr);

    /* is a file with the same base name present in another data
       directory? */

    bool found = false;
    for (unsigned j = 1; j < files.size(); j++) {
      if (j != i && StringIsEqual(path, files[j].filename)) {
        found = true;
        break;
      }
    }

    if (found) {
      /* yes - append the absolute path to allow the user to see the
         difference */
      _tcscpy(buffer, path);
      _tcscat(buffer, _T(" ("));
      _tcscat(buffer, files[i].path);
      _tcscat(buffer, _T(")"));
      path = buffer;
    }

    combo_list.Append(i, path);
  }

  combo_list.current_index = current_index;

  return combo_list;
}
Example #27
0
bool
ParseFileRepository(FileRepository &repository, NLineReader &reader)
{
  AvailableFile file;
  file.Clear();

  char *line;
  while ((line = reader.ReadLine()) != NULL) {
    line = const_cast<char *>(TrimLeft(line));
    if (*line == 0 || *line == '#')
      continue;

    const char *name = line, *value = ParseLine(line);
    if (value == NULL)
      return false;

    if (StringIsEqual(name, "name")) {
      if (!Commit(repository, file))
        return false;

      file.name.assign(value);
    } else if (file.IsEmpty()) {
      /* ignore */
    } else if (StringIsEqual(name, "uri")) {
      file.uri.assign(value);
    } else if (StringIsEqual(name, "area")) {
      file.area = value;
    } else if (StringIsEqual(name, "type")) {
      if (StringIsEqual(value, "airspace"))
        file.type = AvailableFile::Type::AIRSPACE;
      else if (StringIsEqual(value, "waypoint"))
        file.type = AvailableFile::Type::WAYPOINT;
      else if (StringIsEqual(value, "map"))
        file.type = AvailableFile::Type::MAP;
      else if (StringIsEqual(value, "flarmnet"))
        file.type = AvailableFile::Type::FLARMNET;
    }
  }

  return Commit(repository, file);
}
Example #28
0
static void
TestPressure()
{
  TCHAR buffer[256];

  // Test FormatPressure()
  FormatPressure(buffer, AtmosphericPressure::HectoPascal(1013.25),
                 Unit::HECTOPASCAL);
  ok1(StringIsEqual(buffer, _T("1013 hPa")));

  FormatPressure(buffer, AtmosphericPressure::HectoPascal(1013.25),
                 Unit::HECTOPASCAL, false);
  ok1(StringIsEqual(buffer, _T("1013")));

  FormatPressure(buffer, AtmosphericPressure::HectoPascal(1013.25),
                 Unit::MILLIBAR);
  ok1(StringIsEqual(buffer, _T("1013 mb")));

  FormatPressure(buffer, AtmosphericPressure::HectoPascal(1013.25),
                 Unit::MILLIBAR, false);
  ok1(StringIsEqual(buffer, _T("1013")));

  FormatPressure(buffer, AtmosphericPressure::HectoPascal(
      Units::ToSysUnit(103, Unit::TORR)), Unit::TORR);
  ok1(StringIsEqual(buffer, _T("103 mmHg")));

  FormatPressure(buffer, AtmosphericPressure::HectoPascal(
      Units::ToSysUnit(103, Unit::TORR)), Unit::TORR, false);
  ok1(StringIsEqual(buffer, _T("103")));

  FormatPressure(buffer, AtmosphericPressure::HectoPascal(
      Units::ToSysUnit(29.92, Unit::INCH_MERCURY)), Unit::INCH_MERCURY);
  ok1(StringIsEqual(buffer, _T("29.92 inHg")));

  FormatPressure(buffer, AtmosphericPressure::HectoPascal(
      Units::ToSysUnit(29.92, Unit::INCH_MERCURY)),
      Unit::INCH_MERCURY, false);
  ok1(StringIsEqual(buffer, _T("29.92")));
}
Example #29
0
bool
RowFormWidget::SaveValueFileReader(unsigned i, const char *registry_key)
{
  const auto *dfe = (const FileDataField *)GetControl(i).GetDataField();
  Path new_value = dfe->GetPathFile();
  const auto contracted = ContractLocalPath(new_value);
  if (contracted != nullptr)
    new_value = contracted;

  const WideToUTF8Converter new_value2(new_value.c_str());
  if (!new_value2.IsValid())
    return false;

  const char *old_value = Profile::Get(registry_key, "");
  if (StringIsEqual(old_value, new_value2))
    return false;

  Profile::Set(registry_key, new_value2);
  return true;
}
Example #30
0
void
ParsePFLAV(NMEAInputLine &line, FlarmVersion &version, double clock)
{
    char type[2];
    line.Read(type, ARRAY_SIZE(type));
    if (!StringIsEqual(type, "A"))
        return;

    line.Read(version.hardware_version.buffer(),
              version.hardware_version.capacity());
    version.hardware_version.CleanASCII();

    line.Read(version.software_version.buffer(),
              version.software_version.capacity());
    version.software_version.CleanASCII();

    line.Read(version.obstacle_version.buffer(),
              version.obstacle_version.capacity());
    version.obstacle_version.CleanASCII();

    version.available.Update(clock);
}