Develop #10

Merged
SemvdH merged 229 commits from develop into master 2020-10-29 22:50:49 +00:00
11 changed files with 200 additions and 24 deletions
Showing only changes of commit 083f27411e - Show all commits

View File

@@ -164,10 +164,10 @@ namespace ClientApp.Utils
break;
}
}
/*else if (DataParser.isRawData(messageBytes))
else if (DataParser.isRawDataBikeServer(messageBytes))
{
Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}");
}*/
}
totalBufferReceived -= expectedMessageLength;
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);

View File

@@ -27,7 +27,7 @@ namespace ClientApp.Utils
//new PC("DESKTOP-M2CIH87", "Fabian"),
//new PC("T470S", "Shinichi"),
//new PC("DESKTOP-DHS478C", "semme"),
new PC("HP-ZBOOK-SEM", "Sem")
//new PC("HP-ZBOOK-SEM", "Sem")
//new PC("DESKTOP-TV73FKO", "Wouter"),
//new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
//new PC("NA", "Bart")

View File

@@ -19,6 +19,7 @@
<ItemGroup>
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
<PackageReference Include="PropertyChanged.Fody" Version="3.2.9" />
</ItemGroup>

127
DoctorApp/Models/Chart.cs Normal file
View File

@@ -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<MeasureModel> ChartValues { get; set; }
public Func<double, string> 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<MeasureModel>()
.X(model => model.DateTime.Ticks)
.Y(model => model.Value);
Charting.For<MeasureModel>(mapper);
ChartValues = new ChartValues<MeasureModel>();
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; }
}
}

View File

@@ -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; }

View File

@@ -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;
@@ -130,6 +130,9 @@ namespace DoctorApp.Utils
{
MainViewModel.TransferDataToClientBPM(payloadbytes);
}
totalBufferReceived -= expectedMessageLength;
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
}
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);

View File

@@ -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;
@@ -18,6 +19,17 @@ namespace DoctorApp.ViewModels
public PatientInfo PatientInfo { get; set; }
public ObservableCollection<string> ChatLog { 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; }
@@ -33,10 +45,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<string>();
ChatLog = new ObservableCollection<string>();
client = mainWindowViewModel.client;
@@ -66,8 +81,9 @@ namespace DoctorApp.ViewModels
SetResistance = new RelayCommand<object>((parameter) =>
{
client.sendMessage(DataParser.getSetResistanceJson(Username, float.Parse(((TextBox)parameter).Text)));
this.Resistance = 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);
});
}
@@ -76,7 +92,12 @@ namespace DoctorApp.ViewModels
{
//TODO
//Parsen van de data you fuck
this.BPM = bytes[1];
PatientInfo.BPM = bytes[1];
if (MySelectedItem == "BPM")
{
Chart.NewValue(PatientInfo.BPM);
}
}
public void BikeData(byte[] bytes)
@@ -90,17 +111,20 @@ namespace DoctorApp.ViewModels
{
throw new Exception();
}
this.Distance = bytes[3];
this.Speed = (bytes[4] | (bytes[5] << 8)) * 0.01;
PatientInfo.Distance = bytes[3];
PatientInfo.Speed = (bytes[4] | (bytes[5] << 8)) * 0.01;
break;
case 0x19:
this.Acc_Power = bytes[3] | (bytes[4] << 8);
this.Curr_Power = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
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);
}
}

View File

@@ -53,7 +53,7 @@ namespace DoctorApp.ViewModels
string username = DataParser.getNameFromBytesBike(bytes);
foreach(ClientInfoViewModel item in Tabs)
{
if(item.Username == username)
if(item.PatientInfo.Username == username)
{
item.BikeData(bytes);
}
@@ -65,7 +65,7 @@ namespace DoctorApp.ViewModels
string username = DataParser.getNameFromBytesBPM(bytes);
foreach (ClientInfoViewModel item in Tabs)
{
if (item.Username == username)
if (item.PatientInfo.Username == username)
{
item.BikeData(bytes);
}

View File

@@ -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">
<Grid Margin="15,5,15,15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
@@ -56,13 +55,35 @@
</DockPanel>
</StackPanel>
<ListBox Name="ChatBox" ItemsSource="{Binding PatientInfo.ChatLog}" Grid.Column="1" Margin="59,41,0,0" Grid.RowSpan="3"/>
<TextBox Name="textBox_Chat" Grid.Column="1" HorizontalAlignment="Left" Margin="59,10,0,0" Grid.Row="3" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/>
<TextBox Name="textBox_Chat" Grid.Column="1" HorizontalAlignment="Left" Margin="59,10,0,0" Grid.Row="3" Text="" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/>
<Button x:Name="Send" Content="Send" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" Command="{Binding Chat}" CommandParameter="{Binding ElementName=textBox_Chat}"/>
<Button Content="Start Session" Grid.Column="1" HorizontalAlignment="Left" Margin="69,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Command="{Binding StartSession}" CommandParameter=""/>
<Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Command="{Binding StopSession}" CommandParameter=""/>
<TextBox x:Name="textBox_SetResistance" Grid.Column="1" HorizontalAlignment="Left" Margin="69,128,0,0" Grid.Row="3" TextWrapping="Wrap" VerticalAlignment="Top" Width="97"/>
<Button Content="Set Resistance" Grid.Column="1" HorizontalAlignment="Left" Margin="187,128,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Height="18" Command="{Binding SetResistance}" CommandParameter="{Binding ElementName=textBox_SetResistance}"/>
<Canvas Grid.Row="3" Background="White" Margin="0,33,0,0"/>
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190"/>
<lvc:CartesianChart Grid.Row="3" AnimationsSpeed="0:0:0.5" Hoverable="False" DataTooltip="{x:Null}" Margin="0,33,0,-5">
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="{Binding Chart.ChartValues}"
PointGeometry="{x:Null}"
LineSmoothness="1"
StrokeThickness="6"
Stroke="#F34336"
Fill="Transparent"/>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding Chart.DateTimeFormatter}"
MaxValue="{Binding Chart.AxisMax}"
MinValue="{Binding Chart.AxisMin}"
Unit="{Binding Chart.AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator Step="{Binding Chart.AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190" SelectedItem="{Binding Path=MySelectedItem}">
<ComboBoxItem Content="Speed" IsSelected="True"></ComboBoxItem>
<ComboBoxItem Content="BPM"></ComboBoxItem>
</ComboBox>
</Grid>
</UserControl>

View File

@@ -11,7 +11,7 @@
<TabControl TabStripPlacement="Left" ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Username}"/>
<TextBlock Text="{Binding PatientInfo.Username}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>

View File

@@ -10,7 +10,7 @@
AllowsTransparency="True"
MinHeight="{Binding MinimumHeight}"
MinWidth="{Binding MinimumWidth}"
Title="MainWindow" Height="450" Width="800">
Title="MainWindow" Height="500" Width="900">
<Window.Resources>
<Style TargetType="{x:Type local:MainWindow}">
<Setter Property="Template">