Exemplo n.º 1
0
        /// <summary>
        /// Open the BLE controller for connection
        /// </summary>
        /// <returns>Open success</returns>
        public bool Open()
        {
            if (this.Settings.Address == null)
            {
                throw new Exception("No BlueNRG_HRM address specified");
            }

            this.bag.Clear();

#if BLE_EMULATION
            // using running thread simulate sensors data
            this.isRunning     = true;
            this.readingThread = new Thread(this.ReadingThread);
            this.readingThread.Start();
#else
            this.bleController = new HCISimpleSerialCentralProfileController(BLE_SERIAL_PORT, BLE_BAUD_RATE);

            this.bleController.Start();

            if (!this.bleController.Reset(HCIController.ResetTypeEnum.HardReset))
            {
                Debug.Print("BLE Controller reset failed");
                return(false);
            }

            if (!this.bleController.Init())
            {
                Debug.Print("BLE Controller init failed");
                return(false);
            }

            if (!this.bleController.ConnectTo(this.Settings.Address, out this.bleConnectionHandle))
            {
                Debug.Print("Unable to connect to the BlueNRG_HRM");
                return(false);
            }

            this.bleController.OnNotification += bleController_OnNotification;

            byte[] data;
            if (!this.bleController.ReadCharacteristic(this.bleConnectionHandle, BODY_SENSOR_LOCATION_HANDLE, out data))
            {
                throw new Exception("Unable to read from BlueNRG_HRM");
            }

            if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, HEART_RATE_CONFIG_CHARACTERISTIC_HANDLE, (short)1))
            {
                Debug.Print("Unable write notification 1 on BlueNRG_HRM");
            }
#endif

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Open the BLE controller for connection
        /// </summary>
        /// <returns>Open success</returns>
        public bool Open()
        {
            if (this.Settings.Address == null)
                throw new Exception("No BlueNRG_HRM address specified");

            this.bag.Clear();

#if BLE_EMULATION
            // using running thread simulate sensors data
            this.isRunning = true;
            this.readingThread = new Thread(this.ReadingThread);
            this.readingThread.Start();
#else
            this.bleController = new HCISimpleSerialCentralProfileController(BLE_SERIAL_PORT, BLE_BAUD_RATE);

            this.bleController.Start();

            if (!this.bleController.Reset(HCIController.ResetTypeEnum.HardReset))
            {
                Debug.Print("BLE Controller reset failed");
                return false;
            }

            if (!this.bleController.Init())
            {
                Debug.Print("BLE Controller init failed");
                return false;
            }

            if (!this.bleController.ConnectTo(this.Settings.Address, out this.bleConnectionHandle))
            {
                Debug.Print("Unable to connect to the BlueNRG_HRM");
                return false;
            }

            this.bleController.OnNotification += bleController_OnNotification;

            byte[] data;
            if (!this.bleController.ReadCharacteristic(this.bleConnectionHandle, BODY_SENSOR_LOCATION_HANDLE, out data))
            {
                throw new Exception("Unable to read from BlueNRG_HRM");
            }

            if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, HEART_RATE_CONFIG_CHARACTERISTIC_HANDLE, (short)1))
            {
                Debug.Print("Unable write notification 1 on BlueNRG_HRM");
            }
#endif

            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Open the BLE controller for connection
        /// </summary>
        /// <returns>Open success</returns>
        public bool Open()
        {
            if (this.Settings.Address == null)
                throw new Exception("No TI Sensor Tag address specified");

            this.bag.Clear();

#if !BLE_EMULATION

            this.bleController = new HCISimpleSerialCentralProfileController(BLE_SERIAL_PORT, BLE_BAUD_RATE);

            this.bleController.Start();

            if (!this.bleController.Reset(HCIController.ResetTypeEnum.HardReset))
            {
                Debug.Print("BLE Controller reset failed");
                return false;
            }

            if (!this.bleController.Init())
            {
                Debug.Print("BLE Controller init failed");
                return false;
            }
#endif

#if !BLE_NOTIFICATION
            // using running thread a little connections to get sensors data
            this.isRunning = true;
            this.readingThread = new Thread(this.ReadingThread);
            this.readingThread.Start();
#else
            // using BLE notification
            if (!this.bleController.ConnectTo(this.Settings.Address, out this.bleConnectionHandle))
            {
                Debug.Print("Unable to connect to the TI Sensor Tag");
                return false;
            }

            this.bleController.OnNotification += bleController_OnNotification;

            #region Enable Temperature ...

            if (this.Settings.IsTemperatureEnabled)
            {
                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, IR_TEMP_CONFIG_CHARACTERISTIC_HANDLE, (byte)1))
                {
                    Debug.Print("Unable write config 1 on TI Sensor Tag");
                }

                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, IR_TEMP_NOTIFICATION_CHARACTERISTIC_HANDLE, (short)1))
                {
                    Debug.Print("Unable write notification 1 on TI Sensor Tag");
                }
            }

            #endregion

            #region Enable Humidity ...

            if (this.Settings.IsHumidityEnabled)
            {
                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, HUMIDITY_CONFIG_CHARACTERISTIC_HANDLE, (byte)1))
                {
                    Debug.Print("Unable write config 1 on TI Sensor Tag");
                }

                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, HUMIDITY_NOTIFICATION_CHARACTERISTIC_HANDLE, (short)1))
                {
                    Debug.Print("Unable write notification 1 on TI Sensor Tag");
                }
            }

            #endregion

            #region Enable Accelerometer ...

            if (this.Settings.IsAccelerometerEnabled)
            {
                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, ACCELEROMETER_CONFIG_CHARACTERISTIC_HANDLE, (byte)1))
                {
                    Debug.Print("Unable write config 1 on TI Sensor Tag");
                }

                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, ACCELEROMETER_NOTIFICATION_CHARACTERISTIC_HANDLE, (short)1))
                {
                    Debug.Print("Unable write notification 1 on TI Sensor Tag");
                }
            }

            #endregion
#endif

            return true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Open the BLE controller for connection
        /// </summary>
        /// <returns>Open success</returns>
        public bool Open()
        {
            if (this.Settings.Address == null)
            {
                throw new Exception("No TI Sensor Tag address specified");
            }

            this.bag.Clear();

#if !BLE_EMULATION
            this.bleController = new HCISimpleSerialCentralProfileController(BLE_SERIAL_PORT, BLE_BAUD_RATE);

            this.bleController.Start();

            if (!this.bleController.Reset(HCIController.ResetTypeEnum.HardReset))
            {
                Debug.Print("BLE Controller reset failed");
                return(false);
            }

            if (!this.bleController.Init())
            {
                Debug.Print("BLE Controller init failed");
                return(false);
            }
#endif

#if !BLE_NOTIFICATION
            // using running thread a little connections to get sensors data
            this.isRunning     = true;
            this.readingThread = new Thread(this.ReadingThread);
            this.readingThread.Start();
#else
            // using BLE notification
            if (!this.bleController.ConnectTo(this.Settings.Address, out this.bleConnectionHandle))
            {
                Debug.Print("Unable to connect to the TI Sensor Tag");
                return(false);
            }

            this.bleController.OnNotification += bleController_OnNotification;

            #region Enable Temperature ...

            if (this.Settings.IsTemperatureEnabled)
            {
                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, IR_TEMP_CONFIG_CHARACTERISTIC_HANDLE, (byte)1))
                {
                    Debug.Print("Unable write config 1 on TI Sensor Tag");
                }

                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, IR_TEMP_NOTIFICATION_CHARACTERISTIC_HANDLE, (short)1))
                {
                    Debug.Print("Unable write notification 1 on TI Sensor Tag");
                }
            }

            #endregion

            #region Enable Humidity ...

            if (this.Settings.IsHumidityEnabled)
            {
                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, HUMIDITY_CONFIG_CHARACTERISTIC_HANDLE, (byte)1))
                {
                    Debug.Print("Unable write config 1 on TI Sensor Tag");
                }

                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, HUMIDITY_NOTIFICATION_CHARACTERISTIC_HANDLE, (short)1))
                {
                    Debug.Print("Unable write notification 1 on TI Sensor Tag");
                }
            }

            #endregion

            #region Enable Accelerometer ...

            if (this.Settings.IsAccelerometerEnabled)
            {
                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, ACCELEROMETER_CONFIG_CHARACTERISTIC_HANDLE, (byte)1))
                {
                    Debug.Print("Unable write config 1 on TI Sensor Tag");
                }

                if (!this.bleController.WriteCharacteristic(this.bleConnectionHandle, ACCELEROMETER_NOTIFICATION_CHARACTERISTIC_HANDLE, (short)1))
                {
                    Debug.Print("Unable write notification 1 on TI Sensor Tag");
                }
            }

            #endregion
#endif

            return(true);
        }