Added some things

This commit is contained in:
Keenan D. Buckley
2019-02-15 16:46:19 -07:00
parent b68ece8fd3
commit 0b0347cdaa
117 changed files with 137930 additions and 7379 deletions
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Net;
using System.Net.Sockets;
@@ -9,33 +10,34 @@ using UnityEngine;
public class robotCommunication : MonoBehaviour
{
public bool isData = false;
public static int portNumber = 4388;
public int bytesAvailable;
List<string> keys = new List<string>();
public SortedList<string, float> robotValues =
new SortedList<string, float>
{
{ "Left Pos Inches", 0.0f },
{ "Yaw Angle Deg", 0.0f },
{ "Right Pos Inches", 0.0f },
{ "Elevator Pos Ticks", 0.0f },
{ "Pitch", 0.0f },
{ "Roll", 0.0f },
{ "Yaw", 0.0f },
{ "Distance", 0.0f },
};
public static int portNumber = 4388;
public int bytesAvailable;
List<string> keys = new List<string>();
public float encoder, navX;
public string input, request = "";
IPEndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), portNumber);
Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Socket clientSocket;
short currentIndex;
float currentValue;
public float latency;
// Start is called before the first frame update
void Start()
{
clientSocket.Connect(serverAddress);
startRobopipe();
serverSocket.Bind(serverAddress);
serverSocket.Listen(10);
clientSocket = serverSocket.Accept();
foreach (var valuePair in robotValues)
{
request += valuePair.Key;
@@ -50,6 +52,7 @@ public class robotCommunication : MonoBehaviour
// Update is called once per frame
void Update()
{
latency = Time.deltaTime * 1000;
bytesAvailable = clientSocket.Available;
if (bytesAvailable > 10)
{
@@ -63,8 +66,20 @@ public class robotCommunication : MonoBehaviour
robotValues[keys[i]] = float.Parse(values[i], CultureInfo.InvariantCulture.NumberFormat);
i++;
}
clientSocket.Send(new byte[] { 100 });
isData = true;
clientSocket.Send(Encoding.UTF8.GetBytes("CONT"));
}
}
private void OnApplicationQuit()
{
clientSocket.Send(Encoding.UTF8.GetBytes("EXIT"));
}
private void startRobopipe()
{
Process foo = new Process();
foo.StartInfo.FileName = "Robopipe.jar";
foo.StartInfo.Arguments = "" + portNumber;
foo.Start();
}
}