Пример #1
0
 private void cursor_check()
 {
     if (TextBoxTerminal.SelectionStart <= cursor_initial)
     {
         TextBoxTerminal.Select(TextBoxTerminal.Text.Length, 0);
     }
 }
Пример #2
0
 /**
  *  check user input whenever terminal content changes
  */
 private void TextBoxTerminal_TextChanged(object sender, EventArgs e)
 {
     if (TextBoxTerminal.Text.Length < cursor_initial)
     {
         TextBoxTerminal.Text += " ";
         TextBoxTerminal.Select(TextBoxTerminal.Text.Length, 0);
     }
 }
Пример #3
0
 /**
  *  initialize text box terminal
  */
 private void TextBoxTerminal_Init()
 {
     Array.Sort(cmd_list);
     TextBoxTerminal.Clear();
     TextBoxTerminal.Text = "GCS @ GCS: ~$ ";
     TextBoxTerminal.Select(TextBoxTerminal.Text.Length, 0);
     cursor_initial   = TextBoxTerminal.Text.Length;
     terminal_blocked = false;
 }
Пример #4
0
        private void TextBoxTerminalInput_KeyDown(object sender, KeyEventArgs e)
        {
            string RawInput = "";
            string Input    = "";

            if (e.KeyCode == Keys.Enter)
            {
                TextBoxTerminal.AppendText("> " + TextBoxTerminalInput.Text + "\r\n");
                RawInput = TextBoxTerminalInput.Text;
                Input    = RawInput.Trim().ToLower();
                TextBoxTerminalInput.Text = "";
                if (Input == "help" | Input == "?")
                {
                    TextBoxTerminal.AppendText("╔════════════════════════════╗\r\n║ VisionClient Terminal Help ║\r\n╚════════════════════════════╝\r\n\r\nCommands:\r\n\r\nclear\t\tClear the display.\r\nconnect\t\tAttempt to connect to the server, or ping the server if already connected.\r\ndisconnect\tDisconnect from the server.\r\nexit\t\tClose the VisionClient program. (Synonyms: \"bye\", \"quit\")\r\nhelp\t\tDisplay this menu. (Synonyms: \"?\")\r\nmagic\t\tAbracadabra!\r\nsend\t\tAttempt to send the entered data to the server. Syntax is: \"send <data>\". The server will listen for the following strings: \"C\", \"C0\", \"C1\", \"C2\", \"C3\", \"C4\", \"T\", \"T0\", \"T1\", \"T2\".\r\n");
                }
                else if (Input == "magic")
                {
                    TextBoxTerminal.AppendText(" ██████╗ ██╗  ██╗███████╗███████╗██████╗ ███████╗███████╗ █████╗ ██████╗ ███████╗\r\n██╔═████╗╚██╗██╔╝██╔════╝██╔════╝╚════██╗╚════██║██╔════╝██╔══██╗██╔══██╗██╔════╝\r\n██║██╔██║ ╚███╔╝ ███████╗█████╗   █████╔╝    ██╔╝███████╗╚██████║██║  ██║█████╗  \r\n████╔╝██║ ██╔██╗ ╚════██║██╔══╝   ╚═══██╗   ██╔╝ ╚════██║ ╚═══██║██║  ██║██╔══╝  \r\n╚██████╔╝██╔╝ ██╗███████║██║     ██████╔╝   ██║  ███████║ █████╔╝██████╔╝██║     \r\n ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═╝     ╚═════╝    ╚═╝  ╚══════╝ ╚════╝ ╚═════╝ ╚═╝\r\n");
                }
                else if (Input == "clear")
                {
                    TextBoxTerminal.Text = "";
                }
                else if (Input == "connect")
                {
                    if (m_Comm.IsConnected())
                    {
                        m_Comm.SendData("1");
                        LabelStatus.Text = "Current connection status: ONLINE.";
                    }
                    else
                    {
                        m_Comm.Run();
                    }
                }
                else if (Input == "disconnect")
                {
                    m_Comm.Stop();
                    TextBoxTerminal.AppendText("Disconnected. Please note that you will not be able to reconnect for several minutes, due to underlying networking protocols.\r\n");
                }
                else if (Input == "quit" | Input == "bye" | Input == "exit")
                {
                    Application.Exit();
                }
                else if (Input.Length >= 4 && Input.Substring(0, 4) == "send")
                {
                    m_Comm.SendData(RawInput.Substring(5, Input.Length - 5));
                }
                else
                {
                    TextBoxTerminal.AppendText("ERROR: Command \"" + RawInput + "\" not found.\r\n");
                }
            }
        }
Пример #5
0
        /**
         *  background worker job completed
         */
        private void backgroundWorker_terminal_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            terminal_blocked = false;
            string res = (string)e.Result;

            TextBoxTerminal.Text += res + "\r\n";
            TextBoxTerminal.Text += current_station_name + " @ GCS: ~$ ";
            TextBoxTerminal.Select(TextBoxTerminal.Text.Length, 0);
            cursor_initial = TextBoxTerminal.Text.Length;
            TextBoxTerminal.ScrollToCaret();
        }
Пример #6
0
        /**
         *  capture special key presses
         */
        private void TextBoxTerminal_KeyDown(object sender, KeyEventArgs e)
        {
            // if focus is NOT of the terminal, don't do anything
            if (TextBoxTerminal.Focus() == false)
            {
                return;
            }

            // when ENTER is pressed
            if (e.KeyCode == Keys.Enter)
            {
                int    len      = TextBoxTerminal.Text.Length - cursor_initial;
                string sentense = TextBoxTerminal.Text.Substring(cursor_initial, len);
                cmd_history.Add(sentense);
                cmd_history_index = cmd_history.Count - 1;

                if (cmd_history.Count > cmd_history_max)
                {
                    cmd_history.RemoveAt(0);
                }

                backgroundWorker_terminal.RunWorkerAsync(sentense);

                cursor_initial   = TextBoxTerminal.Text.Length;
                terminal_blocked = true;
            }

            // when ctrl+l is pressed, clear screen, except for current line
            if (e.Control && e.KeyCode == Keys.L)
            {
                int    len      = TextBoxTerminal.Text.Length - cursor_initial;
                string sentense = TextBoxTerminal.Text.Substring(cursor_initial, len);

                cursor_initial = 14;

                TextBoxTerminal.Text = current_station_name + " @ GCS: ~$ " + sentense;
                TextBoxTerminal.Select(TextBoxTerminal.Text.Length, 0);
            }

            // up/down key to see previous cmds
            if (e.KeyCode == Keys.Down)
            {
            }
            if (e.KeyCode == Keys.Up)
            {
            }

            if (!e.Control)
            {
                cursor_check();
            }
        }
Пример #7
0
 private void Log(string message)
 {
     TextBoxTerminal.AppendText(message + "\r\n");
     File.WriteAllText("outlog.txt", message + "\r\n");
 }
Пример #8
0
        private string cmd_img_trans_test(string[] cmd_words)
        {
            double t1 = epoch_now();

            AddDataObj_terminal = new AddDataDelegate(AddDataMethod_terminal);
            string res = "";
            DFrame msg = new DFrame();

            // initiate img transmission
            msg.source_id  = gcs.id;
            msg.target_id  = 0x03;
            msg.route      = 0;
            msg.payload[0] = 10; // img transfer request
            msg.payload[1] = Convert.ToByte('N');
            msg.len        = 2;
            msg.send(serial_ch1);

            // wait for first pkg, which tells the size of the img
            byte[] tmp;
            int    img_size    = 0;
            Int16  pkg_num     = 0;
            Int16  block_size  = 0;
            int    timeout_cnt = 0;

            while (timeout_cnt < 300)
            {
                if (img_raw_buff.TryDequeue(out tmp))
                {
                    if (tmp[1] != 0xFF | tmp[2] != 0xFF)
                    {
                        continue;
                    }
                    pkg_num    = BitConverter.ToInt16(tmp, 3);
                    img_size   = BitConverter.ToInt32(tmp, 5);
                    block_size = BitConverter.ToInt16(tmp, 9);
                    res        = "    img request accepted \r\n";
                    res       += "    number of pkg: " + Convert.ToString(pkg_num) + "\r\n";
                    res       += "    size of img: " + Convert.ToString(img_size) + "\r\n";
                    res       += "    img block size: " + Convert.ToString(block_size) + "\r\n";
                    TextBoxTerminal.Invoke(this.AddDataObj_terminal, res);
                    break;
                }
                else
                {
                    timeout_cnt += 1;
                    Thread.Sleep(1);
                }
            }

            if (timeout_cnt >= 300)
            {
                res = "    timeout\r\n";
                TextBoxTerminal.Invoke(this.AddDataObj_terminal, res);
                return("");
            }


            // receive the rest of the img
            Int16     pkg_cnt = 0;
            const int max_try = 10;
            int       try_cnt = 0;

            byte[]       img_buf      = new byte[img_size];
            List <Int16> received_pkg = new List <Int16>();

            msg.payload[1] = Convert.ToByte('R');
            msg.len        = 4;
            for (pkg_cnt = 0; pkg_cnt < pkg_num; pkg_cnt++)
            {
                try_cnt = 0;
                while (try_cnt < max_try)
                {
                    msg.payload[2] = (byte)(pkg_cnt & 0x00FF);
                    msg.payload[3] = (byte)(pkg_cnt >> 8);
                    res            = "requesting pkg " + Convert.ToString(pkg_cnt) + "\r\n";
                    TextBoxTerminal.Invoke(this.AddDataObj_terminal, res);
                    msg.send(serial_ch1);
                    timeout_cnt = 0;
                    while (timeout_cnt < 400)
                    {
                        if (img_raw_buff.TryDequeue(out tmp))
                        {
                            if (BitConverter.ToInt16(tmp, 1) != pkg_cnt)
                            {
                                continue;
                            }

                            Int16 pkg_cnt_get = BitConverter.ToInt16(tmp, 1);
                            received_pkg.Add(pkg_cnt);

                            // copy received pkg to local buffer
                            int pkg_len = (pkg_cnt == pkg_num - 1) ? img_size % block_size : block_size;
                            Buffer.BlockCopy(tmp, 3,
                                             img_buf, pkg_cnt * block_size, pkg_len);

                            res = "    received pkg: " + Convert.ToString(pkg_cnt_get) + "\r\n";
                            TextBoxTerminal.Invoke(this.AddDataObj_terminal, res);
                            break;
                        }
                        else
                        {
                            timeout_cnt += 1;
                            Thread.Sleep(1);
                        }
                    }

                    if (timeout_cnt >= 400)
                    {
                        try_cnt += 1;
                        //Thread.Sleep(1);
                    }
                    else
                    {
                        break;
                    }
                }
            }


            // check whether the reception is complete


            // request re-transmission of missing pkgs

            // write picture to file
            BinaryWriter img_write = new BinaryWriter(File.Open("try.jpg", FileMode.Create));

            img_write.Write(img_buf);
            img_write.Close();

            res = "time take: " + Convert.ToString(Math.Round(epoch_now() - t1, 2)) + " seconds";
            TextBoxTerminal.Invoke(this.AddDataObj_terminal, res);

            return(" ");
        }
Пример #9
0
 private void AddDataMethod_terminal(string s)
 {
     TextBoxTerminal.AppendText(s);
 }