Эх сурвалжийг харах

hold temporary the original cs files

Bart Reedijk 10 жил өмнө
parent
commit
493b39cf55

+ 112 - 0
Proftaak Remote Healthcare/FietsSimulator/Program.cs.orig

@@ -0,0 +1,112 @@
+using System;
+using System.Collections.Generic;
+using System.IO.Ports;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Threading;
+
+namespace FietsSimulator
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+<<<<<<< .merge_file_a07428
+            new FietsSimulator("COM6");
+=======
+            string[] ports = SerialPort.GetPortNames();
+            Console.WriteLine("Availabe Comports: \n" + String.Join(" \n", ports));
+            Console.WriteLine("Enter Comport:");
+            string port = Console.ReadLine();
+            new FietsSimulator(port);
+            Console.WriteLine("Started Simulator");
+>>>>>>> .merge_file_a04204
+            while (true)
+            {
+                Thread.Sleep(10);
+            }
+        }
+    }
+
+<<<<<<< .merge_file_a07428
+=======
+    class FietsSimulator
+    {
+        private SerialPort comport;
+        private Mode curmode;
+        private int curvalue;
+        private int _power;
+        public int Power
+        {
+            get { return _power; }
+            set
+            {
+                if (value >= 25 && value <= 400)
+                    _power = value;
+                if (value < 25)
+                    _power = 25;
+                if (value > 400)
+                    _power = 400;
+            }
+        }
+
+        private enum Mode
+        {
+            NONE,
+            CONSOLE,
+            DISTANCE,
+            TIME
+        }
+
+        public FietsSimulator(String addr)
+        {
+            this.comport = new SerialPort(addr, 9600);
+            comport.DataReceived += new SerialDataReceivedEventHandler(ReceiveData);
+            comport.Open();
+        }
+
+        private void ReceiveData(object sender, SerialDataReceivedEventArgs e)
+        {
+            string message = comport.ReadLine().Trim();
+            Console.WriteLine(message);
+            if (message == "RS")
+            {
+                curmode = Mode.NONE;
+                curvalue = 0;
+                Power = 25;
+                SendData("ACK");
+            }
+            else if (message == "CU")
+            {
+                curmode = Mode.CONSOLE;
+                SendData("ACK");
+            }
+            else if (message.Contains("PW"))
+            {
+                if (curmode != Mode.NONE && message.Split().Length == 2)
+                {
+                    this.Power = Int32.Parse(message.Split(' ')[1]);
+                }
+                else
+                {
+                    SendData("ERROR");
+                }
+            }
+            else if (message == "ST")
+            {
+                SendData("0\t100\t10\t20\t" + Power.ToString() + "\t600\t0504\t200\r");
+                // pulse rpm speed * 10 distance requested_power energy mm:ss actual_power
+            }
+            else
+            {
+                SendData("ERROR");
+            }
+        }
+        private void SendData(string message)
+        {
+            this.comport.WriteLine(message);
+        }
+    }
+>>>>>>> .merge_file_a04204
+}

+ 77 - 0
Proftaak Remote Healthcare/Fietsclient/AppGlobal.cs.orig

@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Fietsclient
+{
+    public class AppGlobal
+    {
+        private static AppGlobal _instance;
+
+        Thread workerThread;
+        public static AppGlobal Instance
+        {
+            get { return _instance ?? (_instance = new AppGlobal()); }
+        }
+
+
+        private KettlerBikeComm _bikeComm;
+
+
+        private AppGlobal()
+        {
+            _bikeComm = new KettlerBikeComm();
+            KettlerBikeComm.IncomingDataEvent += HandleBikeData; //initialize event
+        }
+
+        public void startComPort()
+        {
+<<<<<<< HEAD
+            startComPort("COM4");
+=======
+            startComPort("COM3");
+>>>>>>> Comport
+        }
+
+        public void startComPort(string portname)
+        {
+            Console.WriteLine(portname);
+            _bikeComm.initComm(portname);
+        }
+
+        public void startAskingData()
+        {
+            workerThread = new Thread(() => workerThreadLoop());
+            workerThread.Start();
+        }
+
+        private void workerThreadLoop()
+        {
+            while(true)
+            {
+                Thread.Sleep(1000);
+                _bikeComm.sendData(KettlerBikeComm.STATUS);
+            }
+        }
+
+        //event handler
+        private void HandleBikeData(string[] data) 
+        {
+            //doe iets ermee...
+        }
+
+        public void closeComPort()
+        {
+            if (workerThread != null)
+                workerThread.Suspend();
+            _bikeComm.closeComm();
+        }
+
+
+
+
+    }
+}

+ 214 - 0
Proftaak Remote Healthcare/Fietsclient/MainForm.Designer.cs.orig

@@ -0,0 +1,214 @@
+namespace Fietsclient
+{
+    partial class MainForm
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
+            System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
+            System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
+            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
+            this.textBox1 = new System.Windows.Forms.TextBox();
+            this.button2 = new System.Windows.Forms.Button();
+            this.button3 = new System.Windows.Forms.Button();
+<<<<<<< HEAD
+            this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
+            this.cmbComport = new System.Windows.Forms.ComboBox();
+            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
+            this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
+            this.pgbComport = new System.Windows.Forms.ProgressBar();
+            this.menuStrip1.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
+=======
+            this.cmbComport = new System.Windows.Forms.ComboBox();
+>>>>>>> Comport
+            this.SuspendLayout();
+            // 
+            // textBox1
+            // 
+            this.textBox1.BackColor = System.Drawing.Color.Black;
+            this.textBox1.ForeColor = System.Drawing.Color.White;
+            this.textBox1.Location = new System.Drawing.Point(10, 345);
+            this.textBox1.Multiline = true;
+            this.textBox1.Name = "textBox1";
+            this.textBox1.ReadOnly = true;
+            this.textBox1.Size = new System.Drawing.Size(776, 164);
+            this.textBox1.TabIndex = 1;
+            // 
+            // button2
+            // 
+            this.button2.Location = new System.Drawing.Point(10, 229);
+            this.button2.Name = "button2";
+            this.button2.Size = new System.Drawing.Size(210, 101);
+            this.button2.TabIndex = 2;
+            this.button2.Text = "start asking for status";
+            this.button2.UseVisualStyleBackColor = true;
+            this.button2.Click += new System.EventHandler(this.button2_Click);
+            // 
+            // button3
+            // 
+            this.button3.BackColor = System.Drawing.SystemColors.ControlLight;
+            this.button3.Location = new System.Drawing.Point(119, 39);
+            this.button3.Name = "button3";
+            this.button3.Size = new System.Drawing.Size(101, 23);
+            this.button3.TabIndex = 3;
+            this.button3.Text = "close comport";
+            this.button3.UseVisualStyleBackColor = false;
+            this.button3.Click += new System.EventHandler(this.button3_Click);
+            // 
+<<<<<<< HEAD
+            // checkedListBox1
+            // 
+            this.checkedListBox1.FormattingEnabled = true;
+            this.checkedListBox1.Items.AddRange(new object[] {
+            "pulse",
+            "rpm",
+            "speed",
+            "distance",
+            "requestedpower",
+            "energy",
+            "time",
+            "actualpower"});
+            this.checkedListBox1.Location = new System.Drawing.Point(10, 100);
+            this.checkedListBox1.Margin = new System.Windows.Forms.Padding(2);
+            this.checkedListBox1.Name = "checkedListBox1";
+            this.checkedListBox1.Size = new System.Drawing.Size(210, 124);
+            this.checkedListBox1.TabIndex = 4;
+            // 
+            // cmbComport
+            // 
+            this.cmbComport.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.cmbComport.FormattingEnabled = true;
+            this.cmbComport.Location = new System.Drawing.Point(11, 39);
+            this.cmbComport.Margin = new System.Windows.Forms.Padding(2);
+            this.cmbComport.Name = "cmbComport";
+            this.cmbComport.Size = new System.Drawing.Size(100, 21);
+            this.cmbComport.TabIndex = 5;
+            this.cmbComport.SelectionChangeCommitted += new System.EventHandler(this.cmbComport_SelectionChangeCommitted);
+            // 
+            // menuStrip1
+            // 
+            this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
+            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.helpToolStripMenuItem});
+            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+            this.menuStrip1.Name = "menuStrip1";
+            this.menuStrip1.Padding = new System.Windows.Forms.Padding(4, 2, 0, 2);
+            this.menuStrip1.Size = new System.Drawing.Size(794, 24);
+            this.menuStrip1.TabIndex = 6;
+            this.menuStrip1.Text = "menuStrip1";
+            // 
+            // helpToolStripMenuItem
+            // 
+            this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
+            this.helpToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
+            this.helpToolStripMenuItem.Text = "Help";
+            // 
+            // chart1
+            // 
+            chartArea1.Name = "ChartArea1";
+            this.chart1.ChartAreas.Add(chartArea1);
+            legend1.Name = "Legend1";
+            this.chart1.Legends.Add(legend1);
+            this.chart1.Location = new System.Drawing.Point(237, 39);
+            this.chart1.Margin = new System.Windows.Forms.Padding(2);
+            this.chart1.Name = "chart1";
+            series1.ChartArea = "ChartArea1";
+            series1.Legend = "Legend1";
+            series1.Name = "Series1";
+            this.chart1.Series.Add(series1);
+            this.chart1.Size = new System.Drawing.Size(548, 291);
+            this.chart1.TabIndex = 7;
+            this.chart1.Text = "chart1";
+            // 
+            // pgbComport
+            // 
+            this.pgbComport.Location = new System.Drawing.Point(13, 66);
+            this.pgbComport.Name = "pgbComport";
+            this.pgbComport.Size = new System.Drawing.Size(207, 23);
+            this.pgbComport.TabIndex = 8;
+            // 
+=======
+            // cmbComport
+            // 
+            this.cmbComport.FormattingEnabled = true;
+            this.cmbComport.Location = new System.Drawing.Point(188, 12);
+            this.cmbComport.Name = "cmbComport";
+            this.cmbComport.Size = new System.Drawing.Size(121, 21);
+            this.cmbComport.TabIndex = 4;
+            this.cmbComport.SelectionChangeCommitted += new System.EventHandler(this.cmbComport_SelectionChangeCommitted);
+            // 
+>>>>>>> Comport
+            // MainForm
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.AutoScroll = true;
+<<<<<<< HEAD
+            this.ClientSize = new System.Drawing.Size(794, 519);
+            this.Controls.Add(this.pgbComport);
+            this.Controls.Add(this.chart1);
+            this.Controls.Add(this.cmbComport);
+            this.Controls.Add(this.checkedListBox1);
+=======
+            this.ClientSize = new System.Drawing.Size(830, 343);
+            this.Controls.Add(this.cmbComport);
+>>>>>>> Comport
+            this.Controls.Add(this.button3);
+            this.Controls.Add(this.button2);
+            this.Controls.Add(this.textBox1);
+            this.Controls.Add(this.menuStrip1);
+            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
+            this.MainMenuStrip = this.menuStrip1;
+            this.Name = "MainForm";
+            this.Text = "Client";
+            this.menuStrip1.ResumeLayout(false);
+            this.menuStrip1.PerformLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+        private System.Windows.Forms.TextBox textBox1;
+        private System.Windows.Forms.Button button2;
+        private System.Windows.Forms.Button button3;
+<<<<<<< HEAD
+        private System.Windows.Forms.CheckedListBox checkedListBox1;
+        private System.Windows.Forms.ComboBox cmbComport;
+        private System.Windows.Forms.MenuStrip menuStrip1;
+        private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem;
+        private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
+        private System.Windows.Forms.ProgressBar pgbComport;
+=======
+        private System.Windows.Forms.ComboBox cmbComport;
+>>>>>>> Comport
+    }
+}
+

+ 108 - 0
Proftaak Remote Healthcare/Fietsclient/MainForm.cs.orig

@@ -0,0 +1,108 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.IO.Ports;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+
+namespace Fietsclient
+{
+    public partial class MainForm : Form
+    {
+        private readonly AppGlobal _global;
+        private SerialPort ComPort;
+        string port;
+
+        public MainForm(AppGlobal global)
+        {
+            InitializeComponent();
+            _global = global;
+            KettlerBikeComm.IncomingDataEvent += HandleBikeData;
+<<<<<<< HEAD
+            KettlerBikeComm.IncomingDebugLineEvent += addTextToLog;
+            getAvailablePorts();
+=======
+            foreach (String item in getComports())
+            {
+                cmbComport.Items.Add(item);
+            }
+
+>>>>>>> Comport
+        }
+
+
+        private void button1_Click(object sender, EventArgs e)
+        {
+            _global.startComPort(port);
+
+        }
+
+        private void HandleBikeData(string[] data)
+        {
+            String logString = "";
+            foreach (int indexChecked in checkedListBox1.CheckedIndices)
+            {
+                object item = checkedListBox1.Items[indexChecked];
+                logString += item.ToString() + " : " + data[indexChecked] + " ";
+            }
+
+            addTextToLog(logString);
+
+            /*addTextToLog("pulse: " + data[0] + ", rpm: " + data[1] + ",  speed*10: " + data[2] + ",  distance: " + data[3] +
+                ",  requested_power: " + data[4] + ", energy: " + data[5] + ", mm:ss: " + data[6] + ", actual_power: " + data[7]);*/
+        }
+
+        private void addTextToLog(string text)
+        {
+            if (this.InvokeRequired)
+            {
+                this.Invoke((new Action(() => addTextToLog(text))));
+                return;
+            }
+
+            textBox1.AppendText(text + "\n");
+        }
+
+        private void button2_Click(object sender, EventArgs e)
+        {
+            _global.startAskingData();
+        }
+
+        private void button3_Click(object sender, EventArgs e)
+        {
+            _global.closeComPort();
+        }
+
+<<<<<<< HEAD
+        private void getAvailablePorts()
+        {
+            string[] ports = SerialPort.GetPortNames();
+            cmbComport.Items.AddRange(ports);
+=======
+        private String[] getComports()
+        {
+            return SerialPort.GetPortNames();
+>>>>>>> Comport
+        }
+
+        private void cmbComport_SelectionChangeCommitted(object sender, EventArgs e)
+        {
+<<<<<<< HEAD
+            if (!(cmbComport.Text == ""))
+            {
+                _global.startComPort(cmbComport.Text);
+                pgbComport.Value = 100;
+            }
+        }
+
+=======
+            port = cmbComport.SelectedItem.ToString();
+        }
+>>>>>>> Comport
+    }
+}