internal static void AddConnectionProvider(EConnectionType dbType, IConnectionProvider connectionProvider)
 {
     if (!_connectionProviders.ContainsKey(dbType))
     {
         _connectionProviders.Add(dbType, connectionProvider);
     }
 }
        void HandleReceivedBuffer(CClientSocket ClientSocket, int ConnectionIndex, EConnectionType ConnectionType, byte[] buffer)
        {
            byte packet = buffer[0];

            byte[] arguments = null;

            if (buffer.Length > 1)
            {
                arguments = new byte[buffer.Length - 1];
                Buffer.BlockCopy(buffer, 1, arguments, 0, arguments.Length);
            }

            foreach (SPacketCallback PacketCallback in PacketCallbacks)
            {
                if (PacketCallback.ConnectionType != ConnectionType)
                {
                    continue;
                }

                if (PacketCallback.Packet != packet)
                {
                    continue;
                }

                PacketCallback.OnPacketCallback(ClientSocket, ConnectionIndex, arguments);
                break;
            }
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseServer{PacketEnum, classType}" /> class.
 /// You need to manually Load the config and set the port if you use this version!
 /// </summary>
 /// <param name="logFile">The log file.</param>
 /// <param name="connectionType">Type of the connection.</param>
 /// <param name="pingPacketInterval">The ping packet interval.</param>
 /// <param name="tcpTimeout">The TCP timeout.</param>
 public BaseServer(string logFile, EConnectionType connectionType, int pingPacketInterval, int tcpTimeout) : base(logFile, connectionType, tcpTimeout)
 {
     Clients                   = new Dictionary <int, ClientConnection>();
     PingPacketInterval        = pingPacketInterval;
     pingSender.PingCompleted += PingCallback;
     PingTimer                 = new Timer(new TimerCallback(PingClients), null, 0, PingPacketInterval);
 }
        public SteamController(HidDevice device, EConnectionType connection = SteamController.EConnectionType.Unknown)
        {
            State.Buttons = new SteamControllerButtons();

            _device        = device;
            ConnectionType = connection;

            Initalized = false;
        }
Example #5
0
 public AndroidLogcat(AndroidLogcat rhs)
 {
     AdbFullPath         = rhs.AdbFullPath;
     SelectedDevice      = rhs.SelectedDevice;
     CaptureOutputToFile = rhs.CaptureOutputToFile;
     AppendOutputFile    = rhs.AppendOutputFile;
     LogBuffers          = rhs.LogBuffers.Dup();
     FilterSpecs         = rhs.FilterSpecs.Dup();
     LogFormat           = rhs.LogFormat;
     ConnectionType      = rhs.ConnectionType;
     IPAddressHistory    = rhs.IPAddressHistory.Dup();
     ConnectionPort      = rhs.ConnectionPort;
 }
Example #6
0
 public AndroidLogcat(XElement node)
 {
     AdbFullPath         = node.Element(XmlTag.ADBPath).As <string>();
     SelectedDevice      = node.Element(XmlTag.Device).As <string>();
     CaptureOutputToFile = node.Element(XmlTag.CaptureOutput).As <bool>();
     AppendOutputFile    = node.Element(XmlTag.AppendOutput).As <bool>();
     LogBuffers          = node.Element(XmlTag.LogBuffers).As <ELogBuffer[]>();
     FilterSpecs         = node.Element(XmlTag.FilterSpecs).As <FilterSpec[]>();
     LogFormat           = node.Element(XmlTag.LogFormat).As <ELogFormat>();
     ConnectionType      = node.Element(XmlTag.ConnType).As <EConnectionType>();
     IPAddressHistory    = node.Element(XmlTag.IPAddrHistory).As <string[]>();
     ConnectionPort      = node.Element(XmlTag.Port).As <int>();
 }
Example #7
0
 public void Read(BinaryReader reader)
 {
     ID                = reader.ReadInt32();
     ConnectionType    = (EConnectionType)reader.ReadInt32(); //Added 2015-12-24
     communicationPort = reader.ReadInt32();                  //Added 2015-12-24
     Name              = reader.ReadStringNative();
     IP                = reader.ReadStringNative();
     Location          = reader.ReadStringNative();
     lng               = reader.ReadSingle();
     lat               = reader.ReadSingle();
     Connected         = reader.ReadBoolean();
     Available         = reader.ReadBoolean();
 }
Example #8
0
        /*private void SendReport()
        {
            {
                byte[] outDataFinal = null;
                if (_device.DevicePath.Contains(@"00001124-0000-1000-8000-00805f9b34fb"))
                {
                    outDataFinal = new byte[] {
                        0xa2,
                        0x31,
                        0x02
                    }.Concat(data.Skip(1)).Concat(new byte[44]).Take(79).ToArray();

                    Crc32 crcE = new Crc32();
                    byte[] crc = crcE.ComputeHash(outDataFinal, 0, outDataFinal.Length - 4);

                    outDataFinal[outDataFinal.Length - 1] = crc[0];
                    outDataFinal[outDataFinal.Length - 2] = crc[1];
                    outDataFinal[outDataFinal.Length - 3] = crc[2];
                    outDataFinal[outDataFinal.Length - 4] = crc[3];
                }
                else
                {
                    outDataFinal = new byte[] { 0x00 }.Concat(data).Concat(new byte[99]).Take(79).ToArray();
                }
                bool success = _device.WriteReport(outDataFinal.Skip(1).ToArray());
            }
        }*/

        public DualSenseController(HidDevice device, AccessMode AccessMode, EConnectionType ConnectionType = EConnectionType.Unknown)
        {
            this.AccessMode = AccessMode;
            this.ConnectionType = ConnectionType;

            State.Controls["cluster_left"] = new ControlDPad();
            State.Controls["cluster_right"] = new ControlButtonQuad();
            State.Controls["bumper_left"] = new ControlButton();
            State.Controls["bumper_right"] = new ControlButton();
            //State.Controls["bumpers2"] = new ControlButtonPair();
            State.Controls["trigger_left"] = new ControlTrigger();
            State.Controls["trigger_right"] = new ControlTrigger();
            State.Controls["menu_left"] = new ControlButton();
            State.Controls["menu_right"] = new ControlButton();
            State.Controls["home"] = new ControlButton();
            State.Controls["mute"] = new ControlButtonPS5Mute(AccessMode);
            State.Controls["stick_left"] = new ControlStickWithClick();
            State.Controls["stick_right"] = new ControlStickWithClick();
            State.Controls["touch_center"] = new ControlTouch(TouchCount: 2, HasClick: true);
            State.Controls["motion"] = new ControlMotion();

            // According to this the normalized domain of the DS4 gyro is 1024 units per rad/s: https://gamedev.stackexchange.com/a/87178

            _device = device;
            /*
            //new Thread(() =>
            {
                //Thread.Sleep(1);
                {
                    byte oldFlags = data[2];
                    data[2] |= 0x08;
                    SendReport();
                    data[2] = oldFlags;
                }
                //Thread.Sleep(1);
                {
                    byte oldFlags = data[2];
                    data[2] |= 0x04;
                    data[45] = 0xff;// (byte)random.Next(0, 255);
                    data[46] = 0x00;// (byte)random.Next(0, 255);
                    data[47] = 0x00;// (byte)random.Next(0, 255);
                    SendReport();
                    data[2] = oldFlags;
                }
            }//).Start();
            */

            PollingState = EPollingState.Inactive;

            _device.DeviceReport += OnReport;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseNetworkMachine{packetsEnumType, classType}" /> class.
        /// </summary>
        /// <param name="logFile">The log file. When string.Empty dont use logfiles!</param>
        /// <param name="connectionType">Type of the connection.</param>
        /// <param name="tcpTimeout">The TCP timeout.</param>
        internal BaseNetworkMachine(string logFile, EConnectionType connectionType, int tcpTimeout)
        {
            if (logFile != string.Empty)
            {
                SetupLogger("Logs", logFile + "_" + DateTime.Now.ToString("ddMMyyyyHHmmssfffff") + ".txt");
            }

            Debug.Assert(connectionType != EConnectionType.NONE, "Machine has to have a Connection Type!");
            _connectionType = connectionType;

            string s  = typeof(classType).ToString();
            string s1 = typeof(BaseNetworkMachine <packetsEnumType, classType>).ToString();

            InitPacketEnum(typeof(EBasePackets), ref _packetMethods);
            InitPacketEnum(typeof(packetsEnumType), ref _packetMethods);

            Console.Title = GetConsoleWindowTitle();
            TCPTimeout    = tcpTimeout;
        }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Server"/> class.
        /// </summary>
        /// <param name="ip">The IP on which to listen to.</param>
        /// <param name="dataSize">Data size for received data.</param>
        public Server(EConnectionType type, IPAddress ip, int port, int dataSize = 1024)
        {
            this.port     = port;
            this.ip       = ip;
            this.dataSize = dataSize;
            this.data     = new byte[dataSize];

            switch (type)
            {
            case EConnectionType.Client:
                break;

            case EConnectionType.Server:
                this.clientsList = new Dictionary <Socket, Client>();
                this.acceptIncomingConnections = true;
                break;
            }
            this.mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        }
Example #11
0
        /// <summary>
        /// Disconnects the specified unique identifier.
        /// </summary>
        /// <param name="uniqueID">The unique identifier.</param>
        public void Disconnect(int uniqueID = -1)
        {
            if (Clients.ContainsKey(uniqueID))
            {
                ClientListMutex.WaitOne();

                EConnectionType et = Clients[uniqueID].ConnectionType;

                PacketDesc_ClientDisconnected dcPkt = new PacketDesc_ClientDisconnected();
                dcPkt.OtherClientID        = uniqueID;
                dcPkt.PacketTarget         = et;
                dcPkt.PacketOriginClientID = UniqueID;
                SendPacketToAllClients(dcPkt, uniqueID);

                ConsoleLogger.WriteToLog("Disconnected Client ID:" + uniqueID, true);

                if (Clients[uniqueID].ThisClient != null)
                {
                    if (Clients[uniqueID].ThisClient.Connected)
                    {
                        Clients[uniqueID].ThisClient.GetStream().Close();
                        if (Clients[uniqueID].ThisClient != null)
                        {
                            Clients[uniqueID].ThisClient.Close();
                        }
                    }

                    Clients[uniqueID].ThisClient = null;
                    Clients.Remove(uniqueID);
                    NumClientThreads--;
                }

                ClientListMutex.ReleaseMutex();

                if (OnClientDisconnected != null)
                {
                    OnClientDisconnected(uniqueID);
                }
            }
        }
Example #12
0
        public IController NewDevice(IDevice device)
        {
            HidDevice _device = device as HidDevice;

            if (_device == null)
            {
                return(null);
            }

            if (_device.VendorId != DualSenseController.VendorId)
            {
                return(null);
            }

            if (!new int[] {
                DualSenseController.ProductId,
            }.Contains(_device.ProductId))
            {
                return(null);
            }

            string bt_hid_id = @"00001124-0000-1000-8000-00805f9b34fb";

            string devicePath = _device.DevicePath.ToString();

            EConnectionType ConType = EConnectionType.Unknown;

            //switch (_device.ProductId)
            {
                //case DualSenseController.ProductId:
                if (devicePath.Contains(bt_hid_id))
                {
                    ConType = EConnectionType.Bluetooth;
                }
                else
                {
                    ConType = EConnectionType.USB;
                }
                //break;
            }

            {
                string deviceInstanceId = DevPKey.PnpDevicePropertyAPI.devicePathToInstanceId(_device.DevicePath);
                Guid?  ContrainerID     = DevPKey.PnpDevicePropertyAPI.GetDeviceContainerId(deviceInstanceId);
                if (ContrainerID.HasValue)
                {
                    lock (Controllers)
                    {
                        DualSenseController ctrl = null;
                        if (Controllers.ContainsKey(ContrainerID.Value))
                        {
                            // TODO handle subdevices, such as the audio device
                            //ctrl = Controllers[ContrainerID.Value];
                            //ctrl.AddDevice(_device);
                        }
                        else
                        {
                            Controllers[ContrainerID.Value] = new DualSenseController(_device, AccessMode, ConType);
                            ctrl = Controllers[ContrainerID.Value];
                        }

                        DeviceToControllerKeyMap[device.UniqueKey] = ContrainerID.Value;
                        if (!ControllerToDeviceKeyMap.ContainsKey(ContrainerID.Value))
                        {
                            ControllerToDeviceKeyMap[ContrainerID.Value] = new HashSet <string>();
                        }
                        ControllerToDeviceKeyMap[ContrainerID.Value].Add(device.UniqueKey);
                        return(ctrl);
                    }
                }
            }

            return(null);
        }
 public static IConnectionProvider GetConnectionProvider(EConnectionType dbType)
 {
     return(_connectionProviders[dbType]);
 }
        public IController NewDevice(IDevice device)
        {
            HidDevice _device = device as HidDevice;

            if (_device == null)
            {
                return(null);
            }

            if (_device.VendorId != SteamController.VendorId)
            {
                return(null);
            }

            if (!new int[] {
                SteamController.ProductIdDongle,
                SteamController.ProductIdWired,
                SteamController.ProductIdBT,
                SteamController.ProductIdChell,
            }.Contains(_device.ProductId))
            {
                return(null);
            }

            {
                string devicePath = _device.DevicePath.ToString();

                EConnectionType ConType = EConnectionType.Unknown;
                SteamController.EControllerType CtrlType = SteamController.EControllerType.Gordon;
                switch (_device.ProductId)
                {
                case SteamController.ProductIdBT:
                    if (!devicePath.Contains("col03"))
                    {
                        return(null);                                   // skip anything that isn't the controller's custom HID device
                    }
                    ConType = EConnectionType.Bluetooth;
                    break;

                case SteamController.ProductIdWired:
                    if (!devicePath.Contains("mi_02"))
                    {
                        return(null);                                   // skip anything that isn't the controller's custom HID device
                    }
                    ConType = EConnectionType.USB;
                    break;

                case SteamController.ProductIdDongle:
                    if (devicePath.Contains("mi_00"))
                    {
                        return(null);                                  // skip the dongle itself
                    }
                    ConType = EConnectionType.Dongle;
                    break;

                case SteamController.ProductIdChell:
                    if (!devicePath.Contains("mi_02"))
                    {
                        return(null);                                   // skip odd 2nd device
                    }
                    ConType  = EConnectionType.USB;
                    CtrlType = SteamController.EControllerType.Chell;
                    break;
                }

                SemaphoreSlim SharedDongleLock = null;
                if (ConType == EConnectionType.Dongle)
                {
                    string deviceInstanceId = DevPKey.PnpDevicePropertyAPI.devicePathToInstanceId(_device.DevicePath);
                    Guid?  ContrainerID     = DevPKey.PnpDevicePropertyAPI.GetDeviceContainerId(deviceInstanceId);
                    if (ContrainerID.HasValue)
                    {
                        lock (SharedDongleLocks)
                        {
                            if (!SharedDongleLocks.ContainsKey(ContrainerID.Value) || !SharedDongleLocks[ContrainerID.Value].TryGetTarget(out SharedDongleLock))
                            {
                                SharedDongleLock = new SemaphoreSlim(1);
                                SharedDongleLocks.Add(ContrainerID.Value, new WeakReference <SemaphoreSlim>(SharedDongleLock));
                            }

                            Console.WriteLine(ContrainerID.Value.ToString());

                            // clear any dead refs
                            foreach (Guid key in SharedDongleLocks.Keys.ToList()) // ToList to clone the key list so we can modify it
                            {
                                if (!SharedDongleLocks[key].TryGetTarget(out _))
                                {
                                    SharedDongleLocks.Remove(key);
                                }
                            }
                        }
                    }
                }

                SteamController ctrl = new SteamController(_device, SharedDongleLock, ConType, CtrlType);
                //ctrl.HalfInitalize();
                return(ctrl);
            }
        }
        public IController NewDevice(IDevice device)
        {
            HidDevice _device = device as HidDevice;

            if (_device == null)
            {
                return(null);
            }

            if (_device.VendorId == DualShock4Controller.VENDOR_SONY)
            {
                if (!new int[] {
                    DualShock4Controller.PRODUCT_SONY_DONGLE,
                    DualShock4Controller.PRODUCT_SONY_DS4V1,
                    DualShock4Controller.PRODUCT_SONY_DS4V2,
                }.Contains(_device.ProductId))
                {
                    return(null);
                }
            }
            else if (_device.VendorId == DualShock4Controller.VENDOR_BROOK)
            {
                if (_device.ProductId == DualShock4Controller.PRODUCT_BROOK_MARS)
                {
                    if (_device.DevicePath.Contains(@"&col01"))
                    {
                        DualShock4Controller ctrl = new DualShock4Controller(_device, EConnectionType.USB);
                        return(ctrl);
                    }
                }
                return(null);
            }
            else
            {
                return(null);
            }

            string deviceInstanceId = DevPKey.PnpDevicePropertyAPI.devicePathToInstanceId(_device.DevicePath);
            bool   IsVigem          = DevPKey.PnpDevicePropertyAPI.GetDeviceUINumber(deviceInstanceId).HasValue;
            bool   IsReWasd         = DevPKey.PnpDevicePropertyAPI.GetDeviceContainerId(deviceInstanceId) == CONTAINER_ID_REWASD_VIRTUAL_DS4;

            string bt_hid_id = @"00001124-0000-1000-8000-00805f9b34fb";

            string devicePath = _device.DevicePath.ToString();

            EConnectionType ConType = EConnectionType.Unknown;

            DualShock4Controller.DS4VirtualType VirtualType = DualShock4Controller.DS4VirtualType.NotVirtual;
            if (IsVigem)
            {
                ConType     = EConnectionType.Virtual;
                VirtualType = DualShock4Controller.DS4VirtualType.ViGEm;
            }
            else if (IsReWasd)
            {
                ConType     = EConnectionType.Virtual;
                VirtualType = DualShock4Controller.DS4VirtualType.reWASD;
            }
            else
            {
                switch (_device.ProductId)
                {
                case DualShock4Controller.PRODUCT_SONY_DS4V1:
                case DualShock4Controller.PRODUCT_SONY_DS4V2:
                    if (devicePath.Contains(bt_hid_id))
                    {
                        ConType = EConnectionType.Bluetooth;
                    }
                    else
                    {
                        ConType = EConnectionType.USB;
                    }
                    break;

                case DualShock4Controller.PRODUCT_SONY_DONGLE:
                    ConType = EConnectionType.Dongle;
                    break;
                }
            }

            {
                Guid?ContrainerID = DevPKey.PnpDevicePropertyAPI.GetDeviceContainerId(deviceInstanceId);
                if (ContrainerID.HasValue)
                {
                    lock (Controllers)
                    {
                        DualShock4Controller ctrl = null;
                        if (Controllers.ContainsKey(ContrainerID.Value))
                        {
                            // TODO handle subdevices, such as the audio device
                            //ctrl = Controllers[ContrainerID.Value];
                            //ctrl.AddDevice(_device);
                        }
                        else
                        {
                            Controllers[ContrainerID.Value] = new DualShock4Controller(_device, ConType, VirtualType);
                            ctrl = Controllers[ContrainerID.Value];
                        }

                        DeviceToControllerKeyMap[device.UniqueKey] = ContrainerID.Value;
                        if (!ControllerToDeviceKeyMap.ContainsKey(ContrainerID.Value))
                        {
                            ControllerToDeviceKeyMap[ContrainerID.Value] = new HashSet <string>();
                        }
                        ControllerToDeviceKeyMap[ContrainerID.Value].Add(device.UniqueKey);
                        return(ctrl);
                    }
                }
            }

            return(null);
        }
 public static void AddConnectionProvider(this IServiceCollection services, EConnectionType dbType, IConnectionProvider connectionProvider)
 {
     ConnectionFactory.AddConnectionProvider(dbType, connectionProvider);
 }
Example #17
0
    public void LoadXML(XmlReader r)
    {
        Name = r.GetAttribute("Name");
        string type = r.GetAttribute("Type");

        ConnectionType = EConnectionType.RTP;
        if (type == "WebRTC")
        {
            ConnectionType = EConnectionType.WebRTC;
        }
        if (type == "Ovrvision")
        {
            ConnectionType = EConnectionType.Ovrvision;
        }
        else if (type == "RTP")
        {
            ConnectionType = EConnectionType.RTP;
        }
        else if (type == "Local")
        {
            ConnectionType = EConnectionType.Local;
            int count;
            int.TryParse(r.GetAttribute("Count"), out count);
            for (int i = 0; i < count; ++i)
            {
                int idx;
                if (int.TryParse(r.GetAttribute("Index" + i.ToString()), out idx))
                {
                    CameraIndex.Add(idx);
                }
            }
        }
        else if (type == "Movie")
        {
            ConnectionType = EConnectionType.Movie;
            MediaPath      = r.GetAttribute("Path");
        }

        type        = r.GetAttribute("StreamCodec");
        StreamCodec = EStreamCodec.Coded;
        if (type == "Raw")
        {
            StreamCodec = EStreamCodec.Raw;
        }
        else if (type == "Coded")
        {
            StreamCodec = EStreamCodec.Coded;
        }
        else if (type == "Ovrvision")
        {
            StreamCodec = EStreamCodec.Ovrvision;
        }

        IP       = r.GetAttribute("IP");
        URL      = r.GetAttribute("URL");
        Location = r.GetAttribute("Location");
        string v = r.GetAttribute("Longitude");

        if (v != null && v != "")
        {
            lng = double.Parse(v);
        }

        v = r.GetAttribute("Latitude");
        if (v != null && v != "")
        {
            lat = double.Parse(v);
        }
    }
        public IController NewDevice(IDevice device)
        {
            HidDevice    _device  = device as HidDevice;
            XInputDevice _deviceX = device as XInputDevice;

            if (_device == null && _deviceX == null)
            {
                return(null);
            }

            // TODO this check system should only run if FullControl mode is enabled
            //      this is all irrelevent if we have a system where we can get the true ProductName, VID, and PID of the XInput controller
            //      if we ever gain access to that info, we will have to make sure the below logic is still present for if the XInput provider
            //      doesn't have that info (check presence of Properties perhapse?)
            //      It might be simpler to keep the XInputDevice handling as is if the VID/PID/ProductName are null but if they are known immediately rumble
            //      In this design, if we see a HID device for the controller and we want to correct it, we'd start a count-down and if we didn't see any XInput
            //      devices we could manually trigger within that time (inlcuding one that came through just ahead) we'd force run over all the memorized ones
            //      Note that for some reason this doesn't work properly for an APEX2 on USB, it switches right back to XInput again.
            if (_device != null)
            {
                if (device.VendorId == 0x045E && device.ProductId == 0x028E)
                {
                    if (this.AccessMode != AccessMode.FullControl)
                    {
                        return(null);
                    }

                    if (device.Properties["ProductName"] == "Controller (Flydigi 2.4G x360)" ||
                        device.Properties["ProductName"] == "Controller (Flydigi 2.4G Android)") // APEX2 on USB does this for some reason
                    {
                        lock (CandidateXInputLock)
                            SawCandidateHidDeviceForXInput = DateTime.UtcNow;
                        CheckXInputData();
                    }
                    return(null);
                }
            }
            else if (_deviceX != null)
            {
                if (this.AccessMode != AccessMode.FullControl)
                {
                    return(null);
                }

                lock (CandidateXInputLock)
                {
                    CandidateXInputDevicesX[(byte)_deviceX.UserIndex]        = new WeakReference <XInputDevice>(_deviceX);
                    CandidateXInputDevicesLastSeen[(byte)_deviceX.UserIndex] = DateTime.UtcNow;
                }
                CheckXInputData();
                return(null);
            }

            // if we are in full control mode, check for xbox here and if it is a flydigi controller send the command that changes the mode here and return null

            if (_device.VendorId == FlydigiController.VENDOR_FLYDIGI)
            {
                if (!new int[] {
                    FlydigiController.PRODUCT_FLYDIGI_DONGLE_1,
                    FlydigiController.PRODUCT_FLYDIGI_DONGLE_2,
                    FlydigiController.PRODUCT_FLYDIGI_DONGLE_3,
                    FlydigiController.PRODUCT_FLYDIGI_USB,
                }.Contains(_device.ProductId))
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }

            //string bt_hid_id = @"00001124-0000-1000-8000-00805f9b34fb";

            string devicePath = _device.DevicePath.ToString();

            uint[]          Usages  = device.Properties.ContainsKey("Usages") ? device.Properties["Usages"] as uint[] : null;
            EConnectionType ConType = EConnectionType.Unknown;

            switch (_device.VendorId)
            {
            case FlydigiController.VENDOR_FLYDIGI:
                if (_device.Properties.ContainsKey("ProductName") && (((_device.Properties["ProductName"] as string)?.ToLowerInvariant()?.Contains("flydigi") ?? false) || ((_device.Properties["ProductName"] as string)?.ToLowerInvariant()?.Contains("feizhi") ?? false)))
                {
                    //&& devicePath.Contains("mi_02")
                    if (Usages.Contains(0xffa00001u))
                    {
                    }
                    else
                    {
                        return(null);
                    }
                    //if (devicePath.Contains(bt_hid_id))
                    //{
                    //    ConType = EConnectionType.Bluetooth;
                    //}
                    //else
                    //{
                    //    ConType = EConnectionType.USB;
                    //}
                }
                //else if (_device.ProductId == FlydigiController.PRODUCT_FLYDIGI_USB && devicePath.Contains("mi_00"))
                //{
                //
                //}
                else
                {
                    return(null);
                }
                break;
            }

            lock (Controllers)
            {
                FlydigiController ctrl = new FlydigiController(_device, ConType);
                Controllers[_device.UniqueKey] = ctrl;
                //Console.WriteLine($"Controllers[\"{_device.UniqueKey}\"] = {ctrl};");
                return(ctrl);
            }
        }