Skip to content

Commit 7303223

Browse files
committed
Add code kill button
Very useful during troubleshooting, plus helpful for LV teams.
1 parent 94bcf24 commit 7303223

File tree

6 files changed

+112
-2
lines changed

6 files changed

+112
-2
lines changed

FRC-Extension/Buttons/KillButton.cs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using EnvDTE;
7+
using Microsoft.VisualStudio.Shell;
8+
using RobotDotNet.FRC_Extension.RoboRIO_Code;
9+
using Task = System.Threading.Tasks.Task;
10+
11+
namespace RobotDotNet.FRC_Extension.Buttons
12+
{
13+
public class KillButton : ButtonBase
14+
{
15+
private bool m_killing = false;
16+
17+
public KillButton(Frc_ExtensionPackage package)
18+
: base(package, false, GuidList.guidFRC_ExtensionCmdSet, (int)PkgCmdIDList.cmdidKillButton)
19+
{
20+
21+
}
22+
23+
public override async void ButtonCallback(object sender, EventArgs e)
24+
{
25+
var menuCommand = sender as OleMenuCommand;
26+
if (menuCommand == null)
27+
{
28+
return;
29+
}
30+
if (!m_killing)
31+
{
32+
try
33+
{
34+
SettingsPageGrid page;
35+
string teamNumber = m_package.GetTeamNumber(out page);
36+
37+
if (teamNumber == null) return;
38+
39+
DeployManager m = new DeployManager(m_package.PublicGetService(typeof (DTE)) as DTE);
40+
41+
var writer = OutputWriter.Instance;
42+
43+
menuCommand.Visible = false;
44+
m_killing = true;
45+
46+
//Connect to RoboRIO
47+
writer.WriteLine("Attempting to Connect to RoboRIO");
48+
49+
Task<bool> rioConnectionTask = m.StartConnectionTask(teamNumber);
50+
Task delayTask = Task.Delay(10000);
51+
52+
//Successfully extracted files.
53+
54+
writer.WriteLine("Waiting for Connection to Finish");
55+
if (await Task.WhenAny(rioConnectionTask, delayTask) == rioConnectionTask)
56+
{
57+
//Connected
58+
if (rioConnectionTask.Result == true)
59+
{
60+
writer.WriteLine("Killing currently running robot code.");
61+
await RoboRIOConnection.RunCommand(DeployProperties.KillOnlyCommand, ConnectionUser.LvUser);
62+
writer.WriteLine("Done.");
63+
m_killing = false;
64+
menuCommand.Visible = true;
65+
}
66+
else
67+
{
68+
//Did not successfully connect
69+
writer.WriteLine("Failed to Connect to RoboRIO. Exiting.");
70+
m_killing = false;
71+
menuCommand.Visible = true;
72+
}
73+
}
74+
else
75+
{
76+
//Timedout
77+
writer.WriteLine("RoboRIO connection timedout. Exiting.");
78+
m_killing = false;
79+
menuCommand.Visible = true;
80+
}
81+
}
82+
catch (Exception ex)
83+
{
84+
m_output.WriteLine(ex.ToString());
85+
m_killing = false;
86+
menuCommand.Visible = true;
87+
OutputWriter.Instance.WriteLine("Code Kill Failed");
88+
}
89+
}
90+
}
91+
}
92+
}

FRC-Extension/FRC-Extension.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<Compile Include="Buttons\DeployDebugButton.cs" />
166166
<Compile Include="Buttons\DownloadMonoButton.cs" />
167167
<Compile Include="Buttons\InstallMonoButton.cs" />
168+
<Compile Include="Buttons\KillButton.cs" />
168169
<Compile Include="Buttons\NetConsoleButton.cs" />
169170
<Compile Include="Buttons\SettingsButton.cs" />
170171
<Compile Include="MonoCode\MonoDeploy.cs" />

FRC-Extension/FRC-Extension.vsct

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,15 @@
9898
</Strings>
9999
</Button>
100100

101-
<Button guid="guidFRC_ExtensionCmdSet" id="cmdidNetconsole" priority="0x0103" type="Button">
101+
<Button guid="guidFRC_ExtensionCmdSet" id="cmdidKillCode" priority="0x0102" type="Button">
102+
<Parent guid="guidFRC_ExtensionCmdSet" id="FRCMainMenuGroup"/>
103+
<CommandFlag>DynamicVisibility</CommandFlag>
104+
<Strings>
105+
<ButtonText>Kill Robot Code</ButtonText>
106+
</Strings>
107+
</Button>
108+
109+
<Button guid="guidFRC_ExtensionCmdSet" id="cmdidNetconsole" priority="0x0104" type="Button">
102110
<Parent guid="guidFRC_ExtensionCmdSet" id="FRCMainMenuGroup" />
103111
<CommandFlag>DynamicVisibility</CommandFlag>
104112
<CommandFlag>DefaultInvisible</CommandFlag>
@@ -108,7 +116,7 @@
108116

109117
</Button>
110118

111-
<Button guid="guidFRC_ExtensionCmdSet" id="cmdidSettings" priority="0x0102" type="Button">
119+
<Button guid="guidFRC_ExtensionCmdSet" id="cmdidSettings" priority="0x0103" type="Button">
112120
<Parent guid="guidFRC_ExtensionCmdSet" id="FRCMainMenuGroup" />
113121
<Strings>
114122
<ButtonText>Settings</ButtonText>
@@ -181,6 +189,7 @@
181189
<IDSymbol name="cmdidNetconsole" value ="0x0103"/>
182190
<IDSymbol name="cmdidSettings" value="0x0102" />
183191
<IDSymbol name="cmdidDebugCode" value="0x0106"/>
192+
<IDSymbol name="cmdidKillCode" value="0x0107"/>
184193
<IDSymbol name="cmdidAboutButton" value="0x0220"/>
185194
<IDSymbol name="MonoSubMenu" value="0x1100"/>
186195
<IDSymbol name="MonoSubMenuGroup" value="0x1150"/>

FRC-Extension/FRC-ExtensionPackage.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ internal DialogPage PublicGetDialogPage(Type dialogPageType)
7474
private DeployDebugButton m_deployButton;
7575
private DeployDebugButton m_debugButton;
7676

77+
private KillButton m_killButton;
78+
7779
//private MonoButtons m_monoButtons;
7880
private DownloadMonoButton m_downloadMonoButton;
7981
private InstallMonoButton m_installMonoButton;
@@ -100,6 +102,8 @@ protected override void Initialize()
100102

101103
m_deployButton = new DeployDebugButton(this, (int)PkgCmdIDList.cmdidDeployCode, false);
102104
m_debugButton = new DeployDebugButton(this, (int)PkgCmdIDList.cmdidDebugCode, true);
105+
106+
m_killButton = new KillButton(this);
103107

104108

105109
string monoFolder = WPILibFolderStructure.CreateMonoFolder();

FRC-Extension/PkgCmdID.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ static class PkgCmdIDList
2121

2222
public const uint cmdidAboutButton = 0x0220;
2323

24+
public const uint cmdidKillButton = 0x107;
25+
2426
};
2527
}

FRC-Extension/RoboRIOCode/DeployProperties.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public static class DeployProperties
1616
". /etc/profile.d/natinst-path.sh; /usr/local/frc/bin/frcKillRobot.sh -t -r",
1717
};
1818

19+
public const string KillOnlyCommand = "/usr/local/frc/bin/frcKillRobot.sh";
20+
1921
public const string DebugFlagDir = "/tmp/";
2022

2123
public static readonly string[] DebugFlagCommand =

0 commit comments

Comments
 (0)