예제 #1
0
        protected override IGattCharacteristic CreateNative(Guid uuid, CharacteristicProperties properties, GattPermissions permissions)
        {
            var ch = new GattCharacteristic(this.context, this, uuid, properties, permissions);

            this.Native.AddCharacteristic(ch.Native);
            return(ch);
        }
예제 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="template">Requiered characteristic template</param>
 /// <param name="service">Required parent service</param>
 /// <param name="presentationFormat">Optional overriding of presentation format</param>
 public KnownCharacteristicInfo(ICharacteristicTemplate template, IServiceInfo service, CharacteristicProperties properties, IPresentationFormat presentationFormat)
 {
     Template           = template ?? throw new ArgumentNullException(nameof(template));
     Service            = service ?? throw new ArgumentNullException(nameof(service));
     PresentationFormat = presentationFormat ?? template.PresentationFormat;
     Properties         = properties;
 }
예제 #3
0
        public virtual IGattCharacteristic AddCharacteristic(Guid uuid, CharacteristicProperties properties, GattPermissions permissions)
        {
            var characteristic = this.CreateNative(uuid, properties, permissions);

            this.internalList.Add(characteristic);
            return(characteristic);
        }
예제 #4
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));
        }
예제 #5
0
 /// <summary>
 /// Add a characteristic to the parcel
 /// </summary>
 /// <param name="iCharacteristic">A characteristic</param>
 /// <param name="iProperties">Properties for the characteristic</param>
 /// <returns>True if the characteristic is not already in the parcel</returns>
 public bool AddCharacteristic(Guid iCharacteristic, CharacteristicProperties iProperties)
 {
     if (!Characteristics.ContainsKey(iCharacteristic))
     {
         Characteristics.Add(iCharacteristic, new CharacteristicsParcel(Service, iCharacteristic, iProperties));
         return(true);
     }
     return(false);
 }
예제 #6
0
        public GeneralCharacteristicInfo(IServiceInfo service, Guid uuid, CharacteristicProperties properties, IPresentationFormat presentationFormat) : base(uuid)
        {
            Service            = service ?? throw new ArgumentNullException(nameof(service));
            PresentationFormat = presentationFormat ?? WellKnownPresentationFormats.Unknown;
            Properties         = properties;

            // derive name from UUID
            Name = GetDefaultName();
        }
예제 #7
0
 public UwpGattCharacteristic(IGattService service,
                              Guid characteristicUuid,
                              CharacteristicProperties properties,
                              GattPermissions permissions) : base(service, characteristicUuid, properties, permissions)
 {
     this.nativeReady       = new Subject <GattLocalCharacteristic>();
     this.connectedDevices  = new List <IDevice>();
     this.SubscribedDevices = new ReadOnlyCollection <IDevice>(this.connectedDevices);
 }
예제 #8
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);
        }
예제 #9
0
        protected GattCharacteristicProperties ToNative(CharacteristicProperties props)
        {
            var value = props
                        .ToString()
                        .Replace(CharacteristicProperties.WriteNoResponse.ToString(), GattCharacteristicProperties.WriteWithoutResponse.ToString())
                        .Replace(CharacteristicProperties.NotifyEncryptionRequired.ToString(), String.Empty)
                        .Replace(CharacteristicProperties.IndicateEncryptionRequired.ToString(), String.Empty);

            return((GattCharacteristicProperties)Enum.Parse(typeof(GattCharacteristicProperties), value));
        }
        protected AbstractGattCharacteristic(IGattService service,
                                             Guid characteristicUuid,
                                             CharacteristicProperties properties,
                                             GattPermissions permissions)
        {
            this.Service     = service;
            this.Uuid        = characteristicUuid;
            this.Properties  = properties;
            this.Permissions = permissions;

            this.InternalDescriptors = new List <IGattDescriptor>();
            this.Descriptors         = new ReadOnlyCollection <IGattDescriptor>(this.InternalDescriptors);
        }
예제 #11
0
        public GattCharacteristic(CBPeripheralManager manager,
                                  IGattService service,
                                  Guid characteristicUuid,
                                  CharacteristicProperties properties,
                                  GattPermissions permissions) : base(service, characteristicUuid, properties, permissions)
        {
            this.manager     = manager;
            this.subscribers = new ConcurrentDictionary <NSUuid, IDevice>();

            this.Native = new CBMutableCharacteristic(
                characteristicUuid.ToCBUuid(),
                properties.ToNative(),
                null,
                (CBAttributePermissions)(int)permissions   // TODO
                );
        }
예제 #12
0
        public GattCharacteristic(GattContext context,
                                  IGattService service,
                                  Guid uuid,
                                  CharacteristicProperties properties,
                                  GattPermissions permissions) : base(service, uuid, properties, permissions)
        {
            this.context     = context;
            this.subscribers = new Dictionary <string, IDevice>();
            this.Native      = new BluetoothGattCharacteristic(
                uuid.ToUuid(),
                properties.ToNative(),
                permissions.ToNative()
                );

            this.NotificationDescriptor = new BluetoothGattDescriptor(
                NotifyDescriptorId.ToUuid(),
                GattDescriptorPermission.Write | GattDescriptorPermission.Read
                );
            this.Native.AddDescriptor(this.NotificationDescriptor);
        }
예제 #13
0
 protected override IGattCharacteristic CreateNative(Guid uuid, CharacteristicProperties properties, GattPermissions permissions)
 {
     return(new GattCharacteristic(this.context, this, uuid, properties, permissions));
 }
예제 #14
0
 protected override IGattCharacteristic CreateNative(Guid uuid, CharacteristicProperties properties, GattPermissions permissions)
 => new UwpGattCharacteristic(this, uuid, properties, permissions);
예제 #15
0
        //public static Guid FromCBUuid(this CBUUID uuid)
        //{
        //var bytes = uuid.Data.ToArray();
        //return new Guid(bytes);
        //}


        public static CBCharacteristicProperties ToNative(this CharacteristicProperties properties)
        {
            var native = ConvertFlags <CBCharacteristicProperties>(properties);

            return(native);
        }
예제 #16
0
 public MockGattCharacteristic(IGattService service, Guid guid, CharacteristicProperties properties)
     : base(service, guid, properties)
 {
 }
예제 #17
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);
            }
예제 #18
0
 public GattCharacteristic(BluetoothGattCharacteristic native, IGattService service, Guid uuid, CharacteristicProperties properties) : base(service, uuid, properties)
 {
     this.native = native;
 }
예제 #19
0
 public GattCharacteristic(GattCharacteristic1 native, IGattService service, CharacteristicProperties properties)
     : base(service, Guid.Parse(native.UUID), properties)
 {
     this.native = native;
 }
예제 #20
0
 protected abstract IGattCharacteristic CreateNative(Guid uuid, CharacteristicProperties properties, GattPermissions permissions);
예제 #21
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="service">Service owning this characteristic</param>
 /// <param name="characteristic">The characteristic</param>
 /// <param name="properties">Required characteristic properties</param>
 public CharacteristicsParcel(Guid service, Guid characteristic, CharacteristicProperties properties)
 {
     Service        = service;
     Characteristic = characteristic;
     Properties     = properties;
 }
 protected AbstractGattCharacteristic(IGattService service, Guid uuid, CharacteristicProperties properties)
 {
     this.Service    = service;
     this.Uuid       = uuid;
     this.Properties = properties;
 }
예제 #23
0
 public GattCharacteristic(IGattService service, Guid uuid, CharacteristicProperties properties) : base(service, uuid, properties)
 {
 }