void CAI302WaypointUploader::Run(OperationEnvironment &env) { Waypoints waypoints; env.SetText(_("Loading Waypoints...")); if (!reader.Parse(waypoints, env)) { env.SetErrorMessage(_("Failed to load file.")); return; } if (waypoints.size() > 9999) { env.SetErrorMessage(_("Too many waypoints.")); return; } env.SetText(_("Uploading Waypoints")); env.SetProgressRange(waypoints.size() + 1); env.SetProgressPosition(0); if (!device.ClearPoints(env)) { if (!env.IsCancelled()) env.SetErrorMessage(_("Failed to erase waypoints.")); return; } if (!device.EnableBulkMode(env)) { if (!env.IsCancelled()) env.SetErrorMessage(_("Failed to switch baud rate.")); return; } unsigned id = 1; for (auto i = waypoints.begin(), end = waypoints.end(); i != end; ++i, ++id) { if (env.IsCancelled()) break; env.SetProgressPosition(id); if (!device.WriteNavpoint(id, *i, env)) { if (!env.IsCancelled()) env.SetErrorMessage(_("Failed to write waypoint.")); break; } } device.DisableBulkMode(env); }
static bool ShowParseWarning(int line, const TCHAR *str, OperationEnvironment &operation) { StaticString<256> buffer; buffer.Format(_T("%s: %d\r\n\"%s\""), _("Parse Error at Line"), line, str); operation.SetErrorMessage(buffer.c_str()); return false; }
bool AirspaceParser::Parse(TLineReader &reader, OperationEnvironment &operation) { bool ignore = false; // Create and init ProgressDialog operation.SetProgressRange(1024); const long file_size = reader.GetSize(); TempAirspaceType temp_area; AirspaceFileType filetype = AFT_UNKNOWN; TCHAR *line; // Iterate through the lines for (unsigned line_num = 1; (line = reader.ReadLine()) != NULL; line_num++) { // Skip empty line if (StringIsEmpty(line)) continue; if (filetype == AFT_UNKNOWN) { filetype = DetectFileType(line); if (filetype == AFT_UNKNOWN) continue; } // Parse the line if (filetype == AFT_OPENAIR) if (!ParseLine(airspaces, line, temp_area) && !ShowParseWarning(line_num, line, operation)) return false; if (filetype == AFT_TNP) if (!ParseLineTNP(airspaces, line, temp_area, ignore) && !ShowParseWarning(line_num, line, operation)) return false; // Update the ProgressDialog if ((line_num & 0xff) == 0) operation.SetProgressPosition(reader.Tell() * 1024 / file_size); } if (filetype == AFT_UNKNOWN) { operation.SetErrorMessage(_("Unknown airspace filetype")); return false; } // Process final area (if any) if (!temp_area.points.empty()) temp_area.AddPolygon(airspaces); return true; }
bool DeviceDescriptor::Open(OperationEnvironment &env, bool show_error_messages) { TCHAR buffer[64]; LogStartUp(_T("Opening device %s"), config.GetPortName(buffer, 64)); if (config.port_type == DeviceConfig::PortType::INTERNAL) return OpenInternalSensors(); const struct DeviceRegister *driver = FindDriverByName(config.driver_name); if (driver == NULL) { if (show_error_messages) { StaticString<256> msg; msg.Format(_T("%s: %s."), _("No such driver"), config.driver_name.c_str()); env.SetErrorMessage(msg); } return false; } reopen_clock.Update(); Port *port = OpenPort(config, *this); if (port == NULL) { if (show_error_messages) { TCHAR name_buffer[64]; const TCHAR *name = config.GetPortName(name_buffer, 64); StaticString<256> msg; msg.Format(_T("%s: %s."), _("Unable to open port"), name); env.SetErrorMessage(msg); } return false; } if (!Open(*port, *driver, env)) { delete port; return false; } return true; }
bool DeviceDescriptor::DoOpen(OperationEnvironment &env) { assert(config.IsAvailable()); if (config.port_type == DeviceConfig::PortType::INTERNAL) return OpenInternalSensors(); if (config.port_type == DeviceConfig::PortType::DROIDSOAR_V2) return OpenDroidSoarV2(); if (config.port_type == DeviceConfig::PortType::I2CPRESSURESENSOR) return OpenI2Cbaro(); if (config.port_type == DeviceConfig::PortType::NUNCHUCK) return OpenNunchuck(); if (config.port_type == DeviceConfig::PortType::IOIOVOLTAGE) return OpenVoltage(); if (config.port_type == DeviceConfig::PortType::ADCAIRSPEED) return OpenAdcAirspeed(); reopen_clock.Update(); Port *port = OpenPort(config, *this); if (port == NULL) { TCHAR name_buffer[64]; const TCHAR *name = config.GetPortName(name_buffer, 64); StaticString<256> msg; msg.Format(_T("%s: %s."), _("Unable to open port"), name); env.SetErrorMessage(msg); return false; } while (port->GetState() == PortState::LIMBO) { env.Sleep(200); if (env.IsCancelled() || port->GetState() == PortState::FAILED) { delete port; return false; } } if (!Open(*port, env)) { delete port; return false; } return true; }
bool DeviceDescriptor::DoOpen(OperationEnvironment &env) { assert(config.IsAvailable()); if (config.port_type == DeviceConfig::PortType::INTERNAL) return OpenInternalSensors(); if (config.port_type == DeviceConfig::PortType::DROIDSOAR_V2) return OpenDroidSoarV2(); if (config.port_type == DeviceConfig::PortType::I2CPRESSURESENSOR) return OpenI2Cbaro(); if (config.port_type == DeviceConfig::PortType::NUNCHUCK) return OpenNunchuck(); if (config.port_type == DeviceConfig::PortType::IOIOVOLTAGE) return OpenVoltage(); reopen_clock.Update(); Port *port = OpenPort(config, port_listener, *this); if (port == nullptr) { TCHAR name_buffer[64]; const TCHAR *name = config.GetPortName(name_buffer, 64); StaticString<256> msg; msg.Format(_T("%s: %s."), _("Unable to open port"), name); env.SetErrorMessage(msg); return false; } DumpPort *dump_port = new DumpPort(port); dump_port->Disable(); if (!port->WaitConnected(env) || !OpenOnPort(dump_port, env)) { if (!env.IsCancelled()) ++n_failures; delete dump_port; return false; } ResetFailureCounter(); return true; }
bool DeviceDescriptor::DoOpen(OperationEnvironment &env) { assert(config.IsAvailable()); { ScopeLock protect(mutex); error_message.clear(); } if (config.port_type == DeviceConfig::PortType::INTERNAL) return OpenInternalSensors(); if (config.port_type == DeviceConfig::PortType::DROIDSOAR_V2) return OpenDroidSoarV2(); if (config.port_type == DeviceConfig::PortType::I2CPRESSURESENSOR) return OpenI2Cbaro(); if (config.port_type == DeviceConfig::PortType::NUNCHUCK) return OpenNunchuck(); if (config.port_type == DeviceConfig::PortType::IOIOVOLTAGE) return OpenVoltage(); reopen_clock.Update(); Port *port; try { port = OpenPort(io_service, config, this, *this); } catch (const std::runtime_error &e) { TCHAR name_buffer[64]; const TCHAR *name = config.GetPortName(name_buffer, 64); LogError(WideToUTF8Converter(name), e); StaticString<256> msg; const UTF8ToWideConverter what(e.what()); if (what.IsValid()) { ScopeLock protect(mutex); error_message = what; } msg.Format(_T("%s: %s (%s)"), _("Unable to open port"), name, (const TCHAR *)what); env.SetErrorMessage(msg); return false; } if (port == nullptr) { TCHAR name_buffer[64]; const TCHAR *name = config.GetPortName(name_buffer, 64); StaticString<256> msg; msg.Format(_T("%s: %s."), _("Unable to open port"), name); env.SetErrorMessage(msg); return false; } DumpPort *dump_port = new DumpPort(port); dump_port->Disable(); if (!port->WaitConnected(env) || !OpenOnPort(dump_port, env)) { if (!env.IsCancelled()) ++n_failures; delete dump_port; return false; } ResetFailureCounter(); return true; }