Example #1
0
void
Profile::GetDeviceConfig(const ProfileMap &map, unsigned n,
                         DeviceConfig &config)
{
  char buffer[64];

  bool have_port_type = ReadPortType(map, n, config.port_type);

  MakeDeviceSettingName(buffer, "Port", n, "BluetoothMAC");
  map.Get(buffer, config.bluetooth_mac);

  MakeDeviceSettingName(buffer, "Port", n, "IOIOUartID");
  map.Get(buffer, config.ioio_uart_id);

  MakeDeviceSettingName(buffer, "Port", n, "IPAddress");
  if (!map.Get(buffer, config.ip_address))
    config.ip_address.clear();

  MakeDeviceSettingName(buffer, "Port", n, "TCPPort");
  if (!map.Get(buffer, config.tcp_port))
    config.tcp_port = 4353;

  config.path.clear();
  if ((!have_port_type ||
       config.port_type == DeviceConfig::PortType::SERIAL) &&
      !LoadPath(map, config, n) && LoadPortIndex(map, config, n))
    config.port_type = DeviceConfig::PortType::SERIAL;

  MakeDeviceSettingName(buffer, "Port", n, "BaudRate");
  if (!map.Get(buffer, config.baud_rate)) {
    /* XCSoar before 6.2 used to store a "speed index", not the real
       baud rate - try to import the old settings */

    static constexpr unsigned speed_index_table[] = {
      1200,
      2400,
      4800,
      9600,
      19200,
      38400,
      57600,
      115200
    };

    MakeDeviceSettingName(buffer, "Speed", n, "Index");
    unsigned speed_index;
    if (map.Get(buffer, speed_index) &&
        speed_index < ARRAY_SIZE(speed_index_table))
      config.baud_rate = speed_index_table[speed_index];
  }

  MakeDeviceSettingName(buffer, "Port", n, "BulkBaudRate");
  if (!map.Get(buffer, config.bulk_baud_rate))
    config.bulk_baud_rate = 0;

  strcpy(buffer, "DeviceA");
  buffer[strlen(buffer) - 1] += n;
  map.Get(buffer, config.driver_name);

  MakeDeviceSettingName(buffer, "Port", n, "Enabled");
  map.Get(buffer, config.enabled);

  MakeDeviceSettingName(buffer, "Port", n, "SyncFromDevice");
  map.Get(buffer, config.sync_from_device);

  MakeDeviceSettingName(buffer, "Port", n, "SyncToDevice");
  map.Get(buffer, config.sync_to_device);

  MakeDeviceSettingName(buffer, "Port", n, "K6Bt");
  map.Get(buffer, config.k6bt);

  MakeDeviceSettingName(buffer, "Port", n, "I2C_Bus");
  map.Get(buffer, config.i2c_bus);

  MakeDeviceSettingName(buffer, "Port", n, "I2C_Addr");
  map.Get(buffer, config.i2c_addr);

  MakeDeviceSettingName(buffer, "Port", n, "PressureUse");
  map.GetEnum(buffer, config.press_use);

  MakeDeviceSettingName(buffer, "Port", n, "SensorOffset");
  map.Get(buffer, config.sensor_offset);

  MakeDeviceSettingName(buffer, "Port", n, "SensorFactor");
  map.Get(buffer, config.sensor_factor);

  MakeDeviceSettingName(buffer, "Port", n, "UseSecondDevice");
  map.Get(buffer, config.use_second_device);

  MakeDeviceSettingName(buffer, "Port", n, "SecondDevice");
  map.Get(buffer, config.driver2_name);
}
Example #2
0
void
Profile::GetDeviceConfig(unsigned n, DeviceConfig &config)
{
    TCHAR buffer[64];

    config.port_type = ReadPortType(n);

    MakeDeviceSettingName(buffer, _T("Port"), n, _T("BluetoothMAC"));
    Get(buffer, config.bluetooth_mac);

    MakeDeviceSettingName(buffer, _T("Port"), n, _T("IOIOUartID"));
    Get(buffer, config.ioio_uart_id);

    MakeDeviceSettingName(buffer, _T("Port"), n, _T("TCPPort"));
    if (!Get(buffer, config.tcp_port))
        config.tcp_port = 4353;

    config.path.clear();
    if (config.port_type == DeviceConfig::PortType::SERIAL &&
            !LoadPath(config, n) && !LoadPortIndex(config, n)) {
        if (IsAltair() && n == 0)
            config.path = _T("COM3:");
        else if (IsAltair() && n == 2)
            config.path = _T("COM2:");
    }

    MakeDeviceSettingName(buffer, _T("Port"), n, _T("BaudRate"));
    if (!Get(buffer, config.baud_rate)) {
        /* XCSoar before 6.2 used to store a "speed index", not the real
           baud rate - try to import the old settings */

        static gcc_constexpr_data unsigned speed_index_table[] = {
            1200,
            2400,
            4800,
            9600,
            19200,
            38400,
            57600,
            115200
        };

        MakeDeviceSettingName(buffer, _T("Speed"), n, _T("Index"));
        unsigned speed_index;
        if (Get(buffer, speed_index) &&
                speed_index < ARRAY_SIZE(speed_index_table))
            config.baud_rate = speed_index_table[speed_index];
        else if (IsAltair())
            config.baud_rate = 38400;
        else
            config.baud_rate = 4800;
    }

    MakeDeviceSettingName(buffer, _T("Port"), n, _T("BulkBaudRate"));
    if (!Get(buffer, config.bulk_baud_rate))
        config.bulk_baud_rate = 0;

    _tcscpy(buffer, _T("DeviceA"));
    buffer[_tcslen(buffer) - 1] += n;
    if (!Get(buffer, config.driver_name)) {
        if (IsAltair() && n == 0)
            config.driver_name = _T("Altair RU");
        else if (IsAltair() && n == 1)
            config.driver_name = _T("Vega");
        else if (IsAltair() && n == 2)
            config.driver_name = _T("NmeaOut");
        else
            config.driver_name.clear();
    }
}