static bool LoadPath(const ProfileMap &map, DeviceConfig &config, unsigned n) { char buffer[64]; MakeDeviceSettingName(buffer, "Port", n, "Path"); return map.Get(buffer, config.path); }
static bool LoadPath(DeviceConfig &config, unsigned n) { TCHAR buffer[64]; MakeDeviceSettingName(buffer, _T("Port"), n, _T("Path")); return Profile::Get(buffer, config.path); }
void Profile::SetDeviceConfig(unsigned n, const DeviceConfig &config) { TCHAR buffer[64]; WritePortType(n, config.port_type); MakeDeviceSettingName(buffer, CONF("Port"), n, _T("Index")); Set(buffer, config.port_index); MakeDeviceSettingName(buffer, CONF("Speed"), n, _T("Index")); Set(buffer, config.speed_index); _tcscpy(buffer, CONF("DeviceA")); buffer[_tcslen(buffer) - 1] += n; Set(buffer, config.driver_name); }
static bool ReadPortType(const ProfileMap &map, unsigned n, DeviceConfig::PortType &type) { char name[64]; MakeDeviceSettingName(name, "Port", n, "Type"); const char *value = map.Get(name); return value != NULL && StringToPortType(value, type); }
static enum DeviceConfig::port_type ReadPortType(unsigned n) { TCHAR name[64], value[64]; MakeDeviceSettingName(name, CONF("Port"), n, _T("Type")); if (!Profile::Get(name, value, sizeof(value) / sizeof(value[0]))) return DeviceConfig::SERIAL; return StringToPortType(value); }
static void WritePortType(ProfileMap &map, unsigned n, DeviceConfig::PortType type) { const char *value = PortTypeToString(type); if (value == NULL) return; char name[64]; MakeDeviceSettingName(name, "Port", n, "Type"); map.Set(name, value); }
static bool WritePortType(unsigned n, enum DeviceConfig::port_type type) { const TCHAR *value = PortTypeToString(type); if (value == NULL) return false; TCHAR name[64]; MakeDeviceSettingName(name, CONF("Port"), n, _T("Type")); return Profile::Set(name, value); }
void Profile::SetDeviceConfig(unsigned n, const DeviceConfig &config) { TCHAR buffer[64]; WritePortType(n, config.port_type); MakeDeviceSettingName(buffer, _T("Port"), n, _T("BluetoothMAC")); Set(buffer, config.bluetooth_mac); MakeDeviceSettingName(buffer, _T("Port"), n, _T("IOIOUartID")); Set(buffer, config.ioio_uart_id); MakeDeviceSettingName(buffer, _T("Port"), n, _T("Path")); Set(buffer, config.path); MakeDeviceSettingName(buffer, _T("Port"), n, _T("BaudRate")); Set(buffer, config.baud_rate); MakeDeviceSettingName(buffer, _T("Port"), n, _T("BulkBaudRate")); Set(buffer, config.bulk_baud_rate); MakeDeviceSettingName(buffer, _T("Port"), n, _T("TCPPort")); Set(buffer, config.tcp_port); _tcscpy(buffer, _T("DeviceA")); buffer[_tcslen(buffer) - 1] += n; Set(buffer, config.driver_name); }
void Profile::GetDeviceConfig(unsigned n, DeviceConfig &config) { TCHAR buffer[64]; unsigned Temp = 0; config.port_type = ReadPortType(n); MakeDeviceSettingName(buffer, CONF("Port"), n, _T("Index")); if (Get(buffer, Temp)) config.port_index = Temp; else if (is_altair() && n == 0) config.port_index = 2; else if (is_altair() && n == 2) config.port_index = 1; else config.port_index = 0; MakeDeviceSettingName(buffer, CONF("Speed"), n, _T("Index")); if (Get(buffer, Temp)) config.speed_index = Temp; else if (is_altair()) config.speed_index = 5; else config.speed_index = 2; _tcscpy(buffer, CONF("DeviceA")); buffer[_tcslen(buffer) - 1] += n; if (!Get(buffer, config.driver_name, sizeof(config.driver_name) / sizeof(config.driver_name[0]))) { if (is_altair() && n == 0) _tcscpy(config.driver_name, _T("Altair RU")); else if (is_altair() && n == 1) _tcscpy(config.driver_name, _T("Vega")); else if (is_altair() && n == 2) _tcscpy(config.driver_name, _T("NmeaOut")); else config.driver_name[0] = '\0'; } }
void Profile::GetDeviceConfig(unsigned n, DeviceConfig &config) { TCHAR buffer[64]; unsigned Temp = 0; config.port_type = ReadPortType(n); MakeDeviceSettingName(buffer, CONF("Port"), n, _T("Index")); if (Get(buffer, Temp)) config.port_index = Temp; MakeDeviceSettingName(buffer, CONF("Speed"), n, _T("Index")); if (Get(buffer, Temp)) config.speed_index = Temp; config.driver_name[0] = '\0'; _tcscpy(buffer, CONF("DeviceA")); buffer[_tcslen(buffer) - 1] += n; Get(buffer, config.driver_name, sizeof(config.driver_name) / sizeof(config.driver_name[0])); }
static DeviceConfig::PortType ReadPortType(unsigned n) { TCHAR name[64], value[64]; MakeDeviceSettingName(name, _T("Port"), n, _T("Type")); if (!Profile::Get(name, value, ARRAY_SIZE(value))) return n == 0 ? (IsAndroid() ? DeviceConfig::PortType::INTERNAL : DeviceConfig::PortType::SERIAL) : DeviceConfig::PortType::DISABLED; return StringToPortType(value); }
static bool LoadPortIndex(DeviceConfig &config, unsigned n) { TCHAR buffer[64]; MakeDeviceSettingName(buffer, _T("Port"), n, _T("Index")); unsigned index; if (!Profile::Get(buffer, index)) return false; /* adjust the number, compatibility quirk for XCSoar 5 */ if (index < 10) ++index; else if (index == 10) index = 0; _stprintf(buffer, _T("COM%u:"), index); config.path = buffer; return true; }
static bool LoadPortIndex(const ProfileMap &map, DeviceConfig &config, unsigned n) { char buffer[64]; MakeDeviceSettingName(buffer, "Port", n, "Index"); unsigned index; if (!map.Get(buffer, index)) return false; /* adjust the number, compatibility quirk for XCSoar 5 */ if (index < 10) ++index; else if (index == 10) index = 0; TCHAR path[64]; _stprintf(path, _T("COM%u:"), index); config.path = path; return true; }
void Profile::SetDeviceConfig(ProfileMap &map, unsigned n, const DeviceConfig &config) { char buffer[64]; WritePortType(map, n, config.port_type); MakeDeviceSettingName(buffer, "Port", n, "BluetoothMAC"); map.Set(buffer, config.bluetooth_mac); MakeDeviceSettingName(buffer, "Port", n, "IOIOUartID"); map.Set(buffer, config.ioio_uart_id); MakeDeviceSettingName(buffer, "Port", n, "Path"); map.Set(buffer, config.path); MakeDeviceSettingName(buffer, "Port", n, "BaudRate"); map.Set(buffer, config.baud_rate); MakeDeviceSettingName(buffer, "Port", n, "BulkBaudRate"); map.Set(buffer, config.bulk_baud_rate); MakeDeviceSettingName(buffer, "Port", n, "IPAddress"); map.Set(buffer, config.ip_address); MakeDeviceSettingName(buffer, "Port", n, "TCPPort"); map.Set(buffer, config.tcp_port); strcpy(buffer, "DeviceA"); buffer[strlen(buffer) - 1] += n; map.Set(buffer, config.driver_name); MakeDeviceSettingName(buffer, "Port", n, "Enabled"); map.Set(buffer, config.enabled); MakeDeviceSettingName(buffer, "Port", n, "SyncFromDevice"); map.Set(buffer, config.sync_from_device); MakeDeviceSettingName(buffer, "Port", n, "SyncToDevice"); map.Set(buffer, config.sync_to_device); MakeDeviceSettingName(buffer, "Port", n, "K6Bt"); map.Set(buffer, config.k6bt); MakeDeviceSettingName(buffer, "Port", n, "I2C_Bus"); map.Set(buffer, config.i2c_bus); MakeDeviceSettingName(buffer, "Port", n, "I2C_Addr"); map.Set(buffer, config.i2c_addr); MakeDeviceSettingName(buffer, "Port", n, "PressureUse"); map.SetEnum(buffer, config.press_use); MakeDeviceSettingName(buffer, "Port", n, "SensorOffset"); auto offset = DeviceConfig::UsesCalibration(config.port_type) ? config.sensor_offset : fixed(0); // Has new calibration data been delivered ? if (CommonInterface::Basic().sensor_calibration_available) offset = CommonInterface::Basic().sensor_calibration_offset; map.Set(buffer, offset); MakeDeviceSettingName(buffer, "Port", n, "SensorFactor"); auto factor = DeviceConfig::UsesCalibration(config.port_type) ? config.sensor_factor : fixed(0); // Has new calibration data been delivered ? if (CommonInterface::Basic().sensor_calibration_available) factor = CommonInterface::Basic().sensor_calibration_factor; map.Set(buffer, factor); MakeDeviceSettingName(buffer, "Port", n, "UseSecondDevice"); map.Set(buffer, config.use_second_device); MakeDeviceSettingName(buffer, "Port", n, "SecondDevice"); map.Set(buffer, config.driver2_name); }
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); }
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(); } }