Beispiel #1
0
        private void MapDevice(AttachedDeviceDetails deviceDetails)
        {
            var index = GetDeviceIndexForDevice(deviceDetails);

            for (var i = 0; i < deviceDetails.Size; ++i)
            {
                _memoryMap[deviceDetails.StartAddress + i] = index;
            }
        }
Beispiel #2
0
        public void AttachDevice(ushort startAddress, ushort size, IIoDevice device)
        {
            var details = new AttachedDeviceDetails
            {
                StartAddress = startAddress,
                Size         = size,
                Device       = device,
            };

            _devices.Add(details);
            MapDevice(details);
        }
Beispiel #3
0
        //_devices.FirstOrDefault(x => x.StartAddress <= address && x.StartAddress + (int)x.Size >= address);


        private byte GetDeviceIndexForDevice(AttachedDeviceDetails device)
        {
            var existingDevice = _deviceMap.FirstOrDefault(x => x.Value.Device.Id.Equals(device.Device.Id) && x.Value.StartAddress.Equals(device.StartAddress));

            if (existingDevice.Value != null)
            {
                return(existingDevice.Key);
            }

            var newId = (byte)(_deviceMap.Keys.Any() ? _deviceMap.Keys.Max() + 1 : 0);

            _deviceMap[newId] = device;

            return(newId);
        }