InvokeLog() public static method

public static InvokeLog ( string msg ) : void
msg string
return void
Exemplo n.º 1
0
        public Status fn03_UnitTests(UnitTests ut, System.ComponentModel.BackgroundWorker bgw)
        {
            MainWindow.InvokeLog("Start unit tests command...");
            Status s = WriteCommand(0x03);

            if (s != Status.Success)
            {
                return(s);
            }

            byte[] read;
            if (ReadCommand(out read) != Status.Success)
            {
                return(Status.Error);
            }

            int count = 0;

            count += read [0];
            count += (read [1] << 8);
            count += (read [2] << 16);
            count += (read [3] << 24);

            for (int i = 0; i < count; i++)
            {
                if (bgw.CancellationPending)
                {
                    Cancel();
                    break;
                }

                bgw.ReportProgress((100 * i) / count);

                UnitTestDataItem item = new UnitTestDataItem();
                if (ReadCommand(out read) != Status.Success)
                {
                    continue;
                }
                item.Source = System.Text.Encoding.ASCII.GetString(read);

                if (ReadCommand(out read) != Status.Success)
                {
                    continue;
                }
                item.Name = System.Text.Encoding.ASCII.GetString(read);

                if (ReadCommand(out read) != Status.Success)
                {
                    continue;
                }
                item.Result = (read [0] != 0);

                ut.Add(item);
            }
            return(Status.Success);
        }
Exemplo n.º 2
0
        // Read a result message consisting of a size N coded on two bytes (LittleEndian) and N bytes.
        // If an error occurs while reading, returns Status.Error
        // If the read is incomplete, wait for a lapse, empty the pipe, send RESEND and restart the complete read.
        // This could be optimized...
        private Status ReadCommand(out byte [] buffer)
        {
            Status s;

            byte[] localBuffer = null;
            buffer = null;

            while (true)
            {
                // Read the size of data to read
                uint   count          = 0;
                byte[] numReadWritten = new byte [2];
                s = ReadCommand(numReadWritten, ref count);
                if (s == Status.Error)
                {
                    return(Status.Error);
                }

                if (count != 2)
                {
                    // Incomplete
                    Resend();
                    continue;
                }


                // Read data
                uint msgLength = (uint)numReadWritten [0] | ((uint)numReadWritten [1] << 8);
                localBuffer = new byte [msgLength];
#if LOG_IO
                MainWindow.InvokeLog("---- Requesting " + msgLength + " bytes");
#endif
                s = ReadCommand(localBuffer, ref count);
#if LOG_IO
                MainWindow.InvokeLog("---- Received " + count + " bytes");
#endif
                if (s == Status.Error)
                {
                    return(Status.Error);
                }

                if (count != msgLength)
                {
                    // Incomplete
                    Resend();
                    continue;
                }

                Ack();
                break;
            }

            buffer = localBuffer;
            return(Status.Success);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Empty the pipe to remove any garbage
        /// </summary>
        /// <returns></returns>
        public Status Empty()
        {
            uint count = 256;

            byte[] read = new byte[count];

            // Empty the pipe

            MainWindow.InvokeLog("Emptying pipe...");
            while (ReadCommand(read, ref count) != Status.Error && count == 256)
            {
                ;
            }

            return(Status.Success);
        }
Exemplo n.º 4
0
        public Client.Status Read(byte [] buffer, ref uint count)
        {
            bool bResult = ReadFile(pipeHandle, buffer, (uint)buffer.Length, ref count, (uint)0);

            if (!bResult)
            {
                return(Client.Status.Error);
            }
            rbytes += count;
#if LOG_IO
            StringBuilder sb = new StringBuilder("-> ");
            foreach (byte b in buffer)
            {
                sb.AppendFormat(" {0:X2}", b);
            }
            MainWindow.InvokeLog(sb.ToString());
#endif
            return(Client.Status.Success);
        }
Exemplo n.º 5
0
        public Status fn01_HelloWorld(out string result)
        {
            result = string.Empty;

            MainWindow.InvokeLog("Send test command...");
            if (WriteCommand(0x01) != Status.Success)
            {
                MainWindow.InvokeLog("Send failed");
                return(Status.Error);
            }

            byte [] read;
            if (ReadCommand(out read) != Status.Success)
            {
                MainWindow.InvokeLog("Receive failed");
                return(Status.Error);
            }

            result = System.Text.Encoding.ASCII.GetString(read);
            return(Status.Success);
        }
Exemplo n.º 6
0
        public Status fn00_Connect()
        {
            // Send a connection message to SharpOS.
            MainWindow.InvokeLog("Try to connect...");
            if (WriteCommand(0x00) != Status.Success)
            {
                return(Status.Error);
            }

            byte[] read;
            if (ReadCommand(out read) != Status.Success)
            {
                return(Status.Error);
            }
            if (read [0] == 0)
            {
                MainWindow.InvokeLog("Connection refused by SharpOS");
                return(Status.Error);
            }

            return(Status.Success);
        }
Exemplo n.º 7
0
        public Client.Status Write(byte [] buffer)
        {
            uint bytesWritten = 0;

#if LOG_IO
            StringBuilder sb = new StringBuilder("<- ");
            foreach (byte b in buffer)
            {
                sb.AppendFormat(" {0:X2}", b);
            }
            MainWindow.InvokeLog(sb.ToString());
#endif
            bool bResult = WriteFile(pipeHandle, buffer, (uint)buffer.Length, ref bytesWritten, 0);
            if (!bResult)
            {
                MainWindow.InvokeLog("Communicator.Send() failed");
                return(Client.Status.Error);
            }
            wbytes += bytesWritten;

            Thread.Sleep(50);

            return(Client.Status.Success);
        }
Exemplo n.º 8
0
        public Status fn02_MemoryDump(uint address, out byte [] result, System.ComponentModel.BackgroundWorker bgw)
        {
            MainWindow.InvokeLog("Start memory dump command...");
            Status s = WriteCommand(0x02, (byte)(address & 0xFF), (byte)((address >> 8) & 0xFF), (byte)((address >> 16) & 0xFF), (byte)((address >> 24) & 0xFF));

            if (s != Status.Success)
            {
                result = null;
                return(Status.Error);
            }

            result = new byte [4096];

            int currentOffset = 0;

            for (int i = 0; i < 16; i++)
            {
                bgw.ReportProgress((100 * i) / 16);

                byte[] read;
                if (ReadCommand(out read) != Status.Success)
                {
                    break;
                }

                Array.Copy(read, 0, result, currentOffset, read.Length);
                currentOffset += read.Length;

                if (Ack() != Status.Success)
                {
                    break;
                }
            }

            return(s);
        }