Develop #10

Merged
SemvdH merged 229 commits from develop into master 2020-10-29 22:50:49 +00:00
7 changed files with 72 additions and 13 deletions
Showing only changes of commit f5eb59694e - Show all commits

View File

@@ -31,6 +31,9 @@ namespace Client
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null); client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
} }
/// <summary>
/// initializes the VR engine and sets the callbacks
/// </summary>
private void initEngine() private void initEngine()
{ {
engineConnection = EngineConnection.INSTANCE; engineConnection = EngineConnection.INSTANCE;
@@ -38,6 +41,9 @@ namespace Client
if (!engineConnection.Connected) engineConnection.Connect(); if (!engineConnection.Connected) engineConnection.Connect();
} }
/// <summary>
/// retries to connect to the VR engine if no tunnel id was found
/// </summary>
private void retryEngineConnection() private void retryEngineConnection()
{ {
Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!"); 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(); engineConnection.CreateConnection();
} }
/// <summary>
/// callback method for when the TCP client is connected
/// </summary>
/// <param name="ar">the result of the async read</param>
private void OnConnect(IAsyncResult ar) private void OnConnect(IAsyncResult ar)
{ {
this.client.EndConnect(ar); this.client.EndConnect(ar);
@@ -60,6 +70,10 @@ namespace Client
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);
} }
/// <summary>
/// callback method for when there is a message read
/// </summary>
/// <param name="ar">the result of the async read</param>
private void OnRead(IAsyncResult ar) private void OnRead(IAsyncResult ar)
{ {
int receivedBytes = this.stream.EndRead(ar); int receivedBytes = this.stream.EndRead(ar);
@@ -93,6 +107,7 @@ namespace Client
string responseStatus = DataParser.getResponseStatus(payloadbytes); string responseStatus = DataParser.getResponseStatus(payloadbytes);
if (responseStatus == "OK") if (responseStatus == "OK")
{ {
Console.WriteLine("Username and password correct!");
this.connected = true; this.connected = true;
initEngine(); initEngine();
} }
@@ -103,7 +118,7 @@ namespace Client
} }
break; break;
case DataParser.START_SESSION: case DataParser.START_SESSION:
Console.WriteLine("Start session identifier"); Console.WriteLine("Session started!");
this.sessionRunning = true; this.sessionRunning = true;
sendMessage(DataParser.getStartSessionJson()); sendMessage(DataParser.getStartSessionJson());
break; break;
@@ -143,11 +158,19 @@ namespace Client
} }
/// <summary>
/// starts sending a message to the server
/// </summary>
/// <param name="message">the message to send</param>
private void sendMessage(byte[] message) private void sendMessage(byte[] message)
{ {
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
} }
/// <summary>
/// callback method for when a message is fully written to the server
/// </summary>
/// <param name="ar">the async result representing the asynchronous call</param>
private void OnWrite(IAsyncResult ar) private void OnWrite(IAsyncResult ar)
{ {
this.stream.EndWrite(ar); this.stream.EndWrite(ar);
@@ -155,6 +178,10 @@ namespace Client
#region interface #region interface
//maybe move this to other place //maybe move this to other place
/// <summary>
/// bpm method for receiving the BPM value from the bluetooth bike or the simulation
/// </summary>
/// <param name="bytes">the message</param>
public void BPM(byte[] bytes) public void BPM(byte[] bytes)
{ {
if (!sessionRunning) if (!sessionRunning)
@@ -166,9 +193,14 @@ namespace Client
throw new ArgumentNullException("no bytes"); throw new ArgumentNullException("no bytes");
} }
byte[] message = DataParser.GetRawDataMessage(bytes); byte[] message = DataParser.GetRawDataMessage(bytes);
Console.WriteLine("got bpm message: " + message);
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
} }
/// <summary>
/// method for receiving the bike message from the bluetooth bike or the simulation
/// </summary>
/// <param name="bytes">the message</param>
public void Bike(byte[] bytes) public void Bike(byte[] bytes)
{ {
if (!sessionRunning) if (!sessionRunning)
@@ -180,15 +212,23 @@ namespace Client
throw new ArgumentNullException("no bytes"); throw new ArgumentNullException("no bytes");
} }
byte[] message = DataParser.GetRawDataMessage(bytes); byte[] message = DataParser.GetRawDataMessage(bytes);
Console.WriteLine("got bike message: " + message);
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
} }
#endregion #endregion
/// <summary>
/// wether or not the client stream is connected
/// </summary>
/// <returns>true if it's connected, false if not</returns>
public bool IsConnected() public bool IsConnected()
{ {
return this.connected; return this.connected;
} }
/// <summary>
/// tries to log in to the server by asking for a username and password
/// </summary>
private void tryLogin() private void tryLogin()
{ {
//TODO File in lezen //TODO File in lezen
@@ -206,6 +246,10 @@ namespace Client
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
} }
/// <summary>
/// sets the handler for the client, so either the bike simulator or the bluetooth bike handler
/// </summary>
/// <param name="handler"></param>
public void setHandler(IHandler handler) public void setHandler(IHandler handler)
{ {
this.handler = handler; this.handler = handler;

View File

@@ -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) while (true)
{ {

View File

@@ -44,6 +44,7 @@ namespace Hardware
/// </summary> /// </summary>
public void Connect() public void Connect()
{ {
BLE bleBike = new BLE(); BLE bleBike = new BLE();
Thread.Sleep(1000); // We need some time to list available devices Thread.Sleep(1000); // We need some time to list available devices

View File

@@ -47,6 +47,7 @@ namespace Hardware.Simulators
public void StartSimulation() public void StartSimulation()
{ {
Console.WriteLine("simulating bike...");
//Example BLE Message //Example BLE Message
//4A-09-4E-05-19-16-00-FF-28-00-00-20-F0 //4A-09-4E-05-19-16-00-FF-28-00-00-20-F0

View File

@@ -106,8 +106,21 @@ namespace RH_Engine
data = new data = new
{ {
name = "dashboard", name = "dashboard",
parent = uuidBike,
components = new components = new
{ {
transform = new
{
position = new float[]
{
-1.5f, 1f, 0f
},
scale = 1,
rotation = new int[]
{
-30, 90,0
}
},
panel = new panel = new
{ {
size = new int[] { 1, 1 }, size = new int[] { 1, 1 },
@@ -130,7 +143,7 @@ namespace RH_Engine
data = new data = new
{ {
id = uuidPanel, id = uuidPanel,
color = new int[] { 1, 1, 1, 1 } color = new float[] { 0f, 0f, 0f, 0f }
} }
}; };

View File

@@ -17,9 +17,9 @@ namespace RH_Engine
//new PC("DESKTOP-M2CIH87", "Fabian"), //new PC("DESKTOP-M2CIH87", "Fabian"),
//new PC("T470S", "Shinichi"), //new PC("T470S", "Shinichi"),
//new PC("DESKTOP-DHS478C", "semme"), //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-TV73FKO", "Wouter"),
new PC("DESKTOP-SINMKT1", "Ralf van Aert"), //new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
//new PC("NA", "Bart") //new PC("NA", "Bart")
}; };
@@ -179,6 +179,7 @@ namespace RH_Engine
bool speedReplied = false; bool speedReplied = false;
bool moveReplied = true; bool moveReplied = true;
panelId = JSONParser.getPanelID(message); panelId = JSONParser.getPanelID(message);
WriteTextMessage(stream, mainCommand.ColorPanel(panelId));
WriteTextMessage(stream, mainCommand.ClearPanel(panelId)); WriteTextMessage(stream, mainCommand.ClearPanel(panelId));
@@ -186,6 +187,7 @@ namespace RH_Engine
(message) => (message) =>
{ {
Console.WriteLine(message); Console.WriteLine(message);
SendMessageAndOnResponse(stream, mainCommand.bikeSpeed(panelId, "bikeSpeed", 5.0), "bikeSpeed", SendMessageAndOnResponse(stream, mainCommand.bikeSpeed(panelId, "bikeSpeed", 5.0), "bikeSpeed",
(message) => (message) =>
{ {
@@ -245,7 +247,6 @@ namespace RH_Engine
// WriteTextMessage(stream, mainCommand.SwapPanel(uuidPanel)); // WriteTextMessage(stream, mainCommand.SwapPanel(uuidPanel));
// Console.WriteLine("Swap panel: " + ReadPrefMessage(stream)); // Console.WriteLine("Swap panel: " + ReadPrefMessage(stream));
Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand)); Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand));
} }
/// <summary> /// <summary>
@@ -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, 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, 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) //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) private static void Force(NetworkStream stream, string message, string serial, HandleSerial action)

View File

@@ -167,7 +167,6 @@ namespace Server
private bool verifyLogin(string username, string password) private bool verifyLogin(string username, string password)
{ {
Console.WriteLine("got hashes " + username + "\n" + password);
if (!File.Exists(fileName)) if (!File.Exists(fileName))