public async Task <bool> ConnectAsync() { try { if (IsActive) { return(true); } SendMessageToUI("Starting Connection process"); await Log.Instance.WriteLineAsync("DroneClient:Connecting"); _RequestedState = RequestedState.Initialize; _ConfigurationWorker.Start(); _NavDataWorker.Start(); //TODO revoir InitState _CommandWorker.Start(); _WatchdogWorker.Start(); // We Check if the differents workers have been well initialized int attempt = 0; while (!IsActive && attempt < 10) { await Task.Delay(100); attempt++; } if (attempt == 10) { return(false); } SendMessageToUI("All workers have been activated"); attempt = 0; while (_RequestedState != RequestedState.None && attempt < 10) { await Task.Delay(100); attempt++; } if (attempt == 10) { Close(); DisposeOverride(); return(false); } SendMessageToUI("Connected with the Drone successfully"); InitConfiguration(); //SetIndoorConfiguration(); RequestConfiguration(); SendMessageToUI("Configuration sent to the Drone successfully"); return(true); } catch (Exception ex) { SendMessageToUI(ex.Message); return(false); } }
public async Task <bool> ConnectAsync() { bool isConnected = false; try { if (IsActive) { return(true); } else { //We close the workers previously started. Close(); } SendMessageToUI("Starting Connection process"); await Log.Instance.WriteLineAsync("DroneClient:Connecting"); _RequestedState = RequestedState.Initialize; _ConfigurationWorker.Start(); _NavDataWorker.Start(); _CommandWorker.Start(); _WatchdogWorker.Start(); // We Check if the differents workers have been well initialized int attempt = 0; while (!IsActive && attempt < 10) { await Task.Delay(100); attempt++; } if (attempt < 10) { SendMessageToUI("All workers have been activated"); attempt = 0; // We Check if the AR.Drone is well initialized while (_RequestedState != RequestedState.None && attempt < 10) { await Task.Delay(100); attempt++; } if (attempt < 10) { SendMessageToUI("Connected with the Drone successfully"); await InitMultiConfiguration(); SetDefaultConfiguration(); RequestConfiguration(); SendMessageToUI("Configuration sent to the Drone successfully"); isConnected = true; } } } catch (Exception ex) { SendMessageToUI(ex.Message); return(false); } if (!isConnected) { Close(); DisposeOverride(); } return(isConnected); }