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)); } }
public WriteViewModel(CharacteristicInfo characteristicInfo) { _characteristicInfo = characteristicInfo; _commandRunner = IoC.Get <CommandRunner>(); CanWrite = true; _selectedDisplayFormat = DisplayFormats.FirstOrDefault(x => x.Model == characteristicInfo.WriteDisplayFormat) ?? DisplayFormats[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); }
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; }
public void SaveCharacteristic(CharacteristicInfo characteristicInfo) { lock (_dbLock) { using (var db = new LiteDatabase(_dataBaseFilePath)) { var devices = db.GetCollection <CharacteristicInfo>(); devices.Upsert(characteristicInfo); } } }
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")); } }
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)); }
/// <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("无效字符串"); } }
protected CharacteristicCommandBase(CharacteristicInfo characteristicInfo) { CharacteristicInfo = characteristicInfo; _deviceController = IoC.Get <DeviceController>(); }
public UnsubscribeCommand(CharacteristicInfo characteristicInfo) : base(characteristicInfo) { _subscriptionService = IoC.Get <CharacteristicSubscriptionService>(); }
public ReadBytesCommand(CharacteristicInfo characteristicInfo, BluetoothCacheMode cacheMode) : base(characteristicInfo) { CacheMode = cacheMode; }
public CharacteristicRenamedMessage(CharacteristicInfo characteristicInfo) { CharacteristicInfo = characteristicInfo; }
public NotesViewModel(CharacteristicInfo characteristicInfo) { _characteristicInfo = characteristicInfo; Text = _characteristicInfo.Notes; }
public WriteClientConfigDescriptorCommand(CharacteristicInfo characteristicInfo, GattClientCharacteristicConfigurationDescriptorValue descriptor) : base(characteristicInfo) { Descriptor = descriptor; }
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]); }
public BytesCommandBase(CharacteristicInfo characteristicInfo) : base(characteristicInfo) { }
public ClientConfigDescriptorCommandBase(CharacteristicInfo gattCharacteristic) : base(gattCharacteristic) { }
public CharacteristicInfoViewModel(CharacteristicInfo characteristicInfo) { _characteristicInfo = characteristicInfo; }
public WriteBytesCommand(CharacteristicInfo characteristicInfo, byte[] bytes, bool withoutResponse = false) : base(characteristicInfo) { WithoutResponse = withoutResponse; Bytes = bytes; }