Skip to content

Commit

Permalink
add exception handling to udp send
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjarv committed May 11, 2018
1 parent 1dbc7df commit 68aee20
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
41 changes: 24 additions & 17 deletions JoystickProxyWin/Joystick Proxy/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Joystick_Proxy
{
public partial class Form1 : Form
{
private static bool _debug = true;
private static bool _debug = false;

private DirectInput _directInput = new DirectInput();

Expand Down Expand Up @@ -137,27 +137,34 @@ private void SendEvents(ControllerDevice device, List<string> events)

private void SendEvent(ControllerDevice device, string e)
{
if (_socket == null || _endPoint == null)
return;
try
{
if (_socket == null || _endPoint == null)
return;

bool supportedDevice = SupportedDevices.ContainsKey(device.UsbId);
string outgoingString = String.Format("{0},{1},{2}", device.UsbId, device.Name, e);
bool supportedDevice = SupportedDevices.ContainsKey(device.UsbId);
string outgoingString = String.Format("{0},{1},{2}", device.UsbId, device.Name, e);

if (supportedDevice)
{
byte[] send_buffer = Encoding.ASCII.GetBytes(outgoingString);
_socket.SendTo(send_buffer, _endPoint);
}
if (supportedDevice)
{
byte[] send_buffer = Encoding.ASCII.GetBytes(outgoingString);
_socket.SendTo(send_buffer, _endPoint);
}

if(logFileStream != null)
if (logFileStream != null)
{
double timestamp = DateTime.UtcNow.ToUniversalTime()
.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
.TotalMilliseconds;
logFileStream.WriteLine(Math.Round(timestamp) + "," + outgoingString);
}

Debug(outgoingString);
}
catch (Exception ex)
{
double timestamp = DateTime.UtcNow.ToUniversalTime()
.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
.TotalMilliseconds;
logFileStream.WriteLine(Math.Round(timestamp) + "," + outgoingString);
Console.WriteLine(ex);
}

Debug(outgoingString);
}

private static void Debug(string outgoingString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void StickEvent(JoystickState state)
Joystick.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 20, -20), Joystick.transform.localEulerAngles.y, Joystick.transform.localEulerAngles.z);
break;
case "RotationZ":
Joystick.transform.localEulerAngles = new Vector3(Joystick.transform.localEulerAngles.x, ConvertRange(entry.Value, 0, 65535, 30, -30), Joystick.transform.localEulerAngles.z);
Joystick.transform.localEulerAngles = new Vector3(Joystick.transform.localEulerAngles.x, ConvertRange(entry.Value, 0, 65535, -30, 30), Joystick.transform.localEulerAngles.z);
break;
}
}
Expand Down

0 comments on commit 68aee20

Please sign in to comment.