diff --git a/ClientApp/ClientApp.csproj b/ClientApp/ClientApp.csproj index 637f86c..13750b2 100644 --- a/ClientApp/ClientApp.csproj +++ b/ClientApp/ClientApp.csproj @@ -7,6 +7,14 @@ Images\Logo\icon1.ico + + true + + + + true + + diff --git a/ClientApp/Utils/Client.cs b/ClientApp/Utils/Client.cs index 69f9f1b..bebc366 100644 --- a/ClientApp/Utils/Client.cs +++ b/ClientApp/Utils/Client.cs @@ -164,10 +164,10 @@ namespace ClientApp.Utils break; } } - else if (DataParser.isRawData(messageBytes)) + /*else if (DataParser.isRawData(messageBytes)) { Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}"); - } + }*/ totalBufferReceived -= expectedMessageLength; expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0); @@ -211,7 +211,7 @@ namespace ClientApp.Utils { throw new ArgumentNullException("no bytes"); } - byte[] message = DataParser.GetRawDataMessage(bytes); + byte[] message = DataParser.GetRawBPMDataMessageServer(bytes); if (engineConnection.Connected && engineConnection.FollowingRoute) { @@ -238,7 +238,7 @@ namespace ClientApp.Utils { throw new ArgumentNullException("no bytes"); } - byte[] message = DataParser.GetRawDataMessage(bytes); + byte[] message = DataParser.GetRawBikeDataMessageServer(bytes); bool canSendToEngine = engineConnection.Connected && engineConnection.FollowingRoute; switch (bytes[0]) { diff --git a/DoctorApp/ViewModels/ClientInfoViewModel.cs b/DoctorApp/ViewModels/ClientInfoViewModel.cs index faccc0a..d186d78 100644 --- a/DoctorApp/ViewModels/ClientInfoViewModel.cs +++ b/DoctorApp/ViewModels/ClientInfoViewModel.cs @@ -19,11 +19,11 @@ namespace DoctorApp.ViewModels public string Status { get; set; } - public int Speed { get; set; } + public double Speed { get; set; } public int BPM { get; set; } - public int Resistance { get; set; } + public float Resistance { get; set; } public int Acc_Power { get; set; } public int Curr_Power { get; set; } @@ -71,7 +71,8 @@ namespace DoctorApp.ViewModels SetResistance = new RelayCommand((parameter) => { - client.sendMessage(DataParser.getSetResistanceJson(Username, float.Parse(((TextBox)parameter).Text))); + client.sendMessage(DataParser.getSetResistanceJson(Username, float.Parse(((TextBox)parameter).Text))); + this.Resistance = float.Parse(((TextBox)parameter).Text); }); } @@ -80,12 +81,31 @@ namespace DoctorApp.ViewModels { //TODO //Parsen van de data you fuck + this.BPM = bytes[1]; } public void BikeData(byte[] bytes) { //TODO //Parsen van de data you fuck + switch (bytes[0]) + { + case 0x10: + if (bytes[1] != 25) + { + throw new Exception(); + } + this.Distance = bytes[3]; + this.Speed = (bytes[4] | (bytes[5] << 8)) * 0.01; + break; + case 0x19: + this.Acc_Power = bytes[3] | (bytes[4] << 8); + this.Curr_Power = (bytes[5]) | (bytes[6] & 0b00001111) << 8; + break; + default: + throw new Exception(); + } + } diff --git a/DoctorApp/ViewModels/MainViewModel.cs b/DoctorApp/ViewModels/MainViewModel.cs index 64df762..d245e2f 100644 --- a/DoctorApp/ViewModels/MainViewModel.cs +++ b/DoctorApp/ViewModels/MainViewModel.cs @@ -55,7 +55,7 @@ namespace DoctorApp.ViewModels public void TransferDataToClientBike(byte[] bytes) { - string username = DataParser.getNameFromBytes(bytes); + string username = DataParser.getNameFromBytesBike(bytes); foreach(ClientInfoViewModel item in Tabs) { if(item.Username == username) @@ -67,7 +67,7 @@ namespace DoctorApp.ViewModels public void TransferDataToClientBPM(byte[] bytes) { - string username = DataParser.getNameFromBytes(bytes); + string username = DataParser.getNameFromBytesBPM(bytes); foreach (ClientInfoViewModel item in Tabs) { if (item.Username == username) diff --git a/Hashing/DataParser.cs b/Hashing/DataParser.cs index 44141dc..ed132cd 100644 --- a/Hashing/DataParser.cs +++ b/Hashing/DataParser.cs @@ -54,6 +54,8 @@ namespace Util return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)); } + + public static byte[] LoginAsDoctor(string mUsername, string mPassword) { dynamic json = new @@ -81,13 +83,9 @@ namespace Util private static string ASCIIBytesToString(byte[] bytes, int offset, int length) { - unsafe - { - fixed (byte* pAscii = bytes) - { - return new String((sbyte*)pAscii, offset, length); - } - } + byte[] nameArray = new byte[length]; + Array.Copy(bytes, offset, nameArray, 0, length); + return Encoding.UTF8.GetString(nameArray); } public static bool GetUsernamePassword(byte[] jsonbytes, out string username, out string password)