Merge branch 'develop' into try-refactor-to-page

This commit is contained in:
shinichi
2020-10-14 08:42:53 +02:00
7 changed files with 61 additions and 20 deletions

View File

@@ -10,5 +10,7 @@ namespace ClientApp.Models
public bool ConnectedToServer { get; set; }
public bool ConnectedToVREngine { get; set; }
public bool DoctorConnected { get; set; }
public bool CanConnectToVR { get; set; }
}
}

View File

@@ -8,15 +8,18 @@ using ProftaakRH;
namespace ClientApp.Utils
{
public delegate void EngineCallback();
public class Client : IDataReceiver
{
public EngineCallback engineConnectFailed;
public EngineCallback engineConnectSuccess;
private TcpClient client;
private NetworkStream stream;
private byte[] buffer = new byte[1024];
private bool connected;
private byte[] totalBuffer = new byte[1024];
private int totalBufferReceived = 0;
private EngineConnection engineConnection;
public EngineConnection engineConnection;
private bool sessionRunning = false;
private IHandler handler = null;
private LoginViewModel LoginViewModel;
@@ -40,7 +43,7 @@ namespace ClientApp.Utils
private void initEngine()
{
engineConnection = EngineConnection.INSTANCE;
engineConnection.OnNoTunnelId = retryEngineConnection;
engineConnection.OnNoTunnelId = RetryEngineConnection;
engineConnection.OnSuccessFullConnection = engineConnected;
if (!engineConnection.Connected) engineConnection.Connect();
}
@@ -48,24 +51,16 @@ namespace ClientApp.Utils
/// <summary>
/// retries to connect to the VR engine if no tunnel id was found
/// </summary>
private void retryEngineConnection()
public void RetryEngineConnection()
{
Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!");
Console.WriteLine("-- Press ENTER to retry connecting to the VR engine.");
Console.WriteLine("-- Press 'q' and then ENTER to not connect to the VR engine");
string input = Console.ReadLine();
if (input == string.Empty) engineConnection.CreateConnection();
else
{
Console.WriteLine("Skipping connecting to VR engine...");
engineConnection.Stop();
}
engineConnectFailed?.Invoke();
}
private void engineConnected()
{
Console.WriteLine("successfully connected to VR engine");
engineConnectSuccess?.Invoke();
engineConnection.initScene();
if (engineConnection.Connected && sessionRunning && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
}
@@ -126,6 +121,7 @@ namespace ClientApp.Utils
this.LoginViewModel.setLoginStatus(true);
this.connected = true;
initEngine();
}
else
{

View File

@@ -14,7 +14,11 @@ namespace ClientApp.ViewModels
{
public string Username { get; set; }
public ICommand LoginCommand { get; set; }
public bool LoginStatus { get; set; }
public bool InvertedLoginStatus { get; set; }
private MainWindowViewModel mainWindowViewModel;
public LoginViewModel(MainWindowViewModel mainWindowViewModel)
{

View File

@@ -11,10 +11,14 @@ namespace ClientApp.ViewModels
public ICommand RetryVREngineCommand { get; set; }
public MainWindowViewModel MainWindowViewModel { get; set; }
private Client client;
public MainViewModel(MainWindowViewModel mainWindowViewModel)
{
this.MainWindowViewModel = mainWindowViewModel;
client = this.MainWindowViewModel.client;
client.engineConnectFailed = retryEngineConnection;
client.engineConnectSuccess = succesEngineConnection;
this.RetryServerCommand = new RelayCommand(() =>
{
//try connect server
@@ -23,8 +27,28 @@ namespace ClientApp.ViewModels
this.RetryVREngineCommand = new RelayCommand(() =>
{
//try connect vr-engine
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
this.MainWindowViewModel.InfoModel.CanConnectToVR = false;
client.engineConnection.CreateConnection();
});
}
private void retryEngineConnection()
{
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = false;
this.MainWindowViewModel.InfoModel.CanConnectToVR = true;
client.engineConnection.CreateConnection();
}
private void succesEngineConnection()
{
this.MainWindowViewModel.InfoModel.ConnectedToVREngine = true;
this.MainWindowViewModel.InfoModel.CanConnectToVR = false;
}
}
}

View File

@@ -40,7 +40,7 @@
</Button.Content>
</Button>
<Button Grid.Column="1" Grid.Row="1" Command="{Binding RetryVREngineCommand}" Width="50" Height="20">
<Button Grid.Column="1" Grid.Row="1" Command="{Binding RetryVREngineCommand}" Width="50" Height="20" IsEnabled="{Binding MainWindowViewModel.InfoModel.CanConnectToVR}">
<Button.Content>
<TextBlock TextWrapping="Wrap" Text="retry"/>
</Button.Content>

View File

@@ -215,6 +215,11 @@ namespace RH_Engine
return showOnPanel(uuidPanel, serialCode, "Resistance: " + resistance + " %", 3);
}
public string showMessage(string uuidPanel, string serialCode, string message)
{
return showOnPanel(uuidPanel, serialCode, "Last message: " + message, 5);
}
public string SwapPanelCommand(string uuid)
{
dynamic payload = new

View File

@@ -36,6 +36,12 @@ namespace RH_Engine
private static string bikeId = string.Empty;
private static string headId = string.Empty;
private static double bikeSpeed = 6.66;
private static int bpm = 6;
private static int power = 6;
private static int resistance = 6;
private static string lastMessage = "No message received yet";
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
private static void Main(string[] args)
@@ -189,11 +195,8 @@ namespace RH_Engine
bool speedReplied = false;
bool moveReplied = true;
panelId = JSONParser.getPanelID(message);
WriteTextMessage(stream, mainCommand.ColorPanel(panelId));
WriteTextMessage(stream, mainCommand.ClearPanel(panelId));
showPanel(stream, mainCommand, 5.3, 83, 52, 53);
showPanel(stream, mainCommand);
//while (!(speedReplied && moveReplied)) { }
@@ -338,8 +341,10 @@ namespace RH_Engine
}
private static void showPanel(NetworkStream stream, Command mainCommand, double bikeSpeed, int bpm, int power, int resistance)
private static void showPanel(NetworkStream stream, Command mainCommand)
{
WriteTextMessage(stream, mainCommand.ColorPanel(panelId));
WriteTextMessage(stream, mainCommand.ClearPanel(panelId));
SendMessageAndOnResponse(stream, mainCommand.showBikespeed(panelId, "bikeSpeed", bikeSpeed), "bikeSpeed",
(message) =>
{
@@ -360,6 +365,11 @@ namespace RH_Engine
{
// TODO check if is drawn
});
SendMessageAndOnResponse(stream, mainCommand.showMessage(panelId, "message", lastMessage), "message",
(message) =>
{
// TODO check if is drawn
});
// Check if every text is drawn!