Develop #10
@@ -6,6 +6,14 @@
|
|||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
|
<PackageReference Include="AsyncAwaitBestPractices.MVVM" Version="4.3.0" />
|
||||||
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
|
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
|
||||||
|
|||||||
@@ -123,13 +123,14 @@ namespace DoctorApp.Utils
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (DataParser.isRawData(messageBytes))
|
else if (DataParser.isRawDataBikeDoctor(messageBytes))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Received data: {BitConverter.ToString(payloadbytes)}");
|
MainViewModel.TransferDataToClientBike(payloadbytes);
|
||||||
|
}
|
||||||
|
else if (DataParser.isRawDataBPMDoctor(messageBytes))
|
||||||
|
{
|
||||||
|
MainViewModel.TransferDataToClientBPM(payloadbytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalBufferReceived -= expectedMessageLength;
|
|
||||||
expectedMessageLength = BitConverter.ToInt32(totalBuffer, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -76,6 +76,18 @@ namespace DoctorApp.ViewModels
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void BPMData(byte [] bytes)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//Parsen van de data you fuck
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BikeData(byte[] bytes)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//Parsen van de data you fuck
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using Util;
|
using Util;
|
||||||
@@ -51,6 +52,30 @@ namespace DoctorApp.ViewModels
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void TransferDataToClientBike(byte[] bytes)
|
||||||
|
{
|
||||||
|
string username = DataParser.getNameFromBytes(bytes);
|
||||||
|
foreach(ClientInfoViewModel item in Tabs)
|
||||||
|
{
|
||||||
|
if(item.Username == username)
|
||||||
|
{
|
||||||
|
item.BikeData(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TransferDataToClientBPM(byte[] bytes)
|
||||||
|
{
|
||||||
|
string username = DataParser.getNameFromBytes(bytes);
|
||||||
|
foreach (ClientInfoViewModel item in Tabs)
|
||||||
|
{
|
||||||
|
if (item.Username == username)
|
||||||
|
{
|
||||||
|
item.BikeData(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices.WindowsRuntime;
|
using System.Runtime.InteropServices.WindowsRuntime;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Util
|
namespace Util
|
||||||
@@ -68,6 +69,27 @@ namespace Util
|
|||||||
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
|
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string getNameFromBytesBike(byte[] bytes)
|
||||||
|
{
|
||||||
|
return ASCIIBytesToString(bytes, 8, bytes.Length - 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string getNameFromBytesBPM(byte[] bytes)
|
||||||
|
{
|
||||||
|
return ASCIIBytesToString(bytes, 2, bytes.Length - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ASCIIBytesToString(byte[] bytes, int offset, int length)
|
||||||
|
{
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
fixed (byte* pAscii = bytes)
|
||||||
|
{
|
||||||
|
return new String((sbyte*)pAscii, offset, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static bool GetUsernamePassword(byte[] jsonbytes, out string username, out string password)
|
public static bool GetUsernamePassword(byte[] jsonbytes, out string username, out string password)
|
||||||
{
|
{
|
||||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(jsonbytes));
|
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(jsonbytes));
|
||||||
@@ -146,7 +168,7 @@ namespace Util
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bytes">message</param>
|
/// <param name="bytes">message</param>
|
||||||
/// <returns>if message contains raw data</returns>
|
/// <returns>if message contains raw data</returns>
|
||||||
public static bool isRawData(byte[] bytes)
|
public static bool isRawDataBikeServer(byte[] bytes)
|
||||||
{
|
{
|
||||||
if (bytes.Length <= 5)
|
if (bytes.Length <= 5)
|
||||||
{
|
{
|
||||||
@@ -155,6 +177,34 @@ namespace Util
|
|||||||
return bytes[4] == 0x02;
|
return bytes[4] == 0x02;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool isRawDataBPMServer(byte[] bytes)
|
||||||
|
{
|
||||||
|
if (bytes.Length <= 5)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("bytes to short");
|
||||||
|
}
|
||||||
|
return bytes[4] == 0x03;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool isRawDataBikeDoctor(byte[] bytes)
|
||||||
|
{
|
||||||
|
if (bytes.Length <= 5)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("bytes to short");
|
||||||
|
}
|
||||||
|
return bytes[4] == 0x04;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool isRawDataBPMDoctor(byte[] bytes)
|
||||||
|
{
|
||||||
|
if (bytes.Length <= 5)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("bytes to short");
|
||||||
|
}
|
||||||
|
return bytes[4] == 0x05;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// constructs a message with the payload, messageId and clientId
|
/// constructs a message with the payload, messageId and clientId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -179,11 +229,34 @@ namespace Util
|
|||||||
/// <param name="payload"></param>
|
/// <param name="payload"></param>
|
||||||
/// <param name="clientId"></param>
|
/// <param name="clientId"></param>
|
||||||
/// <returns>the message ready for sending</returns>
|
/// <returns>the message ready for sending</returns>
|
||||||
public static byte[] GetRawDataMessage(byte[] payload)
|
public static byte[] GetRawBikeDataMessageServer(byte[] payload)
|
||||||
{
|
{
|
||||||
return getMessage(payload, 0x02);
|
return getMessage(payload, 0x02);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] GetRawBPMDataMessageServer(byte[] payload)
|
||||||
|
{
|
||||||
|
return getMessage(payload, 0x03);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] GetRawBikeDataDoctor(byte[] payload, string username)
|
||||||
|
{
|
||||||
|
|
||||||
|
return GetRawDataDoctor(payload, username, 0x04);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] GetRawBPMDataDoctor(byte[] payload, string username)
|
||||||
|
{
|
||||||
|
return GetRawDataDoctor(payload,username,0x05);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] GetRawDataDoctor(byte[] payload, string username, byte messageID)
|
||||||
|
{
|
||||||
|
|
||||||
|
return getMessage(payload.Concat(Encoding.ASCII.GetBytes(username)).ToArray(), messageID);
|
||||||
|
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// constructs a message with the payload and clientId and assumes the payload is json
|
/// constructs a message with the payload and clientId and assumes the payload is json
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -136,26 +136,16 @@ namespace Server
|
|||||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (DataParser.isRawData(message))
|
else if (DataParser.isRawDataBikeServer(message))
|
||||||
{
|
{
|
||||||
// print the raw data
|
saveData?.WriteDataRAWBike(payloadbytes);
|
||||||
//Console.WriteLine(BitConverter.ToString(payloadbytes));
|
|
||||||
// TODO change, checking for length is not that safe
|
|
||||||
if (payloadbytes.Length == 8)
|
|
||||||
{
|
|
||||||
saveData?.WriteDataRAWBike(payloadbytes);
|
|
||||||
}
|
|
||||||
else if (payloadbytes.Length == 2)
|
|
||||||
{
|
|
||||||
saveData?.WriteDataRAWBPM(payloadbytes);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("received raw data with weird lenght " + BitConverter.ToString(payloadbytes));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (DataParser.isRawDataBPMServer(message))
|
||||||
|
{
|
||||||
|
saveData?.WriteDataRAWBPM(payloadbytes);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool handleLogin(byte[] payloadbytes)
|
private bool handleLogin(byte[] payloadbytes)
|
||||||
|
|||||||
Reference in New Issue
Block a user