// Read in data from the Assets\CharacteristicsData.json file. Note the mis-spelling Assets\Chacteristics!! private async Task InitBleAsync() { string path = ""; try { string dname = @"Assets\ChacteristicsData\"; // Read in the Default device. DefaultDevice = await InitBleDefault(dname); // Read in the full set of devices StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; var dir = await InstallationFolder.GetFolderAsync(dname); var files = await dir.GetFilesAsync(); foreach (var file in files) { path = file.Path; InitSingleBleFile(AllDevices, file, DefaultDevice); InitSingleBleFile(AllRawDevices, file, null); // read in a device without adding in default services } } catch (Exception e) { System.Diagnostics.Debug.WriteLine($"ERROR: BLE NAMES: {e.Message} with path {path}"); } }
public static NameCharacteristic Get(NameDevice device, GattDeviceService service, GattCharacteristic characteristic) { if (device == null) { return(null); } foreach (var s in device.Services) { if (string.Compare(s.UUID, service.Uuid.ToString("D"), StringComparison.InvariantCultureIgnoreCase) == 0) { foreach (var c in s.Characteristics) { if (string.Compare(c.UUID, characteristic.Uuid.ToString("D"), StringComparison.InvariantCultureIgnoreCase) == 0) { return(c); } } } } return(null); }
private void InitSingleBleFile(NameAllBleDevices allDevices, StorageFile file, NameDevice defaultDevice) { if (File.Exists(file.Path)) { var contents = File.ReadAllText(file.Path); var newlist = Newtonsoft.Json.JsonConvert.DeserializeObject <NameAllBleDevices>(contents); foreach (var item in newlist.AllDevices) { // Check to make sure that at least one of IsRead IsNotify IsIndicate IsWrite IsWriteWithoutResponse is used // OK for the defaults to not have things specified. if (item.Name != "##DEFAULT##") { foreach (var service in item.Services) { foreach (var characteristic in service.Characteristics) { if (!characteristic.IsIndicate && !characteristic.IsNotify && !characteristic.IsRead && !characteristic.IsWrite && !characteristic.IsWriteWithoutResponse) { System.Diagnostics.Debug.WriteLine($"JSON ERROR: {file.Name} service {service.Name} characteristic {characteristic.Name} has no 'verb' like IsRead:true etc. "); } } } } // Add in all of the values from the default if (defaultDevice != null) { foreach (var nameService in DefaultDevice.Services) { item.Services.Add(nameService); } } // And now either replace or update. var index = allDevices.GetBleIndex(item.Name); if (index < 0) { allDevices.AllDevices.Add(item); } else { allDevices.AllDevices[index] = item; // replace or add. } } } }