Compare commits
86 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2e1c90c16 | ||
|
|
86a8b2b789 | ||
|
|
aa2e16de89 | ||
|
|
b112fc131e | ||
|
|
6725f2ff85 | ||
|
|
89fe104418 | ||
|
|
2177f9bd19 | ||
|
|
28dc2c2f9c | ||
|
|
cd1a95ae85 | ||
|
|
cad1a508e6 | ||
|
|
06e1d1edee | ||
|
|
7c98aa6536 | ||
|
|
d6cf5902da | ||
|
|
c1ee84fd2e | ||
|
|
9f7a01170b | ||
|
|
6dd9bd4107 | ||
|
|
4207eaefea | ||
|
|
acc2fddf82 | ||
|
|
87b9ee65d0 | ||
|
|
a333d6cd8d | ||
|
|
dffdae2cb4 | ||
|
|
baf89dac3f | ||
|
|
b98ac77261 | ||
|
|
6d599cfcd2 | ||
|
|
c48e396e81 | ||
|
|
da9d3184a1 | ||
|
|
2b6ea121c9 | ||
|
|
478a2daab7 | ||
|
|
8b8dd901c7 | ||
|
|
aa5ea7a3e0 | ||
|
|
aeb5d59ce9 | ||
|
|
ab1662f0fe | ||
|
|
f07c3f9484 | ||
|
|
2adfcc5bd7 | ||
|
|
3acdc942bc | ||
|
|
84cbcb4a6d | ||
|
|
8385f09313 | ||
|
|
3ea42b65ed | ||
|
|
55d3dd4eee | ||
|
|
960327a3e3 | ||
|
|
083f27411e | ||
|
|
d9c8b7c6df | ||
|
|
de9716128c | ||
|
|
f934dee2d0 | ||
|
|
107d95b81a | ||
|
|
c50f898ec0 | ||
|
|
fb443a33d7 | ||
|
|
8249632d00 | ||
|
|
134bf235c3 | ||
|
|
bc738d0fa3 | ||
|
|
2ecc90ff2c | ||
|
|
6a9e2b57ac | ||
|
|
973ff20da4 | ||
|
|
d98c32a508 | ||
|
|
dcf6c3c6d0 | ||
|
|
689f7030e4 | ||
|
|
4a238d9207 | ||
|
|
31be096b94 | ||
|
|
7eb7b03d4f | ||
|
|
17a17e3c6d | ||
|
|
163d2321cc | ||
|
|
c9e913474c | ||
|
|
63b5c6ab73 | ||
|
|
6b355a0b72 | ||
|
|
9a46b17067 | ||
|
|
b748bcf5c8 | ||
|
|
62525f3a23 | ||
|
|
783c40d7d3 | ||
|
|
e9e3381960 | ||
|
|
75ff7fe336 | ||
|
|
cc046d6611 | ||
|
|
5751bbed81 | ||
|
|
a76433803c | ||
|
|
ae01646de6 | ||
|
|
e8a4901f09 | ||
|
|
b868515ade | ||
|
|
93eeea856f | ||
|
|
0427fa89aa | ||
|
|
fd9b321292 | ||
|
|
6fb9d0efaa | ||
|
|
540a640bc6 | ||
|
|
777ed65707 | ||
|
|
44abffd7e7 | ||
|
|
9ef51ddeca | ||
|
|
4af7b3bc44 | ||
|
|
3dc1709943 |
@@ -19,11 +19,11 @@
|
||||
</DataTemplate>
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Styles/Fonts.xaml"/>
|
||||
<ResourceDictionary Source="Styles/Colors.xaml"/>
|
||||
<ResourceDictionary Source="Styles/Buttons.xaml"/>
|
||||
<ResourceDictionary Source="Styles/Texts.xaml"/>
|
||||
<ResourceDictionary Source="Styles/Windows.xaml"/>
|
||||
<ResourceDictionary Source="WPFStuff/Styles/Fonts.xaml"/>
|
||||
<ResourceDictionary Source="WPFStuff/Styles/Colors.xaml"/>
|
||||
<ResourceDictionary Source="WPFStuff/Styles/Buttons.xaml"/>
|
||||
<ResourceDictionary Source="WPFStuff/Styles/Texts.xaml"/>
|
||||
<ResourceDictionary Source="WPFStuff/Styles/Windows.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
|
||||
@@ -7,6 +7,14 @@
|
||||
<ApplicationIcon>Images\Logo\icon1.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Images\CoolBackground.jpg" />
|
||||
<None Remove="Images\Icons\CheckMark.png" />
|
||||
@@ -21,13 +29,13 @@
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\Icons\CheckMark.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\Icons\CrossMark.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\Logo\icon1.ico">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\re15.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace ClientApp.Utils
|
||||
private byte[] totalBuffer = new byte[1024];
|
||||
private int totalBufferReceived = 0;
|
||||
public EngineConnection engineConnection;
|
||||
private bool sessionRunning = false;
|
||||
private bool sessionRunning = true;
|
||||
private IHandler handler = null;
|
||||
private LoginViewModel LoginViewModel;
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace ClientApp.Utils
|
||||
/// </summary>
|
||||
private void initEngine()
|
||||
{
|
||||
Debug.WriteLine("init engine");
|
||||
engineConnection = EngineConnection.INSTANCE;
|
||||
engineConnection.OnNoTunnelId = RetryEngineConnection;
|
||||
engineConnection.OnSuccessFullConnection = engineConnected;
|
||||
@@ -88,6 +89,7 @@ namespace ClientApp.Utils
|
||||
/// <param name="ar">the result of the async read</param>
|
||||
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");
|
||||
@@ -144,30 +146,46 @@ namespace ClientApp.Utils
|
||||
case DataParser.STOP_SESSION:
|
||||
Console.WriteLine("Stop session identifier");
|
||||
this.sessionRunning = false;
|
||||
stopBikeInSimulation();
|
||||
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;
|
||||
}
|
||||
}
|
||||
else if (DataParser.isRawData(messageBytes))
|
||||
else if (DataParser.isRawDataBikeServer(messageBytes))
|
||||
{
|
||||
Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}");
|
||||
}
|
||||
}
|
||||
|
||||
totalBufferReceived -= expectedMessageLength;
|
||||
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
|
||||
@@ -211,16 +229,14 @@ namespace ClientApp.Utils
|
||||
{
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawDataMessage(bytes);
|
||||
byte[] message = DataParser.GetRawBPMDataMessageServer(bytes);
|
||||
|
||||
if (engineConnection.Connected && engineConnection.FollowingRoute)
|
||||
if (engineConnection != null && engineConnection.Connected && engineConnection.FollowingRoute)
|
||||
{
|
||||
engineConnection.BikeBPM = bytes[1];
|
||||
|
||||
}
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
this.stream?.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -238,22 +254,30 @@ namespace ClientApp.Utils
|
||||
{
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawDataMessage(bytes);
|
||||
bool canSendToEngine = engineConnection.Connected && engineConnection.FollowingRoute;
|
||||
byte[] message = DataParser.GetRawBikeDataMessageServer(bytes);
|
||||
bool canSendToEngine = engineConnection != null && engineConnection.Connected && engineConnection.FollowingRoute && this.sessionRunning;
|
||||
switch (bytes[0])
|
||||
{
|
||||
|
||||
case 0x10:
|
||||
|
||||
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
|
||||
else if (engineConnection != null) engineConnection.BikeSpeed = 0;
|
||||
break;
|
||||
case 0x19:
|
||||
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
||||
else if (engineConnection != null) engineConnection.BikePower = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
this.stream?.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
private void stopBikeInSimulation()
|
||||
{
|
||||
engineConnection.BikeSpeed = 0;
|
||||
engineConnection.BikePower = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -301,6 +325,7 @@ namespace ClientApp.Utils
|
||||
this.stream.Dispose();
|
||||
this.client.Dispose();
|
||||
this.handler.stop();
|
||||
this.engineConnection.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using RH_Engine;
|
||||
@@ -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")
|
||||
@@ -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)
|
||||
@@ -178,7 +179,7 @@ namespace ClientApp.Utils
|
||||
Console.WriteLine("set tunnel id to " + tunnelId);
|
||||
if (tunnelId == null)
|
||||
{
|
||||
Write("could not find a valid tunnel id!");
|
||||
//Write("could not find a valid tunnel id!");
|
||||
OnNoTunnelId?.Invoke();
|
||||
Connected = false;
|
||||
FollowingRoute = false;
|
||||
@@ -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();
|
||||
@@ -256,9 +256,9 @@ namespace ClientApp.Utils
|
||||
WriteTextMessage(mainCommand.ShowRoute("showRouteFalse", false));
|
||||
});
|
||||
});
|
||||
setEnvironment();
|
||||
setEnvironment();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void setEnvironment()
|
||||
@@ -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));
|
||||
}
|
||||
@@ -348,7 +349,7 @@ namespace ClientApp.Utils
|
||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
|
||||
for (int i = 0; i < 256 * 256; i++)
|
||||
{
|
||||
height[i] = improvedPerlin.GetValue(x /10, x / 10, x * 100) / 3.5f + 1;
|
||||
height[i] = improvedPerlin.GetValue(x / 10, x / 10, x * 100) / 3.5f + 1;
|
||||
|
||||
//if (height[i] > 1.1f)
|
||||
//{
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace ClientApp.ViewModels
|
||||
public string Username { get; set; }
|
||||
public ICommand LoginCommand { get; set; }
|
||||
|
||||
public bool LoginStatus { get; set; }
|
||||
public bool LoginStatus { get; set; } = false;
|
||||
|
||||
public bool InvertedLoginStatus { get; set; }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:ClientApp.Views"
|
||||
xmlns:viewModels="clr-namespace:ClientApp.ViewModels"
|
||||
xmlns:Util="clr-namespace:Util.MagicCode"
|
||||
mc:Ignorable="d"
|
||||
ShowsNavigationUI="False"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
@@ -14,13 +15,11 @@
|
||||
</DockPanel.Background>
|
||||
<StackPanel VerticalAlignment="Center" Width="auto">
|
||||
<Label Content="Username" HorizontalContentAlignment="Center" />
|
||||
<TextBox x:Name="Username" Text="{Binding Username}" TextWrapping="Wrap" Width="120"/>
|
||||
<TextBox x:Name="Username" Text="{Binding Username}" TextWrapping="Wrap" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True" />
|
||||
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
||||
<PasswordBox x:Name="Password" Width="120"/>
|
||||
<PasswordBox x:Name="Password" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True"/>
|
||||
<Button x:Name="Login" Content="Login" Command="{Binding LoginCommand}" CommandParameter="{Binding ElementName=Password}" Margin="0,20,0,0" Width="120"/>
|
||||
<Popup IsOpen="{Binding InvertedLoginStatus}" PopupAnimation = "Slide" HorizontalAlignment="Center">
|
||||
<Label Content="Login failed" Foreground="Red" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Background="Transparent"/>
|
||||
</Popup>
|
||||
<Label Content="Login failed" Foreground="Red" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Background="Transparent" IsEnabled="{Binding InvertedLoginStatus}"/>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Page>
|
||||
|
||||
@@ -9,22 +9,22 @@
|
||||
<ResourceDictionary>
|
||||
<DataTemplate DataType="{x:Type viewModels:MainViewModel}">
|
||||
<views:MainView />
|
||||
<!-- This is a UserControl -->
|
||||
<!-- This is a Page -->
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type viewModels:LoginViewModel}">
|
||||
<views:LoginView />
|
||||
<!-- This is a UserControl -->
|
||||
<!-- This is a Page -->
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type viewModels:ClientInfoViewModel}">
|
||||
<views:ClientInfoView/>
|
||||
</DataTemplate>
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Styles/Fonts.xaml"/>
|
||||
<ResourceDictionary Source="Styles/Colors.xaml"/>
|
||||
<ResourceDictionary Source="Styles/Buttons.xaml"/>
|
||||
<ResourceDictionary Source="Styles/Texts.xaml"/>
|
||||
<ResourceDictionary Source="Styles/Windows.xaml"/>
|
||||
<ResourceDictionary Source="WPFStuff/Styles/Fonts.xaml"/>
|
||||
<ResourceDictionary Source="WPFStuff/Styles/Colors.xaml"/>
|
||||
<ResourceDictionary Source="WPFStuff/Styles/Buttons.xaml"/>
|
||||
<ResourceDictionary Source="WPFStuff/Styles/Texts.xaml"/>
|
||||
<ResourceDictionary Source="WPFStuff/Styles/Windows.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
|
||||
|
||||
@@ -1,21 +1,38 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ApplicationIcon>doctor.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
|
||||
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="3.2.9" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="img\doctor.ico" />
|
||||
<None Remove="img\patient.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="img\doctor.ico">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="img\patient.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||
<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="Prism.Wpf" Version="8.0.0.1909" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="3.2.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||
|
||||
</Project>
|
||||
127
DoctorApp/Models/Chart.cs
Normal file
127
DoctorApp/Models/Chart.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
25
DoctorApp/Models/PatientInfo.cs
Normal file
25
DoctorApp/Models/PatientInfo.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Util;
|
||||
|
||||
namespace DoctorApp.Models
|
||||
{
|
||||
class PatientInfo : ObservableObject
|
||||
{
|
||||
public ObservableCollection<string> ChatLog { get; set; }
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Status { get; set; }
|
||||
|
||||
public double Speed { get; set; }
|
||||
|
||||
public int BPM { get; set; }
|
||||
|
||||
public float Resistance { get; set; }
|
||||
public int Acc_Power { get; set; }
|
||||
|
||||
public int Curr_Power { get; set; }
|
||||
|
||||
public int Distance { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using DoctorApp.ViewModels;
|
||||
using Microsoft.Win32;
|
||||
using ProftaakRH;
|
||||
using Util;
|
||||
|
||||
namespace DoctorApp.Utils
|
||||
{
|
||||
public delegate void EngineCallback();
|
||||
public class Client : IDataReceiver
|
||||
public class Client
|
||||
{
|
||||
private TcpClient client;
|
||||
private NetworkStream stream;
|
||||
@@ -18,8 +20,6 @@ namespace DoctorApp.Utils
|
||||
private bool connected;
|
||||
private byte[] totalBuffer = new byte[1024];
|
||||
private int totalBufferReceived = 0;
|
||||
private bool sessionRunning = false;
|
||||
private IHandler handler = null;
|
||||
private LoginViewModel LoginViewModel;
|
||||
private MainViewModel MainViewModel;
|
||||
private ClientInfoViewModel ClientInfoViewModel;
|
||||
@@ -83,6 +83,7 @@ namespace DoctorApp.Utils
|
||||
|
||||
string identifier;
|
||||
bool isJson = DataParser.getJsonIdentifier(messageBytes, out identifier);
|
||||
|
||||
if (isJson)
|
||||
{
|
||||
switch (identifier)
|
||||
@@ -91,7 +92,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;
|
||||
|
||||
@@ -102,58 +103,96 @@ namespace DoctorApp.Utils
|
||||
Debug.WriteLine($"login failed \"{responseStatus}\"");
|
||||
}
|
||||
break;
|
||||
/*case DataParser.START_SESSION:
|
||||
case DataParser.START_SESSION:
|
||||
Console.WriteLine("Session started!");
|
||||
this.sessionRunning = true;
|
||||
sendMessage(DataParser.getStartSessionJson());
|
||||
break;
|
||||
case DataParser.STOP_SESSION:
|
||||
Console.WriteLine("Stop session identifier");
|
||||
this.sessionRunning = false;
|
||||
sendMessage(DataParser.getStopSessionJson());
|
||||
break;*/
|
||||
break;
|
||||
case DataParser.SET_RESISTANCE:
|
||||
Console.WriteLine("Set resistance identifier");
|
||||
if (this.handler == null)
|
||||
{
|
||||
Console.WriteLine("handler is null");
|
||||
sendMessage(DataParser.getSetResistanceResponseJson(false));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handler.setResistance(DataParser.getResistanceFromJson(payloadbytes));
|
||||
sendMessage(DataParser.getSetResistanceResponseJson(true));
|
||||
}
|
||||
break;
|
||||
case DataParser.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)}");
|
||||
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);
|
||||
}
|
||||
else if (DataParser.IsHistoricBikeData(messageBytes))
|
||||
{
|
||||
|
||||
|
||||
// todo change to name of patient
|
||||
string name = MainViewModel.Tabs[0].PatientInfo.Username;
|
||||
string result = "PATIENT INFO FOR " + name + "\n\n";
|
||||
for (int i = 0; i < payloadbytes.Length; i += 8)
|
||||
{
|
||||
byte[] res = new byte[8];
|
||||
Array.Copy(payloadbytes, i, res, 0, 8);
|
||||
result += handleBikeHistory(res);
|
||||
}
|
||||
|
||||
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/" + name + ".txt";
|
||||
File.WriteAllText(path,result);
|
||||
}
|
||||
Array.Copy(totalBuffer, expectedMessageLength, totalBuffer, 0, (totalBufferReceived - expectedMessageLength)); //maybe unsafe idk
|
||||
totalBufferReceived -= expectedMessageLength;
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// starts sending a message to the server
|
||||
/// </summary>
|
||||
/// <param name="message">the message to send</param>
|
||||
public void sendMessage(byte[] message)
|
||||
private string handleBikeHistory(byte[] bytes)
|
||||
{
|
||||
string res = string.Empty;
|
||||
switch (bytes[0])
|
||||
{
|
||||
case 0x10:
|
||||
res += "Time elapsed: " + bytes[2] / 4 + "s\n";
|
||||
res += "Distance traveled: " + bytes[3] + "\n";
|
||||
int input = bytes[4] | (bytes[5] << 8);
|
||||
res += $"Speed {input * 0.01}m/s\n";
|
||||
res += $"Heart rate: { Convert.ToString(bytes[6], 10)}";
|
||||
break;
|
||||
case 0x19:
|
||||
res += $"RPM: {bytes[2]}\n";
|
||||
int accumPower = bytes[3] | (bytes[4] << 8);
|
||||
res += $"Accumulated power: {accumPower} watt\n";
|
||||
int instantPower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
||||
if (instantPower != 0xFFF)
|
||||
{
|
||||
res += $"Instant power: {instantPower} watt\n";
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
return res + "\n";
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// starts sending a message to the server
|
||||
/// </summary>
|
||||
/// <param name="message">the message to send</param>
|
||||
public void sendMessage(byte[] message)
|
||||
{
|
||||
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
@@ -167,63 +206,6 @@ namespace DoctorApp.Utils
|
||||
this.stream.EndWrite(ar);
|
||||
}
|
||||
|
||||
#region interface
|
||||
//maybe move this to other place
|
||||
/// <summary>
|
||||
/// bpm method for receiving the BPM value from the bluetooth bike or the simulation
|
||||
/// </summary>
|
||||
/// <param name="bytes">the message</param>
|
||||
public void BPM(byte[] bytes)
|
||||
{
|
||||
if (!sessionRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (bytes == null)
|
||||
{
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawDataMessage(bytes);
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// method for receiving the bike message from the bluetooth bike or the simulation
|
||||
/// </summary>
|
||||
/// <param name="bytes">the message</param>
|
||||
public void Bike(byte[] bytes)
|
||||
{
|
||||
|
||||
if (!sessionRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (bytes == null)
|
||||
{
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawDataMessage(bytes);
|
||||
|
||||
/* switch (bytes[0])
|
||||
{
|
||||
|
||||
case 0x10:
|
||||
|
||||
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
|
||||
break;
|
||||
case 0x19:
|
||||
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
||||
break;
|
||||
}*/
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// wether or not the client stream is connected
|
||||
/// </summary>
|
||||
@@ -240,21 +222,12 @@ namespace DoctorApp.Utils
|
||||
|
||||
string hashPassword = Util.Hasher.HashString(password);
|
||||
|
||||
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, hashPassword));
|
||||
byte[] message = DataParser.getJsonMessage(DataParser.LoginAsDoctor(username, hashPassword));
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sets the handler for the client, so either the bike simulator or the bluetooth bike handler
|
||||
/// </summary>
|
||||
/// <param name="handler"></param>
|
||||
public void SetHandler(IHandler handler)
|
||||
{
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
internal void SetLoginViewModel(LoginViewModel loginViewModel)
|
||||
{
|
||||
this.LoginViewModel = loginViewModel;
|
||||
@@ -273,9 +246,9 @@ namespace DoctorApp.Utils
|
||||
public void Dispose()
|
||||
{
|
||||
Debug.WriteLine("client dispose called");
|
||||
sendMessage(DataParser.getDisconnectJson(LoginViewModel.Username));
|
||||
this.stream.Dispose();
|
||||
this.client.Dispose();
|
||||
this.handler?.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using DoctorApp.Utils;
|
||||
using DoctorApp.Models;
|
||||
using DoctorApp.Utils;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
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;
|
||||
@@ -11,24 +13,21 @@ using Util;
|
||||
|
||||
namespace DoctorApp.ViewModels
|
||||
{
|
||||
|
||||
|
||||
class ClientInfoViewModel : ObservableObject
|
||||
{
|
||||
public ObservableCollection<string> ChatLog { get; set; }
|
||||
public string Username { get; set; }
|
||||
public PatientInfo PatientInfo { get; set; }
|
||||
|
||||
public string Status { get; set; }
|
||||
|
||||
public int Speed { get; set; }
|
||||
|
||||
public int BPM { get; set; }
|
||||
|
||||
public int Resistance { get; set; }
|
||||
public int Acc_Power { get; set; }
|
||||
|
||||
public int Curr_Power { get; set; }
|
||||
|
||||
public int Distance { get; set; }
|
||||
private string _mySelectedItem;
|
||||
public string MySelectedItem
|
||||
{
|
||||
get { return _mySelectedItem; }
|
||||
set
|
||||
{
|
||||
Chart.Clear();
|
||||
_mySelectedItem = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand StartSession { get; set; }
|
||||
|
||||
@@ -42,38 +41,107 @@ namespace DoctorApp.ViewModels
|
||||
|
||||
public ICommand SetResistance { get; set; }
|
||||
|
||||
public ICommand SaveHistoricData { get; set; }
|
||||
|
||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||
private Client client;
|
||||
|
||||
public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel)
|
||||
public Chart Chart { get; set; }
|
||||
|
||||
public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel, string username)
|
||||
{
|
||||
MainWindowViewModel = mainWindowViewModel;
|
||||
ChatLog = new ObservableCollection<string>();
|
||||
this.PatientInfo = new PatientInfo() { Username = username, Status = "Waiting to start" };
|
||||
this.Chart = new Chart(this.PatientInfo);
|
||||
PatientInfo.ChatLog = new ObservableCollection<string>();
|
||||
client = mainWindowViewModel.client;
|
||||
|
||||
StartSession = new RelayCommand(()=>{
|
||||
client.sendMessage(DataParser.getStartSessionJson(Username));
|
||||
Status = "Session started";
|
||||
StartSession = new RelayCommand(() =>
|
||||
{
|
||||
client.sendMessage(DataParser.getStartSessionJson(PatientInfo.Username));
|
||||
PatientInfo.Status = "Session started";
|
||||
});
|
||||
|
||||
StopSession = new RelayCommand(() => {
|
||||
client.sendMessage(DataParser.getStopSessionJson(Username));
|
||||
Status = "Session stopped, waiting to start again.";
|
||||
StopSession = new RelayCommand(() =>
|
||||
{
|
||||
client.sendMessage(DataParser.getStopSessionJson(PatientInfo.Username));
|
||||
PatientInfo.Status = "Session stopped, waiting to start again.";
|
||||
});
|
||||
|
||||
Chat = new RelayCommand<object>((parameter) =>
|
||||
{
|
||||
client.sendMessage(DataParser.getChatJson(Username, ((TextBox)parameter).Text));
|
||||
ChatLog.Add(DateTime.Now+": "+ ((TextBox)parameter).Text);
|
||||
client.sendMessage(DataParser.getChatJson(PatientInfo.Username, ((TextBox)parameter).Text));
|
||||
PatientInfo.ChatLog.Add(DateTime.Now + ": " + ((TextBox)parameter).Text);
|
||||
});
|
||||
|
||||
//TODO RelayCommand ChatToAll
|
||||
|
||||
SetResistance = new RelayCommand<object>((parameter) =>
|
||||
{
|
||||
client.sendMessage(DataParser.getSetResistanceJson(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);
|
||||
});
|
||||
|
||||
// request the historic data from the server
|
||||
this.SaveHistoricData = new RelayCommand<object>((parameter) =>
|
||||
{
|
||||
this.client.sendMessage(DataParser.GetGetFileMessage(PatientInfo.Username));
|
||||
// data is stored on the server
|
||||
// send request to server that we want to get the current historic data from the patient
|
||||
// server sends this back
|
||||
// we parse it
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void BPMData(byte[] bytes)
|
||||
{
|
||||
//TODO
|
||||
//Parsen van de data you fuck
|
||||
PatientInfo.BPM = bytes[1];
|
||||
if (bytes[0] == 0x00)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
if (MySelectedItem == "Speed")
|
||||
{
|
||||
Chart.NewValue(PatientInfo.Speed);
|
||||
}
|
||||
break;
|
||||
case 0x19:
|
||||
PatientInfo.Acc_Power = bytes[3] | (bytes[4] << 8);
|
||||
PatientInfo.Curr_Power = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
||||
break;
|
||||
default:
|
||||
Debug.WriteLine("rip");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,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 Util;
|
||||
@@ -21,18 +22,15 @@ namespace DoctorApp.ViewModels
|
||||
{
|
||||
this.MainWindowViewModel = mainWindowViewModel;
|
||||
client = this.MainWindowViewModel.client;
|
||||
Tabs= new ObservableCollection<ClientInfoViewModel>();
|
||||
Tabs = new ObservableCollection<ClientInfoViewModel>();
|
||||
}
|
||||
|
||||
public void NewConnectedUser(string username)
|
||||
{
|
||||
Debug.WriteLine("new tab with name " + username);
|
||||
App.Current.Dispatcher.Invoke((Action)delegate
|
||||
{
|
||||
Tabs.Add(new ClientInfoViewModel(MainWindowViewModel)
|
||||
{
|
||||
Username = username,
|
||||
Status = "Waiting to start"
|
||||
});
|
||||
Tabs.Add(new ClientInfoViewModel(MainWindowViewModel, username));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,7 +40,7 @@ namespace DoctorApp.ViewModels
|
||||
{
|
||||
foreach (ClientInfoViewModel item in Tabs)
|
||||
{
|
||||
if (item.Username == username)
|
||||
if (item.PatientInfo.Username == username)
|
||||
{
|
||||
Tabs.Remove(item);
|
||||
break;
|
||||
@@ -50,7 +48,35 @@ 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(DataParser.getDataWithoutName(bytes, 0, 8));
|
||||
return;
|
||||
}
|
||||
}
|
||||
Debug.WriteLine("[MainViewModel] did not find client (bike) username is " + username);
|
||||
}
|
||||
|
||||
public void TransferDataToClientBPM(byte[] bytes)
|
||||
{
|
||||
string username = DataParser.getNameFromBytesBPM(bytes);
|
||||
foreach (ClientInfoViewModel item in Tabs)
|
||||
{
|
||||
if (item.PatientInfo.Username == username)
|
||||
{
|
||||
item.BPMData(DataParser.getDataWithoutName(bytes, 0, 2));
|
||||
return;
|
||||
}
|
||||
}
|
||||
Debug.WriteLine("[MainViewModel] did not find client (bpm) username is " + username);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<UserControl x:Class="DoctorApp.Views.ClientInfoView"
|
||||
<UserControl x:Class="DoctorApp.Views.ClientInfoView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
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*"/>
|
||||
@@ -18,16 +18,20 @@
|
||||
<RowDefinition Height="180*"/>
|
||||
<RowDefinition Height="180*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal" Grid.RowSpan="2" Margin="0,0,0,22">
|
||||
<StackPanel.Resources>
|
||||
<Style TargetType="{x:Type Label}">
|
||||
<Setter Property="Margin" Value="0,0,20,0"/>
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<Label Content="{Binding Path=Username}"/>
|
||||
<Label Content="{Binding Path=Status}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Margin="0,10,0,0" Grid.RowSpan="2" Grid.Row="1">
|
||||
|
||||
<Grid Grid.RowSpan="2" Margin="0,0,0,22">
|
||||
<StackPanel Orientation="Horizontal" >
|
||||
<StackPanel.Resources>
|
||||
<Style TargetType="{x:Type Label}">
|
||||
<Setter Property="Margin" Value="0,0,20,0"/>
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<Label Content="{Binding Path=PatientInfo.Username}"/>
|
||||
<Label Content="{Binding Path=PatientInfo.Status}"/>
|
||||
</StackPanel>
|
||||
<Button Content="Save Historic Data" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="5" Command="{Binding SaveHistoricData}"/>
|
||||
</Grid>
|
||||
<StackPanel Margin="0,10,0,0" Grid.Row="2">
|
||||
<StackPanel.Resources>
|
||||
<Style TargetType="{x:Type DockPanel}">
|
||||
<Setter Property="Margin" Value="0,20,0,0"/>
|
||||
@@ -39,9 +43,9 @@
|
||||
<Label Content="Current BPM" Width="110" DockPanel.Dock="Top"/>
|
||||
</DockPanel>
|
||||
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
|
||||
<TextBox Name="textBox_Resistance" Text="{Binding Path=Resistance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentSpeed" Text="{Binding Path=Speed}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentBPM" Text="{Binding Path=BPM}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_Resistance" Text="{Binding Path=PatientInfo.Resistance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentSpeed" Text="{Binding Path=PatientInfo.Speed, StringFormat=N2}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentBPM" Text="{Binding Path=PatientInfo.BPM}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||
</DockPanel>
|
||||
<DockPanel Height="26" LastChildFill="False">
|
||||
<Label Content="Distance Covered" Width="110" DockPanel.Dock="Right"/>
|
||||
@@ -49,19 +53,41 @@
|
||||
<Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/>
|
||||
</DockPanel>
|
||||
<DockPanel Height="26" LastChildFill="False">
|
||||
<TextBox Name="textBox_DistanceCovered" Text="{Binding Path=Distance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentPower" Text="{Binding Path=Curr_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_AccPower" Text="{Binding Path=Acc_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_DistanceCovered" Text="{Binding Path=PatientInfo.Distance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_CurrentPower" Text="{Binding Path=PatientInfo.Curr_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
|
||||
<TextBox Name="textBox_AccPower" Text="{Binding Path=PatientInfo.Acc_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
<ListBox Name="ChatBox" ItemsSource="{Binding 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"/>
|
||||
<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="" 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>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:DoctorApp.Views"
|
||||
xmlns:viewModels="clr-namespace:DoctorApp.ViewModels"
|
||||
xmlns:Util="clr-namespace:Util.MagicCode"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
>
|
||||
@@ -12,9 +13,9 @@
|
||||
<DockPanel>
|
||||
<StackPanel VerticalAlignment="Center" Width="auto">
|
||||
<Label Content="Username" HorizontalContentAlignment="Center" />
|
||||
<TextBox x:Name="Username" Text="{Binding Username}" TextWrapping="Wrap" Width="120"/>
|
||||
<TextBox x:Name="Username" Text="{Binding Username}" TextWrapping="Wrap" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True"/>
|
||||
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
||||
<PasswordBox x:Name="Password" Width="120"/>
|
||||
<PasswordBox x:Name="Password" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True"/>
|
||||
<Button x:Name="Login" Content="Login" Command="{Binding LoginCommand}" CommandParameter="{Binding ElementName=Password}" Margin="0,20,0,0" Width="120"/>
|
||||
<Popup IsOpen="{Binding InvertedLoginStatus}" PopupAnimation = "Fade" HorizontalAlignment="Left">
|
||||
<Label Content="Login failed" Foreground="Red" Background="#FFFF" />
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
<TabControl TabStripPlacement="Left" ItemsSource="{Binding Tabs}" SelectedItem="{Binding Selected}">
|
||||
<TabControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Username}"/>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="/img/patient.png" Width="25" Margin="0 0 5 0"/>
|
||||
<TextBlock Text="{Binding PatientInfo.Username}" FontSize="20" MaxWidth="100" Width="100" TextTrimming="CharacterEllipsis"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</TabControl.ItemTemplate>
|
||||
<TabControl.ContentTemplate>
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
Background="Transparent"
|
||||
WindowStyle="None"
|
||||
AllowsTransparency="True"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
MinHeight="{Binding MinimumHeight}"
|
||||
MinWidth="{Binding MinimumWidth}"
|
||||
Title="MainWindow" Height="800" Width="1500">
|
||||
<Window.Resources>
|
||||
<Style TargetType="{x:Type local:MainWindow}">
|
||||
<Setter Property="Template">
|
||||
@@ -52,7 +54,7 @@
|
||||
|
||||
<!-- icon -->
|
||||
<Button Grid.Column="0" Style="{StaticResource SystemIconButton}" Command="{Binding MenuCommand}">
|
||||
<Image Source="/Images/Logo/icon1.ico"/>
|
||||
<Image Source="/img/doctor.ico"/>
|
||||
<!--<TextBlock Text="icon"/>-->
|
||||
</Button>
|
||||
|
||||
|
||||
BIN
DoctorApp/doctor.ico
Normal file
BIN
DoctorApp/doctor.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 252 KiB |
BIN
DoctorApp/img/doctor.ico
Normal file
BIN
DoctorApp/img/doctor.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 252 KiB |
BIN
DoctorApp/img/patient.png
Normal file
BIN
DoctorApp/img/patient.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -1,10 +1,14 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Printing.IndexedProperties;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
namespace Util
|
||||
{
|
||||
@@ -19,6 +23,7 @@ namespace Util
|
||||
public const string DISCONNECT = "DISCONNECT";
|
||||
public const string LOGIN_DOCTOR = "LOGIN DOCTOR";
|
||||
public const string MESSAGE = "MESSAGE";
|
||||
public const string GET_FILE = "GET FILE";
|
||||
/// <summary>
|
||||
/// makes the json object with LOGIN identifier and username and password
|
||||
/// </summary>
|
||||
@@ -40,6 +45,16 @@ namespace Util
|
||||
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
|
||||
}
|
||||
|
||||
internal static string getNameFromBytesBike(byte[] bytes)
|
||||
{
|
||||
return getName(bytes, 8, bytes.Length - 8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// converts the given string parameter into a message using our protocol.
|
||||
/// </summary>
|
||||
/// <param name="messageToSend">the message string to send</param>
|
||||
/// <returns>a byte array using our protocol to send the message</returns>
|
||||
public static byte[] GetMessageToSend(string messageToSend)
|
||||
{
|
||||
dynamic json = new
|
||||
@@ -53,6 +68,24 @@ namespace Util
|
||||
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
|
||||
}
|
||||
|
||||
internal static string getNameFromBytesBPM(byte[] bytes)
|
||||
{
|
||||
return getName(bytes, 2, bytes.Length - 2);
|
||||
}
|
||||
|
||||
private static string getName(byte[] bytes, int offset, int lenght)
|
||||
{
|
||||
byte[] nameArray = new byte[lenght];
|
||||
Array.Copy(bytes, offset, nameArray, 0, lenght);
|
||||
return Encoding.UTF8.GetString(nameArray);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// creates a message for when the doctor wants to log in.
|
||||
/// </summary>
|
||||
/// <param name="mUsername">the username of the doctor</param>
|
||||
/// <param name="mPassword">the (hashed) password of the doctor</param>
|
||||
/// <returns>a byte array using our protocol that contains the username and password of the doctor</returns>
|
||||
public static byte[] LoginAsDoctor(string mUsername, string mPassword)
|
||||
{
|
||||
dynamic json = new
|
||||
@@ -68,6 +101,13 @@ namespace Util
|
||||
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the username and password from a given message array.
|
||||
/// </summary>
|
||||
/// <param name="jsonbytes">the array of bytes containing the message</param>
|
||||
/// <param name="username">the username variable that the username will be put into</param>
|
||||
/// <param name="password">the password variable that the password will be put into</param>
|
||||
/// <returns><c>true</c> if the username and password were received correctly, <c>false</c> otherwise</returns>
|
||||
public static bool GetUsernamePassword(byte[] jsonbytes, out string username, out string password)
|
||||
{
|
||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(jsonbytes));
|
||||
@@ -85,6 +125,12 @@ namespace Util
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets message using our protocol of the given identifier and data.
|
||||
/// </summary>
|
||||
/// <param name="mIdentifier">the identifier string of the message</param>
|
||||
/// <param name="data">the payload data of the message</param>
|
||||
/// <returns>a byte array containing the json message with the given parameters, using our protocol.</returns>
|
||||
private static byte[] getJsonMessage(string mIdentifier, dynamic data)
|
||||
{
|
||||
dynamic json = new
|
||||
@@ -95,6 +141,11 @@ namespace Util
|
||||
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets a message using our protocol with only the given identifier string.
|
||||
/// </summary>
|
||||
/// <param name="mIdentifier">the identifier to put into the message</param>
|
||||
/// <returns>a byte array containing the json with only the identifier, using our protocol.</returns>
|
||||
private static byte[] getJsonMessage(string mIdentifier)
|
||||
{
|
||||
dynamic json = new
|
||||
@@ -104,11 +155,21 @@ namespace Util
|
||||
return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the login response of the given status
|
||||
/// </summary>
|
||||
/// <param name="mStatus">the status of the response</param>
|
||||
/// <returns>a byte array containing the response for the given status, using our protocol.</returns>
|
||||
public static byte[] getLoginResponse(string mStatus)
|
||||
{
|
||||
return getJsonMessage(LOGIN_RESPONSE, new { status = mStatus });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the status of the given json message
|
||||
/// </summary>
|
||||
/// <param name="json">the byte array containing a json message using our protocol</param>
|
||||
/// <returns>the response of the message</returns>
|
||||
public static string getResponseStatus(byte[] json)
|
||||
{
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.status;
|
||||
@@ -146,7 +207,7 @@ namespace Util
|
||||
/// </summary>
|
||||
/// <param name="bytes">message</param>
|
||||
/// <returns>if message contains raw data</returns>
|
||||
public static bool isRawData(byte[] bytes)
|
||||
public static bool isRawDataBikeServer(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length <= 5)
|
||||
{
|
||||
@@ -155,6 +216,40 @@ namespace Util
|
||||
return bytes[4] == 0x02;
|
||||
}
|
||||
|
||||
public static bool isRawDataBPMServer(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length <= 5)
|
||||
{
|
||||
throw new ArgumentException("bytes to short");
|
||||
}
|
||||
return bytes[4] == 0x03;
|
||||
}
|
||||
|
||||
public static bool isRawDataBikeDoctor(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length <= 5)
|
||||
{
|
||||
throw new ArgumentException("bytes to short");
|
||||
}
|
||||
return bytes[4] == 0x04;
|
||||
}
|
||||
|
||||
public static bool isRawDataBPMDoctor(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length <= 5)
|
||||
{
|
||||
throw new ArgumentException("bytes to short");
|
||||
}
|
||||
return bytes[4] == 0x05;
|
||||
}
|
||||
|
||||
public static bool IsHistoricBikeData(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length <= 5) throw new ArgumentException("bytes too short");
|
||||
return bytes[4] == 0x06;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// constructs a message with the payload, messageId and clientId
|
||||
/// </summary>
|
||||
@@ -179,11 +274,37 @@ namespace Util
|
||||
/// <param name="payload"></param>
|
||||
/// <param name="clientId"></param>
|
||||
/// <returns>the message ready for sending</returns>
|
||||
public static byte[] GetRawDataMessage(byte[] payload)
|
||||
public static byte[] GetRawBikeDataMessageServer(byte[] payload)
|
||||
{
|
||||
return getMessage(payload, 0x02);
|
||||
}
|
||||
|
||||
public static byte[] GetRawBPMDataMessageServer(byte[] payload)
|
||||
{
|
||||
return getMessage(payload, 0x03);
|
||||
}
|
||||
|
||||
public static byte[] GetRawBikeDataDoctor(byte[] payload, string username)
|
||||
{
|
||||
|
||||
return GetRawDataDoctor(payload, username, 0x04);
|
||||
|
||||
}
|
||||
|
||||
public static byte[] GetRawBPMDataDoctor(byte[] payload, string username)
|
||||
{
|
||||
return GetRawDataDoctor(payload, username, 0x05);
|
||||
}
|
||||
|
||||
private static byte[] GetRawDataDoctor(byte[] payload, string username, byte messageID)
|
||||
{
|
||||
byte[] nameArray = Encoding.ASCII.GetBytes(username);
|
||||
byte[] total = new byte[nameArray.Length + payload.Length];
|
||||
Array.Copy(payload, 0, total, 0, payload.Length);
|
||||
Array.Copy(nameArray, 0, total, payload.Length, nameArray.Length);
|
||||
return getMessage(total, messageID);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// constructs a message with the payload and clientId and assumes the payload is json
|
||||
/// </summary>
|
||||
@@ -195,6 +316,11 @@ namespace Util
|
||||
return getMessage(payload, 0x01);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the message to start a session with the given user username
|
||||
/// </summary>
|
||||
/// <param name="user">the username of the user we want to start the session for</param>
|
||||
/// <returns>a byte array containing the message to start the session of the given user, using our protocol.</returns>
|
||||
public static byte[] getStartSessionJson(string user)
|
||||
{
|
||||
dynamic data = new
|
||||
@@ -204,6 +330,11 @@ namespace Util
|
||||
return getJsonMessage(START_SESSION, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the message to stop a session with the given user username
|
||||
/// </summary>
|
||||
/// <param name="user">the username of the user we want to stop the session for</param>
|
||||
/// <returns>a byte array containing the message to stop the session of the given user, using our protocol.</returns>
|
||||
public static byte[] getStopSessionJson(string user)
|
||||
{
|
||||
dynamic data = new
|
||||
@@ -213,7 +344,13 @@ namespace Util
|
||||
return getJsonMessage(STOP_SESSION, data);
|
||||
}
|
||||
|
||||
public static byte[] getSetResistanceJson(string user,float mResistance)
|
||||
/// <summary>
|
||||
/// gets the message to set the resistance of the given user with the given resistance.
|
||||
/// </summary>
|
||||
/// <param name="user">the username to set the resistance of.</param>
|
||||
/// <param name="mResistance">the resistance value to set</param>
|
||||
/// <returns>a byte array containing a json messsage to set the user's resistance, using our protocol.</returns>
|
||||
public static byte[] getSetResistanceJson(string user, float mResistance)
|
||||
{
|
||||
dynamic data = new
|
||||
{
|
||||
@@ -223,6 +360,11 @@ namespace Util
|
||||
return getJsonMessage(SET_RESISTANCE, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the response message with the given value.
|
||||
/// </summary>
|
||||
/// <param name="mWorked">the boolean value to indicate if the operation we want to send a response for was successful or not.</param>
|
||||
/// <returns>a byte array containing a json message with the response and the given value.</returns>
|
||||
public static byte[] getSetResistanceResponseJson(bool mWorked)
|
||||
{
|
||||
dynamic data = new
|
||||
@@ -232,8 +374,15 @@ namespace Util
|
||||
return getJsonMessage(SET_RESISTANCE, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the message to indicate a new connection for the given user.
|
||||
/// </summary>
|
||||
/// <param name="user">the username of the user to start a connection for.</param>
|
||||
/// <returns>a byte array containing a json message to indicate a new connection for the given user, using our protocol.</returns>
|
||||
public static byte[] getNewConnectionJson(string user)
|
||||
{
|
||||
if (user == null)
|
||||
throw new ArgumentNullException("user null");
|
||||
dynamic data = new
|
||||
{
|
||||
username = user
|
||||
@@ -241,6 +390,11 @@ namespace Util
|
||||
return getJsonMessage(NEW_CONNECTION, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the message for when a user has been disconnected.
|
||||
/// </summary>
|
||||
/// <param name="user">the username of the user that has been disconnected</param>
|
||||
/// <returns>a byte array containing a json message to indicate that the given user has disconnected, using our protocol.</returns>
|
||||
public static byte[] getDisconnectJson(string user)
|
||||
{
|
||||
dynamic data = new
|
||||
@@ -250,31 +404,62 @@ namespace Util
|
||||
return getJsonMessage(DISCONNECT, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the resistance from the given json message
|
||||
/// </summary>
|
||||
/// <param name="json">the json messag</param>
|
||||
/// <returns>the resistance that was in the message</returns>
|
||||
public static float getResistanceFromJson(byte[] json)
|
||||
{
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.resistance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the resistance response from the given json message
|
||||
/// </summary>
|
||||
/// <param name="json">the byte array containin the json message</param>
|
||||
/// <returns>the response of the message, so wether it was successful or not.</returns>
|
||||
public static bool getResistanceFromResponseJson(byte[] json)
|
||||
{
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the username from the given response message.
|
||||
/// </summary>
|
||||
/// <param name="json">the byte array containin the json message</param>
|
||||
/// <returns>the username in the message.</returns>
|
||||
public static string getUsernameFromResponseJson(byte[] json)
|
||||
{
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the chat message from the given json message.
|
||||
/// </summary>
|
||||
/// <param name="json">the byte array containin the json message</param>
|
||||
/// <returns>the chat message in the json message</returns>
|
||||
public static string getChatMessageFromJson(byte[] json)
|
||||
{
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.chat;
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.chat;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the username from the given json message.
|
||||
/// </summary>
|
||||
/// <param name="json">the byte array containin the json message</param>
|
||||
/// <returns>the username that is in the message</returns>
|
||||
public static string getUsernameFromJson(byte[] json)
|
||||
{
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the byte array with the json message to send a message with the given parameters.
|
||||
/// </summary>
|
||||
/// <param name="user">the username of the user that wants to send the message</param>
|
||||
/// <param name="message">the message the user wants to send</param>
|
||||
/// <returns>a byte array containing a json message with the username and corresponding message, using our protocol.</returns>
|
||||
public static byte[] getChatJson(string user, string message)
|
||||
{
|
||||
dynamic data = new
|
||||
@@ -285,6 +470,39 @@ namespace Util
|
||||
return getJsonMessage(MESSAGE, data);
|
||||
}
|
||||
|
||||
public static byte[] getDataWithoutName(byte[] bytes, int offset, int length)
|
||||
{
|
||||
byte[] data = new byte[length];
|
||||
Array.Copy(bytes, offset, data, 0, length);
|
||||
return data;
|
||||
}
|
||||
|
||||
public static byte[] GetGetFileMessage(string mUsername)
|
||||
{
|
||||
if (mUsername == null)
|
||||
{
|
||||
throw new ArgumentNullException("username null");
|
||||
}
|
||||
dynamic data = new
|
||||
{
|
||||
username = mUsername,
|
||||
};
|
||||
return getJsonMessage(GET_FILE, data);
|
||||
}
|
||||
|
||||
public static string GetUsernameFromGetFileBytes(byte[] json)
|
||||
{
|
||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
|
||||
}
|
||||
|
||||
public static string GetDateFromGetFileBytes(byte[] json)
|
||||
{
|
||||
return ((string)((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.dateTime);
|
||||
}
|
||||
|
||||
public static byte[] GetFileMessage(byte[] file)
|
||||
{
|
||||
return getMessage(file, 0x06);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,27 +11,28 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DataParser.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Hasher.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MagicCode\WindowResizer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ObservableObject.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)WPFStuff\MagicCode\FocusAdvancement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)WPFStuff\MagicCode\WindowResizer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)WPFStuff\ObservableObject.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Styles\Buttons.xaml">
|
||||
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Buttons.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Styles\Colors.xaml">
|
||||
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Colors.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Styles\Fonts.xaml">
|
||||
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Fonts.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Styles\Texts.xaml">
|
||||
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Texts.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Styles\Windows.xaml">
|
||||
<Page Include="$(MSBuildThisFileDirectory)WPFStuff\Styles\Windows.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
|
||||
40
Hashing/WPFStuff/MagicCode/FocusAdvancement.cs
Normal file
40
Hashing/WPFStuff/MagicCode/FocusAdvancement.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Util.MagicCode
|
||||
{
|
||||
public static class FocusAdvancement
|
||||
{
|
||||
public static bool GetAdvancesByEnterKey(DependencyObject obj)
|
||||
{
|
||||
return (bool)obj.GetValue(AdvancesByEnterKeyProperty);
|
||||
}
|
||||
|
||||
public static void SetAdvancesByEnterKey(DependencyObject obj, bool value)
|
||||
{
|
||||
obj.SetValue(AdvancesByEnterKeyProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty AdvancesByEnterKeyProperty =
|
||||
DependencyProperty.RegisterAttached("AdvancesByEnterKey", typeof(bool), typeof(FocusAdvancement),
|
||||
new UIPropertyMetadata(OnAdvancesByEnterKeyPropertyChanged));
|
||||
|
||||
static void OnAdvancesByEnterKeyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var element = d as UIElement;
|
||||
if (element == null) return;
|
||||
|
||||
if ((bool)e.NewValue) element.KeyDown += Keydown;
|
||||
else element.KeyDown -= Keydown;
|
||||
}
|
||||
|
||||
static void Keydown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (!e.Key.Equals(Key.Enter)) return;
|
||||
|
||||
var element = sender as UIElement;
|
||||
if (element != null) element.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
|
||||
}
|
||||
}
|
||||
}
|
||||
65
Hashing/WPFStuff/Styles/Buttons.xaml
Normal file
65
Hashing/WPFStuff/Styles/Buttons.xaml
Normal file
@@ -0,0 +1,65 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:ClientApp">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Colors.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style TargetType="{x:Type Button}" x:Key="Hoverless">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Button}">
|
||||
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
|
||||
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="{x:Type Button}" x:Key="SystemIconButton" BasedOn="{StaticResource Hoverless}" >
|
||||
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True"/>
|
||||
<Setter Property="Padding" Value="4"/>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="{x:Type Button}" x:Key="WindowControlButton">
|
||||
<Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True"/>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="VerticalAlignment" Value="Stretch"/>
|
||||
<Setter Property="Foreground" Value="{StaticResource ForegroundMainBrush}"/>
|
||||
<Setter Property="Padding" Value="6"/>
|
||||
|
||||
<Setter Property="LayoutTransform">
|
||||
<Setter.Value>
|
||||
<ScaleTransform ScaleX="2"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Button}">
|
||||
<Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
|
||||
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{StaticResource BackgroundSemiLightBrush}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="{x:Type Button}" x:Key="WindowCloseButton" BasedOn="{StaticResource WindowControlButton}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="Red"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
25
Hashing/WPFStuff/Styles/Colors.xaml
Normal file
25
Hashing/WPFStuff/Styles/Colors.xaml
Normal file
@@ -0,0 +1,25 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:ClientApp">
|
||||
|
||||
<Color x:Key="BackgroundLight">#efefef</Color>
|
||||
<SolidColorBrush x:Key="BackgroundLightBrush" Color="{StaticResource BackgroundLight}"/>
|
||||
|
||||
|
||||
<Color x:Key="BackgroundVeryLight">#fafafa</Color>
|
||||
<SolidColorBrush x:Key="BackgroundVeryLightBrush" Color="{StaticResource BackgroundVeryLight}"/>
|
||||
|
||||
<Color x:Key="BackgroundSemiLight">#d7d7d7</Color>
|
||||
<SolidColorBrush x:Key="BackgroundSemiLightBrush" Color="{StaticResource BackgroundSemiLight}"/>
|
||||
|
||||
<Color x:Key="ForegroundMain">#686868</Color>
|
||||
<SolidColorBrush x:Key="ForegroundMainBrush" Color="{StaticResource ForegroundMain}"/>
|
||||
|
||||
<Color x:Key="ForegroundVeryDark">#000</Color>
|
||||
<SolidColorBrush x:Key="ForegroundVeryDarkBrush" Color="{StaticResource ForegroundVeryDark}"/>
|
||||
|
||||
<Color x:Key="ForegroundWhite">#fff</Color>
|
||||
<SolidColorBrush x:Key="ForegroundWhiteBrush" Color="{StaticResource ForegroundWhite}"/>
|
||||
|
||||
|
||||
</ResourceDictionary>
|
||||
5
Hashing/WPFStuff/Styles/Fonts.xaml
Normal file
5
Hashing/WPFStuff/Styles/Fonts.xaml
Normal file
@@ -0,0 +1,5 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:ClientApp">
|
||||
|
||||
</ResourceDictionary>
|
||||
11
Hashing/WPFStuff/Styles/Texts.xaml
Normal file
11
Hashing/WPFStuff/Styles/Texts.xaml
Normal file
@@ -0,0 +1,11 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:ClientApp">
|
||||
|
||||
<Style TargetType="{x:Type TextBlock}" x:Key="HeaderText">
|
||||
<Setter Property="Foreground" Value="{StaticResource ForegroundMainBrush}"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
<Setter Property="Margin" Value="0 4"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
5
Hashing/WPFStuff/Styles/Windows.xaml
Normal file
5
Hashing/WPFStuff/Styles/Windows.xaml
Normal file
@@ -0,0 +1,5 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:ClientApp">
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -93,19 +93,26 @@ namespace Hardware.Simulators
|
||||
//Generate an ANT message for page 0x10
|
||||
private byte[] GenerateBike0x10()
|
||||
{
|
||||
//SOMEONE FIX THIS!!!!!!!!!
|
||||
|
||||
try
|
||||
{
|
||||
byte[] bikeByte = { 0x10, Convert.ToByte(equipmentType), Convert.ToByte(elapsedTime * 4 % 64), Convert.ToByte(distanceTraveled), speedArray[0], speedArray[1], Convert.ToByte(BPM), 0xFF };
|
||||
byte[] bikeByte = { 0x10, check(equipmentType), check(elapsedTime * 4 % 64), check((int)Math.Round(distanceTraveled)), speedArray[0], speedArray[1], check(BPM), 0xFF };
|
||||
return bikeByte;
|
||||
}
|
||||
catch (OverflowException e)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
return GenerateBike0x10();
|
||||
byte[] res = { 0x10,0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0xFF};
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
private byte check(int value)
|
||||
{
|
||||
|
||||
return value > 255 ? Convert.ToByte(255) : value < 0 ? Convert.ToByte(0) : Convert.ToByte(value);
|
||||
}
|
||||
|
||||
//Generate an ANT message for BPM
|
||||
private byte[] GenerateHeart()
|
||||
{
|
||||
|
||||
@@ -15,8 +15,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "..\Server\Server.
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DoctorApp", "..\DoctorApp\DoctorApp.csproj", "{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestRH", "..\UnitTestRH\UnitTestRH.csproj", "{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B} = {BECC2E56-E65C-42A0-AF80-DDE32DCD5E0B}
|
||||
{7D751284-17E8-434C-A7F6-2EB37572E7AE} = {7D751284-17E8-434C-A7F6-2EB37572E7AE}
|
||||
{7EF854C1-73EB-4099-A7D7-057CCEEE6F8F} = {7EF854C1-73EB-4099-A7D7-057CCEEE6F8F}
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994} = {A232F2D5-AF98-4777-BF3A-FBDDFBC02994}
|
||||
{C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3} = {C1A3CCE4-5FBB-4655-BFE1-7AF2B7D58CA3}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
..\Hashing\Hashing.projitems*{0b6ccc1d-5e76-420e-b54d-eb3e5ffea6cb}*SharedItemsImports = 5
|
||||
..\Hashing\Hashing.projitems*{70277749-d423-4871-b692-2efc5a6ed932}*SharedItemsImports = 13
|
||||
..\Hashing\Hashing.projitems*{7d751284-17e8-434c-a7f6-2eb37572e7ae}*SharedItemsImports = 5
|
||||
..\Hashing\Hashing.projitems*{7ef854c1-73eb-4099-a7d7-057cceee6f8f}*SharedItemsImports = 5
|
||||
@@ -47,6 +57,10 @@ Global
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A232F2D5-AF98-4777-BF3A-FBDDFBC02994}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0B6CCC1D-5E76-420E-B54D-EB3E5FFEA6CB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace RH_Engine
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
}
|
||||
|
||||
private string showOnPanel(string uuidPanel, string serialCode, string mText, int index)
|
||||
public string showOnPanel(string uuidPanel, string serialCode, string mText, int index)
|
||||
{
|
||||
dynamic payload = new
|
||||
{
|
||||
@@ -253,6 +253,11 @@ namespace RH_Engine
|
||||
return AddModel("bike", serial, "data\\NetworkEngine\\models\\bike\\bike.fbx");
|
||||
}
|
||||
|
||||
public string AddBikeModelAnim(string serial, float scalar)
|
||||
{
|
||||
return AddModel("bike", serial, "data\\NetworkEngine\\models\\bike\\bike_anim.fbx", "Armature|Fietsen", new float[] { 0, 0, 0 }, scalar, new float[] { 0, 0, 0 });
|
||||
}
|
||||
|
||||
public string AddModel(string nodeName, string serial, string fileLocation)
|
||||
{
|
||||
return AddModel(nodeName, serial, fileLocation, null, new float[] { 0, 0, 0 }, 1, new float[] { 0, 0, 0 });
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace RH_Engine
|
||||
//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("DESKTOP-SINMKT1", "Ralf van Aert"),
|
||||
//new PC("NA", "Bart")
|
||||
};
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace RH_Engine
|
||||
|
||||
//Add route, bike and put camera and bike to follow route at same speed.
|
||||
SendMessageAndOnResponse(stream, mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
|
||||
SendMessageAndOnResponse(stream, mainCommand.AddBikeModel("bikeID"), "bikeID",
|
||||
SendMessageAndOnResponse(stream, mainCommand.AddBikeModelAnim("bikeID", 0.01f), "bikeID",
|
||||
(message) =>
|
||||
{
|
||||
bikeId = JSONParser.GetResponseUuid(message);
|
||||
|
||||
117
Server/Client.cs
117
Server/Client.cs
@@ -1,9 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Timers;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
using Util;
|
||||
|
||||
namespace Server
|
||||
@@ -20,6 +23,12 @@ namespace Server
|
||||
public string username = null;
|
||||
private DateTime sessionStart;
|
||||
private string fileName;
|
||||
private Timer timer;
|
||||
private volatile byte[] BikeDataBuffer;
|
||||
private volatile byte[] BPMDataBuffer;
|
||||
private bool BPMdata = false;
|
||||
private bool Bikedata = false;
|
||||
private object token = new object { };
|
||||
|
||||
public Client(Communication communication, TcpClient tcpClient)
|
||||
{
|
||||
@@ -28,12 +37,19 @@ namespace Server
|
||||
this.tcpClient = tcpClient;
|
||||
this.stream = this.tcpClient.GetStream();
|
||||
this.fileName = Directory.GetCurrentDirectory() + "/userInfo.dat";
|
||||
this.timer = new Timer();
|
||||
this.BikeDataBuffer = new byte[16];
|
||||
this.BPMDataBuffer = new byte[2];
|
||||
this.timer.Interval = 1000;
|
||||
this.timer.AutoReset = false;
|
||||
this.timer.Elapsed += SendDataToDoctor;
|
||||
Console.WriteLine("token is " + token);
|
||||
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null);
|
||||
}
|
||||
|
||||
private void OnRead(IAsyncResult ar)
|
||||
{
|
||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead))
|
||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.tcpClient.Client.Connected)
|
||||
return;
|
||||
|
||||
int receivedBytes = this.stream.EndRead(ar);
|
||||
@@ -64,6 +80,8 @@ namespace Server
|
||||
}
|
||||
}
|
||||
|
||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.tcpClient.Client.Connected)
|
||||
return;
|
||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
||||
|
||||
}
|
||||
@@ -91,36 +109,47 @@ namespace Server
|
||||
|
||||
string identifier;
|
||||
bool isJson = DataParser.getJsonIdentifier(message, out identifier);
|
||||
|
||||
if (isJson)
|
||||
{
|
||||
switch (identifier)
|
||||
{
|
||||
case DataParser.LOGIN:
|
||||
handleLogin(payloadbytes);
|
||||
if (handleLogin(payloadbytes))
|
||||
communication.NewLogin(this);
|
||||
break;
|
||||
case DataParser.LOGIN_DOCTOR:
|
||||
if (communication.doctor != null)
|
||||
if (communication.Doctor != null)
|
||||
return;
|
||||
|
||||
if (handleLogin(payloadbytes))
|
||||
{
|
||||
communication.doctor = this;
|
||||
Console.WriteLine("Set doctor to " + communication.doctor + " , this is " + this);
|
||||
communication.Doctor = this;
|
||||
}
|
||||
break;
|
||||
case DataParser.START_SESSION:
|
||||
this.communication.StartSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
||||
if (communication.Doctor != this)
|
||||
this.timer.Start();
|
||||
break;
|
||||
case DataParser.STOP_SESSION:
|
||||
this.communication.StopSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
||||
this.timer.Stop();
|
||||
break;
|
||||
case DataParser.SET_RESISTANCE:
|
||||
bool worked = DataParser.getResistanceFromResponseJson(payloadbytes);
|
||||
Console.WriteLine($"set resistance worked is " + worked);
|
||||
//bool worked = DataParser.getResistanceFromResponseJson(payloadbytes);
|
||||
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
|
||||
//set resistance on doctor GUI
|
||||
|
||||
break;
|
||||
case DataParser.DISCONNECT:
|
||||
communication.Disconnect(this);
|
||||
communication.LogOff(this);
|
||||
break;
|
||||
case DataParser.MESSAGE:
|
||||
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
|
||||
break;
|
||||
case DataParser.GET_FILE:
|
||||
getClientBikeData(payloadbytes);
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||
@@ -132,26 +161,58 @@ namespace Server
|
||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
||||
|
||||
}
|
||||
else if (DataParser.isRawData(message))
|
||||
else if (DataParser.isRawDataBikeServer(message))
|
||||
{
|
||||
// print the raw data
|
||||
Console.WriteLine(BitConverter.ToString(payloadbytes));
|
||||
// TODO change, checking for length is not that safe
|
||||
if (payloadbytes.Length == 8)
|
||||
//Bikedata = true;
|
||||
saveData?.WriteDataRAWBike(payloadbytes);
|
||||
lock (token)
|
||||
{
|
||||
saveData?.WriteDataRAWBike(payloadbytes);
|
||||
Array.Copy(this.BikeDataBuffer, 0, this.BikeDataBuffer, 8, 8);
|
||||
Array.Copy(payloadbytes, 0, this.BikeDataBuffer, 0, 8);
|
||||
}
|
||||
else if (payloadbytes.Length == 2)
|
||||
if (this.username != null)
|
||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(payloadbytes, this.username));
|
||||
|
||||
}
|
||||
else if (DataParser.isRawDataBPMServer(message))
|
||||
{
|
||||
//BPMdata = true;
|
||||
saveData?.WriteDataRAWBPM(payloadbytes);
|
||||
lock (token)
|
||||
{
|
||||
saveData?.WriteDataRAWBPM(payloadbytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("received raw data with weird lenght " + BitConverter.ToString(payloadbytes));
|
||||
Array.Copy(payloadbytes, 0, this.BPMDataBuffer, 0, 2);
|
||||
}
|
||||
if (this.username != null)
|
||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(payloadbytes, this.username));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void getClientBikeData(byte[] payloadbytes)
|
||||
{
|
||||
//ugly
|
||||
//get the raw bike data of the user with the specified username
|
||||
string username = DataParser.GetUsernameFromGetFileBytes(payloadbytes);
|
||||
string path = Directory.GetCurrentDirectory() + "/" + username + "/";
|
||||
string bytes = string.Empty;
|
||||
StringBuilder sb = new StringBuilder(bytes);
|
||||
try
|
||||
{
|
||||
DirectoryInfo dirInf = new DirectoryInfo(Directory.GetCurrentDirectory() + "/" + username + "/");
|
||||
DirectoryInfo[] directoryInfos = dirInf.GetDirectories();
|
||||
DirectoryInfo latest = directoryInfos[directoryInfos.Length - 1];
|
||||
path = path + latest.Name + "/rawBike.bin";
|
||||
FileInfo fi = new FileInfo(path);
|
||||
|
||||
if ((int)fi.Length >= 1024) return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine("[SERVER CLIENT] excetion while trying to get raw bike data: " + e.Message);
|
||||
}
|
||||
|
||||
Debug.WriteLine("[SERVER CLIENT] about to send " + sb.ToString());
|
||||
communication.Doctor.sendMessage(DataParser.GetFileMessage(File.ReadAllBytes(path)));
|
||||
}
|
||||
|
||||
private bool handleLogin(byte[] payloadbytes)
|
||||
@@ -166,8 +227,6 @@ namespace Server
|
||||
Console.WriteLine("Log in");
|
||||
this.username = username;
|
||||
sendMessage(DataParser.getLoginResponse("OK"));
|
||||
//sendMessage(DataParser.getStartSessionJson());
|
||||
communication.NewLogin(this);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -251,5 +310,17 @@ namespace Server
|
||||
{
|
||||
this.saveData = null;
|
||||
}
|
||||
|
||||
private void SendDataToDoctor(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
lock (token)
|
||||
{
|
||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(this.BikeDataBuffer.Take(8).ToArray(), this.username));
|
||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(this.BikeDataBuffer.Skip(8).ToArray(), this.username));
|
||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(this.BPMDataBuffer, this.username));
|
||||
}
|
||||
this.timer.Start();
|
||||
Debug.WriteLine("[serverclient] send bike and bpm data timer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Util;
|
||||
|
||||
namespace Server
|
||||
@@ -12,7 +9,24 @@ namespace Server
|
||||
{
|
||||
private TcpListener listener;
|
||||
private List<Client> clients;
|
||||
public Client doctor;
|
||||
private Client mDoctor;
|
||||
public Client Doctor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.mDoctor;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.mDoctor = value;
|
||||
if (this.mDoctor != null)
|
||||
this.clients.ForEach((client) =>
|
||||
{
|
||||
this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
||||
client.sendMessage(DataParser.getNewConnectionJson(this.mDoctor.username));
|
||||
});
|
||||
}
|
||||
}
|
||||
public Communication(TcpListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
@@ -33,34 +47,39 @@ namespace Server
|
||||
|
||||
var tcpClient = listener.EndAcceptTcpClient(ar);
|
||||
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
|
||||
clients.Add(new Client(this, tcpClient));
|
||||
new Client(this, tcpClient);
|
||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
||||
}
|
||||
|
||||
internal void Disconnect(Client client)
|
||||
{
|
||||
clients.Remove(client);
|
||||
doctor.sendMessage(DataParser.getDisconnectJson(client.username));
|
||||
}
|
||||
|
||||
public void NewLogin(Client client)
|
||||
{
|
||||
if (doctor == null)
|
||||
this.clients.Add(client);
|
||||
if (this.Doctor != null)
|
||||
{
|
||||
doctor = client;
|
||||
Doctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
||||
client.sendMessage(DataParser.getNewConnectionJson(Doctor.username));
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
public void LogOff(Client client)
|
||||
{
|
||||
if (this.Doctor == client)
|
||||
{
|
||||
doctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
||||
this.clients.ForEach((client) =>
|
||||
{
|
||||
client.sendMessage(DataParser.getDisconnectJson(this.mDoctor.username));
|
||||
});
|
||||
this.Doctor = null;
|
||||
}
|
||||
|
||||
Doctor?.sendMessage(DataParser.getDisconnectJson(client.username));
|
||||
this.clients.Remove(client);
|
||||
}
|
||||
|
||||
public void StartSessionUser(string user)
|
||||
{
|
||||
foreach(Client client in clients)
|
||||
foreach (Client client in clients)
|
||||
{
|
||||
if(client.username == user)
|
||||
if (client.username == user)
|
||||
{
|
||||
client.sendMessage(DataParser.getStartSessionJson(user));
|
||||
client.StartSession();
|
||||
@@ -80,5 +99,16 @@ namespace Server
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SendMessageToClient(string user, byte[] message)
|
||||
{
|
||||
foreach (Client c in clients)
|
||||
{
|
||||
if (c.username == user)
|
||||
{
|
||||
c.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
418
UnitTestRH/CommandTest.cs
Normal file
418
UnitTestRH/CommandTest.cs
Normal file
@@ -0,0 +1,418 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using ProftaakRH;
|
||||
using RH_Engine;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace UnitTestRH
|
||||
{
|
||||
[TestClass]
|
||||
public class CommandTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void TerrainAdd_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/terrain/add";
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
|
||||
|
||||
int[] terrainSizeArray = new int[2] { 4, 4 };
|
||||
float[] terrainHeightsArray = new float[16] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
string terrainAddCommand = command.TerrainAdd(terrainSizeArray, terrainHeightsArray, testSerial);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test terrain
|
||||
JArray jArrayTerrainSize = (JArray)json.data.data.data.size;
|
||||
JArray jArrayTerrainHeights = (JArray)json.data.data.data.heights;
|
||||
|
||||
int[] outSizeArray = jArrayTerrainSize.Select(ja => (int)ja).ToArray();
|
||||
float[] outHeightsArray = jArrayTerrainHeights.Select(ja => (float)ja).ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(terrainSizeArray, outSizeArray);
|
||||
CollectionAssert.AreEqual(terrainHeightsArray, json.data.data.data.heights.ToObject<float[]>());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddLayer_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/node/addlayer";
|
||||
|
||||
|
||||
string testUuid = "dummyUuid";
|
||||
string diffuseExpected = @"data\NetworkEngine\textures\terrain\grass_green_d.jpg";
|
||||
string normalExpected = @"data\NetworkEngine\textures\terrain\grass_green_n.jpg";
|
||||
int minHeightExpected = 0;
|
||||
int maxHeightExpected = 10;
|
||||
int fadeDistExpected = 1;
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.AddLayer(testUuid, testSerial);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test AddLayer
|
||||
Assert.AreEqual(testUuid, (string)json.data.data.data.id);
|
||||
Assert.AreEqual(diffuseExpected, (string)json.data.data.data.diffuse);
|
||||
Assert.AreEqual(normalExpected, (string)json.data.data.data.normal);
|
||||
Assert.AreEqual(minHeightExpected, (int)json.data.data.data.minHeight);
|
||||
Assert.AreEqual(maxHeightExpected, (int)json.data.data.data.maxHeight);
|
||||
Assert.AreEqual(fadeDistExpected, (int)json.data.data.data.fadeDist);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UpdateTerrain_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/terrain/update";
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.UpdateTerrain();
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void renderTerrain_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/node/add";
|
||||
|
||||
|
||||
string nameExpected = "newNode";
|
||||
int[] positionExpected = new int[] { -80, 0, -80 };
|
||||
float scaleExpected = 1f;
|
||||
int[] rotationExpected = new int[] { 0, 0, 0 };
|
||||
|
||||
bool smoothnormalsExpected = true;
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.renderTerrain(testSerial);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(nameExpected, (string)json.data.data.data.name);
|
||||
|
||||
//Test data components
|
||||
|
||||
//Test transform
|
||||
JArray jArrayPosition = (JArray)json.data.data.data.components.transform.position;
|
||||
JArray jArrayRotation = (JArray)json.data.data.data.components.transform.rotation;
|
||||
|
||||
int[] outPositionArray = jArrayPosition.Select(ja => (int)ja).ToArray();
|
||||
int[] outRotationArray = jArrayRotation.Select(ja => (int)ja).ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(positionExpected, outPositionArray);
|
||||
CollectionAssert.AreEqual(rotationExpected, outRotationArray);
|
||||
|
||||
|
||||
//Test terrain
|
||||
Assert.AreEqual(smoothnormalsExpected, (bool)json.data.data.data.components.terrain.smoothnormals);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeleteNode_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/node/delete";
|
||||
|
||||
string uuid = "dummyUuid";
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.DeleteNode(uuid, testSerial);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void addPanel_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/node/add";
|
||||
|
||||
string uuidBike = "dummyUuidBike";
|
||||
|
||||
string nameExpected = "dashboard";
|
||||
|
||||
//components
|
||||
//transform
|
||||
float[] positionExpected = new float[] { -1.5f, 1f, 0f };
|
||||
int scaleExpected = 1;
|
||||
int[] rotationExpected = new int[] { -30, 90, 0 };
|
||||
|
||||
//panel
|
||||
int[] sizeExpected = new int[] { 1, 1 };
|
||||
int[] resolutionExpected = new int[] { 512, 512 };
|
||||
int[] backgroundExpected = new int[] { 1, 1, 1, 1 };
|
||||
bool castShadowExpected = false;
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.addPanel(testSerial, uuidBike);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(nameExpected, (string)json.data.data.data.name);
|
||||
Assert.AreEqual(uuidBike, (string)json.data.data.data.parent);
|
||||
|
||||
//Test components
|
||||
|
||||
//Test transform
|
||||
JArray jArrayPosition = (JArray)json.data.data.data.components.transform.position;
|
||||
JArray jArrayRotation = (JArray)json.data.data.data.components.transform.rotation;
|
||||
|
||||
float[] outPositionArray = jArrayPosition.Select(ja => (float)ja).ToArray();
|
||||
int[] outRotationArray = jArrayRotation.Select(ja => (int)ja).ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(positionExpected, outPositionArray);
|
||||
CollectionAssert.AreEqual(rotationExpected, outRotationArray);
|
||||
|
||||
Assert.AreEqual(scaleExpected, (int)json.data.data.data.components.transform.scale);
|
||||
|
||||
//Test panel
|
||||
CollectionAssert.AreEqual(sizeExpected, ((JArray)json.data.data.data.components.panel.size).Select(ja => (int)ja).ToArray());
|
||||
CollectionAssert.AreEqual(resolutionExpected, ((JArray)json.data.data.data.components.panel.resolution).Select(ja => (int)ja).ToArray());
|
||||
CollectionAssert.AreEqual(backgroundExpected, ((JArray)json.data.data.data.components.panel.background).Select(ja => (int)ja).ToArray());
|
||||
Assert.AreEqual(castShadowExpected, (bool)json.data.data.data.components.panel.castShadow);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ColorPanel_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/panel/setclearcolor";
|
||||
|
||||
string uuidPanel = "dummyUuidPanel";
|
||||
|
||||
float[] colorExpected = new float[] { 0f, 0f, 0f, 0f };
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.ColorPanel(uuidPanel);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuidPanel, (string)json.data.data.data.id);
|
||||
CollectionAssert.AreEqual(colorExpected, ((JArray)json.data.data.data.color).Select(ja => (float)ja).ToArray());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SwapPanel_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/panel/swap";
|
||||
|
||||
string uuid = "dummyUuid";
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.SwapPanel(uuid);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void showOnPanel_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
string testSerial = "dummySerialCode";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/panel/drawtext";
|
||||
|
||||
string uuidPanel = "dummyUuidPanel";
|
||||
string text = "dummyText";
|
||||
int index = 3;
|
||||
int[] positionExpected = new int[] { 4, 24 + index * 32 };
|
||||
double sizeExpected = 32.0;
|
||||
int[] colorExpected = new int[] { 0, 0, 0, 1 };
|
||||
string fontExpected = "segoeui";
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.showOnPanel(uuidPanel, testSerial, text, index);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
Assert.AreEqual(testSerial, (string)json.data.data.serial);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuidPanel, (string)json.data.data.data.id);
|
||||
Assert.AreEqual(text, (string)json.data.data.data.text);
|
||||
CollectionAssert.AreEqual(positionExpected, ((JArray)json.data.data.data.position).Select(ja => (int)ja).ToArray());
|
||||
Assert.AreEqual(sizeExpected, (double)json.data.data.data.size);
|
||||
CollectionAssert.AreEqual(colorExpected, ((JArray)json.data.data.data.color).Select(ja => (int)ja).ToArray());
|
||||
Assert.AreEqual(fontExpected, (string)json.data.data.data.font);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SwapPanelCommand_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/panel/swap";
|
||||
|
||||
string uuid = "dummyUuid";
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.SwapPanelCommand(uuid);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test message
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClearPanel_TestMethod()
|
||||
{
|
||||
string testTunnelID = "dummyTunnelID";
|
||||
|
||||
string payloadId = "tunnel/send";
|
||||
string messageId = "scene/panel/clear";
|
||||
|
||||
string uuid = "dummyUuid";
|
||||
|
||||
|
||||
Command command = new Command(testTunnelID);
|
||||
|
||||
string terrainAddCommand = command.ClearPanel(uuid);
|
||||
|
||||
dynamic json = JsonConvert.DeserializeObject(terrainAddCommand);
|
||||
|
||||
//Test payload
|
||||
Assert.AreEqual(payloadId, (string)json.id);
|
||||
Assert.AreEqual(testTunnelID, (string)json.data.dest);
|
||||
|
||||
//Test terrain
|
||||
Assert.AreEqual(messageId, (string)json.data.data.id);
|
||||
|
||||
//Test data
|
||||
Assert.AreEqual(uuid, (string)json.data.data.data.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
74
UnitTestRH/DataParserTest.cs
Normal file
74
UnitTestRH/DataParserTest.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json;
|
||||
using RH_Engine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Util;
|
||||
|
||||
namespace UnitTestRH
|
||||
{
|
||||
[TestClass]
|
||||
public class DataParserTest
|
||||
{
|
||||
|
||||
public byte[] GetPayload(byte[] message)
|
||||
{
|
||||
byte[] payload = new byte[message.Length - 5];
|
||||
Array.Copy(message, 5, payload, 0, message.Length - 5);
|
||||
return payload;
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestGetMessageToSend()
|
||||
{
|
||||
byte[] toTest = DataParser.GetMessageToSend("test");
|
||||
|
||||
dynamic res = JsonConvert.DeserializeObject(Encoding.ASCII.GetString((toTest)));
|
||||
Assert.AreEqual("MESSAGE", (string)res.identifier);
|
||||
Assert.AreEqual("test", (string)res.data.message);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestIsRawDataBikeServer()
|
||||
{
|
||||
byte[] testArr = { 0x34,0x00,0x00,0x00,0x02};
|
||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x02,0x49,0x65 };
|
||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBikeServer(testArr));
|
||||
Assert.IsTrue(DataParser.isRawDataBikeServer(testArr2));
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestIsRawDataBikeDoctor()
|
||||
{
|
||||
byte[] testArr = { 0x34, 0x00, 0x00, 0x00, 0x04 };
|
||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x04, 0x49, 0x65 };
|
||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBikeDoctor(testArr));
|
||||
Assert.IsTrue(DataParser.isRawDataBikeDoctor(testArr2));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestIsRawDataBPMServer()
|
||||
{
|
||||
byte[] testArr = { 0x34, 0x00, 0x00, 0x00, 0x03};
|
||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x03, 0x49, 0x65 };
|
||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBPMServer(testArr));
|
||||
Assert.IsTrue(DataParser.isRawDataBPMServer(testArr2));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestIsRawDataBPMDoctor()
|
||||
{
|
||||
byte[] testArr = { 0x34, 0x00, 0x00, 0x00, 0x05 };
|
||||
byte[] testArr2 = { 0x34, 0x00, 0x00, 0x00, 0x05, 0x49, 0x65 };
|
||||
Assert.ThrowsException<ArgumentException>(() => DataParser.isRawDataBPMDoctor(testArr));
|
||||
Assert.IsTrue(DataParser.isRawDataBPMDoctor(testArr2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
26
UnitTestRH/UnitTestRH.csproj
Normal file
26
UnitTestRH/UnitTestRH.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ClientApp\ClientApp.csproj" />
|
||||
<ProjectReference Include="..\DoctorApp\DoctorApp.csproj" />
|
||||
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
|
||||
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
|
||||
<ProjectReference Include="..\Server\Server.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user