Bläddra i källkod

Fixed sending new data types and implemented them

Kenneth van Ewijk 10 år sedan
förälder
incheckning
7f4edf99b7

+ 1 - 0
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);

+ 10 - 0
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;
             }
         }
 

+ 12 - 3
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);
         }
     }
 }

+ 9 - 4
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;
         }
     }

+ 2 - 2
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")]

+ 5 - 2
ErgometerIPR/ErgometerServer/ClientThread.cs

@@ -20,6 +20,7 @@ namespace ErgometerServer
 
         bool running;
         bool loggedin;
+        public bool personaldatareceived;
 
         List<Meting> metingen;
         List<ChatMessage> chat;
@@ -32,6 +33,7 @@ namespace ErgometerServer
             this.session = 0;
             this.running = false;
             this.loggedin = false;
+            this.personaldatareceived = false;
 
             metingen = new List<Meting>();
             chat = new List<ChatMessage>();
@@ -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:

+ 8 - 0
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");
                         }

+ 4 - 4
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);

+ 4 - 2
ErgometerIPR/ErgometerServer/Server.cs

@@ -122,7 +122,8 @@ namespace ErgometerServer
             List<int> sessions = new List<int>();
             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<Tuple<int, string>> sessions = new List<Tuple<int, string>>();
             foreach (ClientThread thread in clients)
             {
-                sessions.Add(new Tuple<int, string>(thread.session, thread.name));
+                if (thread.personaldatareceived)
+                    sessions.Add(new Tuple<int, string>(thread.session, thread.name));
             }
             return sessions;
         }