diff --git a/Client/Client.cs b/Client/Client.cs index b4e605d..9115f01 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -31,6 +31,9 @@ namespace Client client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null); } + /// + /// initializes the VR engine and sets the callbacks + /// private void initEngine() { engineConnection = EngineConnection.INSTANCE; @@ -38,6 +41,9 @@ namespace Client if (!engineConnection.Connected) engineConnection.Connect(); } + /// + /// retries to connect to the VR engine if no tunnel id was found + /// private void retryEngineConnection() { Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!"); @@ -47,6 +53,10 @@ namespace Client engineConnection.CreateConnection(); } + /// + /// callback method for when the TCP client is connected + /// + /// the result of the async read private void OnConnect(IAsyncResult ar) { this.client.EndConnect(ar); @@ -60,6 +70,10 @@ namespace Client this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null); } + /// + /// callback method for when there is a message read + /// + /// the result of the async read private void OnRead(IAsyncResult ar) { int receivedBytes = this.stream.EndRead(ar); @@ -93,6 +107,7 @@ namespace Client string responseStatus = DataParser.getResponseStatus(payloadbytes); if (responseStatus == "OK") { + Console.WriteLine("Username and password correct!"); this.connected = true; initEngine(); } @@ -103,7 +118,7 @@ namespace Client } break; case DataParser.START_SESSION: - Console.WriteLine("Start session identifier"); + Console.WriteLine("Session started!"); this.sessionRunning = true; sendMessage(DataParser.getStartSessionJson()); break; @@ -143,11 +158,19 @@ namespace Client } + /// + /// starts sending a message to the server + /// + /// the message to send private void sendMessage(byte[] message) { stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); } + /// + /// callback method for when a message is fully written to the server + /// + /// the async result representing the asynchronous call private void OnWrite(IAsyncResult ar) { this.stream.EndWrite(ar); @@ -155,6 +178,10 @@ namespace Client #region interface //maybe move this to other place + /// + /// bpm method for receiving the BPM value from the bluetooth bike or the simulation + /// + /// the message public void BPM(byte[] bytes) { if (!sessionRunning) @@ -166,9 +193,14 @@ namespace Client throw new ArgumentNullException("no bytes"); } byte[] message = DataParser.GetRawDataMessage(bytes); + Console.WriteLine("got bpm message: " + message); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); } + /// + /// method for receiving the bike message from the bluetooth bike or the simulation + /// + /// the message public void Bike(byte[] bytes) { if (!sessionRunning) @@ -180,15 +212,23 @@ namespace Client throw new ArgumentNullException("no bytes"); } byte[] message = DataParser.GetRawDataMessage(bytes); + Console.WriteLine("got bike message: " + message); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); } #endregion + /// + /// wether or not the client stream is connected + /// + /// true if it's connected, false if not public bool IsConnected() { return this.connected; } + /// + /// tries to log in to the server by asking for a username and password + /// private void tryLogin() { //TODO File in lezen @@ -206,6 +246,10 @@ namespace Client this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); } + /// + /// sets the handler for the client, so either the bike simulator or the bluetooth bike handler + /// + /// public void setHandler(IHandler handler) { this.handler = handler; diff --git a/Client/Program.cs b/Client/Program.cs index 89ed605..303b929 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -21,18 +21,18 @@ namespace Client { } - BLEHandler bLEHandler = new BLEHandler(client); + //BLEHandler bLEHandler = new BLEHandler(client); - bLEHandler.Connect(); + //bLEHandler.Connect(); - client.setHandler(bLEHandler); + //client.setHandler(bLEHandler); - //BikeSimulator bikeSimulator = new BikeSimulator(client); + BikeSimulator bikeSimulator = new BikeSimulator(client); - //bikeSimulator.StartSimulation(); + bikeSimulator.StartSimulation(); - //client.setHandler(bikeSimulator); + client.setHandler(bikeSimulator); while (true) { diff --git a/ProftaakRH/BLEHandler.cs b/ProftaakRH/BLEHandler.cs index 269b0a1..c368072 100644 --- a/ProftaakRH/BLEHandler.cs +++ b/ProftaakRH/BLEHandler.cs @@ -44,6 +44,7 @@ namespace Hardware /// public void Connect() { + BLE bleBike = new BLE(); Thread.Sleep(1000); // We need some time to list available devices diff --git a/ProftaakRH/BikeSimulator.cs b/ProftaakRH/BikeSimulator.cs index 3d11209..4dad948 100644 --- a/ProftaakRH/BikeSimulator.cs +++ b/ProftaakRH/BikeSimulator.cs @@ -47,6 +47,7 @@ namespace Hardware.Simulators public void StartSimulation() { + Console.WriteLine("simulating bike..."); //Example BLE Message //4A-09-4E-05-19-16-00-FF-28-00-00-20-F0 diff --git a/RH-Engine/Command.cs b/RH-Engine/Command.cs index 110965f..3875448 100644 --- a/RH-Engine/Command.cs +++ b/RH-Engine/Command.cs @@ -106,8 +106,21 @@ namespace RH_Engine data = new { name = "dashboard", + parent = uuidBike, components = new { + transform = new + { + position = new float[] + { + -1.5f, 1f, 0f + }, + scale = 1, + rotation = new int[] + { + -30, 90,0 + } + }, panel = new { size = new int[] { 1, 1 }, @@ -130,7 +143,7 @@ namespace RH_Engine data = new { id = uuidPanel, - color = new int[] { 1, 1, 1, 1 } + color = new float[] { 0f, 0f, 0f, 0f } } }; diff --git a/RH-Engine/Program.cs b/RH-Engine/Program.cs index 7bd7770..ae25339 100644 --- a/RH-Engine/Program.cs +++ b/RH-Engine/Program.cs @@ -17,9 +17,9 @@ namespace RH_Engine //new PC("DESKTOP-M2CIH87", "Fabian"), //new PC("T470S", "Shinichi"), //new PC("DESKTOP-DHS478C", "semme"), - //new PC("HP-ZBOOK-SEM", "Sem"), + new PC("HP-ZBOOK-SEM", "Sem"), //new PC("DESKTOP-TV73FKO", "Wouter"), - new PC("DESKTOP-SINMKT1", "Ralf van Aert"), + //new PC("DESKTOP-SINMKT1", "Ralf van Aert"), //new PC("NA", "Bart") }; @@ -179,6 +179,7 @@ namespace RH_Engine bool speedReplied = false; bool moveReplied = true; panelId = JSONParser.getPanelID(message); + WriteTextMessage(stream, mainCommand.ColorPanel(panelId)); WriteTextMessage(stream, mainCommand.ClearPanel(panelId)); @@ -186,6 +187,7 @@ namespace RH_Engine (message) => { Console.WriteLine(message); + SendMessageAndOnResponse(stream, mainCommand.bikeSpeed(panelId, "bikeSpeed", 5.0), "bikeSpeed", (message) => { @@ -245,7 +247,6 @@ namespace RH_Engine // WriteTextMessage(stream, mainCommand.SwapPanel(uuidPanel)); // Console.WriteLine("Swap panel: " + ReadPrefMessage(stream)); Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand)); - } /// @@ -328,7 +329,7 @@ namespace RH_Engine { WriteTextMessage(stream, mainCommand.RouteFollow(routeId, bikeId, speed, new float[] { 0, -(float)Math.PI / 2f, 0 }, new float[] { 0, 0, 0 })); WriteTextMessage(stream, mainCommand.RouteFollow(routeId, cameraId, speed)); - WriteTextMessage(stream, mainCommand.RouteFollow(routeId, panelId, speed, 0, "XYZ", 1, false, new float[] { 0, 0, 0 }, new float[] { 0f, 0f, 150f })); + //WriteTextMessage(stream, mainCommand.RouteFollow(routeId, panelId, speed, 1f, "XYZ", 1, false, new float[] { 0, 0, 0 }, new float[] { 0f, 5f, 5f })); } //string routeID, string nodeID, float speedValue, float offsetValue, string rotateValue, float smoothingValue, bool followHeightValue, float[] rotateOffsetVector, float[] positionOffsetVector) private static void Force(NetworkStream stream, string message, string serial, HandleSerial action) diff --git a/Server/Client.cs b/Server/Client.cs index 9091295..a38f747 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -167,7 +167,6 @@ namespace Server private bool verifyLogin(string username, string password) { - Console.WriteLine("got hashes " + username + "\n" + password); if (!File.Exists(fileName))