[ADD] added writing contents to file
This commit is contained in:
@@ -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; }
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
@@ -123,9 +125,6 @@ namespace DoctorApp.Utils
|
|||||||
}
|
}
|
||||||
else if (DataParser.isRawDataBikeDoctor(messageBytes))
|
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);
|
MainViewModel.TransferDataToClientBike(payloadbytes);
|
||||||
}
|
}
|
||||||
else if (DataParser.isRawDataBPMDoctor(messageBytes))
|
else if (DataParser.isRawDataBPMDoctor(messageBytes))
|
||||||
@@ -134,7 +133,18 @@ namespace DoctorApp.Utils
|
|||||||
}
|
}
|
||||||
else if (DataParser.IsHistoricBikeData(messageBytes))
|
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
|
Array.Copy(totalBuffer, expectedMessageLength, totalBuffer, 0, (totalBufferReceived - expectedMessageLength)); //maybe unsafe idk
|
||||||
totalBufferReceived -= expectedMessageLength;
|
totalBufferReceived -= expectedMessageLength;
|
||||||
@@ -147,11 +157,40 @@ namespace DoctorApp.Utils
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private string handleBikeHistory(byte[] bytes)
|
||||||
/// starts sending a message to the server
|
{
|
||||||
/// </summary>
|
string res = string.Empty;
|
||||||
/// <param name="message">the message to send</param>
|
switch (bytes[0])
|
||||||
public void sendMessage(byte[] message)
|
{
|
||||||
|
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);
|
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,28 +192,15 @@ namespace Server
|
|||||||
string path = Directory.GetCurrentDirectory() + "/" + username + "/";
|
string path = Directory.GetCurrentDirectory() + "/" + username + "/";
|
||||||
string bytes = string.Empty;
|
string bytes = string.Empty;
|
||||||
StringBuilder sb = new StringBuilder(bytes);
|
StringBuilder sb = new StringBuilder(bytes);
|
||||||
int length = 0;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DirectoryInfo dirInf = new DirectoryInfo(Directory.GetCurrentDirectory() + "/" + username + "/");
|
DirectoryInfo dirInf = new DirectoryInfo(Directory.GetCurrentDirectory() + "/" + username + "/");
|
||||||
DirectoryInfo[] directoryInfos = dirInf.GetDirectories();
|
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];
|
if ((int)fi.Length >= 1024) return;
|
||||||
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");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -221,7 +208,7 @@ namespace Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
Debug.WriteLine("[SERVER CLIENT] about to send " +sb.ToString());
|
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)
|
private bool handleLogin(byte[] payloadbytes)
|
||||||
|
|||||||
Reference in New Issue
Block a user