Browse Source

commit tussendor

Bart Reedijk 10 years ago
parent
commit
591079e76c

+ 7 - 7
Proftaak Remote Healthcare/FietsClientV2/CurrentData.cs

@@ -12,23 +12,23 @@ namespace FietsClient
     {//faggsd
     {//faggsd
         private string userID;
         private string userID;
         public bool isDoctor { set; get; }
         public bool isDoctor { set; get; }
-        private List<Session> testResult;
+        public List<Session> sessions { get; private set; }
 
 
 
 
         public CurrentData(string id)
         public CurrentData(string id)
         {
         {
             this.userID = id;
             this.userID = id;
-            testResult = new List<Session>();
+            sessions = new List<Session>();
         }
         }
 
 
         public void setSessionList(List<Session> tests)
         public void setSessionList(List<Session> tests)
         {
         {
-            testResult = tests;
+            sessions = tests;
         }
         }
 
 
         public List<Session> GetSessions()
         public List<Session> GetSessions()
         {
         {
-            return testResult;
+            return sessions;
         }
         }
 
 
         public String GetUserID()
         public String GetUserID()
@@ -38,12 +38,12 @@ namespace FietsClient
 
 
         public void setSession(Session s)
         public void setSession(Session s)
         {
         {
-            testResult.Add(s);
+            sessions.Add(s);
         }
         }
 
 
-        public void SetMeasurment(Measurement measurment)
+        public void AddMeasurementToLastSession(Measurement measurment)
         {
         {
-            testResult.Last().AddMeasurement(measurment);
+            sessions.Last().AddMeasurement(measurment);
         }
         }
     }
     }
 }
 }

+ 5 - 1
Proftaak Remote Healthcare/FietsClientV2/DataHandler.cs

@@ -91,7 +91,11 @@ namespace FietsClient
 
 
         public void closeComm()
         public void closeComm()
         {
         {
-            ComPort.Close();
+            if (ComPort != null)
+            {
+                ComPort.Close();
+            }
+            
         }
         }
 
 
         public void sendData(string data)
         public void sendData(string data)

+ 62 - 36
Proftaak Remote Healthcare/FietsClientV2/Forms/DoctorSessionUC.Designer.cs

@@ -28,12 +28,12 @@
         /// </summary>
         /// </summary>
         private void InitializeComponent()
         private void InitializeComponent()
         {
         {
-            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea7 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
-            System.Windows.Forms.DataVisualization.Charting.Series series7 = new System.Windows.Forms.DataVisualization.Charting.Series();
-            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea8 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
-            System.Windows.Forms.DataVisualization.Charting.Series series8 = new System.Windows.Forms.DataVisualization.Charting.Series();
-            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea9 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
-            System.Windows.Forms.DataVisualization.Charting.Series series9 = new System.Windows.Forms.DataVisualization.Charting.Series();
+            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea4 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
+            System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series();
+            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea5 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
+            System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series();
+            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea6 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
+            System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series();
             this.groupBox1 = new System.Windows.Forms.GroupBox();
             this.groupBox1 = new System.Windows.Forms.GroupBox();
             this.rpmChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
             this.rpmChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
             this.bpmBox = new System.Windows.Forms.GroupBox();
             this.bpmBox = new System.Windows.Forms.GroupBox();
@@ -76,6 +76,8 @@
             this.label3 = new System.Windows.Forms.Label();
             this.label3 = new System.Windows.Forms.Label();
             this.label2 = new System.Windows.Forms.Label();
             this.label2 = new System.Windows.Forms.Label();
             this.label1 = new System.Windows.Forms.Label();
             this.label1 = new System.Windows.Forms.Label();
+            this.button2 = new System.Windows.Forms.Button();
+            this.button1 = new System.Windows.Forms.Button();
             this.groupBox1.SuspendLayout();
             this.groupBox1.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.rpmChart)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.rpmChart)).BeginInit();
             this.bpmBox.SuspendLayout();
             this.bpmBox.SuspendLayout();
@@ -97,18 +99,18 @@
             // 
             // 
             // rpmChart
             // rpmChart
             // 
             // 
-            chartArea7.Name = "ChartArea1";
-            this.rpmChart.ChartAreas.Add(chartArea7);
+            chartArea4.Name = "ChartArea1";
+            this.rpmChart.ChartAreas.Add(chartArea4);
             this.rpmChart.Location = new System.Drawing.Point(6, 19);
             this.rpmChart.Location = new System.Drawing.Point(6, 19);
             this.rpmChart.Name = "rpmChart";
             this.rpmChart.Name = "rpmChart";
-            series7.BorderWidth = 10;
-            series7.ChartArea = "ChartArea1";
-            series7.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
-            series7.Name = "Rounds per minute";
-            series7.XValueMember = "Time";
-            series7.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Time;
-            series7.YValueMembers = "Rounds per minutes";
-            this.rpmChart.Series.Add(series7);
+            series4.BorderWidth = 10;
+            series4.ChartArea = "ChartArea1";
+            series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
+            series4.Name = "Rounds per minute";
+            series4.XValueMember = "Time";
+            series4.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Time;
+            series4.YValueMembers = "Rounds per minutes";
+            this.rpmChart.Series.Add(series4);
             this.rpmChart.Size = new System.Drawing.Size(388, 285);
             this.rpmChart.Size = new System.Drawing.Size(388, 285);
             this.rpmChart.TabIndex = 2;
             this.rpmChart.TabIndex = 2;
             this.rpmChart.Text = "rounds per minute";
             this.rpmChart.Text = "rounds per minute";
@@ -125,18 +127,18 @@
             // 
             // 
             // bpmChart
             // bpmChart
             // 
             // 
-            chartArea8.Name = "ChartArea1";
-            this.bpmChart.ChartAreas.Add(chartArea8);
+            chartArea5.Name = "ChartArea1";
+            this.bpmChart.ChartAreas.Add(chartArea5);
             this.bpmChart.Location = new System.Drawing.Point(6, 19);
             this.bpmChart.Location = new System.Drawing.Point(6, 19);
             this.bpmChart.Name = "bpmChart";
             this.bpmChart.Name = "bpmChart";
-            series8.BorderWidth = 10;
-            series8.ChartArea = "ChartArea1";
-            series8.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
-            series8.Name = "Beats per minute";
-            series8.XValueMember = "Time";
-            series8.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Time;
-            series8.YValueMembers = "Beats per minutes";
-            this.bpmChart.Series.Add(series8);
+            series5.BorderWidth = 10;
+            series5.ChartArea = "ChartArea1";
+            series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
+            series5.Name = "Beats per minute";
+            series5.XValueMember = "Time";
+            series5.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Time;
+            series5.YValueMembers = "Beats per minutes";
+            this.bpmChart.Series.Add(series5);
             this.bpmChart.Size = new System.Drawing.Size(388, 285);
             this.bpmChart.Size = new System.Drawing.Size(388, 285);
             this.bpmChart.TabIndex = 1;
             this.bpmChart.TabIndex = 1;
             this.bpmChart.Text = "beats per second";
             this.bpmChart.Text = "beats per second";
@@ -153,25 +155,27 @@
             // 
             // 
             // speedChart
             // speedChart
             // 
             // 
-            chartArea9.Name = "ChartArea1";
-            this.speedChart.ChartAreas.Add(chartArea9);
+            chartArea6.Name = "ChartArea1";
+            this.speedChart.ChartAreas.Add(chartArea6);
             this.speedChart.Location = new System.Drawing.Point(6, 19);
             this.speedChart.Location = new System.Drawing.Point(6, 19);
             this.speedChart.Name = "speedChart";
             this.speedChart.Name = "speedChart";
-            series9.BorderWidth = 10;
-            series9.ChartArea = "ChartArea1";
-            series9.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
-            series9.Name = "Speed";
-            series9.XValueMember = "Time";
-            series9.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Time;
-            series9.YValueMembers = "Speed";
-            this.speedChart.Series.Add(series9);
+            series6.BorderWidth = 10;
+            series6.ChartArea = "ChartArea1";
+            series6.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
+            series6.Name = "Speed";
+            series6.XValueMember = "Time";
+            series6.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Time;
+            series6.YValueMembers = "Speed";
+            this.speedChart.Series.Add(series6);
             this.speedChart.Size = new System.Drawing.Size(388, 285);
             this.speedChart.Size = new System.Drawing.Size(388, 285);
             this.speedChart.TabIndex = 0;
             this.speedChart.TabIndex = 0;
             this.speedChart.Text = "Speed chart";
             this.speedChart.Text = "Speed chart";
             // 
             // 
             // sessionInfoBox
             // sessionInfoBox
             // 
             // 
+            this.sessionInfoBox.Controls.Add(this.button2);
             this.sessionInfoBox.Controls.Add(this.setTimeSecondsBox);
             this.sessionInfoBox.Controls.Add(this.setTimeSecondsBox);
+            this.sessionInfoBox.Controls.Add(this.button1);
             this.sessionInfoBox.Controls.Add(this.setPowerBox);
             this.sessionInfoBox.Controls.Add(this.setPowerBox);
             this.sessionInfoBox.Controls.Add(this.setTimeMinutesBox);
             this.sessionInfoBox.Controls.Add(this.setTimeMinutesBox);
             this.sessionInfoBox.Controls.Add(this.setDistanceBox);
             this.sessionInfoBox.Controls.Add(this.setDistanceBox);
@@ -516,6 +520,26 @@
             this.label1.TabIndex = 0;
             this.label1.TabIndex = 0;
             this.label1.Text = "Naam:";
             this.label1.Text = "Naam:";
             // 
             // 
+            // button2
+            // 
+            this.button2.Location = new System.Drawing.Point(99, 281);
+            this.button2.Name = "button2";
+            this.button2.Size = new System.Drawing.Size(75, 23);
+            this.button2.TabIndex = 41;
+            this.button2.Text = "Stop sessie";
+            this.button2.UseVisualStyleBackColor = true;
+            this.button2.Click += new System.EventHandler(this.button2_Click);
+            // 
+            // button1
+            // 
+            this.button1.Location = new System.Drawing.Point(9, 281);
+            this.button1.Name = "button1";
+            this.button1.Size = new System.Drawing.Size(75, 23);
+            this.button1.TabIndex = 40;
+            this.button1.Text = "Start sessie";
+            this.button1.UseVisualStyleBackColor = true;
+            this.button1.Click += new System.EventHandler(this.button1_Click);
+            // 
             // DoctorSessionUC
             // DoctorSessionUC
             // 
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -583,5 +607,7 @@
         private System.Windows.Forms.Label label3;
         private System.Windows.Forms.Label label3;
         private System.Windows.Forms.Label label2;
         private System.Windows.Forms.Label label2;
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Button button2;
+        private System.Windows.Forms.Button button1;
     }
     }
 }
 }

+ 9 - 1
Proftaak Remote Healthcare/FietsClientV2/Forms/DoctorSessionUC.cs

@@ -41,6 +41,14 @@ namespace FietsClient.Forms
             DoctorModel.doctorModel.tcpConnection.SendPower(power);
             DoctorModel.doctorModel.tcpConnection.SendPower(power);
         }
         }
 
 
-        
+        private void button1_Click(object sender, EventArgs e)
+        {
+            DoctorModel.doctorModel.tcpConnection.SendStartStopSession(true, patientID);
+        }
+
+        private void button2_Click(object sender, EventArgs e)
+        {
+            DoctorModel.doctorModel.tcpConnection.SendStartStopSession(false, patientID);
+        }
     }
     }
 }
 }

+ 6 - 6
Proftaak Remote Healthcare/FietsClientV2/Forms/PatientForm.cs

@@ -17,7 +17,7 @@ namespace FietsClient
 {
 {
     public partial class PatientForm : Form
     public partial class PatientForm : Form
     {
     {
-        private TcpConnection _connection;
+        public TcpConnection _connection { get; private set; }
         private PatientModel patientModel;
         private PatientModel patientModel;
 
 
         public PatientForm(TcpConnection connection)
         public PatientForm(TcpConnection connection)
@@ -164,10 +164,10 @@ namespace FietsClient
                         this.sessionBox.Text = s.id.ToString();
                         this.sessionBox.Text = s.id.ToString();
                         this.nameBox.Text = _connection.userID;
                         this.nameBox.Text = _connection.userID;
                         //get measurments
                         //get measurments
-                        List<Measurement> measurments = s.session;
+                        List<Measurement> measurments = s.measurements;
                         //fill boxes
                         //fill boxes
 
 
-                        this.pulseBox.Text = measurments[measurments.Count - 1].bpm.ToString();
+                        this.pulseBox.Text = measurments[measurments.Count - 1].pulse.ToString();
                         this.rpmInfoBox.Text = measurments[measurments.Count - 1].rpm.ToString();
                         this.rpmInfoBox.Text = measurments[measurments.Count - 1].rpm.ToString();
                         this.speedInfoBox.Text = measurments[measurments.Count - 1].speed.ToString();
                         this.speedInfoBox.Text = measurments[measurments.Count - 1].speed.ToString();
                         this.distanceInfoBox.Text = measurments[measurments.Count - 1].distance.ToString();
                         this.distanceInfoBox.Text = measurments[measurments.Count - 1].distance.ToString();
@@ -192,7 +192,7 @@ namespace FietsClient
                         patientModel.bpmPoints = new List<DataPoint>();
                         patientModel.bpmPoints = new List<DataPoint>();
                         for (int i = 0; i < measurments.Count; i++)
                         for (int i = 0; i < measurments.Count; i++)
                         {
                         {
-                            patientModel.bpmPoints.Add(new DataPoint(measurments[i].time, measurments[i].bpm));
+                            patientModel.bpmPoints.Add(new DataPoint(measurments[i].time, measurments[i].pulse));
                         }
                         }
                         //fill bpmgraph
                         //fill bpmgraph
                         this.bpmChart.Series[0].Points.Clear();
                         this.bpmChart.Series[0].Points.Clear();
@@ -250,12 +250,12 @@ namespace FietsClient
 
 
         private void button1_Click(object sender, EventArgs e)
         private void button1_Click(object sender, EventArgs e)
         {
         {
-            patientModel.startAskingData();
+            _connection.StartNewSession();
         }
         }
 
 
         private void button2_Click(object sender, EventArgs e)
         private void button2_Click(object sender, EventArgs e)
         {
         {
-            patientModel.stopAskingData();
+            _connection.StopSessoin();
         }
         }
     }
     }
 }
 }

+ 31 - 9
Proftaak Remote Healthcare/FietsClientV2/PatientModel.cs

@@ -1,4 +1,5 @@
-using System;
+using FietsLibrary.JSONObjecten;
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.ComponentModel;
 using System.Linq;
 using System.Linq;
@@ -17,7 +18,7 @@ namespace FietsClient
 
 
         public static PatientModel patientModel { get { return _patientModel ?? (_patientModel = new PatientModel()); } }
         public static PatientModel patientModel { get { return _patientModel ?? (_patientModel = new PatientModel()); } }
 
 
-        private DataHandler dataHandler;
+        public DataHandler dataHandler { get; private set; }
         private Thread workerThread;
         private Thread workerThread;
 
 
         private string powerLog;
         private string powerLog;
@@ -38,12 +39,25 @@ namespace FietsClient
 
 
         public void startAskingData()
         public void startAskingData()
         {
         {
-	        askdata = true;
-            speedPoints.Clear();
-            bpmPoints.Clear();
-            rpmPoints.Clear();
-            workerThread = new Thread(() => workerThreadLoop());
-            workerThread.Start();
+            bool canStart = false;
+            if (workerThread != null)
+            {
+                if (!(workerThread.ThreadState == ThreadState.Running || workerThread.ThreadState == ThreadState.Background || workerThread.ThreadState == ThreadState.WaitSleepJoin))
+                {
+                    canStart = true;
+                }
+            }
+            else
+                canStart = true;
+            if (canStart)
+            {
+                askdata = true;
+                speedPoints.Clear();
+                bpmPoints.Clear();
+                rpmPoints.Clear();
+                workerThread = new Thread(() => workerThreadLoop());
+                workerThread.Start();
+            }
         }
         }
 
 
         public void stopAskingData()
         public void stopAskingData()
@@ -83,6 +97,7 @@ namespace FietsClient
             if (patientform.InvokeRequired)
             if (patientform.InvokeRequired)
             {
             {
                 patientform.Invoke((new Action(() => HandleBikeData(data))));
                 patientform.Invoke((new Action(() => HandleBikeData(data))));
+                return;
             }
             }
             else
             else
             {
             {
@@ -123,7 +138,14 @@ namespace FietsClient
                     rpmPoints.RemoveAt(0);
                     rpmPoints.RemoveAt(0);
                 patientform.rpmChart.Update();
                 patientform.rpmChart.Update();
             }
             }
-            
+            SaveAndSendData(data);
+        }
+
+        private void SaveAndSendData(string[] data)
+        {
+            Measurement m = new Measurement(data);
+            patientform._connection.currentData.sessions.Last().AddMeasurement(m);
+            patientform._connection.SendNewMeasurement();
         }
         }
 
 
         public void closeComPort()
         public void closeComPort()

+ 42 - 5
Proftaak Remote Healthcare/FietsClientV2/TcpConnection.cs

@@ -219,11 +219,39 @@ namespace FietsClient
                         case "9":
                         case "9":
                             JsonConvert.DeserializeObject<List<User>>(response_parts[1]);
                             JsonConvert.DeserializeObject<List<User>>(response_parts[1]);
                             break;
                             break;
+                        case "10":
+                            response_parts[1] = response_parts[1].TrimEnd('\0');
+                            if (!currentData.isDoctor)
+                            {
+                                if (response_parts[1] == "1")
+                                {
+                                    StartNewSession();
+                                }
+                                else if (response_parts[1] == "0")
+                                {
+                                    StopSessoin();
+                                }
+                            }
+                            break;
+
                     }
                     }
                 }
                 }
             }
             }
         }
         }
 
 
+        public void StartNewSession()
+        {
+            Session session = new Session();
+            currentData.sessions.Add(session);
+            SendNewSession();
+            PatientModel.patientModel.startAskingData();
+        }
+
+        public void StopSessoin()
+        {
+            PatientModel.patientModel.stopAskingData();
+        }
+
         public void SendLogin(string username, string password)
         public void SendLogin(string username, string password)
         {
         {
             // send command ( cmdID | username | password )
             // send command ( cmdID | username | password )
@@ -240,7 +268,7 @@ namespace FietsClient
         public void SendNewSession()
         public void SendNewSession()
         {
         {
             // send command ( cmdID | username )
             // send command ( cmdID | username )
-            SendString("3|" + userID + FietsLibrary.JsonConverter.SerializeSession(currentData.GetSessions().Last()) + "|");
+            SendString("3|" + userID + "|" + FietsLibrary.JsonConverter.SerializeSession(currentData.GetSessions().Last()) + "|");
         }
         }
 
 
         public void SendNewPatient(User user)
         public void SendNewPatient(User user)
@@ -252,7 +280,7 @@ namespace FietsClient
         public void SendNewMeasurement()
         public void SendNewMeasurement()
         {
         {
             // send command ( cmdID | username )
             // send command ( cmdID | username )
-            SendString("5|" + userID + FietsLibrary.JsonConverter.SerializeLastMeasurement(currentData.GetSessions().Last().GetLastMeasurement()) + "|");
+            SendString("5|" + userID + "|" + FietsLibrary.JsonConverter.SerializeLastMeasurement(currentData.GetSessions().Last().GetLastMeasurement()) + "|");
         }
         }
 
 
         public void SendChatMessage(string[] data)
         public void SendChatMessage(string[] data)
@@ -273,19 +301,28 @@ namespace FietsClient
             SendString("8|" + userID + "|");
             SendString("8|" + userID + "|");
         }
         }
 
 
+        public void SendStartStopSession(bool startstop, string PatientUsername)
+        {
+            if (startstop)
+                SendString("10|1|" + PatientUsername + "|");
+            else
+                SendString("10|0|" + PatientUsername + "|");
+            
+        }
+
         public void SendDistance(int distance)
         public void SendDistance(int distance)
         {
         {
-            SendString("10|" + userID + "|" + distance + "|");
+            SendString("20|" + userID + "|" + distance + "|");
         }
         }
 
 
         public void SendTime(int Minutes, int seconds)
         public void SendTime(int Minutes, int seconds)
         {
         {
-            SendString("11|" + userID + "|" + Minutes + ":" + seconds + "|");
+            SendString("21|" + userID + "|" + Minutes + ":" + seconds + "|");
         }
         }
 
 
         public void SendPower(int power)
         public void SendPower(int power)
         {
         {
-            SendString("12|" + userID + "|" + power + "|");
+            SendString("22|" + userID + "|" + power + "|");
         }
         }
 
 
         public void SendString(string s)
         public void SendString(string s)

+ 17 - 7
Proftaak Remote Healthcare/FietsLibrary/JSONObjecten/Measurement.cs

@@ -13,32 +13,42 @@ namespace FietsLibrary.JSONObjecten
         public int pulse { get; private set; }
         public int pulse { get; private set; }
         public int rpm { get; private set; }
         public int rpm { get; private set; }
         public int speed { get; private set; }
         public int speed { get; private set; }
-        public int wattage { get; private set; }
         public int distance { get; private set; }
         public int distance { get; private set; }
         public int requestedPower { get; private set; }
         public int requestedPower { get; private set; }
         public int energy { get; private set; }
         public int energy { get; private set; }
         public int actualPower { get; private set; }
         public int actualPower { get; private set; }
         public int time { get; private set; }
         public int time { get; private set; }
-        public int bpm { get; private set; }
+
+        public Measurement()
+        {
+
+        }
 
 
         public Measurement(int pulse, int rpm, int speed, int wattage, int distance, int requestedPower, int energy, int actualPower, int time, int bpm)
         public Measurement(int pulse, int rpm, int speed, int wattage, int distance, int requestedPower, int energy, int actualPower, int time, int bpm)
         {
         {
             this.pulse = pulse;
             this.pulse = pulse;
             this.rpm = rpm;
             this.rpm = rpm;
             this.speed = speed;
             this.speed = speed;
-            this.wattage = wattage;
             this.distance = distance;
             this.distance = distance;
             this.requestedPower = requestedPower;
             this.requestedPower = requestedPower;
             this.energy = energy;
             this.energy = energy;
             this.actualPower = actualPower;
             this.actualPower = actualPower;
             this.time = time;
             this.time = time;
-            this.bpm = bpm;
         }
         }
 
 
-
-        public override string ToString()
+        public Measurement(string[] data)
         {
         {
-            return "pulse: " + pulse + " - RPM: " + rpm + " speed: " + speed + " - distance: " + distance + " - requested power: " + requestedPower + " - energy: " + energy + " - time: " + time + " - actual power: " + actualPower;
+            pulse = int.Parse(data[0]);
+            rpm = int.Parse(data[1]);
+            speed = int.Parse(data[2]);
+            distance = int.Parse(data[3]);
+            requestedPower = int.Parse(data[4]);
+            energy = int.Parse(data[5]);
+            int time = 0;
+            string[] timeArray = data[6].Split(':');
+            time += (int.Parse(timeArray[0]) * 100);
+            time += int.Parse(timeArray[1]);
+            actualPower = int.Parse(data[7]);
         }
         }
     }
     }
 }
 }

+ 7 - 11
Proftaak Remote Healthcare/FietsLibrary/JSONObjecten/Session.cs

@@ -14,14 +14,12 @@ namespace FietsLibrary.JSONObjecten
     public class Session
     public class Session
     {
     {
         public int id { get; private set; }
         public int id { get; private set; }
-        public List<Measurement> session { get; private set; }
+        public List<Measurement> measurements { get; private set; }
         public bool isActive { get; private set; }
         public bool isActive { get; private set; }
-        public int bikeMode { get; private set; }
         public DateTime date { get; private set; }
         public DateTime date { get; private set; }
         public string note { get; private set; }
         public string note { get; private set; }
-        public string modevalue { get; private set; }
 
 
-        public Session(int bikeMode, string modevalue)
+        public Session()
         {
         {
             if (!(Directory.Exists(@"JSON Files"))) 
             if (!(Directory.Exists(@"JSON Files"))) 
             {
             {
@@ -34,31 +32,29 @@ namespace FietsLibrary.JSONObjecten
             else
             else
                 this.id = 1;
                 this.id = 1;
 
 
-            this.session = new List<Measurement>();
+            this.measurements = new List<Measurement>();
             this.isActive = true;
             this.isActive = true;
-            this.bikeMode = bikeMode;
-            this.modevalue = modevalue;
             this.date = DateTime.Now;
             this.date = DateTime.Now;
             this.note = "";
             this.note = "";
         }
         }
 
 
         public void AddMeasurement(Measurement m)
         public void AddMeasurement(Measurement m)
         {
         {
-            session.Add(m);
+            measurements.Add(m);
         }
         }
 
 
         public Measurement GetLastMeasurement()
         public Measurement GetLastMeasurement()
         {
         {
-            return session.Last();
+            return measurements.Last();
         }
         }
 	
 	
 	public void PrintAll()
 	public void PrintAll()
         {
         {
             Console.WriteLine("pulse" + "\t" + "rpm" + "\t" + "speed" + "\t" + " dist" + "\t" + "req pow" + "\t" + "energy" + "\t" + "time" + "\t\t" + "act pow");
             Console.WriteLine("pulse" + "\t" + "rpm" + "\t" + "speed" + "\t" + " dist" + "\t" + "req pow" + "\t" + "energy" + "\t" + "time" + "\t\t" + "act pow");
 
 
-            for (int i = 0; i < session.Count; i++)
+            for (int i = 0; i < measurements.Count; i++)
             {
             {
-                Console.WriteLine(session[i].pulse + "\t" + session[i].rpm + "\t" + session[i].speed + "\t " + session[i].distance + "\t" + session[i].requestedPower + "\t" + session[i].energy + "\t" + session[i].time + "\t" + session[i].actualPower);
+                Console.WriteLine(measurements[i].pulse + "\t" + measurements[i].rpm + "\t" + measurements[i].speed + "\t " + measurements[i].distance + "\t" + measurements[i].requestedPower + "\t" + measurements[i].energy + "\t" + measurements[i].time + "\t" + measurements[i].actualPower);
             }
             }
         }
         }
     }
     }

+ 5 - 5
Proftaak Remote Healthcare/FietsLibrary/JSONObjecten/User.cs

@@ -13,7 +13,7 @@ namespace FietsLibrary.JSONObjecten
 
 
         public string id { get; private set; }
         public string id { get; private set; }
         public string password { get; private set; }
         public string password { get; private set; }
-        public List<Session> tests { get; private set; }
+        public List<Session> sessions { get; private set; }
         public int age { get; private set; }
         public int age { get; private set; }
         public bool gender { get; private set; }
         public bool gender { get; private set; }
         public int weight { get; private set; }
         public int weight { get; private set; }
@@ -30,7 +30,7 @@ namespace FietsLibrary.JSONObjecten
         {
         {
             this.id = id;
             this.id = id;
             this.password = password;
             this.password = password;
-            this.tests = new List<Session>();
+            this.sessions = new List<Session>();
             this.age = age;
             this.age = age;
             this.gender = gender;
             this.gender = gender;
             this.weight = weight;
             this.weight = weight;
@@ -42,7 +42,7 @@ namespace FietsLibrary.JSONObjecten
         {
         {
             this.id = id;
             this.id = id;
             this.password = password;
             this.password = password;
-            this.tests = new List<Session>();
+            this.sessions = new List<Session>();
             this.age = age;
             this.age = age;
             this.gender = gender;
             this.gender = gender;
             this.weight = weight;
             this.weight = weight;
@@ -51,12 +51,12 @@ namespace FietsLibrary.JSONObjecten
 
 
         public void AddSession(Session session)
         public void AddSession(Session session)
         {
         {
-            tests.Add(session);
+            sessions.Add(session);
         }
         }
 
 
         public List<Session> GetSessions()
         public List<Session> GetSessions()
         {
         {
-            return tests;
+            return sessions;
         }
         }
     }
     }
 }
 }

+ 22 - 10
Proftaak Remote Healthcare/ServerV2/AppGlobal.cs

@@ -45,15 +45,15 @@ namespace ServerV2
             users.Add(new User("admin", "admin", 80, false, 77, true));
             users.Add(new User("admin", "admin", 80, false, 77, true));
 
 
             Random r = new Random();
             Random r = new Random();
-            Session session = new Session(1, "100");
+            Session session = new Session();
             for (int i = 0; i < 20; i++)
             for (int i = 0; i < 20; i++)
                 session.AddMeasurement(new Measurement(r.Next(100, 200), r.Next(60, 100), r.Next(100, 150), r.Next(0, 100), i, r.Next(100), r.Next(100), r.Next(100), i, r.Next(100)));
                 session.AddMeasurement(new Measurement(r.Next(100, 200), r.Next(60, 100), r.Next(100, 150), r.Next(0, 100), i, r.Next(100), r.Next(100), r.Next(100), i, r.Next(100)));
-            users.ElementAt(1).tests.Add(session);
+            users.ElementAt(1).sessions.Add(session);
 
 
-            Session session2 = new Session(2, "100");
+            Session session2 = new Session();
             for (int i = 0; i < 50; i++)
             for (int i = 0; i < 50; i++)
                 session2.AddMeasurement(new Measurement(r.Next(100, 200), r.Next(60, 100), r.Next(100, 150), r.Next(0, 100), i, r.Next(100), r.Next(100), r.Next(100), i, r.Next(100)));
                 session2.AddMeasurement(new Measurement(r.Next(100, 200), r.Next(60, 100), r.Next(100, 150), r.Next(0, 100), i, r.Next(100), r.Next(100), r.Next(100), i, r.Next(100)));
-            users.ElementAt(1).tests.Add(session2);
+            users.ElementAt(1).sessions.Add(session2);
         }
         }
 
 
         private SslStream InitialiseConnection(TcpClient client)
         private SslStream InitialiseConnection(TcpClient client)
@@ -146,17 +146,18 @@ namespace ServerV2
                         currentUser = users.First(item => item.id == response[1]);
                         currentUser = users.First(item => item.id == response[1]);
                         Communication.Send("1|" + FietsLibrary.JsonConverter.GetUserSessions(currentUser), sslStream);
                         Communication.Send("1|" + FietsLibrary.JsonConverter.GetUserSessions(currentUser), sslStream);
                         break;
                         break;
-                    case "2":   //Livedata opvragen
+                    case "2":   //Livedata PUSHEN/OPVRAGEN
                         currentUser = users.First(item => item.id == response[1]);
                         currentUser = users.First(item => item.id == response[1]);
-                        FietsLibrary.JsonConverter.GetLastMeasurement(currentUser.tests.Last());
+                        string lastMeasurement = FietsLibrary.JsonConverter.GetLastMeasurement(currentUser.sessions.Last());
+                        Communication.Send("2|" + lastMeasurement + "|", sslStream);
                         break;
                         break;
                     case "3":   //Nieuwe meetsessie aanmaken
                     case "3":   //Nieuwe meetsessie aanmaken
-                        if (response.Length == 6)
+                        if (true)
                         {
                         {
                             foreach (User u in users)
                             foreach (User u in users)
                             {
                             {
                                 if (u.id == response[1])
                                 if (u.id == response[1])
-                                    u.AddSession(new Session(int.Parse(response[2]), response[3]));
+                                    u.AddSession(new Session());
                             }
                             }
                         }
                         }
                         break;
                         break;
@@ -164,8 +165,11 @@ namespace ServerV2
                         users.Add(new User(response[1], response[2], Int32.Parse(response[3]), Boolean.Parse(response[4]), Int32.Parse(response[5])));
                         users.Add(new User(response[1], response[2], Int32.Parse(response[3]), Boolean.Parse(response[4]), Int32.Parse(response[5])));
                         break;
                         break;
                     case "5":   //data pushen naar meetsessie
                     case "5":   //data pushen naar meetsessie
-                        currentUser = users.First(item => item.id == response[1]);
-                        currentUser.tests.Last().AddMeasurement(JsonConvert.DeserializeObject<Measurement>(response[2]));
+                        currentUser = users.FirstOrDefault(item => item.id == response[1]);
+                        if (currentUser != null && currentUser.sessions.LastOrDefault() != null)
+                        {
+                            currentUser.sessions.Last().AddMeasurement(JsonConvert.DeserializeObject<Measurement>(response[2]));
+                        }
                         break;
                         break;
                     case "6": //chatberichten ontvangen van gebruikers
                     case "6": //chatberichten ontvangen van gebruikers
                         //controleren of het bericht wel tekens bevat
                         //controleren of het bericht wel tekens bevat
@@ -214,6 +218,14 @@ namespace ServerV2
                     case "9": //alles doorsturen voor de dokter
                     case "9": //alles doorsturen voor de dokter
                         Communication.Send(FietsLibrary.JsonConverter.GetUsers(users), sslStream);
                         Communication.Send(FietsLibrary.JsonConverter.GetUsers(users), sslStream);
                         break;
                         break;
+                    case "10":
+                        if (response[1] == "1" || response[1] == "0") //start of stop sesie (met check)
+                        {
+                            Client Case10Client = clients.FirstOrDefault(item => item.username == response[2].TrimEnd('\0'));
+                            string Case10String = "10|" + response[1] + "|";
+                            Communication.Send(Case10String, Case10Client.sslStream);
+                        }
+                        break;
                     default:
                     default:
                         break;
                         break;
                 }
                 }