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

View File

@@ -225,7 +225,6 @@ namespace ClientApp.Utils
string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand"); string handLeftId = JSONParser.GetIdSceneInfoChild(message, "LeftHand");
string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand"); string handRightId = JSONParser.GetIdSceneInfoChild(message, "RightHand");
groundPlaneId = JSONParser.GetIdSceneInfoChild(message, "GroundPlane"); groundPlaneId = JSONParser.GetIdSceneInfoChild(message, "GroundPlane");
Write("--- Ground plane id is " + groundPlaneId);
}); });
// add the route and set the route id // add the route and set the route id
CreateTerrain(); CreateTerrain();
@@ -338,6 +337,7 @@ namespace ClientApp.Utils
private void SetFollowSpeed(float speed) 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, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 }));
WriteTextMessage(mainCommand.RouteFollow(routeId, cameraId, speed)); WriteTextMessage(mainCommand.RouteFollow(routeId, cameraId, speed));
} }

View File

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

View File

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