Beispiel #1
0
        /// <summary>
        /// Gets sensor information.
        /// </summary>
        /// <returns>Sensor information.</returns>
        public SensorInfo GetSensorInfo()
        {
            SensorInfo info = new SensorInfo();

            info.Type = SensorTypes.HeartRateMonitorType;

            try
            {
                sensor = new HeartRateMonitor
                {
                    Interval    = 100,
                    PausePolicy = SensorPausePolicy.None
                };

                info.Name        = sensor.Name;
                info.Vendor      = sensor.Vendor;
                info.MinRange    = sensor.MinValue;
                info.MaxRange    = sensor.MaxValue;
                info.Resolution  = sensor.Resolution;
                info.MinInterval = sensor.MinInterval;
            }
            catch (Exception e)
            {
                global::Tizen.Log.Info(Log.LogTag, e.Message);
                info.Status = "Permission Denied";
            }

            return(info);
        }
Beispiel #2
0
    void Start()
    {
        Device = new HeartRateMonitor();
        ANTScript.AddDevice(Device);

        Initialized = true;
    }
        /// <summary>
        /// Initializes the sensor
        /// </summary>
        /// <exception cref="NotSupportedException">The device does not support the sensor</exception>
        /// <exception cref="UnauthorizedAccessException">The user does not grant your app access to sensors</exception>
        public HeartRateMonitorService()
        {
            try
            {
                // A NotSupportedException will be thrown if the sensor is not available on the device
                _sensor = new HeartRateMonitor();

                // Add an event handler to the sensor
                _sensor.DataUpdated += OnSensorDataUpdated;

                // TODO: Declare how the sensor behaves when the screen turns off or the device goes into power save mode
                // For details see https://docs.tizen.org/application/dotnet/guides/location-sensors/device-sensors
                // _sensor.PausePolicy = SensorPausePolicy.All;

                // TODO: Set the update interval in milliseconds
                // _sensor.Interval = 1000;
            }
            catch (NotSupportedException)
            {
                // TODO: The device does not support the sensor, handle exception as appropriate to your scenario
            }
            catch (UnauthorizedAccessException)
            {
                // TODO: The user does not grant your app access to sensors, handle exception as appropriate to your scenario
            }
        }
Beispiel #4
0
        public IObservable <ushort> WhenReadingTaken()
        {
            this.observable = this.observable ?? Observable.Create <ushort>(ob =>
            {
                var handler = new EventHandler <HeartRateMonitorDataUpdatedEventArgs>((sender, args) =>
                                                                                      ob.OnNext((ushort)args.HeartRate)
                                                                                      );
                var sensor = new HeartRateMonitor
                {
                    Interval = 1000
                };
                sensor.DataUpdated += handler;
                sensor.Start();

                return(() =>
                {
                    sensor.Stop();
                    sensor.DataUpdated -= handler;
                    sensor.Dispose();
                });
            })
                              .Publish()
                              .RefCount();

            return(this.observable);
        }
Beispiel #5
0
    void Start()
    {
        Device = new HeartRateMonitor();
        ANTScript.AddDevice(Device);

        Initialized = true;
    }
Beispiel #6
0
 public HRMStatus(HeartRateMonitor hrm, IHRMPacket hrmPacket)
 {
     HeartRate    = hrm.LastPacket.HeartRate;
     MinHeartRate = hrm.MinHeartRate;
     MaxHeartRate = hrm.MaxHeartRate;
     TotalPackets = hrm.TotalPackets;
     HRMPacket    = hrmPacket;
 }
Beispiel #7
0
        private void InitializeMonitors()
        {
            ConfigM  configM            = null;
            Manifest biometricsManifest = null;

            try
            {
                // lookup the biometrics api using the configuration service
                configM = new ConfigM {
                    ApiUrl = ConfigurationManager.AppSettings["ConfigM"]
                };
                biometricsManifest = configM.GetByName("BiometricsAPI");

                _summaryMonitor = new SummaryMonitor(this)
                {
                    api = biometricsManifest.lineitems["PublicAPI"]
                };
                _temperatureMonitor = new TemperatureMonitor(this)
                {
                    api = biometricsManifest.lineitems["PublicAPI"]
                };
                _heartRateMonitor = new HeartRateMonitor(this)
                {
                    api = biometricsManifest.lineitems["PublicAPI"]
                };
                _glucoseMonitor = new GlucoseMonitor(this)
                {
                    api = biometricsManifest.lineitems["PublicAPI"]
                };
                _oxygenMonitor = new OxygenMonitor(this)
                {
                    api = biometricsManifest.lineitems["PublicAPI"]
                };
                _bostonMonitor = new BostonMonitor(this)
                {
                    api = biometricsManifest.lineitems["PublicAPI"]
                };
                _chicagoMonitor = new ChicagoMonitor(this)
                {
                    api = biometricsManifest.lineitems["PublicAPI"]
                };
                _newYorkMonitor = new NewYorkMonitor(this)
                {
                    api = biometricsManifest.lineitems["PublicAPI"]
                };
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
            }
        }
Beispiel #8
0
        private void OnPrivilegesGranted()
        {
            // create an instance of the monitor
            _monitor = new HeartRateMonitor();
            // specify frequency of the sensor data event by setting the interval value (in milliseconds)
            _monitor.Interval = 1000;

            // stop the measurement when the application goes background
            MessagingCenter.Subscribe <App>(this, "sleep", (sender) => { if (_measuring)
                                                                         {
                                                                             StopMeasurement();
                                                                         }
                                            });
        }
        /// <summary>
        /// Releases all resources used by the current instance
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    _sensor.DataUpdated -= OnSensorDataUpdated;
                    _sensor.Dispose();
                }

                _sensor   = null;
                _disposed = true;
            }
        }
Beispiel #10
0
        private void CreateHRM()
        {
            if (Model.IsSupported)
            {
                HRM              = new HeartRateMonitor();
                HRM.DataUpdated += HRM_DataUpdated;

                canvas.ChartScale = 200;
                canvas.Series     = new List <Series>()
                {
                    new Series()
                    {
                        Color         = SKColors.Red,
                        Name          = "HeartRate",
                        FormattedText = "Heart Rate={0}",
                    },
                };
            }
        }
Beispiel #11
0
        public void Start(HeartRateMonitor hrm)
        {
            if (hrm is ZephyrHxM)
            {
                zephyrHxM = (ZephyrHxM)hrm;
            }
            else
            {
                throw new Exception("Invalid HRM, ZephyrHxM expected");
            }

            ZephyrStart();

            running = true;

            if (LoggerStatusChanged != null)
            {
                LoggerStatusChanged(this, running);
            }
        }
Beispiel #12
0
        public void Start(HeartRateMonitor hrm)
        {
            if (hrm is CMS50)
            {
                cms50 = (CMS50)hrm;
            }
            else
            {
                throw new Exception("Invalid HRM, CMS50 expected");
            }

            CMS50Start();

            running = true;

            if (LoggerStatusChanged != null)
            {
                LoggerStatusChanged(this, running);
            }
        }
Beispiel #13
0
        public void Start(HeartRateMonitor hrm)
        {
            if (hrm is BtHrp)
            {
                btHrp = (BtHrp)hrm;
            }
            else
            {
                throw new Exception("Invalid HRM, BtHrp expected");
            }

            BtHrpStart();

            running = true;

            if (LoggerStatusChanged != null)
            {
                LoggerStatusChanged(this, running);
            }
        }
Beispiel #14
0
        public void Start(HeartRateMonitor hrm)
        {
            if (hrm is HRMEmulator)
            {
                hrmEmulator = (HRMEmulator)hrm;
            }
            else
            {
                throw new Exception("Invalid HRM, HRMEmulator expected");
            }

            HRMEmulatorStart();

            running = true;

            if (LoggerStatusChanged != null)
            {
                LoggerStatusChanged(this, running);
            }
        }
        public void MonitorHeartRate()
        {
            var config = new LoadTestConfiguration
            {
                Duration = TimeSpan.FromSeconds(3)
            };

            var loadTest = new Mock<ILoadTest>();

            loadTest.Setup(k => k.TotalIterations).Returns(1);
            loadTest.Setup(k => k.TotalErrors).Returns(1);
            loadTest.Setup(k => k.Configuration).Returns(config);

            var heartRateMonitor = new HeartRateMonitor(loadTest.Object);

            heartRateMonitor.Start(DateTime.Now, TimeSpan.FromSeconds(2));

            Assert.IsNotNull(heartRateMonitor.Heartbeats);

            Assert.IsTrue(heartRateMonitor.Heartbeats.Any());
        }
Beispiel #16
0
        public void MonitorHeartRate()
        {
            var config = new LoadTestConfiguration
            {
                Duration = TimeSpan.FromSeconds(3)
            };

            var loadTest = new Mock <ILoadTest>();

            loadTest.Setup(k => k.TotalIterations).Returns(1);
            loadTest.Setup(k => k.TotalErrors).Returns(1);
            loadTest.Setup(k => k.Configuration).Returns(config);

            var heartRateMonitor = new HeartRateMonitor(loadTest.Object);

            heartRateMonitor.Start(DateTime.Now, TimeSpan.FromSeconds(2));

            Assert.IsNotNull(heartRateMonitor.Heartbeats);

            Assert.IsTrue(heartRateMonitor.Heartbeats.Any());
        }
Beispiel #17
0
        /// <summary>
        /// Returns a list of user-pertinent data from the heart rate monitor
        /// </summary>
        /// <param name="h">HeartRateMonitor device</param>
        /// <param name="a">Device arguments</param>
        /// <returns></returns>
        public static List <string> FormatHeartRateMonitor(object h, object a)
        {
            HeartRateMonitor hrm  = h as HeartRateMonitor;
            List <string>    data = new List <string>();

            data.Add("ID: " + hrm.ExtendedDeviceNumber.ToString());
            data.Add("Type: " + hrm.DeviceType.ToString());
            if (hrm.Manufacturer != null)
            {
                data.Add(string.Format("Mfr: {0}", hrm.Manufacturer.ManufacturerName));
                data.Add(string.Format("Model: {0}", hrm.Manufacturer.ModelNumber));
            }

            HeartRateMonitorMessageEventArgs args = a as HeartRateMonitorMessageEventArgs;

            if (args != null)
            {
                data.Add("Heartrate: " + args.FormattedHeartRate(true));
            }

            return(data);
        }
Beispiel #18
0
        private void initCampaignDataSources()
        {
            #region Assign sensor model references
            accelerometerModel = new AccelerometerModel
            {
                IsSupported = Accelerometer.IsSupported,
                SensorCount = Accelerometer.Count
            };
            gravityModel = new GravityModel
            {
                IsSupported = GravitySensor.IsSupported,
                SensorCount = GravitySensor.Count
            };
            gyroscopeModel = new GyroscopeModel
            {
                IsSupported = Gyroscope.IsSupported,
                SensorCount = Gyroscope.Count
            };
            hRMModel = new HRMModel
            {
                IsSupported = HeartRateMonitor.IsSupported,
                SensorCount = HeartRateMonitor.Count
            };
            humidityModel = new HumidityModel
            {
                IsSupported = HumiditySensor.IsSupported,
                SensorCount = HumiditySensor.Count
            };
            lightModel = new LightModel
            {
                IsSupported = LightSensor.IsSupported,
                SensorCount = LightSensor.Count
            };
            linearAccelerationModel = new LinearAccelerationModel
            {
                IsSupported = LinearAccelerationSensor.IsSupported,
                SensorCount = LinearAccelerationSensor.Count
            };
            magnetometerModel = new MagnetometerModel
            {
                IsSupported = Magnetometer.IsSupported,
                SensorCount = Magnetometer.Count
            };
            orientationModel = new OrientationModel
            {
                IsSupported = OrientationSensor.IsSupported,
                SensorCount = OrientationSensor.Count
            };
            pressureModel = new PressureModel
            {
                IsSupported = PressureSensor.IsSupported,
                SensorCount = PressureSensor.Count
            };
            proximityModel = new ProximityModel
            {
                IsSupported = ProximitySensor.IsSupported,
                SensorCount = ProximitySensor.Count
            };
            temperatureModel = new TemperatureModel
            {
                IsSupported = TemperatureSensor.IsSupported,
                SensorCount = TemperatureSensor.Count
            };
            ultravioletModel = new UltravioletModel
            {
                IsSupported = UltravioletSensor.IsSupported,
                SensorCount = UltravioletSensor.Count
            };
            #endregion

            #region Assign sensor references and sensor measurement event handlers
            if (accelerometerModel.IsSupported)
            {
                accelerometer                  = new Accelerometer();
                accelerometer.PausePolicy      = SensorPausePolicy.None;
                accelerometer.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                accelerometer.DataUpdated     += storeAccelerometerDataCallback;
                sensorMap[Tools.ACCELEROMETER] = accelerometer;
            }
            if (gravityModel.IsSupported)
            {
                gravity                  = new GravitySensor();
                gravity.PausePolicy      = SensorPausePolicy.None;
                gravity.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                gravity.DataUpdated     += storeGravitySensorDataCallback;
                sensorMap[Tools.GRAVITY] = gravity;
            }
            if (gyroscopeModel.IsSupported)
            {
                gyroscope                  = new Gyroscope();
                gyroscope.PausePolicy      = SensorPausePolicy.None;
                gyroscope.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                gyroscope.DataUpdated     += storeGyroscopeDataCallback;
                sensorMap[Tools.GYROSCOPE] = gyroscope;
            }
            if (hRMModel.IsSupported)
            {
                hRM                  = new HeartRateMonitor();
                hRM.PausePolicy      = SensorPausePolicy.None;
                hRM.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                hRM.DataUpdated     += storeHeartRateMonitorDataCallback;
                sensorMap[Tools.HRM] = hRM;
            }
            if (humidityModel.IsSupported)
            {
                humidity                  = new HumiditySensor();
                humidity.PausePolicy      = SensorPausePolicy.None;
                humidity.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                humidity.DataUpdated     += storeHumiditySensorDataCallback;
                sensorMap[Tools.HUMIDITY] = humidity;
            }
            if (lightModel.IsSupported)
            {
                light                  = new LightSensor();
                light.PausePolicy      = SensorPausePolicy.None;
                light.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                light.DataUpdated     += storeLightSensorDataCallback;
                sensorMap[Tools.LIGHT] = light;
            }
            if (linearAccelerationModel.IsSupported)
            {
                linearAcceleration                  = new LinearAccelerationSensor();
                linearAcceleration.PausePolicy      = SensorPausePolicy.None;
                linearAcceleration.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                linearAcceleration.DataUpdated     += storeLinearAccelerationSensorDataCallback;
                sensorMap[Tools.LINEARACCELERATION] = linearAcceleration;
            }
            if (magnetometerModel.IsSupported)
            {
                magnetometer                  = new Magnetometer();
                magnetometer.PausePolicy      = SensorPausePolicy.None;
                magnetometer.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                magnetometer.DataUpdated     += storeMagnetometerDataCallback;
                sensorMap[Tools.MAGNETOMETER] = magnetometer;
            }
            if (orientationModel.IsSupported)
            {
                orientation                  = new OrientationSensor();
                orientation.PausePolicy      = SensorPausePolicy.None;
                orientation.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                orientation.DataUpdated     += storeOrientationSensorDataCallback;
                sensorMap[Tools.ORIENTATION] = orientation;
            }
            if (pressureModel.IsSupported)
            {
                pressure                  = new PressureSensor();
                pressure.PausePolicy      = SensorPausePolicy.None;
                pressure.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                pressure.DataUpdated     += storePressureSensorDataCallback;
                sensorMap[Tools.PRESSURE] = pressure;
            }
            if (proximityModel.IsSupported)
            {
                proximity                  = new ProximitySensor();
                proximity.PausePolicy      = SensorPausePolicy.None;
                proximity.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                proximity.DataUpdated     += storeProximitySensorDataCallback;
                sensorMap[Tools.PROXIMITY] = proximity;
            }
            if (temperatureModel.IsSupported)
            {
                temperature                  = new TemperatureSensor();
                temperature.PausePolicy      = SensorPausePolicy.None;
                temperature.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                temperature.DataUpdated     += storeTemperatureSensorDataCallback;
                sensorMap[Tools.TEMPERATURE] = temperature;
            }
            if (ultravioletModel.IsSupported)
            {
                ultraviolet                  = new UltravioletSensor();
                ultraviolet.PausePolicy      = SensorPausePolicy.None;
                ultraviolet.Interval         = Tools.DEFAULT_SENSOR_SAMPLING_INTERVAL;
                ultraviolet.DataUpdated     += storeUltravioletSensorDataCallback;
                sensorMap[Tools.ULTRAVIOLET] = ultraviolet;
            }
            #endregion

            loadCampaignSettings();
        }
Beispiel #19
0
        public async Task <JsonResult> SendData(int heartRate)
        {
            try
            {
                using (var httpClient1 = new HttpClient())
                {
                    HeartRateMessage hmMessage = null;
                    dynamic          jsonData  = new ExpandoObject();
                    jsonData.n       = 1;
                    jsonData.timeout = 60000;
                    jsonData.wait    = 0;
                    jsonData.delete  = false;
                    HttpRequestMessage request = new HttpRequestMessage
                    {
                        Content    = new StringContent(JsonConvert.SerializeObject(jsonData), Encoding.UTF8, "application/json"),
                        Method     = HttpMethod.Post,
                        RequestUri = new Uri("https://mq-aws-eu-west-1-1.iron.io/3/projects/57dbdea41e0aa6000858dbae/queues/messages/reservations?oauth=pqYbPAL1MN3mf5PyBu2S")
                    };
                    //reserve message in iron message queue for 1 minute
                    var response = await httpClient1.SendAsync(request);

                    if (response.IsSuccessStatusCode)
                    {
                        IList <HeartRateMessage> messagesLst = null;
                        var ironResponse = await response.Content.ReadAsStringAsync();

                        var ironMessage = JsonConvert.DeserializeObject <IDictionary <string, object> >(ironResponse);
                        if (ironMessage.Count > 0 && ironMessage.ContainsKey("messages"))
                        {
                            messagesLst = JsonConvert.DeserializeObject <IList <HeartRateMessage> >(ironMessage["messages"].ToString());
                        }

                        if (messagesLst != null && messagesLst.LastOrDefault() != null)
                        {
                            hmMessage = messagesLst.LastOrDefault();
                        }

                        Parallel.Invoke(() =>
                        {
                            if (hmMessage != null)
                            {
                                //delete iron queue message after reading
                                DeleteIronMessageByID(hmMessage.id, hmMessage.reservation_id);
                            }
                        }, async() =>
                        {
                            if (hmMessage == null || (hmMessage != null && !string.IsNullOrEmpty(hmMessage.body) && !hmMessage.body.ToUpper().Contains("DONE")))
                            {
                                HeartRateMonitor hrMonitor = new HeartRateMonitor();
                                hrMonitor.deviceID         = mDeviceID;
                                hrMonitor.heartRate        = heartRate;
                                using (var httpClient2 = new HttpClient())
                                {
                                    httpClient2.DefaultRequestHeaders.Accept.Clear();
                                    httpClient2.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                                    httpClient2.DefaultRequestHeaders.Add("Authorization", "Bearer iguZgpnIwr8N60cD7cYgSMbYQm9QZXEY9AaqmeD6f4d2DoyvZNEhcQdzGSSFivDylWcXR5ShTu1AfMSCJi9sAj");
                                    request = new HttpRequestMessage
                                    {
                                        Content    = new StringContent(JsonConvert.SerializeObject(hrMonitor), Encoding.UTF8, "application/json"),
                                        Method     = HttpMethod.Post,
                                        RequestUri = new Uri("https://ingestion-xcdvudaz0dz3.us3.sfdcnow.com/streams/heart_rate_monito001/heart_rate_monito001/event")
                                    };
                                    response = await httpClient2.SendAsync(request);
                                }
                            }
                        });
                    }

                    if (hmMessage == null)
                    {
                        return(Json(null));
                    }
                    else
                    {
                        return(Json(hmMessage.body));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(null));
            }
        }
Beispiel #20
0
        public async Task <JsonResult> SendData(int heartRate)
        {
            try
            {
                HeartRateMessage hmMessage = null;
                using (var httpClient1 = new HttpClient())
                {
                    HeartRateMonitor hrMonitor = new HeartRateMonitor();
                    hrMonitor.deviceID  = ConfigVars.Instance.DeviceID;
                    hrMonitor.heartRate = heartRate;
                    httpClient1.DefaultRequestHeaders.Accept.Clear();
                    httpClient1.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    httpClient1.DefaultRequestHeaders.Add("Authorization", ConfigVars.Instance.DeviceToken);
                    HttpRequestMessage request = new HttpRequestMessage
                    {
                        Content    = new StringContent(JsonConvert.SerializeObject(hrMonitor), Encoding.UTF8, "application/json"),
                        Method     = HttpMethod.Post,
                        RequestUri = new Uri(ConfigVars.Instance.EnpointUrl)
                    };
                    var response = await httpClient1.SendAsync(request);

                    if (response.IsSuccessStatusCode)
                    {
                        using (var httpClient2 = new HttpClient())
                        {
                            dynamic jsonData = new ExpandoObject();
                            jsonData.n       = 1;
                            jsonData.timeout = 60000;
                            jsonData.wait    = 0;
                            jsonData.delete  = false;
                            request          = new HttpRequestMessage
                            {
                                Content    = new StringContent(JsonConvert.SerializeObject(jsonData), Encoding.UTF8, "application/json"),
                                Method     = HttpMethod.Post,
                                RequestUri = new Uri(string.Format("{0}/reservations?oauth={1}", ConfigVars.Instance.IronMQUrl, ConfigVars.Instance.IronMQToken))
                            };

                            response = await httpClient2.SendAsync(request);

                            if (response.IsSuccessStatusCode)
                            {
                                IList <HeartRateMessage> messagesLst = null;
                                var ironResponse = await response.Content.ReadAsStringAsync();

                                var ironMessage = JsonConvert.DeserializeObject <IDictionary <string, object> >(ironResponse);
                                if (ironMessage.Count > 0 && ironMessage.ContainsKey("messages"))
                                {
                                    messagesLst = JsonConvert.DeserializeObject <IList <HeartRateMessage> >(ironMessage["messages"].ToString());
                                }
                                if (messagesLst != null && messagesLst.Where(p => !string.IsNullOrEmpty(p.body) && p.body.Contains(ConfigVars.Instance.DeviceID)).Count() > 0)
                                {
                                    hmMessage = messagesLst.Where(p => p.body.Contains(ConfigVars.Instance.DeviceID)).LastOrDefault();
                                }

                                if (hmMessage != null)
                                {
                                    Parallel.Invoke(() =>
                                    {
                                        //delete iron queue message after reading
                                        DeleteIronMessageByID(hmMessage.id, hmMessage.reservation_id);
                                    });
                                }
                            }
                        }
                    }
                }

                if (hmMessage == null)
                {
                    return(Json(null));
                }
                else
                {
                    return(Json(hmMessage.body));
                }
            }
            catch (Exception ex)
            {
                return(Json(null));
            }
        }
Beispiel #21
0
        }         //private void Run_Click(object sender, EventArgs e)

        /***********************************************
         *  函数名称:ComponentsStartRun()
         *  功能:依据组件类型启动执行相应的组件
         *  参数:component 相应启动执行的组件
         *  返回值:无
         * **********************************************/
        private void ComponentsStartRun(Component component)
        {
            // 若组件为B01:血压组件
            if (component.GetType().Name == "BloodPressure")
            {
                bloodPressure = (BloodPressure)component;
                int x = 1; //设定血压数据获取方式

                //创建生成血压数据的线程
                //Thread GeneratingBPData_thread = new Thread(bloodPressure.GeneratingBloodPressureData); //不带参数创建Thread
                //GeneratingBPData_thread.Start(); //启动线程

                Thread bp_thread = new Thread(new ParameterizedThreadStart(bloodPressure.run)); //带1个参数传递的线程创建
                bp_thread.Start(x);
            }

            // 若组件为B02:体温组件
            else if (component.GetType().Name == "Temperature")
            {
                temperature = (Temperature)component;
                int x = 1; //设定体温数据获取方式

                //创建生成体温数据的线程
                Thread temp_thread = new Thread(new ParameterizedThreadStart(temperature.run)); //带1个参数传递的线程创建
                temp_thread.Start(x);
            }

            // 若组件为B03:心率组件
            else if (component.GetType().Name == "HeartRate")
            {
                heartRate = (HeartRate)component;
                int x = 1; //设定心率数据获取方式

                //创建生成心率数据的线程
                Thread hr_thread = new Thread(new ParameterizedThreadStart(heartRate.run)); //带1个参数传递的线程创建
                hr_thread.Start(x);
            }

            // 若组件为B04:血压传感器组件
            else if (component.GetType().Name == "BloodPressureSensor")
            {
                bloodPressureSensor = (BloodPressureSensor)component;

                //创建血压传感器执行的线程
                Thread bps_thread = new Thread(bloodPressureSensor.run);
                bps_thread.Start();
            }

            // 若组件为B07:显示控制器组件
            else if (component.GetType().Name == "DisplayController")
            {
                displayController = (DisplayController)component;
                displayController.run();
            }

            //若组件为B10:微处理器组件
            else if (component.GetType().Name == "MicroProcessor")
            {
                microProcessor = (MicroProcessor)component;
                //int x = 1; //设定封装为6LoWPAN报文格式
                string x = "6LoWPAN"; //设定封装为6LoWPAN报文格式
                //创建微处理器执行的线程
                Thread mp_thread = new Thread(new ParameterizedThreadStart(microProcessor.run));
                mp_thread.Start(x);
            }

            // 若组件为B24:监控器器组件
            else if (component.GetType().Name == "MyMonitor")
            {
                MyMonitor myMonitor = (MyMonitor)component;
                myMonitor.run();
            }

            //若组件为B25:血压监控器
            else if (component.GetType().Name == "BloodPressureMonitor")
            {
                BloodPressureMonitor bpMonitor = (BloodPressureMonitor)component;
                bpMonitor.run();
            }

            //若组件为B26:体温监控器
            else if (component.GetType().Name == "TemperatureMonitor")
            {
                TemperatureMonitor tempMonitor = (TemperatureMonitor)component;
                tempMonitor.run();
            }

            //B27 心率监控器
            else if (component.GetType().Name == "HeartRateMonitor")
            {
                HeartRateMonitor hrMonitor = (HeartRateMonitor)component;
                hrMonitor.run();
            }

            // 若组件为C01:患者组件
            else if (component.GetType().Name == "Patient")
            {
                patient = (Patient)component;

                //创建患者组件执行的线程
                Thread patient_thread = new Thread(patient.run); //不带参数创建Thread

                patient_thread.Start();                          //启动线程

                //+++++++++++++++++++ Debug +++++++++++++++++++++++++++++++++//
                //foreach (int[] arr in patient.output_ports[0].Port_queue1)
                //{
                //    Console.WriteLine("血压数据:" + arr[0] + " " + arr[1]);
                //}
                //foreach (double arr in patient.output_ports[1].Port_queue1)
                //{
                //    Console.WriteLine("体温数据:" + arr);
                //}
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
            }

            //若组件为C02:血压传感节点组件
            else if (component.GetType().Name == "BloodPressureSensorNode")
            {
                BPSN = (BloodPressureSensorNode)component;

                //创建血压传感节点组件的线程
                Thread bpsn_thread = new Thread(BPSN.run); //不带参数创建Thread
                bpsn_thread.Start();                       //启动线程
            }

            //若组件为C03:体温传感节点组件
            else if (component.GetType().Name == "TemperatureSensorNode")
            {
                TSN = (TemperatureSensorNode)component;

                //创建体温传感节点组件的线程
                Thread tsn_thread = new Thread(TSN.run); //不带参数创建Thread
                tsn_thread.Start();                      //启动线程
            }

            //若组件为C04:心率传感节点组件
            else if (component.GetType().Name == "HeartRateSensorNode")
            {
                HRSN = (HeartRateSensorNode)component;

                //创建心率传感节点组件的线程
                Thread hrsn_thread = new Thread(HRSN.run); //不带参数创建Thread
                hrsn_thread.Start();                       //启动线程
            }

            //若为C05:物联网网关组件
            else if (component.GetType().Name == "IoTGateway")
            {
                IoTG = (IoTGateway)component;
                //创建物联网网关组件执行的线程
                Thread gateway_thread = new Thread(IoTG.run);
                gateway_thread.Start();
            }

            //若为C07:802.15.1Channel组件
            else if (component.GetType().Name == "Channel802_15_1")
            {
                channel802_15_1 = (Channel802_15_1)component;
                //创建802.15.1Channel组件执行的线程
                Thread channel_802151_thread = new Thread(channel802_15_1.run);
                channel_802151_thread.Start();
            }

            //若为C08:802.15.4Channel组件
            else if (component.GetType().Name == "Channel802_15_4")
            {
                channel802_15_4 = (Channel802_15_4)component;
                //创建802.15.4Channel组件执行的线程
                Thread channel_802154_thread = new Thread(channel802_15_4.run);
                channel_802154_thread.Start();
            }

            //若为C09:Ethernet信道组件
            else if (component.GetType().Name == "ChannelEthernet")
            {
                channel_ethernet = (ChannelEthernet)component;
                //创建EthernetChannel组件执行的线程
                Thread channel_ethernet_thread = new Thread(channel_ethernet.run);
                channel_ethernet_thread.Start();
            }

            //若为C10:IPv6路由器组件
            else if (component.GetType().Name == "IPv6Router")
            {
                ipv6Router = (IPv6Router)component;
                //创建IPv6Router组件执行的线程
                Thread ipv6_router_thread = new Thread(ipv6Router.run);
                ipv6_router_thread.Start();
            }

            //若为C11:医疗服务器组件
            else if (component.GetType().Name == "MedicalServer")
            {
                MS = (MedicalServer)component;
                //创建MedicalServer组件执行线程
                Thread ms_thread = new Thread(MS.run);
                ms_thread.Start();
            }
        }
Beispiel #22
0
        /***************************************************************************
        *  函数名称:treeView1_NodeMouseDoubleClick()
        *  功能:组件库列表表项鼠标双击事件,在graphControl绘图控制区创建相应组件
        *  参数:sender;e
        *  返回值:无
        * *************************************************************************/
        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            if (treeView1.SelectedNode.Level > 1)
            {
                string name;
                //int tabIndex = 0; //第一个选项卡
                name = e.Node.Name.ToString();
                switch (name)
                {
                //================================================================//
                //======================创建基本组件==============================//
                //================================================================//
                //B01 人体血压
                case "BloodPressure":
                    bloodPressure = new BloodPressure(this.graphControl, null, null, null);
                    graphControl.AddShape(bloodPressure, bloodPressure.Location);
                    break;

                //B02 人体体温
                case "Temperature":
                    temperature = new Temperature(this.graphControl, null, null, null);
                    graphControl.AddShape(temperature, new PointF(temperature.Location.X, temperature.Location.Y + 80));
                    break;

                //B03 人体心率
                case "HeartRate":
                    heartRate = new HeartRate(this.graphControl, null, null, null);
                    graphControl.AddShape(heartRate, new PointF(heartRate.Location.X, heartRate.Location.Y + 160));
                    break;

                //B04 血压传感器
                case "BloodPressureSensor":
                    bloodPressureSensor = new BloodPressureSensor(this.graphControl, null, null, null);
                    graphControl.AddShape(bloodPressureSensor, new PointF(bloodPressureSensor.Location.X + 110, bloodPressureSensor.Location.Y));
                    break;

                //B05 体温传感器
                case "TemperatureSensor":
                    temperatureSensor = new TemperatureSensor(this.graphControl, null, null, null);
                    graphControl.AddShape(temperatureSensor, new PointF(temperatureSensor.Location.X + 110, temperatureSensor.Location.Y + 80));
                    break;

                //B06 心率传感器
                case "HeartRateSensor":
                    heartRateSensor = new HeartRateSensor(this.graphControl, null, null, null);
                    graphControl.AddShape(heartRateSensor, new PointF(heartRateSensor.Location.X + 110, heartRateSensor.Location.Y + 160));
                    break;

                //B07 显示控制器
                case "DisplayController":
                    displayController = new DisplayController(this.graphControl, null, null, null);
                    graphControl.AddShape(displayController, new PointF(displayController.Location.X + 220, displayController.Location.Y));
                    break;

                //B08 音频控制器
                case "AudioController":
                    audioController = new AudioController(this.graphControl, null, null, null);
                    graphControl.AddShape(audioController, new PointF(audioController.Location.X + 220, audioController.Location.Y + 80));
                    break;

                //B09 电机控制器
                case "ElectricMachineryController":
                    electricMachineryController = new ElectricMachineryController(this.graphControl, null, null, null);
                    graphControl.AddShape(electricMachineryController, new PointF(electricMachineryController.Location.X + 220, electricMachineryController.Location.Y + 160));
                    break;

                //B10 运算器 微处理器
                case "MicroProcessor":
                    microProcessor = new MicroProcessor(this.graphControl, null, null, null);
                    graphControl.AddShape(microProcessor, new PointF(microProcessor.Location.X + 330, microProcessor.Location.Y));
                    break;

                //B11 协议转换器
                case "ProtocolConverter":
                    protocolConverter = new ProtocolConverter(this.graphControl, null, null, null);
                    graphControl.AddShape(protocolConverter, new PointF(protocolConverter.Location.X + 330, protocolConverter.Location.Y + 70));
                    break;

                //B12 数据处理器
                case "DataProcessor":
                    dataProcessor = new DataProcessor(this.graphControl, null, null, null);
                    graphControl.AddShape(dataProcessor, new PointF(dataProcessor.Location.X + 330, dataProcessor.Location.Y + 160));
                    break;

                //B13 数据分析器
                case "DataAnalyzer":
                    dataAnalyzer = new DataAnalyzer(this.graphControl, null, null, null);
                    graphControl.AddShape(dataAnalyzer, new PointF(dataAnalyzer.Location.X + 330, dataAnalyzer.Location.Y + 240));
                    break;

                //B14 有线通信模块
                case "WiredModule":
                    wiredModule = new WiredModule(this.graphControl, null, null, null);
                    graphControl.AddShape(wiredModule, new PointF(wiredModule.Location.X + 440, wiredModule.Location.Y));
                    break;

                //B15 无线通信模块
                case "WirelessModule":
                    wirelessModule = new WirelessModule(this.graphControl, null, null, null);
                    graphControl.AddShape(wirelessModule, new PointF(wirelessModule.Location.X + 440, wirelessModule.Location.Y + 80));
                    break;

                //B16 有线媒介
                case "WiredMedia":
                    wiredMedia = new WiredMedia(this.graphControl, null, null, null);
                    graphControl.AddShape(wiredMedia, new PointF(wiredMedia.Location.X + 440, wiredMedia.Location.Y + 160));
                    break;

                //B17 无线媒介
                case "WirelessMedia":
                    wirelessMedia = new WirelessMedia(this.graphControl, null, null, null);
                    graphControl.AddShape(wirelessMedia, new PointF(wirelessMedia.Location.X + 440, wirelessMedia.Location.Y + 240));
                    break;

                //18 寄存器
                case "Register":
                    register = new Register(this.graphControl, null, null, null);
                    graphControl.AddShape(register, new PointF(register.Location.X + 550, register.Location.Y));
                    break;

                //B19 存储器RAM
                case "RAM":
                    ram = new RAM(this.graphControl, null, null, null);
                    graphControl.AddShape(ram, new PointF(ram.Location.X + 550, ram.Location.Y + 80));
                    break;

                //B20 存储器ROM
                case "ROM":
                    rom = new ROM(this.graphControl, null, null, null);
                    graphControl.AddShape(rom, new PointF(rom.Location.X + 550, rom.Location.Y + 160));
                    break;

                //B21 数据存储器
                case "DataMemory":
                    dataMemory = new DataMemory(this.graphControl, null, null, null);
                    graphControl.AddShape(dataMemory, new PointF(dataMemory.Location.X + 550, dataMemory.Location.Y + 240));
                    break;

                //B22 缓冲区
                case "Buffer":
                    buffer = new MyBuffer(this.graphControl, null, null, null);
                    graphControl.AddShape(buffer, new PointF(buffer.Location.X + 550, buffer.Location.Y + 320));
                    break;

                //B23 路由模块
                case "RouteModule":
                    routeModule = new RouteModule(this.graphControl, null, null, null);
                    graphControl.AddShape(routeModule, new PointF(routeModule.Location.X + 330, routeModule.Location.Y + 320));
                    break;

                //B24 监控器
                case "Monitor":
                    monitor = new MyMonitor(this.graphControl, null, null, null);
                    graphControl.AddShape(monitor, new PointF(monitor.Location.X + 220, monitor.Location.Y + 240));
                    break;

                //B25 血压监控器
                case "BloodPressureMonitor":
                    bpMonitor = new BloodPressureMonitor(this.graphControl, null, null, null);
                    graphControl.AddShape(bpMonitor, new PointF(bpMonitor.Location.X + 220, bpMonitor.Location.Y + 280));
                    break;

                //B26 体温监控器
                case "TemperatureMonitor":
                    tempMonitor = new TemperatureMonitor(this.graphControl, null, null, null);
                    graphControl.AddShape(tempMonitor, new PointF(tempMonitor.Location.X + 220, tempMonitor.Location.Y + 320));
                    break;

                //B27 心率监控器
                case "HeartRateMonitor":
                    hrMonitor = new HeartRateMonitor(this.graphControl, null, null, null);
                    graphControl.AddShape(hrMonitor, new PointF(hrMonitor.Location.X + 220, hrMonitor.Location.Y + 360));
                    break;

                //====================================================================//
                //======================CMIoT组件库中组件=============================//
                //====================================================================//
                //C01 患者组件
                case "Patient":
                    patient = new Patient(this.graphControl);
                    graphControl.AddShape(patient, patient.Location);
                    break;

                //C02 血压传感节点
                case "BloodPressureSensorNode":
                    BPSN = new BloodPressureSensorNode(this.graphControl);
                    //BPSN_InsideForm = new InsideForm(BPSN); //构建内部结构
                    graphControl.AddShape(BPSN, BPSN.Location);
                    break;

                //C03 体温传感节点
                case "TemperatureSensorNode":
                    TSN = new TemperatureSensorNode(this.graphControl);
                    graphControl.AddShape(TSN, TSN.Location);
                    break;

                //C04 心率传感节点
                case "HeartRateSensorNode":
                    HRSN = new HeartRateSensorNode(this.graphControl);
                    graphControl.AddShape(HRSN, HRSN.Location);
                    break;

                //C05 物联网网关
                case "IoTGateway":
                    IoTG = new IoTGateway(this.graphControl);
                    graphControl.AddShape(IoTG, IoTG.Location);
                    break;

                //C06 802.11信道组件
                case "802.11Channel":
                    channel_802_11 = new Channel802_11(this.graphControl, null, null, null);
                    graphControl.AddShape(channel_802_11, channel_802_11.Location);
                    break;

                //C07 802.15.1信道组件
                case "802.15.1Channel":
                    channel802_15_1 = new Channel802_15_1(this.graphControl, null, null, null);
                    graphControl.AddShape(channel802_15_1, channel802_15_1.Location);
                    break;

                //C08 802.15.4信道组件
                case "802.15.4Channel":
                    channel802_15_4 = new Channel802_15_4(this.graphControl, null, null, null);
                    graphControl.AddShape(channel802_15_4, channel802_15_4.Location);
                    break;

                //C09 Ethernet信道组件
                case "EthernetChannel":
                    channel_ethernet = new ChannelEthernet(this.graphControl, null, null, null);
                    graphControl.AddShape(channel_ethernet, channel_ethernet.Location);
                    break;

                //C10 IPv6路由器组件
                case "IPv6Router":
                    ipv6Router = new IPv6Router(this.graphControl);
                    graphControl.AddShape(ipv6Router, ipv6Router.Location);
                    break;

                //C11 医疗服务器组件
                case "MedicalServer":
                    MS = new MedicalServer(this.graphControl);
                    graphControl.AddShape(MS, MS.Location);
                    break;
                }
            } // if (treeView1.SelectedNode.Level > 1)
        }     //treeView1_NodeMouseDoubleClick