diff --git a/ClientApp/ClientApp.csproj b/ClientApp/ClientApp.csproj index 3fdfbd2..edc95d3 100644 --- a/ClientApp/ClientApp.csproj +++ b/ClientApp/ClientApp.csproj @@ -7,6 +7,14 @@ Images\Logo\icon1.ico + + true + + + + true + + diff --git a/ClientApp/Utils/Client.cs b/ClientApp/Utils/Client.cs index fa52f8d..27d980a 100644 --- a/ClientApp/Utils/Client.cs +++ b/ClientApp/Utils/Client.cs @@ -181,7 +181,7 @@ namespace ClientApp.Utils break; } } - else if (DataParser.isRawData(messageBytes)) + else if (DataParser.isRawDataBikeServer(messageBytes)) { Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}"); } @@ -228,7 +228,7 @@ namespace ClientApp.Utils { throw new ArgumentNullException("no bytes"); } - byte[] message = DataParser.GetRawDataMessage(bytes); + byte[] message = DataParser.GetRawBPMDataMessageServer(bytes); if (engineConnection.Connected && engineConnection.FollowingRoute) { @@ -255,7 +255,7 @@ namespace ClientApp.Utils { throw new ArgumentNullException("no bytes"); } - byte[] message = DataParser.GetRawDataMessage(bytes); + byte[] message = DataParser.GetRawBikeDataMessageServer(bytes); bool canSendToEngine = engineConnection.Connected && engineConnection.FollowingRoute; switch (bytes[0]) { diff --git a/DoctorApp/DoctorApp.csproj b/DoctorApp/DoctorApp.csproj index 14b43b7..86a6834 100644 --- a/DoctorApp/DoctorApp.csproj +++ b/DoctorApp/DoctorApp.csproj @@ -23,6 +23,7 @@ + diff --git a/DoctorApp/Models/Chart.cs b/DoctorApp/Models/Chart.cs new file mode 100644 index 0000000..1bab873 --- /dev/null +++ b/DoctorApp/Models/Chart.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Runtime.Serialization; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using LiveCharts; +using LiveCharts.Configurations; +using Util; + +namespace DoctorApp.Models +{ + class Chart : ObservableObject,INotifyPropertyChanged + { + + private double _axisMax; + private double _axisMin; + private double _trend; + + public event PropertyChangedEventHandler PropertyChanged; + + public ChartValues ChartValues { get; set; } + public Func DateTimeFormatter { get; set; } + + public PatientInfo PatientInfo { get; set; } + public double AxisStep { get; set; } + public double AxisUnit { get; set; } + + public double AxisMax + { + get { return _axisMax; } + set + { + _axisMax = value; + OnPropertyChanged("AxisMax"); + } + } + + public double AxisMin + { + get { return _axisMin; } + set + { + _axisMin = value; + OnPropertyChanged("AxisMin"); + } + } + + public bool IsReading { get; set; } + + + + + public Chart(PatientInfo patientInfo) + { + var mapper = Mappers.Xy() + .X(model => model.DateTime.Ticks) + .Y(model => model.Value); + + Charting.For(mapper); + + ChartValues = new ChartValues(); + + DateTimeFormatter = value => new DateTime((long)value).ToString("mm:ss"); + + AxisStep = TimeSpan.FromSeconds(1).Ticks; + + AxisUnit = TimeSpan.TicksPerSecond; + + SetAxisLimits(DateTime.Now); + + IsReading = true; + + ChartValues.Add(new MeasureModel + { + DateTime = DateTime.Now, + Value = 8 + }); + + } + + private void SetAxisLimits(DateTime now) + { + AxisMax = now.Ticks + TimeSpan.FromSeconds(1).Ticks; // lets force the axis to be 1 second ahead + AxisMin = now.Ticks - TimeSpan.FromSeconds(8).Ticks; // and 8 seconds behind + } + + protected virtual void OnPropertyChanged(string propertyName = null) + { + if (PropertyChanged != null) + PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + + public void NewValue(double value) + { + var now = DateTime.Now; + _trend = value; + ChartValues.Add(new MeasureModel + { + DateTime = now, + Value = _trend + }); + + SetAxisLimits(now); + + if (ChartValues.Count > 150) ChartValues.RemoveAt(0); + } + + public void Clear() + { + Debug.WriteLine("clear"); + ChartValues.Clear(); + } + + + + } + + public class MeasureModel + { + public DateTime DateTime { get; set; } + public double Value { get; set; } + } +} diff --git a/DoctorApp/Models/PatientInfo.cs b/DoctorApp/Models/PatientInfo.cs index c7ed295..e2ea0d0 100644 --- a/DoctorApp/Models/PatientInfo.cs +++ b/DoctorApp/Models/PatientInfo.cs @@ -10,11 +10,11 @@ namespace DoctorApp.Models public string Status { get; set; } - public int Speed { get; set; } + public double Speed { get; set; } public int BPM { get; set; } - public int Resistance { get; set; } + public float Resistance { get; set; } public int Acc_Power { get; set; } public int Curr_Power { get; set; } diff --git a/DoctorApp/Utils/Client.cs b/DoctorApp/Utils/Client.cs index 81f245a..1087346 100644 --- a/DoctorApp/Utils/Client.cs +++ b/DoctorApp/Utils/Client.cs @@ -90,7 +90,7 @@ namespace DoctorApp.Utils string responseStatus = DataParser.getResponseStatus(payloadbytes); if (responseStatus == "OK") { - Debug.WriteLine("Username and password correct!"); + Debug.WriteLine("Doctor Username and password correct!"); this.LoginViewModel.setLoginStatus(true); this.connected = true; @@ -121,9 +121,13 @@ namespace DoctorApp.Utils break; } } - else if (DataParser.isRawData(messageBytes)) + else if (DataParser.isRawDataBikeDoctor(messageBytes)) { - Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}"); + MainViewModel.TransferDataToClientBike(payloadbytes); + } + else if (DataParser.isRawDataBPMDoctor(messageBytes)) + { + MainViewModel.TransferDataToClientBPM(payloadbytes); } totalBufferReceived -= expectedMessageLength; diff --git a/DoctorApp/ViewModels/ClientInfoViewModel.cs b/DoctorApp/ViewModels/ClientInfoViewModel.cs index eee0456..ae3d5dd 100644 --- a/DoctorApp/ViewModels/ClientInfoViewModel.cs +++ b/DoctorApp/ViewModels/ClientInfoViewModel.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Diagnostics; using System.Text; using System.Windows.Controls; using System.Windows.Input; @@ -17,6 +18,17 @@ namespace DoctorApp.ViewModels { public PatientInfo PatientInfo { get; set; } + private string _mySelectedItem; + public string MySelectedItem + { + get { return _mySelectedItem; } + set + { + Chart.Clear(); + _mySelectedItem = value; + } + } + public ICommand StartSession { get; set; } public ICommand StopSession { get; set; } @@ -32,10 +44,13 @@ namespace DoctorApp.ViewModels public MainWindowViewModel MainWindowViewModel { get; set; } private Client client; + public Chart Chart { get; set; } + public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel, string username) { MainWindowViewModel = mainWindowViewModel; this.PatientInfo = new PatientInfo() { Username = username, Status = "Waiting to start" }; + this.Chart = new Chart(this.PatientInfo); PatientInfo.ChatLog = new ObservableCollection(); client = mainWindowViewModel.client; @@ -61,11 +76,52 @@ namespace DoctorApp.ViewModels SetResistance = new RelayCommand((parameter) => { - client.sendMessage(DataParser.getSetResistanceJson(PatientInfo.Username, float.Parse(((TextBox)parameter).Text))); + Debug.WriteLine("resistance"); + //client.sendMessage(DataParser.getSetResistanceJson(PatientInfo.Username, float.Parse(((TextBox)parameter).Text))); + PatientInfo.Resistance = float.Parse(((TextBox)parameter).Text); }); } + public void BPMData(byte [] bytes) + { + //TODO + //Parsen van de data you fuck + PatientInfo.BPM = bytes[1]; + if (MySelectedItem == "BPM") + { + Chart.NewValue(PatientInfo.BPM); + } + + } + + public void BikeData(byte[] bytes) + { + //TODO + //Parsen van de data you fuck + switch (bytes[0]) + { + case 0x10: + if (bytes[1] != 25) + { + throw new Exception(); + } + PatientInfo.Distance = bytes[3]; + PatientInfo.Speed = (bytes[4] | (bytes[5] << 8)) * 0.01; + break; + case 0x19: + PatientInfo.Acc_Power = bytes[3] | (bytes[4] << 8); + PatientInfo.Curr_Power = (bytes[5]) | (bytes[6] & 0b00001111) << 8; + break; + default: + throw new Exception(); + } + if (MySelectedItem == "Speed") + { + Chart.NewValue(PatientInfo.Speed); + } + } + } } diff --git a/DoctorApp/ViewModels/MainViewModel.cs b/DoctorApp/ViewModels/MainViewModel.cs index bd02499..0c41d33 100644 --- a/DoctorApp/ViewModels/MainViewModel.cs +++ b/DoctorApp/ViewModels/MainViewModel.cs @@ -48,6 +48,30 @@ namespace DoctorApp.ViewModels } }); } + + public void TransferDataToClientBike(byte[] bytes) + { + string username = DataParser.getNameFromBytesBike(bytes); + foreach(ClientInfoViewModel item in Tabs) + { + if(item.PatientInfo.Username == username) + { + item.BikeData(bytes); + } + } + } + + public void TransferDataToClientBPM(byte[] bytes) + { + string username = DataParser.getNameFromBytesBPM(bytes); + foreach (ClientInfoViewModel item in Tabs) + { + if (item.PatientInfo.Username == username) + { + item.BikeData(bytes); + } + } + } } diff --git a/DoctorApp/Views/ClientInfoView.xaml b/DoctorApp/Views/ClientInfoView.xaml index 9eeca60..5057f24 100644 --- a/DoctorApp/Views/ClientInfoView.xaml +++ b/DoctorApp/Views/ClientInfoView.xaml @@ -5,9 +5,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:DoctorApp.Views" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800" - - > + xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" + d:DesignHeight="450" d:DesignWidth="800"> @@ -56,13 +55,35 @@ - +