Esempio n. 1
0
        internal void AcquireBootloaderDevicesInParallel(byte[] addresses)
        {
            Console.WriteLine();
            ScanningTask[]          tasks     = new ScanningTask[available_ports.Count];
            int                     top       = Console.CursorTop;
            List <BootloaderClient> endpoints = new List <BootloaderClient>();


            for (int i = 0; i < available_ports.Count; i++)
            {
                tasks[i] = new ScanningTask()
                {
                    Row                 = top + i,
                    Thread              = new Thread(new ParameterizedThreadStart(Ack)),
                    AddressList         = addresses,
                    SerialPort          = available_ports[i],
                    EndpointsCollection = endpoints
                };
                tasks[i].Thread.Start(tasks[i]);
            }

            for (int i = 0; i < available_ports.Count; i++)
            {
                tasks[i].Thread.Join();
            }

            Console.CursorTop += available_ports.Count;

            this.discovered_devices.AddRange(endpoints);
            this.discovered_devices.Sort((x, y) => x.BootloaderAddress - y.BootloaderAddress);
        }
Esempio n. 2
0
        public ServiceRegistry GetServiceRegistry(string registryName)
        {
            ScanningTask.Wait();
            ServiceRegistryLoaderDescriptor loader = GetServiceRegistryLoaderDescriptor(registryName);

            if (loader == null)
            {
                ServiceRegistryDescriptor descriptor = GetServiceRegistryDescriptor(registryName);
                return(GetServiceRegistry(descriptor));
            }
            return(GetServiceRegistry(loader));
        }
Esempio n. 3
0
        private void Ack(object obj)
        {
            ScanningTask task = obj as ScanningTask;
            int          col  = 0;

            ColorConsole.WriteXY(0, task.Row, task.SerialPort.PortName);
            col += 3 + 3 + 1;

            var sp        = task.SerialPort;
            var me        = new MessageExtractor();
            int timeout   = 100;
            var endpoints = new List <BootloaderClient>();

            foreach (byte scanned_address in task.AddressList)
            {
                // Show scanned address
                int ccol = col;
                ColorConsole.WriteXY(ccol, task.Row, ConsoleColor.Green, $"0x{scanned_address:X2}");

                // send ping do selected device
                sp.DiscardInBuffer();
                sp.DiscardOutBuffer();
                me.Discard();

                Message ping_message = new Message(scanned_address, MessageType.Ping);
                Message msg          = SendAndWaitForResponse(new BootloaderClient(sp, scanned_address), ping_message, timeout, false, 0);

                if (msg != null)
                {
                    endpoints.Add(new BootloaderClient(sp, scanned_address));
                }


                // Show list of found clients
                ccol += 5;
                ColorConsole.WriteXY(ccol, task.Row, ConsoleColor.Yellow, "[" + string.Join(",", endpoints.Select(x => x.BootloaderAddress.ToString("X2"))) + "]");
            }

            lock (task.EndpointsCollection)
                task.EndpointsCollection.AddRange(endpoints);
        }