Exemple #1
0
        public HubInfo Hub(byte hubId)
        {
            HubInfo result;

            if (!_hubs.TryGetValue(hubId, out result))
            {
                result = new HubInfo()
                {
                    HubId = hubId,
                };

                _hubs.TryAdd(hubId, result);
            }

            return(result);
        }
        private static void AddCachePortAndPortModeInformation(DeviceType type, Version hardwareRevision, Version softwareRevision, HubInfo hub, PortInfo port, ProtocolKnowledge knowledge, IDeviceFactory deviceFactory)
        {
            var device = deviceFactory.Create(type);

            if (device is not null)
            {
                foreach (var message in device.GetStaticPortInfoMessages(hardwareRevision, softwareRevision, hub.SystemType).Select(b => MessageEncoder.Decode(b, null)))
                {
                    var messageToProcess = message;
                    switch (messageToProcess)
                    {
                    case PortModeInformationMessage pmim:
                        messageToProcess = pmim with
                        {
                            HubId  = port.HubId,
                            PortId = port.PortId,
                        };
                        break;

                    case PortInformationMessage pim:
                        messageToProcess = pim with
                        {
                            HubId  = port.HubId,
                            PortId = port.PortId,
                        };
                        break;
                    }

                    ApplyStaticProtocolKnowledge(messageToProcess, knowledge);

                    if (messageToProcess is PortModeInformationMessage pmim2 && pmim2.InformationType == PortModeInformationType.Name)
                    {
                        device.ExtendPortMode(knowledge.PortMode(pmim2.HubId, pmim2.PortId, pmim2.Mode));
                    }
                }
            }
        }