diff --git a/ErgometerApplication/.vs/ErgometerApplication/v14/.suo b/ErgometerApplication/.vs/ErgometerApplication/v14/.suo index 43cbfe4..448324a 100644 Binary files a/ErgometerApplication/.vs/ErgometerApplication/v14/.suo and b/ErgometerApplication/.vs/ErgometerApplication/v14/.suo differ diff --git a/ErgometerApplication/ErgometerApplication/ClientApplicatie.Designer.cs b/ErgometerApplication/ErgometerApplication/ClientApplicatie.Designer.cs index 2185151..6d02edb 100644 --- a/ErgometerApplication/ErgometerApplication/ClientApplicatie.Designer.cs +++ b/ErgometerApplication/ErgometerApplication/ClientApplicatie.Designer.cs @@ -43,13 +43,13 @@ namespace ErgometerApplication this.labelUsername = new System.Windows.Forms.Label(); this.labelHallo = new System.Windows.Forms.Label(); - this.heartBeat = new PanelClientData("Hartslag"); - this.RPM = new PanelClientData("RPM"); - this.speed = new PanelClientData("Snelheid"); - this.distance = new PanelClientData("Afstand (km)"); - this.power = new PanelClientData("Weerstand"); - this.energy = new PanelClientData("Energie"); - this.actualpower = new PanelClientData("Absolute Weerstand"); + this.heartBeat = new PanelClientData("Hartslag", 0, 250); + this.RPM = new PanelClientData("RPM", 0, 100); + this.speed = new PanelClientData("Snelheid", 0, 500); + this.distance = new PanelClientData("Afstand (km)", 0, 1000); + this.power = new PanelClientData("Weerstand", 25, 400); + this.energy = new PanelClientData("Energie", 0, 200); + this.actualpower = new PanelClientData("Absolute Weerstand", 0, 400); this.panelClientContainer.SuspendLayout(); this.panelTopBar.SuspendLayout(); diff --git a/ErgometerApplication/ErgometerApplication/ClientApplicatie.cs b/ErgometerApplication/ErgometerApplication/ClientApplicatie.cs index 19e2004..a2dc2cf 100644 --- a/ErgometerApplication/ErgometerApplication/ClientApplicatie.cs +++ b/ErgometerApplication/ErgometerApplication/ClientApplicatie.cs @@ -27,11 +27,21 @@ namespace ErgometerApplication private void updateTimer_Tick(object sender, EventArgs e) { + Console.WriteLine("Trying to send data...."); if(MainClient.Doctor.Connected) { + Console.WriteLine("Sending data"); MainClient.ComPort.Write("ST"); string response = MainClient.ComPort.Read(); - MainClient.SaveMeting(response); + Meting m = MainClient.SaveMeting(response); + + heartBeat.updateValue(m.HeartBeat); + RPM.updateValue(m.RPM); + speed.updateValue(m.Speed); + distance.updateValue(m.Distance); + power.updateValue(m.Power); + energy.updateValue(m.Energy); + actualpower.updateValue(m.ActualPower); } } @@ -62,10 +72,20 @@ namespace ErgometerApplication } else { */ - MainClient.Connect(SerialPort.GetPortNames()[0], username, password); - panelClientContainer.BringToFront(); - this.labelUsername.Text = panelLogin.textBoxUsername.Text; - panelTopBar.Visible = true; + if(MainClient.Connect(SerialPort.GetPortNames()[0], username, password)) + { + panelClientContainer.BringToFront(); + this.labelUsername.Text = panelLogin.textBoxUsername.Text; + panelTopBar.Visible = true; + updateTimer.Start(); + } + else + { + panelLogin.lblVerification.Text = "De inloggegevens zijn onjuist."; + panelLogin.lblVerification.ForeColor = Color.Red; + panelLogin.lblVerification.Visible = true; + } + //} } } @@ -112,6 +132,7 @@ namespace ErgometerApplication panelLogin.BringToFront(); panelTopBar.Visible = false; sessionLogout(); + updateTimer.Stop(); } } } \ No newline at end of file diff --git a/ErgometerApplication/ErgometerApplication/DataSaving.cs b/ErgometerApplication/ErgometerApplication/DataSaving.cs deleted file mode 100644 index 7bdb2fb..0000000 --- a/ErgometerApplication/ErgometerApplication/DataSaving.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -//using ErgometerLibrary; -namespace ErgometerApplication -{ - class DataSaving - { - //List local_data = null; - //private List ReadFile() - //{ - // string path; - // OpenFileDialog file = new OpenFileDialog(); - // file.Filter = "Ergometer files(*.ergo) | *.ergo | All files(*.*) | *.*"; - // if (file.ShowDialog() == DialogResult.OK) - // { - // path = file.FileName; - // List readFile = Newtonsoft.Json.JsonConvert.DeserializeObject>(System.IO.File.ReadAllText(path)); - // return readFile; - // } - // else - // { - // return null; - // } - //} - //private List SaveData(Meting meting, List _data) - //{ - // List local_data = _data; - // local_data.Add(meting); - // return local_data; - //} - //private void WriteFile(List _data) - //{ - // string json = Newtonsoft.Json.JsonConvert.SerializeObject(_data); - // string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "ErgometerSessionData.ergo"); - // System.IO.File.WriteAllText(path, json); - // Console.WriteLine("Writing file: " + path); - //} - - - } -} diff --git a/ErgometerApplication/ErgometerApplication/ErgometerApplication.csproj b/ErgometerApplication/ErgometerApplication/ErgometerApplication.csproj index 6ff639d..fc4e4bc 100644 --- a/ErgometerApplication/ErgometerApplication/ErgometerApplication.csproj +++ b/ErgometerApplication/ErgometerApplication/ErgometerApplication.csproj @@ -70,8 +70,6 @@ Component - - Form diff --git a/ErgometerApplication/ErgometerApplication/MainClient.cs b/ErgometerApplication/ErgometerApplication/MainClient.cs index a6e709b..547c67c 100644 --- a/ErgometerApplication/ErgometerApplication/MainClient.cs +++ b/ErgometerApplication/ErgometerApplication/MainClient.cs @@ -17,6 +17,7 @@ namespace ErgometerApplication public static List Metingen { get; } public static int Session; + public static bool Loggedin; public static string HOST = "127.0.0.1"; public static int PORT = 8888; @@ -28,10 +29,37 @@ namespace ErgometerApplication Metingen = new List(); Session = 0; + Loggedin = false; } - public static void Connect(string comport, string name, string password) + public static bool Connect(string comport, string name, string password) { + if (!Doctor.Connected) + { + Doctor.Connect(HOST, PORT); + + NetCommand net = NetHelper.ReadNetCommand(Doctor); + if (net.Type == NetCommand.CommandType.SESSION) + Session = net.Session; + else + throw new Exception("Session not assigned"); + } + + if(! Loggedin) + { + NetCommand command = new NetCommand(name, false, password, Session); + NetHelper.SendNetCommand(Doctor, command); + + NetCommand response = NetHelper.ReadNetCommand(Doctor); + if (response.Type == NetCommand.CommandType.RESPONSE && response.Response == NetCommand.ResponseType.LOGINWRONG) + { + Loggedin = false; + return false; + } + + Loggedin = true; + } + if (!ComPort.IsOpen()) { if (ComPort.Connect(comport)) @@ -52,25 +80,8 @@ namespace ErgometerApplication else throw new Exception("Comport was unable to connect"); } - else - throw new Exception("Comport is already connected"); - - if(!Doctor.Connected) - { - Doctor.Connect(HOST, PORT); - - NetCommand net = NetHelper.ReadNetCommand(Doctor); - if (net.Type == NetCommand.CommandType.SESSION) - Session = net.Session; - else - throw new Exception("Session not assigned"); - - NetCommand command = new NetCommand(name, false, password, Session); - NetHelper.SendNetCommand(Doctor, command); - } - else - throw new Exception("Client is already connected"); + return true; } public static void Disconnect() @@ -84,19 +95,16 @@ namespace ErgometerApplication else throw new Exception("Comport was unable to disconnect"); } - else - throw new Exception("Comport is already closed"); if (Doctor.Connected) { NetHelper.SendNetCommand(Doctor, new NetCommand(NetCommand.CommandType.LOGOUT, Session)); + Loggedin = false; Doctor.Close(); } - else - throw new Exception("Client is already disconnected"); } - public static void SaveMeting(string meting) + public static Meting SaveMeting(string meting) { Meting m = Meting.Parse(meting); Metingen.Add(m); @@ -104,6 +112,8 @@ namespace ErgometerApplication { NetHelper.SendNetCommand(Doctor, new NetCommand(m, Session)); } + + return m; } } } diff --git a/ErgometerApplication/ErgometerApplication/PanelClientData.cs b/ErgometerApplication/ErgometerApplication/PanelClientData.cs index 9a39e06..375a764 100644 --- a/ErgometerApplication/ErgometerApplication/PanelClientData.cs +++ b/ErgometerApplication/ErgometerApplication/PanelClientData.cs @@ -13,8 +13,14 @@ namespace ErgometerApplication public ProgressBar progressBarMeting; public Label metingName; - public PanelClientData(string name) : base() + private int min; + private int max; + + public PanelClientData(string name, int min, int max) : base() { + this.min = min; + this.max = max; + this.metingName = new System.Windows.Forms.Label(); this.progressBarMeting = new System.Windows.Forms.ProgressBar(); this.labelMetingCurrentValue = new System.Windows.Forms.Label(); @@ -47,7 +53,7 @@ namespace ErgometerApplication this.progressBarMeting.Name = "progressBarMeting"; this.progressBarMeting.Size = new System.Drawing.Size(183, 23); this.progressBarMeting.TabIndex = 1; - this.progressBarMeting.Value = 50; + this.progressBarMeting.Value = 0; // // labelMetingCurrentValue // @@ -58,7 +64,7 @@ namespace ErgometerApplication this.labelMetingCurrentValue.Name = "labelMetingCurrentValue"; this.labelMetingCurrentValue.Size = new System.Drawing.Size(57, 32); this.labelMetingCurrentValue.TabIndex = 2; - this.labelMetingCurrentValue.Text = "255"; + this.labelMetingCurrentValue.Text = "0"; } public void setText(string text) @@ -69,19 +75,30 @@ namespace ErgometerApplication public void updateValue(int value) { this.labelMetingCurrentValue.Text = value.ToString(); - this.progressBarMeting.Value = value; + this.progressBarMeting.Value = ValueToPercentage(value); } public void updateValue(double value) { this.labelMetingCurrentValue.Text = value.ToString(); - this.progressBarMeting.Value = (int)value; + this.progressBarMeting.Value = ValueToPercentage((int)value); } public void updateValue(decimal value) { this.labelMetingCurrentValue.Text = value.ToString(); - this.progressBarMeting.Value = (int)value; + this.progressBarMeting.Value = ValueToPercentage((int)value); + } + + private int ValueToPercentage(int value) + { + if (value < min) + return 0; + + if (value > max) + return 100; + + return ((value - min) * 100) / (max - min); } } } diff --git a/ErgometerApplication/ErgometerApplication/ServerCommunicator.cs b/ErgometerApplication/ErgometerApplication/ServerCommunicator.cs deleted file mode 100644 index 79c49cf..0000000 --- a/ErgometerApplication/ErgometerApplication/ServerCommunicator.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Sockets; -using System.Text; -using System.Threading.Tasks; -//using ErgometerLibrary; - -namespace ErgometerApplication -{ - class ServerCommunicator - { - public TcpClient client { get; set; } - public int sessionId { get; set; } -// public List data { get; set; } - } -} diff --git a/ErgometerApplication/ErgometerApplication/bin/Debug/ErgometerLibrary.dll b/ErgometerApplication/ErgometerApplication/bin/Debug/ErgometerLibrary.dll index 46d1c57..2bfff15 100644 Binary files a/ErgometerApplication/ErgometerApplication/bin/Debug/ErgometerLibrary.dll and b/ErgometerApplication/ErgometerApplication/bin/Debug/ErgometerLibrary.dll differ