20 Commits

Author SHA1 Message Date
Sem van der Hoeven
6dd9bd4107 [ADD] finished writing historic data to documents 2020-10-29 22:57:50 +01:00
Sem van der Hoeven
87b9ee65d0 [ADD] added writing contents to file 2020-10-29 22:51:14 +01:00
Sem van der Hoeven
dffdae2cb4 [EDIT] tried adding lots of bike data 2020-10-29 21:01:45 +01:00
Sem van der Hoeven
baf89dac3f [ADD] added checking of all folders in username directory 2020-10-29 20:35:21 +01:00
Sem van der Hoeven
b98ac77261 [EDIT] some comments 2020-10-29 17:44:47 +01:00
shinichi
6d599cfcd2 wip gtg 2020-10-29 17:01:14 +01:00
shinichi
da9d3184a1 token and volatile 2020-10-19 16:41:38 +02:00
fabjuuuh
2b6ea121c9 Merge remote-tracking branch 'origin/develop' into develop 2020-10-19 16:24:34 +02:00
fabjuuuh
478a2daab7 hi 2020-10-19 16:24:24 +02:00
shinichi
8b8dd901c7 Merge branch 'NextFocusOnEnter' into develop 2020-10-19 16:19:10 +02:00
fabjuuuh
aa5ea7a3e0 works kinda 2020-10-19 16:13:51 +02:00
shinichi
aeb5d59ce9 implemented nextfocuable 2020-10-19 15:32:14 +02:00
shinichi
ab1662f0fe Merge branch 'develop' into NextFocusOnEnter 2020-10-19 15:15:34 +02:00
shinichi
f07c3f9484 moving and fixing 2020-10-19 15:14:01 +02:00
fabjuuuh
2adfcc5bd7 fix 2020-10-19 15:13:27 +02:00
shinichi
3acdc942bc move files and copy code
from stackoverflow :P
2020-10-19 14:53:47 +02:00
shinichi
84cbcb4a6d send data to doctor 2020-10-19 14:35:51 +02:00
Logophilist
8385f09313 Bike animation added 2020-10-19 14:25:09 +02:00
fabjuuuh
3ea42b65ed Merge branch 'dataOnTabs' into develop 2020-10-19 14:11:59 +02:00
Sem van der Hoeven
55d3dd4eee actually fixed overflow exception 2020-10-19 14:09:03 +02:00
27 changed files with 435 additions and 68 deletions

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using RH_Engine;
@@ -236,7 +236,7 @@ namespace ClientApp.Utils
Write("Starting route follow...");
FollowingRoute = true;
SendMessageAndOnResponse(mainCommand.AddBikeModel("bikeID"), "bikeID",
SendMessageAndOnResponse(mainCommand.AddBikeModelAnim("bikeID", 0.01f), "bikeID",
(message) =>
{
bikeId = JSONParser.GetResponseUuid(message);

View File

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

View File

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

View File

@@ -20,11 +20,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>

View File

@@ -25,6 +25,7 @@
<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>

View File

@@ -1,9 +1,11 @@
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;
@@ -129,7 +131,24 @@ namespace DoctorApp.Utils
{
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);
}
@@ -140,11 +159,40 @@ namespace DoctorApp.Utils
}
/// <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);
}

View File

@@ -41,6 +41,8 @@ namespace DoctorApp.ViewModels
public ICommand SetResistance { get; set; }
public ICommand SaveHistoricData { get; set; }
public MainWindowViewModel MainWindowViewModel { get; set; }
private Client client;
@@ -81,18 +83,37 @@ namespace DoctorApp.ViewModels
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)
public void BPMData(byte[] bytes)
{
//TODO
//Parsen van de data you fuck
PatientInfo.BPM = bytes[1];
if (MySelectedItem == "BPM")
if (bytes[0] == 0x00)
{
Chart.NewValue(PatientInfo.BPM);
}
else
{
PatientInfo.BPM = bytes[1];
if (MySelectedItem == "BPM")
{
Chart.NewValue(PatientInfo.BPM);
}
}
}
public void BikeData(byte[] bytes)
@@ -108,17 +129,18 @@ namespace DoctorApp.ViewModels
}
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:
throw new Exception();
}
if (MySelectedItem == "Speed")
{
Chart.NewValue(PatientInfo.Speed);
Debug.WriteLine("rip");
break;
}
}

View File

@@ -56,7 +56,7 @@ namespace DoctorApp.ViewModels
{
if(item.PatientInfo.Username == username)
{
item.BikeData(bytes);
item.BikeData(DataParser.getDataWithoutName(bytes,0,8));
}
}
}
@@ -68,7 +68,7 @@ namespace DoctorApp.ViewModels
{
if (item.PatientInfo.Username == username)
{
item.BikeData(bytes);
item.BikeData(DataParser.getDataWithoutName(bytes, 0,2));
}
}
}

View File

@@ -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=PatientInfo.Username}"/>
<Label Content="{Binding Path=PatientInfo.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"/>

View File

@@ -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" />

View File

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

View File

@@ -4,9 +4,11 @@ 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
{
@@ -21,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>
@@ -41,6 +44,12 @@ 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>
@@ -59,6 +68,18 @@ 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>
@@ -222,6 +243,12 @@ namespace Util
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
@@ -266,13 +293,17 @@ namespace Util
public static byte[] GetRawBPMDataDoctor(byte[] payload, string username)
{
return GetRawDataDoctor(payload,username,0x05);
return GetRawDataDoctor(payload, username, 0x05);
}
private static byte[] GetRawDataDoctor(byte[] payload, string username, byte messageID)
{
return getMessage(payload.Concat(Encoding.ASCII.GetBytes(username)).ToArray(), messageID);
Debug.WriteLine(BitConverter.ToString(Encoding.ASCII.GetBytes(username)));
byte[] nameArray = Encoding.ASCII.GetBytes(username);
byte[] total = new byte[nameArray.Length + payload.Length];
Array.Copy(payload, 0, total, 0, payload.Length);
Array.Copy(nameArray, 0, total, payload.Length, nameArray.Length);
return getMessage(total, messageID);
}
/// <summary>
@@ -313,14 +344,14 @@ namespace Util
};
return getJsonMessage(STOP_SESSION, data);
}
/// <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)
public static byte[] getSetResistanceJson(string user, float mResistance)
{
dynamic data = new
{
@@ -412,7 +443,7 @@ namespace Util
/// <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>
@@ -441,6 +472,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);
}
}
}

View File

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

View 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));
}
}
}

View 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>

View 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>

View 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>

View 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>

View 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>

View File

@@ -109,7 +109,8 @@ namespace Hardware.Simulators
private byte check(int value)
{
return value > 255 ? Convert.ToByte(255) : Convert.ToByte(value);
return value > 255 ? Convert.ToByte(255) : value < 0 ? Convert.ToByte(0) : Convert.ToByte(value);
}
//Generate an ANT message for BPM

View File

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

View File

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

View File

@@ -1,9 +1,11 @@
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 Util;
@@ -21,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)
{
@@ -29,6 +37,13 @@ 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);
}
@@ -114,9 +129,11 @@ namespace Server
break;
case DataParser.START_SESSION:
this.communication.StartSessionUser(DataParser.getUsernameFromJson(payloadbytes));
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);
@@ -130,6 +147,9 @@ namespace Server
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)}");
break;
@@ -142,14 +162,53 @@ namespace Server
}
else if (DataParser.isRawDataBikeServer(message))
{
//Bikedata = true;
saveData?.WriteDataRAWBike(payloadbytes);
lock (token)
{
Array.Copy(this.BikeDataBuffer, 0, this.BikeDataBuffer, 8, 8);
Array.Copy(payloadbytes, 0, this.BikeDataBuffer, 0, 8);
}
//this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(payloadbytes, this.username));
}
else if (DataParser.isRawDataBPMServer(message))
{
//BPMdata = true;
saveData?.WriteDataRAWBPM(payloadbytes);
lock (token)
{
Array.Copy(payloadbytes, 0, this.BPMDataBuffer, 0, 2);
}
//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)
@@ -247,5 +306,16 @@ 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();
}
}
}