Exemplo n.º 1
0
        public WellKnownCharacteristic(string name, ushort shortId, IPresentationFormat defaultPresentationFormat)
            : base(shortId)
        {
            Name = name;

            PresentationFormat = defaultPresentationFormat;
        }
Exemplo n.º 2
0
        public static object ToValue(this GattReadResult result, IPresentationFormat presentationFormat)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            if (result.Status != GattCommunicationStatus.Success)
            {
                throw new ArgumentException($"Unexpected status: {result.Status}", nameof(result));
            }

            if (presentationFormat == null)
            {
                return(result.Value.ToUnknownFormat());
            }

            byte[] data;
            CryptographicBuffer.CopyToByteArray(result.Value, out data);

            if (presentationFormat.TryGetValue(data, out object value))
            {
                return(value);
            }

            throw new ArgumentException($"Unexpected format of result: {data}", nameof(result));
        }
        public static ICharacteristicInfo ToCharacteristicInfo(this GattCharacteristic characteristic)
        {
            var serviceInfo = characteristic.Service.ToServiceInfo();
            IPresentationFormat preferedFormat = null;
            var properties = characteristic.CharacteristicProperties.ToContract();

            // use default factory to recognize known services
            if (WellKnownCharacteristics.Default.TryCreate(characteristic.Uuid, out ICharacteristicTemplate template))
            {
                return(new KnownCharacteristicInfo(template, serviceInfo, properties, preferedFormat));
            }

            return(new GeneralCharacteristicInfo(serviceInfo, characteristic.Uuid, properties, preferedFormat));
        }
Exemplo n.º 4
0
 protected DevicePollerBase(Guid service, Guid characteristic, IPresentationFormat defaultFormat)
 {
     Service                   = service;
     Characteristic            = characteristic;
     DefaultPresentationFormat = defaultFormat;
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
 public WellKnownCharacteristic(string name, Guid uuid, IPresentationFormat defaultPresentationFormat)
     : base(uuid)
 {
     Name = name;
     PresentationFormat = defaultPresentationFormat;
 }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
 public SimpleDevicePoller(Guid service, Guid characteristic, IPresentationFormat presentationFormat)
     : base(service, characteristic, presentationFormat)
 {
 }