From d6cf5902da5908a1c49dd396543700020def035c Mon Sep 17 00:00:00 2001 From: shinichi Date: Thu, 29 Oct 2020 23:32:47 +0100 Subject: [PATCH] [ADD] update data in doctor applicatie --- DoctorApp/ViewModels/MainViewModel.cs | 12 ++++++++---- DoctorApp/Views/ClientInfoView.xaml | 4 ++-- Hashing/DataParser.cs | 2 -- Server/Client.cs | 13 ++++++++----- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/DoctorApp/ViewModels/MainViewModel.cs b/DoctorApp/ViewModels/MainViewModel.cs index e61b202..f1012d7 100644 --- a/DoctorApp/ViewModels/MainViewModel.cs +++ b/DoctorApp/ViewModels/MainViewModel.cs @@ -52,13 +52,15 @@ namespace DoctorApp.ViewModels public void TransferDataToClientBike(byte[] bytes) { string username = DataParser.getNameFromBytesBike(bytes); - foreach(ClientInfoViewModel item in Tabs) + foreach (ClientInfoViewModel item in Tabs) { - if(item.PatientInfo.Username == username) + if (item.PatientInfo.Username == username) { - item.BikeData(DataParser.getDataWithoutName(bytes,0,8)); + item.BikeData(DataParser.getDataWithoutName(bytes, 0, 8)); + return; } } + Debug.WriteLine("[MainViewModel] did not find client (bike) username is " + username); } public void TransferDataToClientBPM(byte[] bytes) @@ -68,9 +70,11 @@ namespace DoctorApp.ViewModels { if (item.PatientInfo.Username == username) { - item.BikeData(DataParser.getDataWithoutName(bytes, 0,2)); + item.BPMData(DataParser.getDataWithoutName(bytes, 0, 2)); + return; } } + Debug.WriteLine("[MainViewModel] did not find client (bpm) username is " + username); } } diff --git a/DoctorApp/Views/ClientInfoView.xaml b/DoctorApp/Views/ClientInfoView.xaml index 9c954c1..cb1be22 100644 --- a/DoctorApp/Views/ClientInfoView.xaml +++ b/DoctorApp/Views/ClientInfoView.xaml @@ -1,4 +1,4 @@ - - + diff --git a/Hashing/DataParser.cs b/Hashing/DataParser.cs index e6d661d..0eb8b10 100644 --- a/Hashing/DataParser.cs +++ b/Hashing/DataParser.cs @@ -298,7 +298,6 @@ namespace Util private static byte[] GetRawDataDoctor(byte[] payload, string username, byte messageID) { - Debug.WriteLine(BitConverter.ToString(Encoding.ASCII.GetBytes(username))); byte[] nameArray = Encoding.ASCII.GetBytes(username); byte[] total = new byte[nameArray.Length + payload.Length]; Array.Copy(payload, 0, total, 0, payload.Length); @@ -422,7 +421,6 @@ namespace Util /// the response of the message, so wether it was successful or not. public static bool getResistanceFromResponseJson(byte[] json) { - Debug.WriteLine("got message " + Encoding.ASCII.GetString(json)); return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked; } diff --git a/Server/Client.cs b/Server/Client.cs index c9eeb87..7d92ca2 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -129,7 +129,8 @@ namespace Server break; case DataParser.START_SESSION: this.communication.StartSessionUser(DataParser.getUsernameFromJson(payloadbytes)); - this.timer.Start(); + if (communication.Doctor != this) + this.timer.Start(); break; case DataParser.STOP_SESSION: this.communication.StopSessionUser(DataParser.getUsernameFromJson(payloadbytes)); @@ -169,7 +170,8 @@ namespace Server Array.Copy(this.BikeDataBuffer, 0, this.BikeDataBuffer, 8, 8); Array.Copy(payloadbytes, 0, this.BikeDataBuffer, 0, 8); } - //this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(payloadbytes, this.username)); + this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(payloadbytes, this.username)); + } else if (DataParser.isRawDataBPMServer(message)) { @@ -179,8 +181,8 @@ namespace Server { Array.Copy(payloadbytes, 0, this.BPMDataBuffer, 0, 2); } - //this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(payloadbytes, this.username)); - } + this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(payloadbytes, this.username)); + } } @@ -207,7 +209,7 @@ namespace Server Debug.WriteLine("[SERVER CLIENT] excetion while trying to get raw bike data: " + e.Message); } - Debug.WriteLine("[SERVER CLIENT] about to send " +sb.ToString()); + Debug.WriteLine("[SERVER CLIENT] about to send " + sb.ToString()); communication.Doctor.sendMessage(DataParser.GetFileMessage(File.ReadAllBytes(path))); } @@ -316,6 +318,7 @@ namespace Server this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(this.BPMDataBuffer, this.username)); } this.timer.Start(); + Debug.WriteLine("[serverclient] send bike and bpm data timer"); } } }