예제 #1
0
        public static NameDevice GetDevice(string name, NameAllBleDevices allDevices = null)
        {
            if (allDevices == null)
            {
                allDevices = AllDevices;
            }
            if (allDevices == null)
            {
                return(null);
            }

            // Find the matching characteristic ID
            foreach (var device in allDevices.AllDevices)
            {
                if (name.StartsWith(device.Name ?? ""))
                {
                    return(device);
                }
                foreach (var alias in device.Aliases)
                {
                    if (name.StartsWith(alias))
                    {
                        return(device); // e.g. the TI SensorTag 2.0 can also show up as the CC1350
                    }
                }
            }
            return(DefaultDevice);
        }
예제 #2
0
 // Read in data from the Assets\CharacteristicsData.json file. Note the mis-spelling Assets\Chacteristics!!
 public async Task InitAsync()
 {
     AllDevices       = new NameAllBleDevices();
     AllRawDevices    = new NameAllBleDevices();
     AllSerialDevices = new NameAllSerialDevices();
     await InitBleAsync();
     await InitSerialAsync();
 }
예제 #3
0
        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.
                    }
                }
            }
        }