Example #1
0
        public override void OnCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
        {
            base.OnCharacteristicChanged(gatt, characteristic);

            Console.WriteLine("OnCharacteristicChanged: " + characteristic.GetStringValue(0));

            //this.CharacteristicValueUpdated (this, new CharacteristicReadEventArgs () {
            //	Characteristic = new Characteristic (characteristic, gatt, this) }
            //);
        }
Example #2
0
        public override void OnCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
        {
            base.OnCharacteristicRead(gatt, characteristic, status);

            Console.WriteLine("OnCharacteristicRead: " + characteristic.GetStringValue(0));

            this.CharacteristicValueUpdated(this, new CharacteristicReadEventArgs()
            {
                Characteristic = new Characteristic(characteristic, gatt, this)
            }
                                            );
        }
Example #3
0
        public override void OnCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
        {
            base.OnCharacteristicRead(gatt, characteristic, status);
            Log.Debug(TAG, "The Characteristic Was Read");
            lastChange = DateTime.Now;

            /// Reading the device data from the sensor
            // Each char only varies by one digit so only need to look at that single digit
            string uuid = characteristic.Uuid.ToString();

            uuid = uuid.Substring(0, uuid.IndexOf('-'));
            uuid = "" + uuid.Last();

            // Adding the device name if needed
            if (!deviceDetails.ContainsKey(BluetoothConstants.DEVICE_NAME))
            {
                deviceDetails.Add(BluetoothConstants.DEVICE_NAME, gatt.Device.Name);
            }

            // Holds the key
            string key   = "";
            string value = characteristic.GetStringValue(0);

            // Getting which char was read
            switch (uuid)
            {
            case "4":
                key = BluetoothConstants.MODEL_NUMBER;
                Log.Debug(TAG, "The model number is: " + value);
                goto default;

            case "5":
                key = BluetoothConstants.SERIAL_NUMBER;
                Log.Debug(TAG, "The serial number is: " + value);
                goto default;

            case "6":
                key = BluetoothConstants.FW_REV;
                Log.Debug(TAG, "The firmware revision is: " + value);
                goto default;

            case "7":
                key = BluetoothConstants.HW_REV;
                Log.Debug(TAG, "The hardware revision is: " + value);
                goto default;

            case "8":
                key = BluetoothConstants.SW_REV;
                Log.Debug(TAG, "The software revision is: " + value);
                goto default;

            default:
                if (deviceDetails.ContainsKey(key))
                {
                    deviceDetails[key] = value;
                }
                else
                {
                    deviceDetails.Add(key, value);
                }
                break;
            }

            // Removing char from the list, it's been read successfully
            deviceChar.Remove(characteristic);

            // Disabling notifications for the char
            gatt.SetCharacteristicNotification(characteristic, false);

            // If there are more to read
            if (deviceChar.Count > 0)
            {
                requestCharacteristic(gatt);
            }
            else
            {
                // All the device info chars have been read
                connectToService(gatt);
            }
        }
        public override void OnCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
                                                  [GeneratedEnum] GattStatus status)
        {
            switch (status)
            {
            case GattStatus.Success:
                DisplayMessageToUi("Se preiau date...");
                if (BLEHelpers.BLE_CHAR_GLUCOSE_MANUFACTURE.Equals(characteristic.Uuid))
                {
                    string manufacturer = characteristic.GetStringValue(0);
                    _isIsensMeter = manufacturer.Equals("i-SENS");
                    if (!manufacturer.Equals("i-SENS"))
                    {
                        Log.Error("Manfacture Error", "Device not supported");
                        gatt.Disconnect();
                    }
                    else if (_deviceSoftwareRevisionCharacteristic != null)
                    {
                        gatt.ReadCharacteristic(_deviceSoftwareRevisionCharacteristic);
                    }
                    else if (_deviceSerialCharacteristic != null)
                    {
                        gatt.ReadCharacteristic(_deviceSerialCharacteristic);
                    }
                }
                else if (BLEHelpers.BLE_CHAR_SOFTWARE_REVISION.Equals(characteristic.Uuid))
                {
                    if (_isIsensMeter)
                    {
                        Log.Error("Revision", characteristic.GetStringValue(0));
                        _bleSwRevision = characteristic.GetStringValue(0).Split(".");
                        int parseInt = int.Parse(_bleSwRevision[0]);
                        if (parseInt > 1 || _customTimeCharacteristic == null)
                        {
                            Log.Error("Error Revision",
                                      "Revision greater or equal with 1 and mCustomTimeCharacteristic is null. Disconecting...");
                            gatt.Disconnect();
                            return;
                        }
                    }

                    if (_deviceSerialCharacteristic != null)
                    {
                        gatt.ReadCharacteristic(_deviceSerialCharacteristic);
                    }
                }
                else if (BLEHelpers.BLE_CHAR_GLUCOSE_SERIALNUM.Equals(characteristic.Uuid))
                {
                    _serial = characteristic.GetStringValue(0);
                    Log.Error("Serial", _serial);
                    EnableRecordAccessControlPointIndication(gatt);
                }

                break;

            case GattStatus.ConnectionCongested:
                break;

            case GattStatus.Failure:
                break;

            case GattStatus.InsufficientAuthentication:
                break;

            case GattStatus.InsufficientEncryption:
                break;

            case GattStatus.InvalidAttributeLength:
                break;

            case GattStatus.InvalidOffset:
                break;

            case GattStatus.ReadNotPermitted:
                break;

            case GattStatus.RequestNotSupported:
                break;

            case GattStatus.WriteNotPermitted:
                break;

            default:
                Log.Error("OnCharacteristicRead", "Unrecognized Status " + status);
                break;
            }
        }