Develop #10
@@ -31,6 +31,9 @@ namespace Client
|
||||
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// initializes the VR engine and sets the callbacks
|
||||
/// </summary>
|
||||
private void initEngine()
|
||||
{
|
||||
engineConnection = EngineConnection.INSTANCE;
|
||||
@@ -38,6 +41,9 @@ namespace Client
|
||||
if (!engineConnection.Connected) engineConnection.Connect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retries to connect to the VR engine if no tunnel id was found
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
this.client.EndConnect(ar);
|
||||
@@ -60,6 +70,10 @@ namespace Client
|
||||
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)
|
||||
{
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// starts sending a message to the server
|
||||
/// </summary>
|
||||
/// <param name="message">the message to send</param>
|
||||
private void sendMessage(byte[] message)
|
||||
{
|
||||
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)
|
||||
{
|
||||
this.stream.EndWrite(ar);
|
||||
@@ -155,6 +178,10 @@ namespace Client
|
||||
|
||||
#region interface
|
||||
//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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// wether or not the client stream is connected
|
||||
/// </summary>
|
||||
/// <returns>true if it's connected, false if not</returns>
|
||||
public bool IsConnected()
|
||||
{
|
||||
return this.connected;
|
||||
}
|
||||
/// <summary>
|
||||
/// tries to log in to the server by asking for a username and password
|
||||
/// </summary>
|
||||
private void tryLogin()
|
||||
{
|
||||
//TODO File in lezen
|
||||
@@ -206,6 +246,10 @@ namespace Client
|
||||
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)
|
||||
{
|
||||
this.handler = handler;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace Hardware
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
|
||||
BLE bleBike = new BLE();
|
||||
|
||||
Thread.Sleep(1000); // We need some time to list available devices
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
}
|
||||
|
||||
/// <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, 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)
|
||||
|
||||
@@ -167,7 +167,6 @@ namespace Server
|
||||
|
||||
private bool verifyLogin(string username, string password)
|
||||
{
|
||||
Console.WriteLine("got hashes " + username + "\n" + password);
|
||||
|
||||
|
||||
if (!File.Exists(fileName))
|
||||
|
||||
Reference in New Issue
Block a user