Compare commits
19 Commits
unittest-s
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2e1c90c16 | ||
|
|
86a8b2b789 | ||
|
|
aa2e16de89 | ||
|
|
b112fc131e | ||
|
|
6725f2ff85 | ||
|
|
89fe104418 | ||
|
|
2177f9bd19 | ||
|
|
28dc2c2f9c | ||
|
|
d6cf5902da | ||
|
|
9f7a01170b | ||
|
|
6dd9bd4107 | ||
|
|
4207eaefea | ||
|
|
87b9ee65d0 | ||
|
|
dffdae2cb4 | ||
|
|
baf89dac3f | ||
|
|
b98ac77261 | ||
|
|
6d599cfcd2 | ||
|
|
4af7b3bc44 | ||
|
|
3dc1709943 |
@@ -21,7 +21,7 @@ namespace ClientApp.Utils
|
|||||||
private byte[] totalBuffer = new byte[1024];
|
private byte[] totalBuffer = new byte[1024];
|
||||||
private int totalBufferReceived = 0;
|
private int totalBufferReceived = 0;
|
||||||
public EngineConnection engineConnection;
|
public EngineConnection engineConnection;
|
||||||
private bool sessionRunning = false;
|
private bool sessionRunning = true;
|
||||||
private IHandler handler = null;
|
private IHandler handler = null;
|
||||||
private LoginViewModel LoginViewModel;
|
private LoginViewModel LoginViewModel;
|
||||||
|
|
||||||
@@ -146,6 +146,7 @@ namespace ClientApp.Utils
|
|||||||
case DataParser.STOP_SESSION:
|
case DataParser.STOP_SESSION:
|
||||||
Console.WriteLine("Stop session identifier");
|
Console.WriteLine("Stop session identifier");
|
||||||
this.sessionRunning = false;
|
this.sessionRunning = false;
|
||||||
|
stopBikeInSimulation();
|
||||||
Debug.WriteLine("stop");
|
Debug.WriteLine("stop");
|
||||||
break;
|
break;
|
||||||
case DataParser.SET_RESISTANCE:
|
case DataParser.SET_RESISTANCE:
|
||||||
@@ -230,14 +231,12 @@ namespace ClientApp.Utils
|
|||||||
}
|
}
|
||||||
byte[] message = DataParser.GetRawBPMDataMessageServer(bytes);
|
byte[] message = DataParser.GetRawBPMDataMessageServer(bytes);
|
||||||
|
|
||||||
if (engineConnection.Connected && engineConnection.FollowingRoute)
|
if (engineConnection != null && engineConnection.Connected && engineConnection.FollowingRoute)
|
||||||
{
|
{
|
||||||
engineConnection.BikeBPM = bytes[1];
|
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>
|
/// <summary>
|
||||||
@@ -256,21 +255,29 @@ namespace ClientApp.Utils
|
|||||||
throw new ArgumentNullException("no bytes");
|
throw new ArgumentNullException("no bytes");
|
||||||
}
|
}
|
||||||
byte[] message = DataParser.GetRawBikeDataMessageServer(bytes);
|
byte[] message = DataParser.GetRawBikeDataMessageServer(bytes);
|
||||||
bool canSendToEngine = engineConnection.Connected && engineConnection.FollowingRoute;
|
bool canSendToEngine = engineConnection != null && engineConnection.Connected && engineConnection.FollowingRoute && this.sessionRunning;
|
||||||
switch (bytes[0])
|
switch (bytes[0])
|
||||||
{
|
{
|
||||||
|
|
||||||
case 0x10:
|
case 0x10:
|
||||||
|
|
||||||
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
|
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
|
||||||
|
else if (engineConnection != null) engineConnection.BikeSpeed = 0;
|
||||||
break;
|
break;
|
||||||
case 0x19:
|
case 0x19:
|
||||||
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
||||||
|
else if (engineConnection != null) engineConnection.BikePower = 0;
|
||||||
break;
|
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
|
#endregion
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ namespace ClientApp.Utils
|
|||||||
Write("Starting route follow...");
|
Write("Starting route follow...");
|
||||||
FollowingRoute = true;
|
FollowingRoute = true;
|
||||||
|
|
||||||
SendMessageAndOnResponse(mainCommand.AddBikeModelAnim("bikeID", 0.01f), "bikeID",
|
SendMessageAndOnResponse(mainCommand.AddBikeModel("bikeID"), "bikeID",
|
||||||
(message) =>
|
(message) =>
|
||||||
{
|
{
|
||||||
bikeId = JSONParser.GetResponseUuid(message);
|
bikeId = JSONParser.GetResponseUuid(message);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace ClientApp.ViewModels
|
|||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public ICommand LoginCommand { get; set; }
|
public ICommand LoginCommand { get; set; }
|
||||||
|
|
||||||
public bool LoginStatus { get; set; }
|
public bool LoginStatus { get; set; } = false;
|
||||||
|
|
||||||
public bool InvertedLoginStatus { get; set; }
|
public bool InvertedLoginStatus { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,7 @@
|
|||||||
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
||||||
<PasswordBox x:Name="Password" Width="120" Util:FocusAdvancement.AdvancesByEnterKey="True"/>
|
<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"/>
|
<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" IsEnabled="{Binding InvertedLoginStatus}"/>
|
||||||
<Label Content="Login failed" Foreground="Red" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Background="Transparent"/>
|
|
||||||
</Popup>
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
|
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
|
||||||
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
|
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
|
||||||
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
|
<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" />
|
<PackageReference Include="PropertyChanged.Fody" Version="3.2.9" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using DoctorApp.ViewModels;
|
using DoctorApp.ViewModels;
|
||||||
|
using Microsoft.Win32;
|
||||||
using ProftaakRH;
|
using ProftaakRH;
|
||||||
using Util;
|
using Util;
|
||||||
|
|
||||||
@@ -129,6 +131,23 @@ namespace DoctorApp.Utils
|
|||||||
{
|
{
|
||||||
MainViewModel.TransferDataToClientBPM(payloadbytes);
|
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
|
Array.Copy(totalBuffer, expectedMessageLength, totalBuffer, 0, (totalBufferReceived - expectedMessageLength)); //maybe unsafe idk
|
||||||
totalBufferReceived -= expectedMessageLength;
|
totalBufferReceived -= expectedMessageLength;
|
||||||
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
|
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
|
||||||
@@ -138,6 +157,35 @@ namespace DoctorApp.Utils
|
|||||||
return;
|
return;
|
||||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
/// <summary>
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ namespace DoctorApp.ViewModels
|
|||||||
|
|
||||||
public ICommand SetResistance { get; set; }
|
public ICommand SetResistance { get; set; }
|
||||||
|
|
||||||
|
public ICommand SaveHistoricData { get; set; }
|
||||||
|
|
||||||
public MainWindowViewModel MainWindowViewModel { get; set; }
|
public MainWindowViewModel MainWindowViewModel { get; set; }
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@@ -81,19 +83,29 @@ namespace DoctorApp.ViewModels
|
|||||||
PatientInfo.Resistance = 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)
|
public void BPMData(byte[] bytes)
|
||||||
{
|
{
|
||||||
//TODO
|
//TODO
|
||||||
//Parsen van de data you fuck
|
//Parsen van de data you fuck
|
||||||
|
PatientInfo.BPM = bytes[1];
|
||||||
if (bytes[0] == 0x00)
|
if (bytes[0] == 0x00)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PatientInfo.BPM = bytes[1];
|
|
||||||
if (MySelectedItem == "BPM")
|
if (MySelectedItem == "BPM")
|
||||||
{
|
{
|
||||||
Chart.NewValue(PatientInfo.BPM);
|
Chart.NewValue(PatientInfo.BPM);
|
||||||
|
|||||||
@@ -57,8 +57,10 @@ namespace DoctorApp.ViewModels
|
|||||||
if (item.PatientInfo.Username == username)
|
if (item.PatientInfo.Username == username)
|
||||||
{
|
{
|
||||||
item.BikeData(DataParser.getDataWithoutName(bytes, 0, 8));
|
item.BikeData(DataParser.getDataWithoutName(bytes, 0, 8));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Debug.WriteLine("[MainViewModel] did not find client (bike) username is " + username);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TransferDataToClientBPM(byte[] bytes)
|
public void TransferDataToClientBPM(byte[] bytes)
|
||||||
@@ -68,9 +70,11 @@ namespace DoctorApp.ViewModels
|
|||||||
{
|
{
|
||||||
if (item.PatientInfo.Username == username)
|
if (item.PatientInfo.Username == username)
|
||||||
{
|
{
|
||||||
item.BikeData(DataParser.getDataWithoutName(bytes, 0,2));
|
item.BPMData(DataParser.getDataWithoutName(bytes, 0, 2));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Debug.WriteLine("[MainViewModel] did not find client (bpm) username is " + username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<UserControl x:Class="DoctorApp.Views.ClientInfoView"
|
<UserControl x:Class="DoctorApp.Views.ClientInfoView"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
@@ -18,7 +18,9 @@
|
|||||||
<RowDefinition Height="180*"/>
|
<RowDefinition Height="180*"/>
|
||||||
<RowDefinition Height="180*"/>
|
<RowDefinition Height="180*"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<StackPanel Orientation="Horizontal" Grid.RowSpan="2" Margin="0,0,0,22">
|
|
||||||
|
<Grid Grid.RowSpan="2" Margin="0,0,0,22">
|
||||||
|
<StackPanel Orientation="Horizontal" >
|
||||||
<StackPanel.Resources>
|
<StackPanel.Resources>
|
||||||
<Style TargetType="{x:Type Label}">
|
<Style TargetType="{x:Type Label}">
|
||||||
<Setter Property="Margin" Value="0,0,20,0"/>
|
<Setter Property="Margin" Value="0,0,20,0"/>
|
||||||
@@ -27,7 +29,9 @@
|
|||||||
<Label Content="{Binding Path=PatientInfo.Username}"/>
|
<Label Content="{Binding Path=PatientInfo.Username}"/>
|
||||||
<Label Content="{Binding Path=PatientInfo.Status}"/>
|
<Label Content="{Binding Path=PatientInfo.Status}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Margin="0,10,0,0" Grid.RowSpan="2" Grid.Row="1">
|
<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>
|
<StackPanel.Resources>
|
||||||
<Style TargetType="{x:Type DockPanel}">
|
<Style TargetType="{x:Type DockPanel}">
|
||||||
<Setter Property="Margin" Value="0,20,0,0"/>
|
<Setter Property="Margin" Value="0,20,0,0"/>
|
||||||
@@ -40,7 +44,7 @@
|
|||||||
</DockPanel>
|
</DockPanel>
|
||||||
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
|
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
|
||||||
<TextBox Name="textBox_Resistance" Text="{Binding Path=PatientInfo.Resistance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" 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}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" 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"/>
|
<TextBox Name="textBox_CurrentBPM" Text="{Binding Path=PatientInfo.BPM}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
<DockPanel Height="26" LastChildFill="False">
|
<DockPanel Height="26" LastChildFill="False">
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
AllowsTransparency="True"
|
AllowsTransparency="True"
|
||||||
MinHeight="{Binding MinimumHeight}"
|
MinHeight="{Binding MinimumHeight}"
|
||||||
MinWidth="{Binding MinimumWidth}"
|
MinWidth="{Binding MinimumWidth}"
|
||||||
Title="MainWindow" Height="500" Width="900">
|
Title="MainWindow" Height="800" Width="1500">
|
||||||
<Window.Resources>
|
<Window.Resources>
|
||||||
<Style TargetType="{x:Type local:MainWindow}">
|
<Style TargetType="{x:Type local:MainWindow}">
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace Util
|
|||||||
public const string DISCONNECT = "DISCONNECT";
|
public const string DISCONNECT = "DISCONNECT";
|
||||||
public const string LOGIN_DOCTOR = "LOGIN DOCTOR";
|
public const string LOGIN_DOCTOR = "LOGIN DOCTOR";
|
||||||
public const string MESSAGE = "MESSAGE";
|
public const string MESSAGE = "MESSAGE";
|
||||||
|
public const string GET_FILE = "GET FILE";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// makes the json object with LOGIN identifier and username and password
|
/// makes the json object with LOGIN identifier and username and password
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -242,6 +243,12 @@ namespace Util
|
|||||||
return bytes[4] == 0x05;
|
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>
|
/// <summary>
|
||||||
/// constructs a message with the payload, messageId and clientId
|
/// constructs a message with the payload, messageId and clientId
|
||||||
@@ -291,7 +298,6 @@ namespace Util
|
|||||||
|
|
||||||
private static byte[] GetRawDataDoctor(byte[] payload, string username, byte messageID)
|
private static byte[] GetRawDataDoctor(byte[] payload, string username, byte messageID)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(BitConverter.ToString(Encoding.ASCII.GetBytes(username)));
|
|
||||||
byte[] nameArray = Encoding.ASCII.GetBytes(username);
|
byte[] nameArray = Encoding.ASCII.GetBytes(username);
|
||||||
byte[] total = new byte[nameArray.Length + payload.Length];
|
byte[] total = new byte[nameArray.Length + payload.Length];
|
||||||
Array.Copy(payload, 0, total, 0, payload.Length);
|
Array.Copy(payload, 0, total, 0, payload.Length);
|
||||||
@@ -415,7 +421,6 @@ namespace Util
|
|||||||
/// <returns>the response of the message, so wether it was successful or not.</returns>
|
/// <returns>the response of the message, so wether it was successful or not.</returns>
|
||||||
public static bool getResistanceFromResponseJson(byte[] json)
|
public static bool getResistanceFromResponseJson(byte[] json)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("got message " + Encoding.ASCII.GetString(json));
|
|
||||||
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
|
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.worked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,6 +477,32 @@ namespace Util
|
|||||||
return data;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ namespace Server
|
|||||||
break;
|
break;
|
||||||
case DataParser.START_SESSION:
|
case DataParser.START_SESSION:
|
||||||
this.communication.StartSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
this.communication.StartSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
||||||
|
if (communication.Doctor != this)
|
||||||
this.timer.Start();
|
this.timer.Start();
|
||||||
break;
|
break;
|
||||||
case DataParser.STOP_SESSION:
|
case DataParser.STOP_SESSION:
|
||||||
@@ -147,6 +148,9 @@ namespace Server
|
|||||||
case DataParser.MESSAGE:
|
case DataParser.MESSAGE:
|
||||||
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
|
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
|
||||||
break;
|
break;
|
||||||
|
case DataParser.GET_FILE:
|
||||||
|
getClientBikeData(payloadbytes);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||||
break;
|
break;
|
||||||
@@ -166,7 +170,9 @@ namespace Server
|
|||||||
Array.Copy(this.BikeDataBuffer, 0, this.BikeDataBuffer, 8, 8);
|
Array.Copy(this.BikeDataBuffer, 0, this.BikeDataBuffer, 8, 8);
|
||||||
Array.Copy(payloadbytes, 0, this.BikeDataBuffer, 0, 8);
|
Array.Copy(payloadbytes, 0, this.BikeDataBuffer, 0, 8);
|
||||||
}
|
}
|
||||||
//this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(payloadbytes, this.username));
|
if (this.username != null)
|
||||||
|
this.communication.Doctor?.sendMessage(DataParser.GetRawBikeDataDoctor(payloadbytes, this.username));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (DataParser.isRawDataBPMServer(message))
|
else if (DataParser.isRawDataBPMServer(message))
|
||||||
{
|
{
|
||||||
@@ -176,11 +182,39 @@ namespace Server
|
|||||||
{
|
{
|
||||||
Array.Copy(payloadbytes, 0, this.BPMDataBuffer, 0, 2);
|
Array.Copy(payloadbytes, 0, this.BPMDataBuffer, 0, 2);
|
||||||
}
|
}
|
||||||
//this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(payloadbytes, this.username));
|
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)
|
private bool handleLogin(byte[] payloadbytes)
|
||||||
{
|
{
|
||||||
string username;
|
string username;
|
||||||
@@ -286,6 +320,7 @@ namespace Server
|
|||||||
this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(this.BPMDataBuffer, this.username));
|
this.communication.Doctor?.sendMessage(DataParser.GetRawBPMDataDoctor(this.BPMDataBuffer, this.username));
|
||||||
}
|
}
|
||||||
this.timer.Start();
|
this.timer.Start();
|
||||||
|
Debug.WriteLine("[serverclient] send bike and bpm data timer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user