From 7f4edf99b77a13651c11bf2420d969d0ab59bf00 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Mon, 2 Nov 2015 14:08:50 +0100 Subject: [PATCH] Fixed sending new data types and implemented them --- .../ErgometerApplication/ClientApplicatie.cs | 1 + .../Client/ClientThread.cs | 10 ++++++++++ .../ErgometerDoctorApplication/MainClient.cs | 15 ++++++++++++--- ErgometerIPR/ErgometerLibrary/NetCommand.cs | 13 +++++++++---- .../ErgometerLibrary/Properties/AssemblyInfo.cs | 4 ++-- ErgometerIPR/ErgometerServer/ClientThread.cs | 7 +++++-- ErgometerIPR/ErgometerServer/DoctorThread.cs | 8 ++++++++ ErgometerIPR/ErgometerServer/FileHandler.cs | 8 ++++---- ErgometerIPR/ErgometerServer/Server.cs | 6 ++++-- 9 files changed, 55 insertions(+), 17 deletions(-) diff --git a/ErgometerIPR/ErgometerApplication/ClientApplicatie.cs b/ErgometerIPR/ErgometerApplication/ClientApplicatie.cs index fb9b751..89969b2 100644 --- a/ErgometerIPR/ErgometerApplication/ClientApplicatie.cs +++ b/ErgometerIPR/ErgometerApplication/ClientApplicatie.cs @@ -112,6 +112,7 @@ namespace ErgometerApplication panelTopBar.Visible = true; panelClientContainer.BringToFront(); chat = panelClientChat; + MainClient.SendNetCommand(new NetCommand(gewicht, lengte, leeftijd, geslacht, MainClient.Session)); MainClient.ComPort.Write("RS"); MainClient.ComPort.Read(); Thread.Sleep(200); diff --git a/ErgometerIPR/ErgometerDoctorApplication/Client/ClientThread.cs b/ErgometerIPR/ErgometerDoctorApplication/Client/ClientThread.cs index 64cb819..68a4c40 100644 --- a/ErgometerIPR/ErgometerDoctorApplication/Client/ClientThread.cs +++ b/ErgometerIPR/ErgometerDoctorApplication/Client/ClientThread.cs @@ -57,6 +57,16 @@ namespace ErgometerDoctorApplication case NetCommand.CommandType.UITLEG: window.steps.UitlegText.Invoke((MethodInvoker)(() => window.steps.UitlegText.Text = command.UitlegText)); break; + case NetCommand.CommandType.PERSONDATA: + window.panelClientChat.Invoke(window.panelClientChat.passChatMessage, new Object[] { new ChatMessage("Test", "DATA Gewicht=" + command.Gewicht + " Geslacht=" + command.Geslacht + " Leeftijd=" + command.Leeftijd + " Lengte=" + command.Lengte + ".", false) }); + Console.WriteLine("Not fully implemented"); + //NOG DOEN + break; + case NetCommand.CommandType.TESTRESULT: + window.panelClientChat.Invoke(window.panelClientChat.passChatMessage, new Object[] { new ChatMessage("Test", "DATA Vo2Max=" + command.VO2Max + " MET=" + command.MET + " PopulationAvg=" + command.PopulationAvg + " Zscore=" + command.ZScore + " Rating=" + command.Rating + ".", false) }); + Console.WriteLine("Not fully implemented"); + //NOG DOEN + break; } } diff --git a/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs b/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs index 106c5f7..9147b61 100644 --- a/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs +++ b/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs @@ -253,6 +253,9 @@ namespace ErgometerDoctorApplication Thread thread = new Thread(new ThreadStart(cl.run)); thread.IsBackground = true; thread.Start(); + + Thread.Sleep(5); + SendNetCommand(new NetCommand(NetCommand.RequestType.PERSONALDATA, session)); } public static void StartOldClient(string name, int session) @@ -260,9 +263,6 @@ namespace ErgometerDoctorApplication if (IsSessionRunning(session)) return; - SendNetCommand(new NetCommand(NetCommand.RequestType.OLDDATA, session)); - SendNetCommand(new NetCommand(NetCommand.RequestType.CHAT, session)); - //Start new client ClientThread cl = new ClientThread(name, session, true); clients.Add(cl); @@ -271,6 +271,15 @@ namespace ErgometerDoctorApplication Thread thread = new Thread(new ThreadStart(cl.run)); thread.IsBackground = true; thread.Start(); + + SendNetCommand(new NetCommand(NetCommand.RequestType.OLDDATA, session)); + Thread.Sleep(5); + SendNetCommand(new NetCommand(NetCommand.RequestType.CHAT, session)); + Thread.Sleep(5); + SendNetCommand(new NetCommand(NetCommand.RequestType.PERSONALDATA, session)); + Thread.Sleep(5); + SendNetCommand(new NetCommand(NetCommand.RequestType.TESTRESULT, session)); + Thread.Sleep(5); } } } diff --git a/ErgometerIPR/ErgometerLibrary/NetCommand.cs b/ErgometerIPR/ErgometerLibrary/NetCommand.cs index 06492ef..5d64b22 100644 --- a/ErgometerIPR/ErgometerLibrary/NetCommand.cs +++ b/ErgometerIPR/ErgometerLibrary/NetCommand.cs @@ -10,7 +10,7 @@ namespace ErgometerLibrary public class NetCommand { public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST, LENGTH, SESSIONDATA, ERROR, BROADCAST, UITLEG, PERSONDATA, TESTRESULT} - public enum RequestType { USERS, ALLSESSIONS, OLDDATA, SESSIONDATA, CHAT } + public enum RequestType { USERS, ALLSESSIONS, OLDDATA, SESSIONDATA, CHAT, PERSONALDATA, TESTRESULT } public enum ResponseType { LOGINOK, LOGINWRONG, ERROR, NOTLOGGEDIN } public enum ValueType { TIME, POWER, ENERGY, DISTANCE } public enum LengthType { USERS, SESSIONS, SESSIONDATA, DATA } @@ -343,6 +343,10 @@ namespace ErgometerLibrary return new NetCommand(RequestType.SESSIONDATA, session); case "chat": return new NetCommand(RequestType.CHAT, session); + case "personaldata": + return new NetCommand(RequestType.PERSONALDATA, session); + case "testresult": + return new NetCommand(RequestType.TESTRESULT, session); default: throw new FormatException("Error in NetCommand: Request type not recognised"); } @@ -499,19 +503,20 @@ namespace ErgometerLibrary command += "13»ses" + Session + "»" + UitlegText.Replace('\n', '«'); break; case CommandType.PERSONDATA: - command += "13»ses" + Session + "»" + Gewicht + "»" + Lengte + "»" + Leeftijd + "»" + Geslacht; + command += "14»ses" + Session + "»" + Gewicht + "»" + Lengte + "»" + Leeftijd + "»" + Geslacht; + Console.WriteLine(command); break; case CommandType.TESTRESULT: - command += "13»ses" + Session + "»" + VO2Max + "»" + MET + "»" + PopulationAvg + "»" + ZScore + "»" + Rating; + command += "15»ses" + Session + "»" + VO2Max + "»" + MET + "»" + PopulationAvg + "»" + ZScore + "»" + Rating; break; case CommandType.ERROR: command += "ERROR IN NETCOMMAND"; break; - default: throw new FormatException("Error in NetCommand: Cannot find type of command"); } + return command; } } diff --git a/ErgometerIPR/ErgometerLibrary/Properties/AssemblyInfo.cs b/ErgometerIPR/ErgometerLibrary/Properties/AssemblyInfo.cs index f721bc3..ec1730d 100644 --- a/ErgometerIPR/ErgometerLibrary/Properties/AssemblyInfo.cs +++ b/ErgometerIPR/ErgometerLibrary/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0.0")] -[assembly: AssemblyFileVersion("1.0.3.7")] +[assembly: AssemblyVersion("1.2.0.1")] +[assembly: AssemblyFileVersion("1.0.3.8")] diff --git a/ErgometerIPR/ErgometerServer/ClientThread.cs b/ErgometerIPR/ErgometerServer/ClientThread.cs index f636e5a..030b160 100644 --- a/ErgometerIPR/ErgometerServer/ClientThread.cs +++ b/ErgometerIPR/ErgometerServer/ClientThread.cs @@ -20,6 +20,7 @@ namespace ErgometerServer bool running; bool loggedin; + public bool personaldatareceived; List metingen; List chat; @@ -32,6 +33,7 @@ namespace ErgometerServer this.session = 0; this.running = false; this.loggedin = false; + this.personaldatareceived = false; metingen = new List(); chat = new List(); @@ -88,13 +90,14 @@ namespace ErgometerServer case NetCommand.CommandType.PERSONDATA: if (loggedin) { - FileHandler.SavePersonalData(input, session); + personaldatareceived = true; + FileHandler.SavePersonalData(input); } break; case NetCommand.CommandType.TESTRESULT: if (loggedin) { - FileHandler.SaveTestResult(input, session); + FileHandler.SaveTestResult(input); } break; case NetCommand.CommandType.DATA: diff --git a/ErgometerIPR/ErgometerServer/DoctorThread.cs b/ErgometerIPR/ErgometerServer/DoctorThread.cs index d4b062e..3f9037f 100644 --- a/ErgometerIPR/ErgometerServer/DoctorThread.cs +++ b/ErgometerIPR/ErgometerServer/DoctorThread.cs @@ -96,6 +96,14 @@ namespace ErgometerServer Thread.Sleep(10); } break; + case NetCommand.RequestType.PERSONALDATA: + NetCommand response = FileHandler.ReadPersonalData(input.Session); + sendToDoctor(response); + break; + case NetCommand.RequestType.TESTRESULT: + NetCommand resp = FileHandler.ReadTestResult(input.Session); + sendToDoctor(resp); + break; default: throw new FormatException("Unknown Command"); } diff --git a/ErgometerIPR/ErgometerServer/FileHandler.cs b/ErgometerIPR/ErgometerServer/FileHandler.cs index 16a8b47..9bf4c42 100644 --- a/ErgometerIPR/ErgometerServer/FileHandler.cs +++ b/ErgometerIPR/ErgometerServer/FileHandler.cs @@ -215,9 +215,9 @@ namespace ErgometerServer // TESTRESULTS - public static void SaveTestResult(NetCommand input, int session) + public static void SaveTestResult(NetCommand input) { - using (Stream stream = File.Open(GetSessionTest(session), FileMode.Open)) + using (Stream stream = File.Open(GetSessionTest(input.Session), FileMode.Open)) { BinaryWriter writer = new BinaryWriter(stream); writer.Write(input.VO2Max); @@ -251,9 +251,9 @@ namespace ErgometerServer // PERSONALDATA - public static void SavePersonalData(NetCommand input, int session) + public static void SavePersonalData(NetCommand input) { - using (Stream stream = File.Open(GetSessionPersonalData(session), FileMode.Open)) + using (Stream stream = File.Open(GetSessionPersonalData(input.Session), FileMode.Open)) { BinaryWriter writer = new BinaryWriter(stream); writer.Write(input.Geslacht); diff --git a/ErgometerIPR/ErgometerServer/Server.cs b/ErgometerIPR/ErgometerServer/Server.cs index 22f3bdb..0c850d5 100644 --- a/ErgometerIPR/ErgometerServer/Server.cs +++ b/ErgometerIPR/ErgometerServer/Server.cs @@ -122,7 +122,8 @@ namespace ErgometerServer List sessions = new List(); foreach (ClientThread thread in clients) { - sessions.Add(thread.session); + if(thread.personaldatareceived) + sessions.Add(thread.session); } return sessions; } @@ -132,7 +133,8 @@ namespace ErgometerServer List> sessions = new List>(); foreach (ClientThread thread in clients) { - sessions.Add(new Tuple(thread.session, thread.name)); + if (thread.personaldatareceived) + sessions.Add(new Tuple(thread.session, thread.name)); } return sessions; }