Exemple #1
0
        /// <summary>
        ///  Подпрограмма получения массива слов
        /// </summary>
        /// <param name="index"></param>
        /// <param name="channel"></param>
        /// <param name="length"></param>
        /// <param name="time"></param>
        /// <param name="readed"></param>
        public uint[] Read(int index, ushort channel, int length, int time, out int readed)
        {
            Validation(index);
            // Список считываемых данных
            var data = new uint[length];

            int delta_time;

            readed = 0;
            // Цикл чтения данных из платы PCI-429
            var time_begin = DateTime.Now;

            do
            {
                int kern_readed;
                var kern_data = new uint[length - readed];
                // Вызов функции
                var err_pci = _device[index].Read(channel, ref kern_data, length - readed, out kern_readed);
                if (0 != err_pci && 0x4001 != err_pci)
                {
                    throw new Exception <Pci429ExceptionArgs>(new Pci429ExceptionArgs(index),
                                                              "Ошибка получения массива слов интерфейсной платой PCI-429");
                }
                // Сохранение полученных данных
                for (var i = 0; i < kern_readed; i++)
                {
                    data[readed + i] = kern_data[i];
                }
                // Обновления счетчика принятых слов
                readed    += kern_readed;
                delta_time = ( int )(DateTime.Now - time_begin).TotalMilliseconds;
            } while (delta_time < time && length > readed);
            // Проверка времени выполнения
            if (length > readed && delta_time >= time)
            {
                // Ошибка при чтении из платы
                throw new Exception <Pci429ExceptionArgs>(new Pci429ExceptionArgs(index),
                                                          $"Время ожидания {readed:D3} слова в канале {channel,2:D2} интерфейсной платы PCI-429 превышено");
            }
            // Проверка количества считанных данных
            if (length > readed)
            {
                // Ошибка при чтении из платы
                throw new Exception <Pci429ExceptionArgs>(new Pci429ExceptionArgs(index),
                                                          $" Чтение {readed:D3} слова Arinc429 в канале {channel,2:D2} интерфейсной платы PCI-429 завершено с ошибкой");
            }
            // Вывод принятых данных
            var str = string.Empty;

            App.TaskManager.Log.WriteLineAsync(
                $"Полученные данные по каналу {channel:D2}" +
                Environment.NewLine +
                data.Aggregate(str, (current, j) => current + $"0x{j:X8} "));
            return(data);
        }
        public uint CalculateSMBDMaxReadWriteSize()
        {
            if (!smbdNegotiated)
            {
                throw new InvalidOperationException("Not SMBD negotiated!");
            }

            var  list   = new uint[] { maxReadSize, maxWriteSize, maxSMBDReceiveSize, maxSMBDSendSize };
            uint result = list.Aggregate(Math.Min);

            return(result);
        }
        public uint CalculateSmb2MaxReadWriteSize()
        {
            if (!negotiated)
            {
                throw new InvalidOperationException("Not negotiated!");
            }

            // The max payload size is 65536 so that buffer should be less than 65536 minus the header size
            // 100 is large enough to hold READ/WRITE
            uint maxBufferSize = 65536 - 100;
            var  list          = new uint[] { maxReadSize, maxWriteSize, maxBufferSize };
            uint result        = list.Aggregate(Math.Min);

            return(result);
        }
Exemple #4
0
        /// <summary>
        ///  Подпрограмма получения массива слов
        /// </summary>
        /// <param name="index"></param>
        /// <param name="channel"></param>
        /// <param name="readed"></param>
        public uint[] Read(int index, ushort channel, out int readed)
        {
            Validation(index);
            // Вызов функции
            readed = 0;
            const int length  = 256;
            var       data    = new uint[length];
            var       err_pci = _device[index].Read(channel, ref data, length, out readed);

            if (0 != err_pci && 0x4001 != err_pci)
            {
                throw new Exception <Pci429ExceptionArgs>(new Pci429ExceptionArgs(index),
                                                          "Ошибка получения массива слов интерфейсной платой PCI-429");
            }
            // Вывод принятых данных
            var str = string.Empty;

            App.TaskManager.Log.WriteLineAsync(
                $"Полученные данные по каналу {channel:D2}" +
                Environment.NewLine +
                data.Aggregate(str, (current, j) => current + $"0x{j:X8} "));
            return(data);
        }
Exemple #5
0
        public Config(string inputFilePath, string outputFilePath)
        {
            InputFilePath  = inputFilePath;
            OutputFilePath = outputFilePath;

            var raw = ConfigurationManager
                      .AppSettings["BigsortTempPath"];

            GroupsFilePath = Path.Combine(
                raw ?? Path.GetTempPath(),
                Path.GetRandomFileName());

            raw = ConfigurationManager
                  .AppSettings["BigsortMaxRunningTasksCount"];

            MaxRunningTasksCount = raw == null
                ? Consts.MaxRunningTasksCount
                : int.Parse(raw);

            raw = ConfigurationManager
                  .AppSettings["BigsortGrouperEnginesCount"];

            GrouperEnginesCount = raw == null // TODO: / 2 - for SSD and / 4 for HDD
                ? Math.Max(1, Environment.ProcessorCount / 2)
                : int.Parse(raw);

            raw = ConfigurationManager
                  .AppSettings["BigsortUsingBufferLength"];

            if (raw != null)
            {
                UsingBufferLength = int.Parse(raw);
            }
            else
            {
                UsingBufferLength = (int)
                                    ((new ComputerInfo().AvailablePhysicalMemory * 0.8) /
                                     (Consts.MaxGroupsCount * GrouperEnginesCount));

                var pathes = new[]
                {
                    InputFilePath,
                    OutputFilePath,
                    GroupsFilePath,
                };

                uint _, __, sectorsPerCluster, bytesPerSector;
                var  bytesPerClusters = new uint[pathes.Length];
                for (int i = 0; i < pathes.Length;
                     bytesPerClusters[i++] = bytesPerSector * sectorsPerCluster)
                {
                    GetDiskFreeSpace(
                        Path.GetPathRoot(pathes[i]),
                        out bytesPerSector,
                        out sectorsPerCluster,
                        out __,
                        out _
                        );
                }

                Func <uint, uint, uint> lcm, gcd = null;
                gcd = (a, b) => b == 0 ? a : gcd(b, a % b); // Greatest common divisor
                lcm = (a, b) => a / gcd(a, b) * b;          // Least common multipler

                var bytesPerClustersLcm =
                    (int)bytesPerClusters.Aggregate(lcm);

                var startingBufferLength = PhysicalBufferLength;
                UsingBufferLength /= bytesPerClustersLcm;
                UsingBufferLength *= bytesPerClustersLcm;

                if (UsingBufferLength == 0)
                {
                    for (UsingBufferLength = bytesPerClustersLcm;
                         UsingBufferLength > startingBufferLength;
                         UsingBufferLength /= 2
                         )
                    {
                        ;
                    }
                }
            }

            PhysicalBufferLength = UsingBufferLength
                                   + Consts.BufferReadingEnsurance;
        }