Develop #10
@@ -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; }
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -123,9 +125,6 @@ namespace DoctorApp.Utils
|
||||
}
|
||||
else if (DataParser.isRawDataBikeDoctor(messageBytes))
|
||||
{
|
||||
// read the .bin file that is in the message
|
||||
// update the view
|
||||
//Debug.WriteLine($"[DOCTOR CLIENT] Got raw bike data: " + Encoding.ASCII.GetString(payloadbytes));
|
||||
MainViewModel.TransferDataToClientBike(payloadbytes);
|
||||
}
|
||||
else if (DataParser.isRawDataBPMDoctor(messageBytes))
|
||||
@@ -134,7 +133,18 @@ namespace DoctorApp.Utils
|
||||
}
|
||||
else if (DataParser.IsHistoricBikeData(messageBytes))
|
||||
{
|
||||
Debug.WriteLine("[DOCTOR CLIENT] got historic bike data: " + Encoding.ASCII.GetString(payloadbytes));
|
||||
|
||||
//todo read bytes, they are seperated in pairs of 8
|
||||
string result = "PATIENT INFO FOR " + ClientInfoViewModel.PatientInfo.Username + "\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) + "/" + ClientInfoViewModel.PatientInfo.Username + ".txt";
|
||||
File.WriteAllText(path,result);
|
||||
}
|
||||
Array.Copy(totalBuffer, expectedMessageLength, totalBuffer, 0, (totalBufferReceived - expectedMessageLength)); //maybe unsafe idk
|
||||
totalBufferReceived -= expectedMessageLength;
|
||||
@@ -147,11 +157,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], 2)}";
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -192,28 +192,15 @@ namespace Server
|
||||
string path = Directory.GetCurrentDirectory() + "/" + username + "/";
|
||||
string bytes = string.Empty;
|
||||
StringBuilder sb = new StringBuilder(bytes);
|
||||
int length = 0;
|
||||
try
|
||||
{
|
||||
DirectoryInfo dirInf = new DirectoryInfo(Directory.GetCurrentDirectory() + "/" + username + "/");
|
||||
DirectoryInfo[] directoryInfos = dirInf.GetDirectories();
|
||||
for (int i = directoryInfos.Length-1; i >= 0; i--)
|
||||
{
|
||||
DirectoryInfo latest = directoryInfos[directoryInfos.Length - 1];
|
||||
path = path + latest.Name + "/rawBike.bin";
|
||||
FileInfo fi = new FileInfo(path);
|
||||
|
||||
DirectoryInfo info = directoryInfos[i];
|
||||
string newPath = path + info.Name + "/rawBike.bin";
|
||||
Debug.WriteLine("[SERVER CLIENT] checking for " + newPath);
|
||||
|
||||
FileInfo fi = new FileInfo(newPath);
|
||||
length += (int)fi.Length;
|
||||
|
||||
if (length >= 1024) break;
|
||||
string append = Encoding.ASCII.GetString(File.ReadAllBytes(newPath));
|
||||
Debug.WriteLine("[SERVER CLIENT] appending " + append);
|
||||
sb.Append(append);
|
||||
if (i != 0) sb.Append("\n");
|
||||
|
||||
}
|
||||
if ((int)fi.Length >= 1024) return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -221,7 +208,7 @@ namespace Server
|
||||
}
|
||||
|
||||
Debug.WriteLine("[SERVER CLIENT] about to send " +sb.ToString());
|
||||
communication.Doctor.sendMessage(DataParser.GetFileMessage(Encoding.ASCII.GetBytes(sb.ToString())));
|
||||
communication.Doctor.sendMessage(DataParser.GetFileMessage(File.ReadAllBytes(path)));
|
||||
}
|
||||
|
||||
private bool handleLogin(byte[] payloadbytes)
|
||||
|
||||
Reference in New Issue
Block a user