Develop #10

Merged
SemvdH merged 229 commits from develop into master 2020-10-29 22:50:49 +00:00
4 changed files with 14 additions and 5 deletions
Showing only changes of commit fb443a33d7 - Show all commits

View File

@@ -43,6 +43,7 @@ namespace ClientApp.Utils
/// </summary>
private void initEngine()
{
Debug.WriteLine("init engine");
engineConnection = EngineConnection.INSTANCE;
engineConnection.OnNoTunnelId = RetryEngineConnection;
engineConnection.OnSuccessFullConnection = engineConnected;
@@ -88,6 +89,7 @@ namespace ClientApp.Utils
/// <param name="ar">the result of the async read</param>
private void OnRead(IAsyncResult ar)
{
Debug.WriteLine("got message in client app");
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead))
return;
@@ -136,7 +138,7 @@ namespace ClientApp.Utils
}
break;
case DataParser.START_SESSION:
Console.WriteLine("Session started!");
Debug.WriteLine("Session started!");
this.sessionRunning = true;
if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
Debug.WriteLine("start");
@@ -147,25 +149,26 @@ namespace ClientApp.Utils
Debug.WriteLine("stop");
break;
case DataParser.SET_RESISTANCE:
Console.WriteLine("Set resistance identifier");
Debug.WriteLine("Set resistance identifier");
if (this.handler == null)
{
// send that the operation was not successful if the handler is null
Console.WriteLine("handler is null");
Debug.WriteLine("handler is null");
sendMessage(DataParser.getSetResistanceResponseJson(false));
}
else
{
// set the resistance in the vr scene and send that it was successful
float resistance = DataParser.getResistanceFromJson(payloadbytes);
Debug.WriteLine("resistance set was " + resistance);
this.handler.setResistance(resistance);
engineConnection.BikeResistance = resistance;
sendMessage(DataParser.getSetResistanceResponseJson(true));
}
break;
case DataParser.MESSAGE:
Debug.WriteLine("client has received message from doctor");
engineConnection.DoctorMessage = DataParser.getChatMessageFromJson(payloadbytes);
Debug.WriteLine("received message from doctor");
break;
case DataParser.NEW_CONNECTION:
this.LoginViewModel.DoctorConnected(DataParser.getUsernameFromJson(payloadbytes));

View File

@@ -225,7 +225,6 @@ namespace ClientApp.Utils
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
groundPlaneId = JSONParser.GetIdSceneInfoChild(message, "GroundPlane");
Write("--- Ground plane id is " + groundPlaneId);
});
// add the route and set the route id
CreateTerrain();
@@ -338,6 +337,7 @@ namespace ClientApp.Utils
private void SetFollowSpeed(float speed)
{
Write("starting route follow");
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));
}

View File

@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
@@ -338,6 +339,7 @@ namespace Util
/// <returns>the response of the message, so wether it was successful or not.</returns>
public static bool getResistanceFromResponseJson(byte[] json)
{
Debug.WriteLine("got message " + Encoding.ASCII.GetString(json));
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
}

View File

@@ -122,10 +122,14 @@ namespace Server
//bool worked = DataParser.getResistanceFromResponseJson(payloadbytes);
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
//set resistance on doctor GUI
break;
case DataParser.DISCONNECT:
communication.Disconnect(this);
break;
case DataParser.MESSAGE:
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
break;
default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
break;