finished reconnecting on sim not started and then sending the commands

This commit is contained in:
Sem van der Hoeven
2020-10-07 15:08:45 +02:00
parent bff4718d3f
commit 57aa9b6deb
3 changed files with 62 additions and 11 deletions

View File

@@ -56,8 +56,9 @@ namespace Client
private void engineConnected() private void engineConnected()
{ {
Console.WriteLine("successfully connected to VR engine");
engineConnection.initScene(); engineConnection.initScene();
if (this.sessionRunning) engineConnection.StartRouteFollow(); if (engineConnection.Connected && sessionRunning && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
} }
/// <summary> /// <summary>
@@ -127,6 +128,7 @@ namespace Client
case DataParser.START_SESSION: case DataParser.START_SESSION:
Console.WriteLine("Session started!"); Console.WriteLine("Session started!");
this.sessionRunning = true; this.sessionRunning = true;
if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
sendMessage(DataParser.getStartSessionJson()); sendMessage(DataParser.getStartSessionJson());
break; break;
case DataParser.STOP_SESSION: case DataParser.STOP_SESSION:

View File

@@ -37,6 +37,8 @@ namespace Client
private static string bikeId = string.Empty; private static string bikeId = string.Empty;
private static string headId = string.Empty; private static string headId = string.Empty;
public bool FollowingRoute = false;
private static NetworkStream stream; private static NetworkStream stream;
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>(); private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
@@ -89,7 +91,6 @@ namespace Client
serverResponseReader = new ServerResponseReader(stream); serverResponseReader = new ServerResponseReader(stream);
serverResponseReader.callback = HandleResponse; serverResponseReader.callback = HandleResponse;
serverResponseReader.StartRead(); serverResponseReader.StartRead();
Connected = true;
} }
#region VR Message traffic #region VR Message traffic
@@ -110,12 +111,14 @@ namespace Client
WriteTextMessage(tunnelCreate); WriteTextMessage(tunnelCreate);
// wait until we have a tunnel id // wait until we have a tunnel id
while (tunnelId == string.Empty) { } //while (tunnelId == string.Empty) { }
if (tunnelId != null) //if (tunnelId != null)
{ //{
Write("got tunnel id! " + tunnelId); // Write("got tunnel id! " + tunnelId);
OnSuccessFullConnection?.Invoke(); // Connected = true;
} // OnSuccessFullConnection?.Invoke();
//}
} }
@@ -132,17 +135,23 @@ 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")
{ {
tunnelId = JSONParser.GetTunnelID(message); tunnelId = JSONParser.GetTunnelID(message);
Console.WriteLine("set tunnel id to " + tunnelId);
if (tunnelId == null) if (tunnelId == null)
{ {
Write("could not find a valid tunnel id!"); Write("could not find a valid tunnel id!");
OnNoTunnelId?.Invoke(); OnNoTunnelId?.Invoke();
Connected = false; Connected = false;
FollowingRoute = false;
return; return;
} else
{
Write("got tunnel id! " + tunnelId);
Connected = true;
OnSuccessFullConnection?.Invoke();
} }
} }
@@ -157,6 +166,7 @@ namespace Client
public void initScene() public void initScene()
{ {
Write("initializing scene...");
mainCommand = new Command(tunnelId); mainCommand = new Command(tunnelId);
// reset the scene // reset the scene
@@ -181,7 +191,47 @@ namespace Client
internal void StartRouteFollow() internal void StartRouteFollow()
{ {
throw new NotImplementedException(); Write("Starting route follow...");
FollowingRoute = true;
SendMessageAndOnResponse(mainCommand.AddBikeModel("bikeID"), "bikeID",
(message) =>
{
bikeId = JSONParser.GetResponseUuid(message);
SendMessageAndOnResponse(mainCommand.addPanel("panelAdd", bikeId), "panelAdd",
(message) =>
{
panelId = JSONParser.getPanelID(message);
WriteTextMessage(mainCommand.ColorPanel(panelId));
WriteTextMessage(mainCommand.ClearPanel(panelId));
SendMessageAndOnResponse(mainCommand.MoveTo(panelId, "panelMove", new float[] { 0f, 0f, 0f }, "Z", 1, 5), "panelMove",
(message) =>
{
Console.WriteLine(message);
SendMessageAndOnResponse(mainCommand.bikeSpeed(panelId, "bikeSpeed", 5.0), "bikeSpeed",
(message) =>
{
WriteTextMessage(mainCommand.SwapPanel(panelId));
});
});
//while (!(speedReplied && moveReplied)) { }
while (cameraId == string.Empty) { }
SetFollowSpeed(5.0f);
});
});
}
private void SetFollowSpeed(float speed)
{
WriteTextMessage(mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
WriteTextMessage(mainCommand.RouteFollow(routeId, cameraId, speed));
} }
#endregion #endregion

View File

@@ -329,7 +329,6 @@ namespace RH_Engine
{ {
WriteTextMessage(stream, mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 })); WriteTextMessage(stream, mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
WriteTextMessage(stream, mainCommand.RouteFollow(routeId, cameraId, speed)); WriteTextMessage(stream, mainCommand.RouteFollow(routeId, cameraId, speed));
//WriteTextMessage(stream, mainCommand.RouteFollow(routeId, panelId, speed, 1f, "XYZ", 1, false, new float[] { 0, 0, 0 }, new float[] { 0f, 5f, 5f }));
} }
//string routeID, string nodeID, float speedValue, float offsetValue, string rotateValue, float smoothingValue, bool followHeightValue, float[] rotateOffsetVector, float[] positionOffsetVector) //string routeID, string nodeID, float speedValue, float offsetValue, string rotateValue, float smoothingValue, bool followHeightValue, float[] rotateOffsetVector, float[] positionOffsetVector)
private static void Force(NetworkStream stream, string message, string serial, HandleSerial action) private static void Force(NetworkStream stream, string message, string serial, HandleSerial action)