public NotificationsViewModel(CharacteristicInfo characteristicInfo)
        {
            _commandRunner = IoC.Get <CommandRunner>();

            _characteristicInfo = characteristicInfo;
            Descriptors         = new List <ClientDescriptorViewModel>();

            var properties = _characteristicInfo.Properties;

            if (properties.HasFlag(GattCharacteristicProperties.Indicate))
            {
                Descriptors.Add(new ClientDescriptorViewModel(GattClientCharacteristicConfigurationDescriptorValue.Indicate, "Indicate"));
            }

            if (properties.HasFlag(GattCharacteristicProperties.Notify))
            {
                Descriptors.Add(new ClientDescriptorViewModel(GattClientCharacteristicConfigurationDescriptorValue.Notify, "Notify"));
            }

            _selectedDisplayFormat = DisplayFormats.FirstOrDefault(x => x.Model == characteristicInfo.NotificationDisplayFormat) ?? DisplayFormats[0];
            if (_selectedDisplayFormat.Model != characteristicInfo.NotificationDisplayFormat)
            {
                _characteristicInfo.NotificationDisplayFormat = _selectedDisplayFormat.Model;
                Task.Run(() => _infoManagerLazy.Value.SaveCharacteristic(_characteristicInfo));
            }
        }
Exemple #2
0
        public WriteViewModel(CharacteristicInfo characteristicInfo)
        {
            _characteristicInfo = characteristicInfo;
            _commandRunner      = IoC.Get <CommandRunner>();
            CanWrite            = true;

            _selectedDisplayFormat = DisplayFormats.FirstOrDefault(x => x.Model == characteristicInfo.WriteDisplayFormat) ?? DisplayFormats[0];
        }
Exemple #3
0
        public ReadViewModel(CharacteristicInfo characteristicInfo)
        {
            _commandRunner         = IoC.Get <CommandRunner>();
            _characteristicInfo    = characteristicInfo;
            _selectedDisplayFormat = DisplayFormats.FirstOrDefault(x => x.Model == _characteristicInfo.ReadDisplayFormat) ?? DisplayFormats[0];

            DoReadValue(cached: true, hideInConsole: true);
        }
Exemple #4
0
        private void SetCharacteristic(char c, IVariableAttr attr = null)
        {
            var cha = new CharacteristicInfo(EBAType.After, c.ToString() + c);

            if (attr == null)
            {
                attr = this.pVariableAttr;
            }
            attr.Characteristic = cha;
        }
Exemple #5
0
 public void SaveCharacteristic(CharacteristicInfo characteristicInfo)
 {
     lock (_dbLock)
     {
         using (var db = new LiteDatabase(_dataBaseFilePath))
         {
             var devices = db.GetCollection <CharacteristicInfo>();
             devices.Upsert(characteristicInfo);
         }
     }
 }
Exemple #6
0
        public async Task <ICollection <CharacteristicInfo> > GetAllCharacteristicsInfo(ServiceInfo serviceInfo, IEnumerable <GattCharacteristic> characteristics)
        {
            var result   = new List <CharacteristicInfo>();
            var allSaved = GetAllSavedCharacteristics(serviceInfo);

            foreach (var gattCharacteristic in characteristics)
            {
                var characteristicInfo = allSaved.FirstOrDefault(x => x.Uuid == gattCharacteristic.Uuid);

                if (characteristicInfo == null)
                {
                    characteristicInfo                           = new CharacteristicInfo();
                    characteristicInfo.Service                   = serviceInfo;
                    characteristicInfo.Uuid                      = gattCharacteristic.Uuid;
                    characteristicInfo.ReadDisplayFormat         = BytesDisplayFormat.Decimal;
                    characteristicInfo.WriteDisplayFormat        = BytesDisplayFormat.Auto;
                    characteristicInfo.NotificationDisplayFormat = BytesDisplayFormat.Decimal;

                    var gattInfo = _gattInformationProvider.GetCharacteristicInfo(serviceInfo.Uuid, characteristicInfo.Uuid);
                    if (gattInfo != null)
                    {
                        characteristicInfo.Name        = SelectName(gattInfo.Name, gattInfo.OriginalName);
                        characteristicInfo.Description = SelectDescription(gattInfo.Description, gattInfo.Summary, gattInfo.Abstract);
                        characteristicInfo.WebLink     = gattInfo.Link;
                    }

                    if (characteristicInfo.Name == null)
                    {
                        characteristicInfo.Name = "Unknown characteristic";
                    }

                    if (characteristicInfo.Description == null)
                    {
                        characteristicInfo.Description = "No description available.";
                    }

                    SaveCharacteristic(characteristicInfo);
                }

                // not a db property
                characteristicInfo.Properties      = gattCharacteristic.CharacteristicProperties;
                characteristicInfo.AttributeHandle = gattCharacteristic.AttributeHandle;
                characteristicInfo.ProtectionLevel = gattCharacteristic.ProtectionLevel;

                // ToDo: add presentation formats

                characteristicInfo.Initialize(this);
                result.Add(characteristicInfo);
            }

            return(result);
        }
        public bool Unsubscribe(CharacteristicInfo characteristicInfo)
        {
            if (!_subscribedCharacteristics.TryGetValue(characteristicInfo.Uuid, out characteristicInfo))
            {
                return(false);
            }

            var characteristic = GetCharacteristic(characteristicInfo);

            characteristic.ValueChanged -= CharacteristicOnValueChanged;
            _subscribedCharacteristics.Remove(characteristic.Uuid);
            return(true);
        }
        public bool Subscribe(CharacteristicInfo characteristicInfo)
        {
            if (_subscribedCharacteristics.ContainsKey(characteristicInfo.Uuid))
            {
                return(false);
            }

            var characteristic = GetCharacteristic(characteristicInfo);

            characteristic.ValueChanged += CharacteristicOnValueChanged;
            _subscribedCharacteristics.Add(characteristicInfo.Uuid, characteristicInfo);
            return(true);
        }
        public NotificationsViewModel(CharacteristicInfo characteristicInfo)
        {
            _commandRunner = IoC.Get <CommandRunner>();

            _characteristicInfo = characteristicInfo;
            Descriptors         = new List <ClientDescriptorViewModel>();

            var properties = _characteristicInfo.Properties;

            if (properties.HasFlag(GattCharacteristicProperties.Indicate))
            {
                Descriptors.Add(new ClientDescriptorViewModel(GattClientCharacteristicConfigurationDescriptorValue.Indicate, "Indicate"));
            }

            if (properties.HasFlag(GattCharacteristicProperties.Notify))
            {
                Descriptors.Add(new ClientDescriptorViewModel(GattClientCharacteristicConfigurationDescriptorValue.Notify, "Notify"));
            }
        }
Exemple #10
0
        public CharacteristicViewModel(CharacteristicInfo characteristicInfo)
        {
            _characteristicInfo = characteristicInfo;
            Operations          = new List <PropertyChangedBase>();

            if (CanRead)
            {
                Operations.Add(new ReadViewModel(_characteristicInfo));
            }

            if (CanWrite)
            {
                Operations.Add(new WriteViewModel(_characteristicInfo));
            }

            if (CanNotify)
            {
                Operations.Add(new NotificationsViewModel(_characteristicInfo));
            }

            Operations.Add(new NotesViewModel(_characteristicInfo));
        }
Exemple #11
0
        /// <summary>
        /// 获取方法名称
        /// </summary>
        /// <param name="chara"></param>
        /// <returns></returns>
        public static string GetMethodName(this CharacteristicInfo chara)
        {
            var mName = chara.PBAType.ToString();

            switch (chara.Value)
            {
            case "++":
                return(mName + "Adds");

            case "--":
                return(mName + "Subs");

            case "+":
                return(mName + "Add");

            case "-":
                return(mName + "Sub");

            default:
                throw new Exception("无效字符串");
            }
        }
Exemple #12
0
 protected CharacteristicCommandBase(CharacteristicInfo characteristicInfo)
 {
     CharacteristicInfo = characteristicInfo;
     _deviceController  = IoC.Get <DeviceController>();
 }
Exemple #13
0
 public UnsubscribeCommand(CharacteristicInfo characteristicInfo) : base(characteristicInfo)
 {
     _subscriptionService = IoC.Get <CharacteristicSubscriptionService>();
 }
Exemple #14
0
 public ReadBytesCommand(CharacteristicInfo characteristicInfo, BluetoothCacheMode cacheMode) : base(characteristicInfo)
 {
     CacheMode = cacheMode;
 }
Exemple #15
0
 public CharacteristicRenamedMessage(CharacteristicInfo characteristicInfo)
 {
     CharacteristicInfo = characteristicInfo;
 }
Exemple #16
0
 public NotesViewModel(CharacteristicInfo characteristicInfo)
 {
     _characteristicInfo = characteristicInfo;
     Text = _characteristicInfo.Notes;
 }
Exemple #17
0
 public WriteClientConfigDescriptorCommand(CharacteristicInfo characteristicInfo, GattClientCharacteristicConfigurationDescriptorValue descriptor) : base(characteristicInfo)
 {
     Descriptor = descriptor;
 }
Exemple #18
0
 private void SubscriptionServiceOnValueChanged(CharacteristicInfo sender, GattValueChangedEventArgs args)
 {
     Display($"Event in \"{sender.Name}\" ({sender.Uuid}):{Environment.NewLine}{args.CharacteristicValue.ToArraySafe().AsString(sender.NotificationDisplayFormat)}");
 }
 private GattCharacteristic GetCharacteristic(CharacteristicInfo characteristicInfo)
 {
     return(_deviceController.ConnectedDevice.GetGattService(characteristicInfo.Service.Uuid).GetCharacteristics(characteristicInfo.Uuid)[0]);
 }
Exemple #20
0
 public BytesCommandBase(CharacteristicInfo characteristicInfo) : base(characteristicInfo)
 {
 }
Exemple #21
0
 public ClientConfigDescriptorCommandBase(CharacteristicInfo gattCharacteristic) : base(gattCharacteristic)
 {
 }
Exemple #22
0
 public CharacteristicInfoViewModel(CharacteristicInfo characteristicInfo)
 {
     _characteristicInfo = characteristicInfo;
 }
Exemple #23
0
 public WriteBytesCommand(CharacteristicInfo characteristicInfo, byte[] bytes, bool withoutResponse = false) : base(characteristicInfo)
 {
     WithoutResponse = withoutResponse;
     Bytes           = bytes;
 }