o p t i m i z e

This commit is contained in:
Sem van der Hoeven
2020-10-09 12:02:23 +02:00
parent 68994fd3fe
commit 39b935ecbc
2 changed files with 19 additions and 10 deletions

View File

@@ -123,7 +123,7 @@ namespace Client
{
Console.WriteLine("Username and password correct!");
this.connected = true;
//initEngine();
initEngine();
}
else
{
@@ -212,7 +212,7 @@ namespace Client
if (engineConnection.Connected && engineConnection.FollowingRoute)
{
engineConnection.BikeBPM = bytes[1];
engineConnection.UpdateInfoPanel();
}
@@ -225,6 +225,7 @@ namespace Client
/// <param name="bytes">the message</param>
public void Bike(byte[] bytes)
{
bool canSendToEngine = engineConnection.Connected && engineConnection.FollowingRoute;
if (!sessionRunning)
{
return;
@@ -237,15 +238,14 @@ namespace Client
switch (bytes[0])
{
case 0x10:
engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
if (canSendToEngine) engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f;
break;
case 0x19:
engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
if (canSendToEngine) engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
break;
}
if (engineConnection.Connected && engineConnection.FollowingRoute)
engineConnection.UpdateInfoPanel();
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}