Workinng on communication

This commit is contained in:
fabjuuuh
2020-10-16 12:48:14 +02:00
parent b31fa293fb
commit aadbbc16a9
6 changed files with 92 additions and 43 deletions

View File

@@ -130,7 +130,7 @@ namespace ClientApp.Utils
Debug.WriteLine($"login failed \"{responseStatus}\""); Debug.WriteLine($"login failed \"{responseStatus}\"");
} }
break; break;
case DataParser.START_SESSION: /*case DataParser.START_SESSION:
Console.WriteLine("Session started!"); Console.WriteLine("Session started!");
this.sessionRunning = true; this.sessionRunning = true;
if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow(); if (engineConnection.Connected && !engineConnection.FollowingRoute) engineConnection.StartRouteFollow();
@@ -140,7 +140,7 @@ namespace ClientApp.Utils
Console.WriteLine("Stop session identifier"); Console.WriteLine("Stop session identifier");
this.sessionRunning = false; this.sessionRunning = false;
sendMessage(DataParser.getStopSessionJson()); sendMessage(DataParser.getStopSessionJson());
break; break;*/
case DataParser.SET_RESISTANCE: case DataParser.SET_RESISTANCE:
Console.WriteLine("Set resistance identifier"); Console.WriteLine("Set resistance identifier");
if (this.handler == null) if (this.handler == null)

View File

@@ -99,7 +99,7 @@ namespace DoctorApp.Utils
Debug.WriteLine($"login failed \"{responseStatus}\""); Debug.WriteLine($"login failed \"{responseStatus}\"");
} }
break; break;
case DataParser.START_SESSION: /*case DataParser.START_SESSION:
Console.WriteLine("Session started!"); Console.WriteLine("Session started!");
this.sessionRunning = true; this.sessionRunning = true;
sendMessage(DataParser.getStartSessionJson()); sendMessage(DataParser.getStartSessionJson());
@@ -108,7 +108,7 @@ namespace DoctorApp.Utils
Console.WriteLine("Stop session identifier"); Console.WriteLine("Stop session identifier");
this.sessionRunning = false; this.sessionRunning = false;
sendMessage(DataParser.getStopSessionJson()); sendMessage(DataParser.getStopSessionJson());
break; break;*/
case DataParser.SET_RESISTANCE: case DataParser.SET_RESISTANCE:
Console.WriteLine("Set resistance identifier"); Console.WriteLine("Set resistance identifier");
if (this.handler == null) if (this.handler == null)

View File

@@ -2,18 +2,34 @@
using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Command;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text; using System.Text;
using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using Util; using Util;
namespace DoctorApp.ViewModels namespace DoctorApp.ViewModels
{ {
class ClientInfoViewModel class ClientInfoViewModel : ObservableObject
{ {
public ObservableCollection<string> ChatLog { get; set; }
public string Username { get; set; } public string Username { get; set; }
public string Status { get; set; } public string Status { get; set; }
public int Speed { get; set; }
public int BPM { get; set; }
public int Resistance { get; set; }
public int Acc_Power { get; set; }
public int Curr_Power { get; set; }
public int Distance { get; set; }
public ICommand StartSession { get; set; } public ICommand StartSession { get; set; }
public ICommand StopSession { get; set; } public ICommand StopSession { get; set; }
@@ -29,23 +45,38 @@ namespace DoctorApp.ViewModels
public MainWindowViewModel MainWindowViewModel { get; set; } public MainWindowViewModel MainWindowViewModel { get; set; }
private Client client; private Client client;
public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel) public ClientInfoViewModel(MainWindowViewModel mainWindowViewModel)
{ {
MainWindowViewModel = mainWindowViewModel; MainWindowViewModel = mainWindowViewModel;
ChatLog = new ObservableCollection<string>();
client = mainWindowViewModel.client; client = mainWindowViewModel.client;
StartSession = new RelayCommand(()=>{ StartSession = new RelayCommand(()=>{
client.sendMessage(DataParser.getStartSessionJson()); client.sendMessage(DataParser.getStartSessionJson(Username));
Status = "Session started";
}); });
StopSession = new RelayCommand(() => { StopSession = new RelayCommand(() => {
client.sendMessage(DataParser.getStopSessionJson()); client.sendMessage(DataParser.getStopSessionJson(Username));
Status = "Session stopped, waiting to start again.";
}); });
Chat = new RelayCommand<object>((parameter) => Chat = new RelayCommand<object>((parameter) =>
{ {
/*client.sendMessage(DataParser.)*/ client.sendMessage(DataParser.getChatJson(Username, ((TextBox)parameter).Text));
ChatLog.Add(DateTime.Now+": "+ ((TextBox)parameter).Text);
});
//TODO RelayCommand ChatToAll
ClientInfo = new RelayCommand(() =>
{
//TODO POPUP
});
SetResistance = new RelayCommand<object>((parameter) =>
{
client.sendMessage(DataParser.getSetResistanceJson(Username, float.Parse(((TextBox)parameter).Text)));
}); });
} }

View File

@@ -24,8 +24,8 @@
<Setter Property="Margin" Value="0,0,20,0"/> <Setter Property="Margin" Value="0,0,20,0"/>
</Style> </Style>
</StackPanel.Resources> </StackPanel.Resources>
<Label Content="{Binding Username}"/> <Label Content="{Binding Path=Username}"/>
<Label Content="{Binding Status}"/> <Label Content="{Binding Path=Status}"/>
</StackPanel> </StackPanel>
<StackPanel Margin="0,10,0,0" Grid.RowSpan="2" Grid.Row="1"> <StackPanel Margin="0,10,0,0" Grid.RowSpan="2" Grid.Row="1">
<StackPanel.Resources> <StackPanel.Resources>
@@ -39,9 +39,9 @@
<Label Content="Current BPM" Width="110" DockPanel.Dock="Top"/> <Label Content="Current BPM" Width="110" DockPanel.Dock="Top"/>
</DockPanel> </DockPanel>
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch"> <DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
<TextBox Name="textBox_Resistance" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/> <TextBox Name="textBox_Resistance" Text="{Binding Path=Resistance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentSpeed" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/> <TextBox Name="textBox_CurrentSpeed" Text="{Binding Path=Speed}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentBPM" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/> <TextBox Name="textBox_CurrentBPM" Text="{Binding Path=BPM}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
</DockPanel> </DockPanel>
<DockPanel Height="26" LastChildFill="False"> <DockPanel Height="26" LastChildFill="False">
<Label Content="Distance Covered" Width="110" DockPanel.Dock="Right"/> <Label Content="Distance Covered" Width="110" DockPanel.Dock="Right"/>
@@ -49,18 +49,18 @@
<Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/> <Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/>
</DockPanel> </DockPanel>
<DockPanel Height="26" LastChildFill="False"> <DockPanel Height="26" LastChildFill="False">
<TextBox Name="textBox_DistanceCovered" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/> <TextBox Name="textBox_DistanceCovered" Text="{Binding Path=Distance}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentPower" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/> <TextBox Name="textBox_CurrentPower" Text="{Binding Path=Curr_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
<TextBox Name="textBox_AccPower" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/> <TextBox Name="textBox_AccPower" Text="{Binding Path=Acc_Power}" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
</DockPanel> </DockPanel>
</StackPanel> </StackPanel>
<ListBox Name="ChatBox" Grid.Column="1" Margin="59,41,0,0" Grid.RowSpan="3"/> <ListBox Name="ChatBox" ItemsSource="{Binding ChatLog}" Grid.Column="1" Margin="59,41,0,0" Grid.RowSpan="3"/>
<TextBox Name="textBox_Chat" Grid.Column="1" HorizontalAlignment="Left" Margin="59,10,0,0" Grid.Row="3" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/> <TextBox Name="textBox_Chat" Grid.Column="1" HorizontalAlignment="Left" Margin="59,10,0,0" Grid.Row="3" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/>
<Button Content="Button" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" /> <Button x:Name="Send" Content="Send" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" Command="{Binding Chat}" CommandParameter="{Binding ElementName=textBox_Chat}"/>
<Button Content="Start Session" Grid.Column="1" HorizontalAlignment="Left" Margin="69,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97"/> <Button Content="Start Session" Grid.Column="1" HorizontalAlignment="Left" Margin="69,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Command="{Binding StartSession}" CommandParameter=""/>
<Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" /> <Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Command="{Binding StopSession}" CommandParameter=""/>
<TextBox x:Name="textBox_SetResistance" Grid.Column="1" HorizontalAlignment="Left" Margin="69,128,0,0" Grid.Row="3" TextWrapping="Wrap" VerticalAlignment="Top" Width="97"/> <TextBox x:Name="textBox_SetResistance" Grid.Column="1" HorizontalAlignment="Left" Margin="69,128,0,0" Grid.Row="3" TextWrapping="Wrap" VerticalAlignment="Top" Width="97"/>
<Button Content="Set Resistance" Grid.Column="1" HorizontalAlignment="Left" Margin="187,128,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Height="18"/> <Button Content="Set Resistance" Grid.Column="1" HorizontalAlignment="Left" Margin="187,128,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Height="18" Command="{Binding SetResistance}" CommandParameter="{Binding ElementName=textBox_SetResistance}"/>
<Canvas Grid.Row="3" Background="White" Margin="0,33,0,0"/> <Canvas Grid.Row="3" Background="White" Margin="0,33,0,0"/>
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190"/> <ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190"/>
<Button Content="Client Info" Grid.Column="1" HorizontalAlignment="Left" Margin="207,6,0,0" VerticalAlignment="Top" Height="26" Width="82"/> <Button Content="Client Info" Grid.Column="1" HorizontalAlignment="Left" Margin="207,6,0,0" VerticalAlignment="Top" Height="26" Width="82"/>

View File

@@ -182,20 +182,29 @@ namespace Util
return getMessage(payload, 0x01); return getMessage(payload, 0x01);
} }
public static byte[] getStartSessionJson() public static byte[] getStartSessionJson(string user)
{
return getJsonMessage(START_SESSION);
}
public static byte[] getStopSessionJson()
{
return getJsonMessage(STOP_SESSION);
}
public static byte[] getSetResistanceJson(float mResistance)
{ {
dynamic data = new dynamic data = new
{ {
username = user
};
return getJsonMessage(START_SESSION, data);
}
public static byte[] getStopSessionJson(string user)
{
dynamic data = new
{
username = user
};
return getJsonMessage(STOP_SESSION, data);
}
public static byte[] getSetResistanceJson(string user,float mResistance)
{
dynamic data = new
{
username = user,
resistance = mResistance resistance = mResistance
}; };
return getJsonMessage(SET_RESISTANCE, data); return getJsonMessage(SET_RESISTANCE, data);
@@ -243,16 +252,25 @@ namespace Util
return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username; return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
} }
/*public static bool getChatMessageFronJson(byte[] json, out string username, out string chat) public static string getChatMessageFromJson(byte[] json)
{ {
try return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.chat;
{ }
} public static string getUsernameFromJson(byte[] json)
dynamic jsn = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json)); {
username = jsn.data.username; return ((dynamic)JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json))).data.username;
chat = jsn.data.chat; }
}*/
public static byte[] getChatJson(string user, string message)
{
dynamic data = new
{
username = user,
chat = message
};
return getJsonMessage(MESSAGE, data);
}
} }

View File

@@ -160,7 +160,7 @@ namespace Server
Console.WriteLine("Log in"); Console.WriteLine("Log in");
this.username = username; this.username = username;
sendMessage(DataParser.getLoginResponse("OK")); sendMessage(DataParser.getLoginResponse("OK"));
sendMessage(DataParser.getStartSessionJson()); //sendMessage(DataParser.getStartSessionJson());
communication.NewLogin(this); communication.NewLogin(this);
} }
else else