Beispiel #1
0
        /// <summary>
        /// Creates a new device using the scan record to poll the device's serial number and version.
        /// </summary>
        /// <returns>The ble device.</returns>
        /// <param name="deviceManager">Device manager.</param>
        /// <param name="address">Address.</param>
        /// <param name="scanRecord">Scan record.</param>
        public static IDevice CreateBleDeviceOrThrow(this IDeviceManager deviceManager, BluetoothDevice device, byte[] scanRecord)
        {
            ISerialNumber sn;

            if (!ResolveSerialNumber(device, scanRecord, out sn))
            {
                // We could not resolve the device (or it is not ours)
                throw new Exception("Could not validate serial number for: " + device.Name + " @ " + device.Address);
            }

            var ret = deviceManager[sn];

            if (ret != null)
            {
                ret.connection.lastPacket = scanRecord;
            }
            else
            {
                var pv = ResolveProtocolVersion(device, sn, scanRecord);
                ret = deviceManager.CreateDevice(sn, device.Address, pv);
                ret.connection.lastPacket = scanRecord;
            }

            return(ret);
        }
Beispiel #2
0
        int CreateNewDevice()
        {
            List <Type> types = _deviceManager.GetDevicesTypes().ToList();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Choose divice type:");
                int i = 1;
                foreach (var item in types)
                {
                    Console.WriteLine($"{i}. {item.Name}");
                    i++;
                }

                Console.WriteLine("Please type number of device to create it, or type \"b\" to go back");
                string input = Console.ReadLine();
                if (input.ToLower() == "b")
                {
                    return(1);
                }
                if ((Int32.TryParse(input, out int result)) && (result <= types.ToList().Count) && (result > 0))
                {
                    Console.WriteLine("Please enter device name:");
                    string name = Console.ReadLine();
                    Type   type = types.ToList()[result - 1];

                    var  device   = _deviceManager.CreateDevice(type, name);
                    bool complete = false;
                    Console.WriteLine($"Device {name} created.");
                    while (!complete)
                    {
                        Console.WriteLine("Please choose the hub, you want to register it");
                        var hubs = _deviceManager.GetDevices(typeof(IHub)).ToList();
                        for (int j = 1; j <= hubs.Count; j++)
                        {
                            Console.WriteLine($"{j}. {hubs[j - 1].Name}");
                        }
                        string hubnomber = Console.ReadLine();
                        if ((Int32.TryParse(hubnomber, out int hubres)) && (hubres <= hubs.Count) && (hubres > 0))
                        {
                            var hub = hubs[hubres - 1];
                            (hub as IHub).RegisterDevice(device);
                            complete = true;
                            Console.ReadKey();
                        }
                    }
                    return(0);
                }
            }
        }
 /// <summary>
 /// Attempts to resolve the device if it is an appion device.
 /// </summary>
 /// <param name="device">Device.</param>
 private void VerifyClassicDevice(BluetoothDevice device)
 {
     lock (locker) {
         if (!_deviceManager.HasDeviceForAddress(device.Address))
         {
             if (Protocol.APPION_CLASSIC_DEVICE_NAME.Equals(device.Name))
             {
                 Task.Factory.StartNew(async() => {
                     var sn = await ClassicConnection.ResolveSerialNumber(device);
                     if (sn != null)
                     {
                         _deviceManager.CreateDevice(sn, device.Address, EProtocolVersion.Classic);
                     }
                 });
             }
         }
     }
 }