Skip to content

Commit

Permalink
Implemented client-side disconnection if server is down.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcanseco committed Apr 11, 2016
1 parent b77ed8c commit c67d0f7
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 23 deletions.
1 change: 0 additions & 1 deletion raspi-server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def log(sock, msg):
sock.send(sock_message)
print(sock_message)


# socket settings
TCP_IP = '0.0.0.0'
TCP_PORT = 25555
Expand Down
11 changes: 11 additions & 0 deletions windows/ControlStation/ControlStation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
<DependentUpon>AboutBox.cs</DependentUpon>
</Compile>
<Compile Include="DualShock4.cs" />
<Compile Include="ButtonMap.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ButtonMap.Designer.cs">
<DependentUpon>ButtonMap.cs</DependentUpon>
</Compile>
<Compile Include="MainWindow.cs">
<SubType>Form</SubType>
</Compile>
Expand All @@ -97,6 +103,9 @@
<EmbeddedResource Include="AboutBox.resx">
<DependentUpon>AboutBox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="ButtonMap.resx">
<DependentUpon>ButtonMap.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainWindow.resx">
<DependentUpon>MainWindow.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -128,6 +137,8 @@
<None Include="Resources\robot.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\ds4.png" />
<None Include="Resources\ds41.png" />
<Content Include="Resources\robot.ico" />
</ItemGroup>
<ItemGroup>
Expand Down
37 changes: 23 additions & 14 deletions windows/ControlStation/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 32 additions & 6 deletions windows/ControlStation/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ private void disconnectButton_Click(object sender, EventArgs e) {
}
}

/// <summary>
/// takes the text value of the custom command box and
/// sends it to the robot.
/// </summary>
private void sendCustomCommand(object sender, KeyPressEventArgs e) {
if (e.KeyChar == (char)Keys.Return) {
send(txtCustomCommand.Text);
Expand All @@ -171,16 +175,23 @@ public static String GetFilePathTimestamp(DateTime value) {
}
public void send(String s) {
log("GUI: " + s);
socket.Send(System.Text.Encoding.UTF8.GetBytes(s + ";"));
try {
socket.Send(System.Text.Encoding.UTF8.GetBytes(s + ";"));
} catch(Exception ex) {
log("Socket error, disconnecting: " + ex.Message);
log("Disconnecting");
disconnectButton_Click(null, null);
}
}
private void btn_MouseDown(object sender, MouseEventArgs e) {
var btn = (FontAwesomeIcons.IconButton)sender;
btn.BackColor = System.Drawing.Color.Gold;
bool dualMode = dualModeCheckBox.Checked;
switch (btn.Name) {
case "goForward": send("^"); break;
case "goBackward": send("v"); break;
case "turnCW": send(">"); break;
case "turnCCW": send("<"); break;
case "goForward": send("^"); break; // GO FWD
case "goBackward": send("v"); break; // GO BACKWARD
case "turnCW": send(">"); break; // TURN RIGHT
case "turnCCW": send("<"); break; // TURN LEFT
case "raiseBot": send("u"); break; // RETRACT ACTUATORS
case "lowerBot": send("t"); break; // EXTEND ACTUATORS
case "raise_f": send("z"); break; // RAISE FRONT DRUM
Expand Down Expand Up @@ -219,6 +230,12 @@ private void disableCommands() {
miningGroup.Enabled = false;
}

/// <summary>
/// check the connection to the robot
/// </summary>
/// <param name="socket">The socket to check if it's connected.</param>
/// <returns>true if we're connected</returns>
/// <returns>false if we're not connected</returns>
public static bool isConnected(Socket socket) {
try
{
Expand All @@ -227,10 +244,19 @@ public static bool isConnected(Socket socket) {
catch (SocketException) { return false; }
}

// Implement a call with the right signature for events going off
/// <summary>
/// sends a letter 'b' to the robot to receive battery voltage
/// </summary>
private void requestBatt(object source, ElapsedEventArgs e) {
send("b");
}

/// <summary>
/// shows the button mapping window
/// </summary>
private void buttonMapToolStripMenuItem_Click(object sender, EventArgs e) {
ButtonMap buttonMap = new ButtonMap();
buttonMap.Show();
}
}
}
4 changes: 2 additions & 2 deletions windows/ControlStation/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ARES Control Station")]
[assembly: AssemblyDescription("Senior Design 2015-16 project.\r\nCoded by Pablo Canseco with love.\r\nSource Code: https://github.com/pmcanseco/ARES-Control-Station")]
[assembly: AssemblyDescription("Senior Design 2015-16 project.\r\nCoded by Pablo Canseco with love.\r\nSource Code: https://github.com/pmcanseco/ares")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Florida Institute of Technology")]
[assembly: AssemblyProduct("ARES Control Station")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
20 changes: 20 additions & 0 deletions windows/ControlStation/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions windows/ControlStation/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ds4" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ds4.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="robot" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\robot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ds41" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ds41.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

0 comments on commit c67d0f7

Please sign in to comment.