Develop #10
@@ -19,9 +19,7 @@
|
||||
<Label Content="Password" HorizontalContentAlignment="Center"/>
|
||||
<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>
|
||||
|
||||
@@ -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,13 +83,18 @@ namespace DoctorApp.ViewModels
|
||||
PatientInfo.Resistance = float.Parse(((TextBox)parameter).Text);
|
||||
});
|
||||
|
||||
this.SaveHistoricData = new RelayCommand<object>((parameter) =>
|
||||
{
|
||||
this.client.sendMessage(DataParser.GetGetFileMessage(PatientInfo.Username, DateTime.Now));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void BPMData(byte [] bytes)
|
||||
public void BPMData(byte[] bytes)
|
||||
{
|
||||
//TODO
|
||||
//Parsen van de data you fuck
|
||||
if(bytes[0] == 0x00)
|
||||
if (bytes[0] == 0x00)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -95,13 +102,13 @@ namespace DoctorApp.ViewModels
|
||||
{
|
||||
PatientInfo.BPM = bytes[1];
|
||||
if (MySelectedItem == "BPM")
|
||||
{
|
||||
{
|
||||
Chart.NewValue(PatientInfo.BPM);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void BikeData(byte[] bytes)
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -23,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>
|
||||
@@ -72,7 +73,7 @@ namespace Util
|
||||
return getName(bytes, 2, bytes.Length - 2);
|
||||
}
|
||||
|
||||
private static string getName(byte[] bytes , int offset, int lenght)
|
||||
private static string getName(byte[] bytes, int offset, int lenght)
|
||||
{
|
||||
byte[] nameArray = new byte[lenght];
|
||||
Array.Copy(bytes, offset, nameArray, 0, lenght);
|
||||
@@ -286,7 +287,7 @@ 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)
|
||||
@@ -295,8 +296,8 @@ namespace Util
|
||||
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);
|
||||
Array.Copy(nameArray, 0, total, payload.Length, nameArray.Length);
|
||||
return getMessage(total, messageID);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
@@ -337,14 +338,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
|
||||
{
|
||||
@@ -436,7 +437,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>
|
||||
@@ -472,6 +473,33 @@ namespace Util
|
||||
return data;
|
||||
}
|
||||
|
||||
public static byte[] GetGetFileMessage(string mUsername, DateTime mDateTime)
|
||||
{
|
||||
if (mUsername == null)
|
||||
{
|
||||
throw new ArgumentNullException("username null");
|
||||
}
|
||||
dynamic data = new
|
||||
{
|
||||
username = mUsername,
|
||||
dateTime = mDateTime.ToString("yyyy-MM-dd HH-mm-ss")
|
||||
};
|
||||
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, 0x04);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,6 +147,25 @@ namespace Server
|
||||
case DataParser.MESSAGE:
|
||||
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
|
||||
break;
|
||||
case DataParser.GET_FILE:
|
||||
//ugly
|
||||
string username = DataParser.GetUsernameFromGetFileBytes(payloadbytes);
|
||||
string path = Directory.GetCurrentDirectory() + "/" + username + "/" + DataParser.GetDateFromGetFileBytes(payloadbytes) + "/rawBike.bin";
|
||||
int length = Int32.MaxValue;
|
||||
try
|
||||
{
|
||||
FileInfo fi = new FileInfo(path);
|
||||
length = (int)fi.Length;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("couldn't find file " + path);
|
||||
}
|
||||
if (length > 10240)
|
||||
break;
|
||||
|
||||
communication.SendMessageToClient(username, DataParser.GetFileMessage(File.ReadAllBytes(path)));
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user