diff --git a/ClientApp/ClientApp.csproj b/ClientApp/ClientApp.csproj
index 13750b2..edc95d3 100644
--- a/ClientApp/ClientApp.csproj
+++ b/ClientApp/ClientApp.csproj
@@ -29,13 +29,13 @@
Always
- Always
+ PreserveNewest
- Always
+ PreserveNewest
- Always
+ PreserveNewest
Always
diff --git a/ClientApp/Utils/Client.cs b/ClientApp/Utils/Client.cs
index 367fe2d..27d980a 100644
--- a/ClientApp/Utils/Client.cs
+++ b/ClientApp/Utils/Client.cs
@@ -43,6 +43,7 @@ namespace ClientApp.Utils
///
private void initEngine()
{
+ Debug.WriteLine("init engine");
engineConnection = EngineConnection.INSTANCE;
engineConnection.OnNoTunnelId = RetryEngineConnection;
engineConnection.OnSuccessFullConnection = engineConnected;
@@ -88,6 +89,7 @@ namespace ClientApp.Utils
/// the result of the async read
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,18 +149,33 @@ 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)
{
- Console.WriteLine("handler is null");
+ // send that the operation was not successful if the handler is null
+ Debug.WriteLine("handler is null");
sendMessage(DataParser.getSetResistanceResponseJson(false));
}
else
{
- this.handler.setResistance(DataParser.getResistanceFromJson(payloadbytes));
+ // 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);
+ break;
+ case DataParser.NEW_CONNECTION:
+ this.LoginViewModel.DoctorConnected(DataParser.getUsernameFromJson(payloadbytes));
+ break;
+ case DataParser.DISCONNECT:
+ this.LoginViewModel.DoctorDisconnected(DataParser.getUsernameFromJson(payloadbytes));
+ break;
default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
break;
diff --git a/ClientApp/Utils/EngineConnection.cs b/ClientApp/Utils/EngineConnection.cs
index 9ff92e6..5113262 100644
--- a/ClientApp/Utils/EngineConnection.cs
+++ b/ClientApp/Utils/EngineConnection.cs
@@ -43,8 +43,8 @@ namespace ClientApp.Utils
private static string headId = string.Empty;
private static string groundPlaneId = string.Empty;
private static string terrainId = string.Empty;
- private static string lastMessage = "No message received yet";
+ public string DoctorMessage { get; set; }
public float BikeSpeed { get; set; }
public float BikePower { get; set; }
public float BikeBPM { get; set; }
@@ -65,6 +65,7 @@ namespace ClientApp.Utils
BikePower = 0;
BikeBPM = 0;
BikeResistance = 50;
+ DoctorMessage = "No message received yet";
updateTimer = new System.Timers.Timer(1000);
updateTimer.Elapsed += UpdateTimer_Elapsed;
updateTimer.AutoReset = true;
@@ -74,7 +75,7 @@ namespace ClientApp.Utils
noVRResponseTimer.Elapsed += noVRResponseTimeout;
noVRResponseTimer.AutoReset = false;
noVRResponseTimer.Enabled = false;
-
+
}
private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
@@ -224,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();
@@ -324,7 +324,7 @@ namespace ClientApp.Utils
{
// TODO check if is drawn
});
- SendMessageAndOnResponse(mainCommand.showMessage(panelId, "message", lastMessage), "message",
+ SendMessageAndOnResponse(mainCommand.showMessage(panelId, "message", DoctorMessage), "message",
(message) =>
{
// TODO check if is drawn
@@ -337,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));
}
diff --git a/ClientApp/ViewModels/LoginViewModel.cs b/ClientApp/ViewModels/LoginViewModel.cs
index 7b9bfcf..0ec1488 100644
--- a/ClientApp/ViewModels/LoginViewModel.cs
+++ b/ClientApp/ViewModels/LoginViewModel.cs
@@ -42,5 +42,15 @@ namespace ClientApp.ViewModels
this.MainWindowViewModel.SelectedViewModel = new MainViewModel(MainWindowViewModel);
}
}
+
+ internal void DoctorConnected(string name)
+ {
+ this.MainWindowViewModel.InfoModel.DoctorConnected = true;
+ }
+
+ internal void DoctorDisconnected(string name)
+ {
+ this.MainWindowViewModel.InfoModel.DoctorConnected = false;
+ }
}
}
diff --git a/DoctorApp/App.xaml b/DoctorApp/App.xaml
index aac18d8..86b2dd4 100644
--- a/DoctorApp/App.xaml
+++ b/DoctorApp/App.xaml
@@ -9,11 +9,11 @@
-
+
-
+
diff --git a/DoctorApp/DoctorApp.csproj b/DoctorApp/DoctorApp.csproj
index 64333af..86a6834 100644
--- a/DoctorApp/DoctorApp.csproj
+++ b/DoctorApp/DoctorApp.csproj
@@ -9,12 +9,16 @@
+
Always
+
+ PreserveNewest
+
diff --git a/DoctorApp/Utils/Client.cs b/DoctorApp/Utils/Client.cs
index dcb56f8..1087346 100644
--- a/DoctorApp/Utils/Client.cs
+++ b/DoctorApp/Utils/Client.cs
@@ -111,11 +111,10 @@ namespace DoctorApp.Utils
Console.WriteLine("Set resistance identifier");
break;
case DataParser.NEW_CONNECTION:
- Debug.WriteLine("doctor client new connection");
- this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
+ this.MainViewModel.NewConnectedUser(DataParser.getUsernameFromJson(payloadbytes));
break;
case DataParser.DISCONNECT:
- this.MainViewModel.DisconnectedUser(DataParser.getUsernameFromResponseJson(payloadbytes));
+ this.MainViewModel.DisconnectedUser(DataParser.getUsernameFromJson(payloadbytes));
break;
default:
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
@@ -135,6 +134,8 @@ namespace DoctorApp.Utils
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
}
+ if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.client.Connected)
+ return;
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
}
@@ -197,6 +198,7 @@ namespace DoctorApp.Utils
public void Dispose()
{
Debug.WriteLine("client dispose called");
+ sendMessage(DataParser.getDisconnectJson(LoginViewModel.Username));
this.stream.Dispose();
this.client.Dispose();
}
diff --git a/DoctorApp/ViewModels/ClientInfoViewModel.cs b/DoctorApp/ViewModels/ClientInfoViewModel.cs
index 6a81617..ae3d5dd 100644
--- a/DoctorApp/ViewModels/ClientInfoViewModel.cs
+++ b/DoctorApp/ViewModels/ClientInfoViewModel.cs
@@ -17,7 +17,6 @@ namespace DoctorApp.ViewModels
class ClientInfoViewModel : ObservableObject
{
public PatientInfo PatientInfo { get; set; }
- public ObservableCollection ChatLog { get; set; }
private string _mySelectedItem;
public string MySelectedItem
@@ -53,28 +52,24 @@ namespace DoctorApp.ViewModels
this.PatientInfo = new PatientInfo() { Username = username, Status = "Waiting to start" };
this.Chart = new Chart(this.PatientInfo);
PatientInfo.ChatLog = new ObservableCollection();
- ChatLog = new ObservableCollection();
client = mainWindowViewModel.client;
StartSession = new RelayCommand(() =>
{
client.sendMessage(DataParser.getStartSessionJson(PatientInfo.Username));
PatientInfo.Status = "Session started";
- System.Diagnostics.Debug.WriteLine("patient info status" + PatientInfo.Status);
});
StopSession = new RelayCommand(() =>
{
client.sendMessage(DataParser.getStopSessionJson(PatientInfo.Username));
PatientInfo.Status = "Session stopped, waiting to start again.";
- System.Diagnostics.Debug.WriteLine("patient info status" + PatientInfo.Status);
});
Chat = new RelayCommand