From 3494f678e32800f37d3bfab4f3f217d1beaf227b Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 30 Sep 2020 10:15:30 +0200 Subject: [PATCH 001/170] added doctor project --- DokterApp/App.xaml | 9 +++++++++ DokterApp/App.xaml.cs | 17 +++++++++++++++++ DokterApp/AssemblyInfo.cs | 10 ++++++++++ DokterApp/DokterApp.csproj | 9 +++++++++ DokterApp/MainWindow.xaml | 12 ++++++++++++ DokterApp/MainWindow.xaml.cs | 28 ++++++++++++++++++++++++++++ ProftaakRH/ProftaakRH.sln | 12 +++++++++--- 7 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 DokterApp/App.xaml create mode 100644 DokterApp/App.xaml.cs create mode 100644 DokterApp/AssemblyInfo.cs create mode 100644 DokterApp/DokterApp.csproj create mode 100644 DokterApp/MainWindow.xaml create mode 100644 DokterApp/MainWindow.xaml.cs diff --git a/DokterApp/App.xaml b/DokterApp/App.xaml new file mode 100644 index 0000000..3e19741 --- /dev/null +++ b/DokterApp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/DokterApp/App.xaml.cs b/DokterApp/App.xaml.cs new file mode 100644 index 0000000..965e4b2 --- /dev/null +++ b/DokterApp/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace DokterApp +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/DokterApp/AssemblyInfo.cs b/DokterApp/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/DokterApp/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/DokterApp/DokterApp.csproj b/DokterApp/DokterApp.csproj new file mode 100644 index 0000000..6c68d0e --- /dev/null +++ b/DokterApp/DokterApp.csproj @@ -0,0 +1,9 @@ + + + + WinExe + netcoreapp3.1 + true + + + \ No newline at end of file diff --git a/DokterApp/MainWindow.xaml b/DokterApp/MainWindow.xaml new file mode 100644 index 0000000..5ce5844 --- /dev/null +++ b/DokterApp/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/DokterApp/MainWindow.xaml.cs b/DokterApp/MainWindow.xaml.cs new file mode 100644 index 0000000..9215b9b --- /dev/null +++ b/DokterApp/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DokterApp +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/ProftaakRH/ProftaakRH.sln b/ProftaakRH/ProftaakRH.sln index 069a13b..f2df07f 100644 --- a/ProftaakRH/ProftaakRH.sln +++ b/ProftaakRH/ProftaakRH.sln @@ -7,11 +7,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProftaakRH", "ProftaakRH.cs EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RH-Engine", "..\RH-Engine\RH-Engine.csproj", "{984E295E-47A2-41E7-90E5-50FDB9E67694}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "..\Server\Server.csproj", "{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "..\Server\Server.csproj", "{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "..\Client\Client.csproj", "{5759DD20-7A4F-4D8D-B986-A70A7818C112}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "..\Client\Client.csproj", "{5759DD20-7A4F-4D8D-B986-A70A7818C112}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Message", "..\Message\Message.csproj", "{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Message", "..\Message\Message.csproj", "{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DokterApp", "..\DokterApp\DokterApp.csproj", "{B150F08B-13DA-4D17-BD96-7E89F52727C6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU {9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU {9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Release|Any CPU.Build.0 = Release|Any CPU + {B150F08B-13DA-4D17-BD96-7E89F52727C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B150F08B-13DA-4D17-BD96-7E89F52727C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B150F08B-13DA-4D17-BD96-7E89F52727C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B150F08B-13DA-4D17-BD96-7E89F52727C6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.47.2 From c5b9a7ec091369d3198c30daf8fada9c6436caa4 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 30 Sep 2020 11:44:00 +0200 Subject: [PATCH 002/170] made rh engine classes public --- Client/Client.csproj | 1 + Client/Program.cs | 1 + RH-Engine/Command.cs | 2 +- RH-Engine/JSONParser.cs | 2 +- RH-Engine/Program.cs | 19 +------------------ 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/Client/Client.csproj b/Client/Client.csproj index dd9af6e..4ade6d5 100644 --- a/Client/Client.csproj +++ b/Client/Client.csproj @@ -12,6 +12,7 @@ + diff --git a/Client/Program.cs b/Client/Program.cs index 7b722f5..9853e51 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -1,6 +1,7 @@ using System; using Hardware; using Hardware.Simulators; +using RH_Engine; namespace Client { diff --git a/RH-Engine/Command.cs b/RH-Engine/Command.cs index 3ef3bc1..0f53e73 100644 --- a/RH-Engine/Command.cs +++ b/RH-Engine/Command.cs @@ -4,7 +4,7 @@ using System; namespace RH_Engine { - class Command + public class Command { public const string STANDARD_HEAD = "Head"; public const string STANDARD_GROUND = "GroundPlane"; diff --git a/RH-Engine/JSONParser.cs b/RH-Engine/JSONParser.cs index 8621aff..292c524 100644 --- a/RH-Engine/JSONParser.cs +++ b/RH-Engine/JSONParser.cs @@ -3,7 +3,7 @@ using System; namespace RH_Engine { - class JSONParser + public class JSONParser { /// /// returns all the users from the given response diff --git a/RH-Engine/Program.cs b/RH-Engine/Program.cs index 63c86fb..e67206a 100644 --- a/RH-Engine/Program.cs +++ b/RH-Engine/Program.cs @@ -10,7 +10,7 @@ namespace RH_Engine { public delegate void HandleSerial(string message); - class Program + public class Program { private static PC[] PCs = { //new PC("DESKTOP-M2CIH87", "Fabian"), @@ -161,23 +161,6 @@ namespace RH_Engine }); Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand)); - - //command = mainCommand.AddModel("car", "data\\customModels\\TeslaRoadster.fbx"); - //WriteTextMessage(stream, command); - - //command = mainCommand.addPanel(); - // WriteTextMessage(stream, command); - // string response = ReadPrefMessage(stream); - // Console.WriteLine("add Panel response: \n\r" + response); - // string uuidPanel = JSONParser.getPanelID(response); - // WriteTextMessage(stream, mainCommand.ClearPanel(uuidPanel)); - // Console.WriteLine(ReadPrefMessage(stream)); - // WriteTextMessage(stream, mainCommand.bikeSpeed(uuidPanel, 2.42)); - // Console.WriteLine(ReadPrefMessage(stream)); - // WriteTextMessage(stream, mainCommand.ColorPanel(uuidPanel)); - // Console.WriteLine("Color panel: " + ReadPrefMessage(stream)); - // WriteTextMessage(stream, mainCommand.SwapPanel(uuidPanel)); - // Console.WriteLine("Swap panel: " + ReadPrefMessage(stream)); } /// -- 2.47.2 From cc7f2d154c069d0957d9f28dbee731956e2a54cd Mon Sep 17 00:00:00 2001 From: fabjuuuh Date: Wed, 30 Sep 2020 11:52:38 +0200 Subject: [PATCH 003/170] wpf --- DokterApp/Homepage.xaml | 14 ++++++++++++++ DokterApp/Homepage.xaml.cs | 26 ++++++++++++++++++++++++++ DokterApp/MainWindow.xaml | 20 ++++++++++++++++++-- DokterApp/MainWindow.xaml.cs | 12 ++++++++++++ DokterApp/UserControl.xaml | 12 ++++++++++++ DokterApp/UserControl.xaml.cs | 26 ++++++++++++++++++++++++++ Server/SaveData.cs | 2 +- 7 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 DokterApp/Homepage.xaml create mode 100644 DokterApp/Homepage.xaml.cs create mode 100644 DokterApp/UserControl.xaml create mode 100644 DokterApp/UserControl.xaml.cs diff --git a/DokterApp/Homepage.xaml b/DokterApp/Homepage.xaml new file mode 100644 index 0000000..3431c04 --- /dev/null +++ b/DokterApp/Homepage.xaml @@ -0,0 +1,14 @@ + + + + + + diff --git a/DokterApp/Homepage.xaml.cs b/DokterApp/Homepage.xaml.cs new file mode 100644 index 0000000..4e94a78 --- /dev/null +++ b/DokterApp/Homepage.xaml.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DokterApp +{ + /// + /// Interaction logic for Homepage.xaml + /// + public partial class Homepage : Page + { + public Homepage() + { + InitializeComponent(); + } + } +} diff --git a/DokterApp/MainWindow.xaml b/DokterApp/MainWindow.xaml index 5ce5844..d1cf291 100644 --- a/DokterApp/MainWindow.xaml +++ b/DokterApp/MainWindow.xaml @@ -5,8 +5,24 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:DokterApp" mc:Ignorable="d" - Title="MainWindow" Height="450" Width="800"> - + WindowState="Maximized" + Title="Dokter App" > + + + + + + + + + + + /// the network stream to use - private void CreateConnection() + public void CreateConnection() { - initReader(); WriteTextMessage( "{\r\n\"id\" : \"session/list\",\r\n\"serial\" : \"list\"\r\n}"); @@ -119,6 +121,8 @@ namespace Client if (tunnelId == null) { Write("could not find a valid tunnel id!"); + OnNoTunnelId?.Invoke(); + Connected = false; return; } } -- 2.47.2 From f777b583f530945301c857c4e41aeea9120d81a5 Mon Sep 17 00:00:00 2001 From: fabjuuuh Date: Wed, 30 Sep 2020 14:37:40 +0200 Subject: [PATCH 016/170] progress --- DokterApp/ITab.cs | 28 ++++++++++++++++++++++++++++ DokterApp/UserControlForTab.xaml.cs | 1 + DokterApp/UserTab.cs | 14 ++++++++++++++ DokterApp/WindowTabs.xaml | 9 ++------- DokterApp/WindowTabs.xaml.cs | 18 ++++++++++++++++++ ProftaakRH/ProftaakRH.sln | 2 +- 6 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 DokterApp/ITab.cs create mode 100644 DokterApp/UserTab.cs diff --git a/DokterApp/ITab.cs b/DokterApp/ITab.cs new file mode 100644 index 0000000..c01f9ad --- /dev/null +++ b/DokterApp/ITab.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Input; + +namespace DokterApp +{ + public interface ITab + { + string Name { get; set; } + ICommand CloseCommand { get; } + event EventHandler CloseRequested; + } + + public abstract class Tab : ITab + { + public string Name { get; set; } + public ICommand CloseCommand { get; } + public event EventHandler CloseRequested; + + public Tab() + { + //CloseCommand = + } + + } + +} diff --git a/DokterApp/UserControlForTab.xaml.cs b/DokterApp/UserControlForTab.xaml.cs index 2c34c55..6e30162 100644 --- a/DokterApp/UserControlForTab.xaml.cs +++ b/DokterApp/UserControlForTab.xaml.cs @@ -22,5 +22,6 @@ namespace DokterApp { InitializeComponent(); } + } } diff --git a/DokterApp/UserTab.cs b/DokterApp/UserTab.cs new file mode 100644 index 0000000..d24e593 --- /dev/null +++ b/DokterApp/UserTab.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace DokterApp +{ + class UserTab : Tab + { + public UserTab() + { + Name = "Piet"; + } + } +} diff --git a/DokterApp/WindowTabs.xaml b/DokterApp/WindowTabs.xaml index 0ba52cf..bf7a45e 100644 --- a/DokterApp/WindowTabs.xaml +++ b/DokterApp/WindowTabs.xaml @@ -7,14 +7,9 @@ mc:Ignorable="d" Title="WindowTabs" Height="450" Width="800"> - - - - - - - + + public partial class WindowTabs : Window { + public TabControl tbControl; public WindowTabs() { InitializeComponent(); } + + private void tabControl_Load(object sender, RoutedEventArgs e) + { + this.tbControl = (sender as TabControl); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + TabItem newTabItem = new TabItem + { + Header = "Test", + + }; + newTabItem.Content = new UserControlForTab(); + this.tbControl.Items.Add(newTabItem); + } } } diff --git a/ProftaakRH/ProftaakRH.sln b/ProftaakRH/ProftaakRH.sln index f2df07f..5d13d46 100644 --- a/ProftaakRH/ProftaakRH.sln +++ b/ProftaakRH/ProftaakRH.sln @@ -13,7 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "..\Client\Client. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Message", "..\Message\Message.csproj", "{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DokterApp", "..\DokterApp\DokterApp.csproj", "{B150F08B-13DA-4D17-BD96-7E89F52727C6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DokterApp", "..\DokterApp\DokterApp.csproj", "{B150F08B-13DA-4D17-BD96-7E89F52727C6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution -- 2.47.2 From 97f9d863aa07b7af85b11097a361d83469c76d67 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 30 Sep 2020 15:10:47 +0200 Subject: [PATCH 017/170] fix --- Client/EngineConnection.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Client/EngineConnection.cs b/Client/EngineConnection.cs index 8b62c10..655e073 100644 --- a/Client/EngineConnection.cs +++ b/Client/EngineConnection.cs @@ -86,7 +86,10 @@ namespace Client // wait until we have a tunnel id while (tunnelId == string.Empty) { } - Write("got tunnel id! " + tunnelId); + if (tunnelId != null) + { + Write("got tunnel id! " + tunnelId); + } mainCommand = new Command(tunnelId); } -- 2.47.2 From bd8994ad5b2db24ae1af97ef1876246c0c7a7527 Mon Sep 17 00:00:00 2001 From: shinichi Date: Wed, 30 Sep 2020 15:12:10 +0200 Subject: [PATCH 018/170] added start and stop session --- Client/Client.cs | 21 ++++++++++++++++++++- Client/DataParser.cs | 20 +++++++++++++++++++- Server/Client.cs | 13 ++++++++++--- Server/SaveData.cs | 10 ++++------ 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/Client/Client.cs b/Client/Client.cs index e65204f..ca6b53f 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -15,6 +15,7 @@ namespace Client private byte[] totalBuffer = new byte[1024]; private int totalBufferReceived = 0; private EngineConnection engineConnection; + private bool sessionRunning = false; public Client() : this("localhost", 5555) @@ -40,7 +41,7 @@ namespace Client private void OnConnect(IAsyncResult ar) { this.client.EndConnect(ar); - Console.WriteLine("Verbonden!"); + Console.WriteLine("TCP client Verbonden!"); this.stream = this.client.GetStream(); @@ -91,6 +92,16 @@ namespace Client tryLogin(); } break; + case DataParser.START_SESSION: + this.sessionRunning = true; + byte[] startSession = DataParser.getStartSessionJson(); + stream.BeginWrite(startSession, 0, startSession.Length, new AsyncCallback(OnWrite), null); + break; + case DataParser.STOP_SESSION: + this.sessionRunning = false; + byte[] stopSession = DataParser.getStopSessionJson(); + stream.BeginWrite(stopSession, 0, stopSession.Length, new AsyncCallback(OnWrite), null); + break; default: Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}"); break; @@ -118,6 +129,10 @@ namespace Client //maybe move this to other place public void BPM(byte[] bytes) { + if (!sessionRunning) + { + return; + } if (bytes == null) { throw new ArgumentNullException("no bytes"); @@ -128,6 +143,10 @@ namespace Client public void Bike(byte[] bytes) { + if (!sessionRunning) + { + return; + } if (bytes == null) { throw new ArgumentNullException("no bytes"); diff --git a/Client/DataParser.cs b/Client/DataParser.cs index c83b86a..fd1c7e8 100644 --- a/Client/DataParser.cs +++ b/Client/DataParser.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json.Serialization; using System; using System.Globalization; using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; using System.Text; namespace Client @@ -10,7 +11,9 @@ namespace Client public class DataParser { public const string LOGIN = "LOGIN"; - public const string LOGIN_RESPONSE = "LOGIN_RESPONSE"; + public const string LOGIN_RESPONSE = "LOGIN RESPONSE"; + public const string START_SESSION = "START SESSION"; + public const string STOP_SESSION = "STOP SESSION"; /// /// makes the json object with LOGIN identifier and username and password /// @@ -161,6 +164,21 @@ namespace Client return getJsonMessage(Encoding.ASCII.GetBytes(message)); } + public static byte[] getStartSessionJson() + { + return getJsonMessage(START_SESSION, null); + } + + public static byte[] getStopSessionJson() + { + return getJsonMessage(STOP_SESSION, null); + } + + public static byte[] getSetResistanceJson() + { + return null; + } + } } diff --git a/Server/Client.cs b/Server/Client.cs index fc4baca..1b357be 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -105,7 +105,8 @@ namespace Server this.username = username; byte[] response = DataParser.getLoginResponse("OK"); stream.BeginWrite(response, 0, response.Length, new AsyncCallback(OnWrite), null); - this.saveData = new SaveData(Directory.GetCurrentDirectory() + "/" + username, sessionStart.ToString("yyyy-MM-dd HH-mm-ss")); + byte[] startSession = DataParser.getStartSessionJson(); + stream.BeginWrite(startSession, 0, startSession.Length, new AsyncCallback(OnWrite), null); } else { @@ -119,6 +120,12 @@ namespace Server stream.BeginWrite(response, 0, response.Length, new AsyncCallback(OnWrite), null); } break; + case DataParser.START_SESSION: + this.saveData = new SaveData(Directory.GetCurrentDirectory() + "/" + this.username + "/" + sessionStart.ToString("yyyy-MM-dd HH-mm-ss")); + break; + case DataParser.STOP_SESSION: + this.saveData = null; + break; default: Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}"); break; @@ -130,11 +137,11 @@ namespace Server Console.WriteLine(BitConverter.ToString(payloadbytes)); if (payloadbytes.Length == 8) { - saveData.WriteDataRAWBike(payloadbytes); + saveData?.WriteDataRAWBike(payloadbytes); } else if (payloadbytes.Length == 2) { - saveData.WriteDataRAWBPM(payloadbytes); + saveData?.WriteDataRAWBPM(payloadbytes); } else { diff --git a/Server/SaveData.cs b/Server/SaveData.cs index 4163471..15fd0d4 100644 --- a/Server/SaveData.cs +++ b/Server/SaveData.cs @@ -8,11 +8,9 @@ namespace Server class SaveData { private string path; - private string filename; - public SaveData(string path, string filename) + public SaveData(string path) { this.path = path; - this.filename = filename; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); @@ -25,7 +23,7 @@ namespace Server public void WriteDataJSON(string data) { - using (StreamWriter sw = File.AppendText(this.path + "/json" + filename + ".txt")) + using (StreamWriter sw = File.AppendText(this.path + "/json" + ".txt")) { sw.WriteLine(data); } @@ -37,7 +35,7 @@ namespace Server { throw new ArgumentException("data should have length of 2"); } - WriteRawData(data, this.path + "/rawBPM" + filename + ".bin"); + WriteRawData(data, this.path + "/rawBPM" + ".bin"); } public void WriteDataRAWBike(byte[] data) @@ -46,7 +44,7 @@ namespace Server { throw new ArgumentException("data should have length of 8"); } - WriteRawData(data, this.path + "/rawBike" + filename + ".bin"); + WriteRawData(data, this.path + "/rawBike" + ".bin"); } private void WriteRawData(byte[] data, string fileLocation) -- 2.47.2 From 599b79ceee69c3ff8701b75917547b0bf3fadaa2 Mon Sep 17 00:00:00 2001 From: shinichi Date: Wed, 30 Sep 2020 15:26:34 +0200 Subject: [PATCH 019/170] correctly implemented IHandler --- Client/DataParser.cs | 38 +++++++++++++++++++++-------------- ProftaakRH/BLEHandler.cs | 2 +- ProftaakRH/BikeSimulator.cs | 40 +++---------------------------------- ProftaakRH/IHandler.cs | 11 ++++++++++ 4 files changed, 38 insertions(+), 53 deletions(-) create mode 100644 ProftaakRH/IHandler.cs diff --git a/Client/DataParser.cs b/Client/DataParser.cs index fd1c7e8..5289c63 100644 --- a/Client/DataParser.cs +++ b/Client/DataParser.cs @@ -14,6 +14,7 @@ namespace Client public const string LOGIN_RESPONSE = "LOGIN RESPONSE"; public const string START_SESSION = "START SESSION"; public const string STOP_SESSION = "STOP SESSION"; + public const string SET_RESISTANCE = "SET RESISTANCE"; /// /// makes the json object with LOGIN identifier and username and password /// @@ -62,6 +63,15 @@ namespace Client return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01); } + private static byte[] getJsonMessage(string mIdentifier) + { + dynamic json = new + { + identifier = mIdentifier, + }; + return getMessage(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json)), 0x01); + } + public static byte[] getLoginResponse(string mStatus) { return getJsonMessage(LOGIN_RESPONSE, new { status = mStatus }); @@ -153,30 +163,28 @@ namespace Client return getMessage(payload, 0x01); } - /// - /// constructs a message with the message and clientId - /// - /// - /// - /// the message ready for sending - public static byte[] getJsonMessage(string message) - { - return getJsonMessage(Encoding.ASCII.GetBytes(message)); - } - public static byte[] getStartSessionJson() { - return getJsonMessage(START_SESSION, null); + return getJsonMessage(START_SESSION); } public static byte[] getStopSessionJson() { - return getJsonMessage(STOP_SESSION, null); + return getJsonMessage(STOP_SESSION); } - public static byte[] getSetResistanceJson() + public static byte[] getSetResistanceJson(float mResistance) { - return null; + dynamic data = new + { + resistance = mResistance + }; + return getJsonMessage(SET_RESISTANCE, data); + } + + public static float getResistanceFromJson(byte[] json) + { + return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.resistance; } diff --git a/ProftaakRH/BLEHandler.cs b/ProftaakRH/BLEHandler.cs index 6baf843..56de648 100644 --- a/ProftaakRH/BLEHandler.cs +++ b/ProftaakRH/BLEHandler.cs @@ -11,7 +11,7 @@ namespace Hardware /// /// BLEHandler class that handles connection and traffic to and from the bike /// - public class BLEHandler + public class BLEHandler : IHandler { List dataReceivers; private BLE bleBike; diff --git a/ProftaakRH/BikeSimulator.cs b/ProftaakRH/BikeSimulator.cs index daea355..3d11209 100644 --- a/ProftaakRH/BikeSimulator.cs +++ b/ProftaakRH/BikeSimulator.cs @@ -98,32 +98,7 @@ namespace Hardware.Simulators return hartByte; } - //Generate an ANT message for resistance - public byte[] GenerateResistance(float percentage) - { - byte[] antMessage = new byte[13]; - antMessage[0] = 0x4A; - antMessage[1] = 0x09; - antMessage[2] = 0x4E; - antMessage[3] = 0x05; - antMessage[4] = 0x30; - for (int i = 5; i < 11; i++) - { - antMessage[i] = 0xFF; - } - antMessage[11] = (byte)Math.Max(Math.Min(Math.Round(percentage / 0.5), 255), 0); - //antMessage[11] = 50; //hardcoded for testing - byte checksum = 0; - for (int i = 0; i < 12; i++) - { - checksum ^= antMessage[i]; - } - - antMessage[12] = checksum;//reminder that i am dumb :P - - return antMessage; - } //Calculates the needed variables //Input perlin value @@ -143,20 +118,11 @@ namespace Hardware.Simulators } //Set resistance in simulated bike - public void setResistance(byte[] bytes) + public void setResistance(float percentage) { - //TODO check if message is correct - if (bytes.Length == 13) - { - this.resistance = Convert.ToDouble(bytes[11]) / 2; - } + this.resistance = (byte)Math.Max(Math.Min(Math.Round(percentage / 0.5), 255), 0); } - } - - //Interface for receiving a message on the simulated bike - interface IHandler - { - void setResistance(byte[] bytes); } + } diff --git a/ProftaakRH/IHandler.cs b/ProftaakRH/IHandler.cs new file mode 100644 index 0000000..c1ce11e --- /dev/null +++ b/ProftaakRH/IHandler.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ProftaakRH +{ + interface IHandler + { + void setResistance(float percentage); + } +} -- 2.47.2 From c20a1b292ed5a5daf28b6d63e58ebd7d0c9fb07a Mon Sep 17 00:00:00 2001 From: wouter Date: Wed, 30 Sep 2020 16:08:35 +0200 Subject: [PATCH 020/170] upgraded doktor stuff --- DokterApp/UserControlForTab.xaml | 73 +++++++++++++++++++---------- DokterApp/UserControlForTab.xaml.cs | 32 +++++++++++++ DokterApp/WindowTabs.xaml | 7 +-- DokterApp/WindowTabs.xaml.cs | 3 +- 4 files changed, 87 insertions(+), 28 deletions(-) diff --git a/DokterApp/UserControlForTab.xaml b/DokterApp/UserControlForTab.xaml index 5b1b2d0..f45a03f 100644 --- a/DokterApp/UserControlForTab.xaml +++ b/DokterApp/UserControlForTab.xaml @@ -6,37 +6,62 @@ xmlns:local="clr-namespace:DokterApp" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> - + - - - + + + + - -