added route to client vr scene

This commit is contained in:
Sem van der Hoeven
2020-10-07 12:51:09 +02:00
parent 499134fa9a
commit bff4718d3f
4 changed files with 73 additions and 15 deletions

View File

@@ -38,6 +38,7 @@ namespace Client
{ {
engineConnection = EngineConnection.INSTANCE; engineConnection = EngineConnection.INSTANCE;
engineConnection.OnNoTunnelId = retryEngineConnection; engineConnection.OnNoTunnelId = retryEngineConnection;
engineConnection.OnSuccessFullConnection = engineConnected;
if (!engineConnection.Connected) engineConnection.Connect(); if (!engineConnection.Connected) engineConnection.Connect();
} }
@@ -53,6 +54,12 @@ namespace Client
engineConnection.CreateConnection(); engineConnection.CreateConnection();
} }
private void engineConnected()
{
engineConnection.initScene();
if (this.sessionRunning) engineConnection.StartRouteFollow();
}
/// <summary> /// <summary>
/// callback method for when the TCP client is connected /// callback method for when the TCP client is connected
/// </summary> /// </summary>
@@ -193,7 +200,6 @@ namespace Client
throw new ArgumentNullException("no bytes"); throw new ArgumentNullException("no bytes");
} }
byte[] message = DataParser.GetRawDataMessage(bytes); byte[] message = DataParser.GetRawDataMessage(bytes);
Console.WriteLine("got bpm message: " + message);
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
} }
@@ -212,7 +218,6 @@ namespace Client
throw new ArgumentNullException("no bytes"); throw new ArgumentNullException("no bytes");
} }
byte[] message = DataParser.GetRawDataMessage(bytes); byte[] message = DataParser.GetRawDataMessage(bytes);
Console.WriteLine("got bike message: " + message);
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
} }

View File

@@ -8,12 +8,14 @@ namespace Client
{ {
public delegate void HandleSerial(string message); public delegate void HandleSerial(string message);
public delegate void HandleNoTunnelId(); public delegate void HandleNoTunnelId();
public delegate void OnSuccessfullConnection();
public sealed class EngineConnection public sealed class EngineConnection
{ {
private static EngineConnection instance = null; private static EngineConnection instance = null;
private static readonly object padlock = new object(); private static readonly object padlock = new object();
public HandleNoTunnelId OnNoTunnelId; public HandleNoTunnelId OnNoTunnelId;
public OnSuccessfullConnection OnSuccessFullConnection;
private static PC[] PCs = { private static PC[] PCs = {
@@ -29,9 +31,11 @@ namespace Client
private static ServerResponseReader serverResponseReader; private static ServerResponseReader serverResponseReader;
private static string sessionId = string.Empty; private static string sessionId = string.Empty;
private static string tunnelId = string.Empty; private static string tunnelId = string.Empty;
private static string cameraId = string.Empty;
private static string routeId = string.Empty; private static string routeId = string.Empty;
private static string panelId = string.Empty; private static string panelId = string.Empty;
private static string bikeId = string.Empty; private static string bikeId = string.Empty;
private static string headId = string.Empty;
private static NetworkStream stream; private static NetworkStream stream;
@@ -45,6 +49,9 @@ namespace Client
} }
/// <summary>
/// Singleton constructor
/// </summary>
public static EngineConnection INSTANCE public static EngineConnection INSTANCE
{ {
get get
@@ -60,6 +67,11 @@ namespace Client
} }
} }
/// <summary>
/// connects to the vr engine and initalizes the serverResponseReader
/// </summary>
public void Connect() public void Connect()
{ {
TcpClient client = new TcpClient("145.48.6.10", 6666); TcpClient client = new TcpClient("145.48.6.10", 6666);
@@ -68,6 +80,19 @@ namespace Client
CreateConnection(); CreateConnection();
} }
/// <summary>
/// initializes and starts the reading of the responses from the vr server
/// </summary>
/// <param name="stream">the networkstream</param>
private void initReader()
{
serverResponseReader = new ServerResponseReader(stream);
serverResponseReader.callback = HandleResponse;
serverResponseReader.StartRead();
Connected = true;
}
#region VR Message traffic
/// <summary> /// <summary>
/// connects to the server and creates the tunnel /// connects to the server and creates the tunnel
/// </summary> /// </summary>
@@ -89,20 +114,10 @@ namespace Client
if (tunnelId != null) if (tunnelId != null)
{ {
Write("got tunnel id! " + tunnelId); Write("got tunnel id! " + tunnelId);
OnSuccessFullConnection?.Invoke();
} }
mainCommand = new Command(tunnelId);
}
/// <summary>
/// initializes and starts the reading of the responses from the vr server
/// </summary>
/// <param name="stream">the networkstream</param>
private void initReader()
{
serverResponseReader = new ServerResponseReader(stream);
serverResponseReader.callback = HandleResponse;
serverResponseReader.StartRead();
Connected = true;
} }
/// <summary> /// <summary>
@@ -117,6 +132,7 @@ namespace Client
if (id == "session/list") if (id == "session/list")
{ {
sessionId = JSONParser.GetSessionID(message, PCs); sessionId = JSONParser.GetSessionID(message, PCs);
Write("got session id");
} }
else if (id == "tunnel/create") else if (id == "tunnel/create")
{ {
@@ -139,6 +155,39 @@ namespace Client
} }
} }
public void initScene()
{
mainCommand = new Command(tunnelId);
// reset the scene
WriteTextMessage(mainCommand.ResetScene());
//Get sceneinfo and set the id's
SendMessageAndOnResponse(mainCommand.GetSceneInfoCommand("sceneinfo"), "sceneinfo",
(message) =>
{
//Console.WriteLine("\r\n\r\n\r\nscene info" + message);
cameraId = JSONParser.GetIdSceneInfoChild(message, "Camera");
string headId = JSONParser.GetIdSceneInfoChild(message, "Head");
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
//Force(stream, mainCommand.DeleteNode(handLeftId, "deleteHandL"), "deleteHandL", (message) => Console.WriteLine("Left hand deleted"));
//Force(stream, mainCommand.DeleteNode(handRightId, "deleteHandR"), "deleteHandR", (message) => Console.WriteLine("Right hand deleted"));
});
// add the route and set the route id
SendMessageAndOnResponse(mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
}
internal void StartRouteFollow()
{
throw new NotImplementedException();
}
#endregion
#region message send/receive
/// <summary> /// <summary>
/// method that sends the speciefied message with the specified serial, and executes the given action upon receivind a reply from the server with this serial. /// method that sends the speciefied message with the specified serial, and executes the given action upon receivind a reply from the server with this serial.
/// </summary> /// </summary>
@@ -169,6 +218,8 @@ namespace Client
//Write("sent message " + message); //Write("sent message " + message);
} }
#endregion
public void Write(string msg) public void Write(string msg)
{ {
Console.WriteLine( "[ENGINECONNECT] " + msg); Console.WriteLine( "[ENGINECONNECT] " + msg);

View File

@@ -11,7 +11,7 @@ namespace Client
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
Console.WriteLine("Hello World!"); Console.WriteLine("// Connecting... //");
//connect fiets? //connect fiets?
Client client = new Client(); Client client = new Client();

View File

@@ -142,7 +142,9 @@ namespace Server
} }
else if (DataParser.isRawData(message)) else if (DataParser.isRawData(message))
{ {
// print the raw data
Console.WriteLine(BitConverter.ToString(payloadbytes)); Console.WriteLine(BitConverter.ToString(payloadbytes));
// TODO change, checking for length is not that safe
if (payloadbytes.Length == 8) if (payloadbytes.Length == 8)
{ {
saveData?.WriteDataRAWBike(payloadbytes); saveData?.WriteDataRAWBike(payloadbytes);