Пример #1
0
        public PortInfo Port(byte hubId, byte portId)
        {
            var hub = Hub(hubId);

            PortInfo result;

            if (!hub.Ports.TryGetValue(portId, out result))
            {
                result = new PortInfo()
                {
                    HubId  = hub.HubId,
                    PortId = portId,
                };

                hub.Ports.TryAdd(portId, result);
            }

            return(result);
        }
Пример #2
0
        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));
                    }
                }
            }
        }
Пример #3
0
        private static void AddCachePortAndPortModeInformation(DeviceType type, Version hardwareRevision, Version softwareRevision, PortInfo port, ProtocolKnowledge knowledge, IDeviceFactory deviceFactory)
        {
            var device = deviceFactory.Create(type);

            if (device != null)
            {
                foreach (var message in device.GetStaticPortInfoMessages(hardwareRevision, softwareRevision).Select(b => MessageEncoder.Decode(b, null)))
                {
                    switch (message)
                    {
                    case PortModeInformationMessage pmim:
                        pmim.HubId  = port.HubId;
                        pmim.PortId = port.PortId;
                        break;

                    case PortInformationMessage pim:
                        pim.HubId  = port.HubId;
                        pim.PortId = port.PortId;
                        break;
                    }

                    ApplyStaticProtocolKnowledge(message, knowledge);
                }
            }
        }