Exemple #1
0
        //Uploads code to the robot and then runs it.
        public async Task <bool> DeployCode(string teamNumber, bool debug, Project robotProject)
        {
            var writer = OutputWriter.Instance;

            if (robotProject == null)
            {
                writer.WriteLine("Robot Project not valid. Contact RobotDotNet for support.");
                return(false);
            }

            //Connect to Robot Async
            OutputWriter.Instance.WriteLine("Attempting to Connect to RoboRIO");
            Task <bool> rioConnectionTask = StartConnectionTask(teamNumber);
            Task        delayTask         = Task.Delay(10000);

            CodeReturnStruct codeReturn = await BuildAndPrepareCode(debug, robotProject);

            if (codeReturn == null)
            {
                return(false);
            }

            writer.WriteLine("Waiting for Connection to Finish");
            if (await Task.WhenAny(rioConnectionTask, delayTask) == rioConnectionTask)
            {
                //Completed on time
                if (rioConnectionTask.Result)
                {
                    //Connected successfully
                    OutputWriter.Instance.WriteLine("Successfully Connected to RoboRIO.");

                    if (!await CheckMonoInstall())
                    {
                        //TODO: Make this error message better
                        OutputWriter.Instance.WriteLine("Mono not properly installed. Please try reinstalling to Mono Runtime.");
                        return(false);
                    }
                    OutputWriter.Instance.WriteLine("Mono correctly installed");

                    OutputWriter.Instance.WriteLine("Checking RoboRIO Image");
                    if (!await CheckRoboRioImage())
                    {
                        // Ignore image requirement on selected option
                        if (!SettingsProvider.ExtensionSettingsPage.IgnoreImageRequirements)
                        {
                            OutputWriter.Instance.WriteLine(
                                "RoboRIO Image does not match plugin, allowed image versions: " +
                                string.Join(", ", DeployProperties.RoboRioAllowedImages.ToArray()));
                            OutputWriter.Instance.WriteLine(
                                "Please follow FIRST's instructions on imaging your RoboRIO, and try again.");
                            return(false);
                        }
                    }
                    OutputWriter.Instance.WriteLine("RoboRIO Image Correct");
                    //Force making mono directory
                    await CreateMonoDirectory();

                    bool nativeDeploy =
                        await
                        CachedFileHelper.CheckAndDeployNativeLibraries(DeployProperties.UserLibraryDir, "WPI_Native_Libraries",
                                                                       GetProjectPath(robotProject) + "wpinative" + Path.DirectorySeparatorChar,
                                                                       new List <string>());

                    if (!nativeDeploy)
                    {
                        OutputWriter.Instance.WriteLine("Failed to deploy native files.");
                        return(false);
                    }

                    //DeployAllFiles
                    bool retVal = await DeployRobotFiles(codeReturn.RobotFiles);

                    if (!retVal)
                    {
                        OutputWriter.Instance.WriteLine("File deploy failed.");
                        return(false);
                    }
                    OutputWriter.Instance.WriteLine("Successfully Deployed Files. Starting Code.");
                    await StartRobotCode(codeReturn.RobotExe, debug, robotProject);

                    OutputWriter.Instance.WriteLine("Successfully started robot code.");
                    return(true);
                }
                else
                {
                    //Failed to connect
                    writer.WriteLine("Failed to Connect to RoboRIO. Exiting.");
                    return(false);
                }
            }
            else
            {
                //Timedout
                writer.WriteLine("Failed to Connect to RoboRIO. Exiting.");
                return(false);
            }
        }
Exemple #2
0
        //Uploads code to the robot and then runs it.
        public async Task <bool> DeployCodeAsync(string teamNumber, bool debug, Project robotProject)
        {
            var writer = OutputWriter.Instance;

            if (robotProject == null)
            {
                await writer.WriteLineAsync("Robot Project not valid. Contact RobotDotNet for support.").ConfigureAwait(false);

                return(false);
            }

            //Connect to Robot Async
            await OutputWriter.Instance.WriteLineAsync("Attempting to Connect to RoboRIO").ConfigureAwait(false);

            Task <RoboRioConnection> rioConnectionTask = RoboRioConnection.StartConnectionTaskAsync(teamNumber);

            CodeReturnStruct codeReturn = await BuildAndPrepareCodeAsync(debug, robotProject).ConfigureAwait(false);

            if (codeReturn == null)
            {
                return(false);
            }

            await writer.WriteLineAsync("Waiting for Connection to Finish").ConfigureAwait(false);

            // Kill our connection if we have already ran once with this same object.
            m_roboRioConnection?.Dispose();
            m_roboRioConnection = await rioConnectionTask.ConfigureAwait(false);

            if (m_roboRioConnection.Connected)
            {
                //Connected successfully
                await OutputWriter.Instance.WriteLineAsync("Successfully Connected to RoboRIO.").ConfigureAwait(false);

                if (!await CheckMonoInstallAsync().ConfigureAwait(false))
                {
                    //TODO: Make this error message better
                    await OutputWriter.Instance.WriteLineAsync("Mono not properly installed. Please try reinstalling to Mono Runtime.").ConfigureAwait(false);

                    return(false);
                }
                await OutputWriter.Instance.WriteLineAsync("Mono correctly installed").ConfigureAwait(false);

                await OutputWriter.Instance.WriteLineAsync("Checking RoboRIO Image").ConfigureAwait(false);

                if (!await CheckRoboRioImageAsync().ConfigureAwait(false))
                {
                    // Ignore image requirement on selected option
                    if (!SettingsProvider.ExtensionSettingsPage.IgnoreImageRequirements)
                    {
                        await OutputWriter.Instance.WriteLineAsync(
                            "RoboRIO Image does not match plugin, allowed image versions: " +
                            string.Join(", ", DeployProperties.RoboRioAllowedImages.ToArray())).ConfigureAwait(false);

                        await OutputWriter.Instance.WriteLineAsync(
                            "Please follow FIRST's instructions on imaging your RoboRIO, and try again.").ConfigureAwait(false);

                        return(false);
                    }
                }
                await OutputWriter.Instance.WriteLineAsync("RoboRIO Image Correct").ConfigureAwait(false);

                //Force making mono directory
                await CreateMonoDirectoryAsync().ConfigureAwait(false);

                bool nativeDeploy =
                    await
                    CachedFileHelper.CheckAndDeployNativeLibrariesAsync(DeployProperties.UserLibraryDir, "WPI_Native_Libraries",
                                                                        await GetProjectPathAsync(robotProject).ConfigureAwait(false) + "wpinative" + Path.DirectorySeparatorChar,
                                                                        new List <string>(), m_roboRioConnection).ConfigureAwait(false);

                if (!nativeDeploy)
                {
                    await OutputWriter.Instance.WriteLineAsync("Failed to deploy native files.").ConfigureAwait(false);

                    return(false);
                }

                //DeployAllFiles
                bool retVal = await DeployRobotFilesAsync(codeReturn.RobotFiles).ConfigureAwait(false);

                if (!retVal)
                {
                    await OutputWriter.Instance.WriteLineAsync("File deploy failed.").ConfigureAwait(false);

                    return(false);
                }
                await OutputWriter.Instance.WriteLineAsync("Successfully Deployed Files. Starting Code.").ConfigureAwait(false);
                await StartRobotCodeAsync(codeReturn.RobotExe, debug, robotProject).ConfigureAwait(false);

                await OutputWriter.Instance.WriteLineAsync("Successfully started robot code.").ConfigureAwait(false);

                return(true);
            }
            else
            {
                //Failed to connect
                await writer.WriteLineAsync("Failed to Connect to RoboRIO. Exiting.").ConfigureAwait(false);

                return(false);
            }
        }