Example #1
0
        public static GattProperty ToNative(this CharacteristicProperties properties)
        {
            if (properties.HasFlag(CharacteristicProperties.NotifyEncryptionRequired))
            {
                throw new ArgumentException("NotifyEncryptionRequired not supported on Android");
            }

            if (properties.HasFlag(CharacteristicProperties.IndicateEncryptionRequired))
            {
                throw new ArgumentException("IndicateEncryptionRequired not supported on Android");
            }

            var value = properties
                        .ToString()
                        .Replace(
                CharacteristicProperties.WriteNoResponse.ToString(),
                GattProperty.WriteNoResponse.ToString()
                )
                        .Replace(
                CharacteristicProperties.AuthenticatedSignedWrites.ToString(),
                GattProperty.SignedWrite.ToString()
                )
                        .Replace(
                CharacteristicProperties.ExtendedProperties.ToString(),
                GattProperty.ExtendedProps.ToString()
                );

            return((GattProperty)Enum.Parse(typeof(GattProperty), value));
        }
Example #2
0
        public static CBCharacteristicProperties ToNative(this CharacteristicProperties properties)
        {
            var nativeProps = CBCharacteristicProperties.Read;

            if (!properties.HasFlag(CharacteristicProperties.Read))
            {
                nativeProps &= ~CBCharacteristicProperties.Read;
            }

            if (properties.HasFlag(CharacteristicProperties.AuthenticatedSignedWrites))
            {
                nativeProps |= CBCharacteristicProperties.AuthenticatedSignedWrites;
            }

            if (properties.HasFlag(CharacteristicProperties.Broadcast))
            {
                nativeProps |= CBCharacteristicProperties.Broadcast;
            }

            if (properties.HasFlag(CharacteristicProperties.ExtendedProperties))
            {
                nativeProps |= CBCharacteristicProperties.ExtendedProperties;
            }

            if (properties.HasFlag(CharacteristicProperties.Indicate))
            {
                nativeProps |= CBCharacteristicProperties.Indicate;
            }

            if (properties.HasFlag(CharacteristicProperties.IndicateEncryptionRequired))
            {
                nativeProps |= CBCharacteristicProperties.IndicateEncryptionRequired;
            }

            if (properties.HasFlag(CharacteristicProperties.Notify))
            {
                nativeProps |= CBCharacteristicProperties.Notify;
            }

            if (properties.HasFlag(CharacteristicProperties.NotifyEncryptionRequired))
            {
                nativeProps |= CBCharacteristicProperties.NotifyEncryptionRequired;
            }

            if (properties.HasFlag(CharacteristicProperties.Write))
            {
                nativeProps |= CBCharacteristicProperties.Write;
            }

            if (properties.HasFlag(CharacteristicProperties.WriteNoResponse))
            {
                nativeProps |= CBCharacteristicProperties.WriteWithoutResponse;
            }

            return(nativeProps);
        }
Example #3
0
            /// <summary>
            /// Method that loads service and characteristics and checks they are suitable
            /// </summary>
            /// <param name="p0">Gatt server</param>
            /// <returns>True if successful</returns>
            protected override bool IsRequiredServiceSupported(BluetoothGatt p0)
            {
                if (_manager._services != null)
                {
                    foreach (ServiceAndCharacteristicsParcel parcel in _manager._services)
                    {
                        // Get the service
                        BluetoothGattService service = p0.GetService(UUID.FromString(parcel.Service.ToString()));
                        if (service != null)
                        {
                            // Check each characteristic
                            foreach (KeyValuePair <Guid, CharacteristicsParcel> characteristicsParcel in parcel.Characteristics)
                            {
                                if (!_manager._characteristics.ContainsKey(characteristicsParcel.Key))
                                {
                                    // Get the characteristic
                                    BluetoothGattCharacteristic characteristic = service.GetCharacteristic(UUID.FromString(characteristicsParcel.Key.ToString()));

                                    if (characteristic != null)
                                    {
                                        // Add the service to the local dictionary
                                        _manager._characteristics.Add(characteristicsParcel.Key, characteristic);

                                        // Find the required properties of this characteristic
                                        CharacteristicProperties properties = characteristicsParcel.Value.Properties;

                                        // Now check that the characteristic supports the required properties
                                        GattProperty rxProperties = characteristic.Properties;

                                        // Read request
                                        if (properties.HasFlag(CharacteristicProperties.Read))
                                        {
                                            if (!rxProperties.HasFlag(GattProperty.Read))
                                            {
                                                return(false);
                                            }
                                        }

                                        // Write request
                                        if (properties.HasFlag(CharacteristicProperties.Write))
                                        {
                                            if (!rxProperties.HasFlag(GattProperty.Write))
                                            {
                                                return(false);
                                            }
                                        }

                                        // Notifications
                                        if (properties.HasFlag(CharacteristicProperties.Notify))
                                        {
                                            if (!rxProperties.HasFlag(GattProperty.Notify))
                                            {
                                                return(false);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                }
                return(true);
            }