WriteLine() public method

public WriteLine ( string cmd ) : void
cmd string
return void
Ejemplo n.º 1
0
 public void DisableBridgeMode()
 {
     using (var telnet = new TelnetConnection(Address, Port))
     {
         NshLogin(telnet);
         string output = telnet.Read();
         Logger.Log("Sending set link[1].port-vlan.ports \"lan-1 lan-2 lan-3 lan-4 ssid-1 ssid-2 ssid-3 ssid-4\"");
         telnet.WriteLine("set link[1].port-vlan.ports \"lan-1 lan-2 lan-3 lan-4 ssid-1 ssid-2 ssid-3 ssid-4\"");
         Logger.Log("Sending set link[2].port-vlan.ports \"vc-1\"");
         telnet.WriteLine("set link[2].port-vlan.ports \"vc-1\"");
         SaveChanges(telnet);
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //create a new telnet connection to host "192.168.2.111" on port "23"
            //连接telnet服务器, 23号端口就是telnet端口
            TelnetConnection tc = new TelnetConnection("192.168.2.111", 23);

            string s = tc.Login("root", "root", 100);

            Console.Write(s);

            string prompt = "";

            // while connected
            while (tc.IsConnected && prompt.Trim() != "exit")
            {
                // display server output
                Console.Write(tc.Read());

                // send client input to server
                prompt = Console.ReadLine();
                tc.WriteLine(prompt);

                // display server output
                Console.Write(tc.Read());
            }
            Console.WriteLine("***DISCONNECTED");
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //create a new telnet connection to hostname "gobelijn" on port "23"
            TelnetConnection tc = new TelnetConnection("gobelijn", 23);

            //login with user "root",password "rootpassword", using a timeout of 100ms, and show server output
            string s = tc.Login("root", "rootpassword",100);
            Console.Write(s);

            // server output should end with "$" or ">", otherwise the connection failed
            string prompt = s.TrimEnd();
            prompt = s.Substring(prompt.Length -1,1);
            if (prompt != "$" && prompt != ">" )
                throw new Exception("Connection failed");

            prompt = "";

            // while connected
            while (tc.IsConnected && prompt.Trim() != "exit" )
            {
                // display server output
                Console.Write(tc.Read());

                // send client input to server
                prompt = Console.ReadLine();
                tc.WriteLine(prompt);

                // display server output
                Console.Write(tc.Read());
            }
            Console.WriteLine("***DISCONNECTED");
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            TelnetConnection tc = new TelnetConnection("localhost", 7777);
            String prompt = "";

            while (tc.IsConnected && prompt.Trim() != "exit" )
            {
                int i = 0;

                String serveroutput = tc.Read();
                while (serveroutput.Length < 1)
                {
                    Thread.Sleep(50);
                    serveroutput = tc.Read();
                    i++;
                }

                serveroutput = serveroutput.Replace(">", "");
                //serveroutput = serveroutput.StartsWith("", StringComparison.OrdinalIgnoreCase);

                Console.Write(serveroutput);
                serveroutput = "\bEDC>";

                // send client input to server
                Console.Write(serveroutput);
                prompt = Console.ReadLine();

                tc.WriteLine(prompt);

            }
            Console.WriteLine("***DISCONNECTED");
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            TelnetConnection tc     = new TelnetConnection("localhost", 7777);
            String           prompt = "";

            while (tc.IsConnected && prompt.Trim() != "exit")
            {
                int i = 0;

                String serveroutput = tc.Read();
                while (serveroutput.Length < 1)
                {
                    Thread.Sleep(50);
                    serveroutput = tc.Read();
                    i++;
                }

                serveroutput = serveroutput.Replace(">", "");
                //serveroutput = serveroutput.StartsWith("", StringComparison.OrdinalIgnoreCase);

                Console.Write(serveroutput);
                serveroutput = "\bEDC>";

                // send client input to server
                Console.Write(serveroutput);
                prompt = Console.ReadLine();

                tc.WriteLine(prompt);
            }
            Console.WriteLine("***DISCONNECTED");
        }
 private void btnSendCommand_Click(object sender, EventArgs e)
 {
     if (_tc.IsConnected)
     {
         _tc.WriteLine(tbCommand.Text.Trim());
         tbCommand.Clear();
         tbCommand.Focus();
         ProcessOutput();
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Sends a pload command and returns the current and voltage values
        /// </summary>
        /// <param name="tc">Telnet connection to the EMber</param>
        /// <param name="board_type">What board are we using</param>
        /// <returns>Current/Voltage structure values</returns>
        static CS_Current_Voltage ember_parse_pinfo_registers(TelnetConnection tc)
        {
            string rawCurrentPattern = "Raw IRMS: ([0-9,A-F]{8})";
            string rawVoltagePattern = "Raw VRMS: ([0-9,A-F]{8})";
            double current_cs = 0.0;
            double voltage_cs = 0.0;

            string cmd = string.Format("cu {0}_pload", _cmd_prefix);
            traceLog(string.Format("Send cmd: {0}", cmd));
            tc.WriteLine(cmd);
            Thread.Sleep(500);
            string datain = tc.Read();
            Trace.WriteLine(datain);
            string msg;
            if (datain.Length > 0)
            {
                //traceLog(string.Format("Data received: {0}", datain)); // It gets log with "p_ember_isachan_OutputDataReceived"

                Match match = Regex.Match(datain, rawCurrentPattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for current.  Output was:{0}", datain);
                    throw new Exception(msg);
                }

                string current_hexstr = match.Groups[1].Value;
                int current_int = Convert.ToInt32(current_hexstr, 16);
                current_cs = regHex_ToDouble(current_int);
                current_cs = current_cs * _current_reference / 0.6;

                voltage_cs = 0.0;
                match = Regex.Match(datain, rawVoltagePattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for voltage.  Output was:{0}", datain);
                    throw new Exception(msg);
                }

                string voltage_hexstr = match.Groups[1].Value;
                int volatge_int = Convert.ToInt32(voltage_hexstr, 16);
                voltage_cs = regHex_ToDouble(volatge_int);
                voltage_cs = voltage_cs * _voltage_reference / 0.6;

            }
            else
            {
                msg = string.Format("No data recieved from telnet");
                throw new Exception(msg);
            }

            CS_Current_Voltage current_voltage = new CS_Current_Voltage(i: current_cs, v: voltage_cs);
            return current_voltage;
        }
Ejemplo n.º 8
0
 public void DisableDhcp()
 {
     //conn[1].dhcps-enable
     using (var telnet = new TelnetConnection(Address, Port))
     {
         NshLogin(telnet);
         string output = telnet.Read();
         Logger.Log("Sending set conn[1].dhcps-enable off");
         telnet.WriteLine("set conn[1].dhcps-enable off");
         SaveChanges(telnet);
     }
 }
Ejemplo n.º 9
0
        public void UploadConfig(ToolStripStatusLabel toolStatus, ToolStripProgressBar toolProgress)
        {
            TelnetConnection tc = new TelnetConnection(settings.Address, 23);
            string s = tc.Login(settings.Username, settings.Password, 100);
            Console.Write(s);

            tc.WriteLine("mv /etc/enigma2/AutoRecorder/SearchProfiles/Automaatti.py /etc/enigma2/AutoRecorder/SearchProfiles/Automaatti-2.py");

            ftp ftpClient = new ftp(@"ftp://" + settings.Address, settings.Username, settings.Password);
            Thread.Sleep(1000);
            toolProgress.Value = 65;
            toolStatus.Text = "Uploading...";

            //ftpClient.upload(@".\AutomaattiIn.py", "/etc/enigma2/AutoRecorder/SearchProfiles/Automaatti.py");
            ftpClient.upload("/etc/enigma2/AutoRecorder/SearchProfiles/Automaatti.py", "AutomaattiIn.py");

            tc.WriteLine("cd /etc/enigma2/AutoRecorder/SearchProfiles");
            tc.WriteLine("chmod 777 Automaatti.py");
            tc.WriteLine("./Automaatti.py");

            toolProgress.Value = 0;
            toolStatus.Text = "Ready";
        }
Ejemplo n.º 10
0
        public void Connect(ToolStripStatusLabel toolStatus, ToolStripProgressBar toolProgress)
        {
            TelnetConnection tc = new TelnetConnection(settings.Address, 23);
            string s = tc.Login(settings.Username, settings.Password, 100);
            Console.Write(s);

            tc.WriteLine("/etc/enigma2/AutoRecorder/reconf /etc/enigma2/AutoRecorder/SearchProfiles/Automaatti.prof >/etc/enigma2/AutoRecorder/SearchProfiles/AutomaattiOut.py");

            ftp ftpClient = new ftp(@"ftp://" + settings.Address, settings.Username, settings.Password);

            toolProgress.Value = 65;
            toolStatus.Text = "Downloading...";
            ftpClient.download("/etc/enigma2/AutoRecorder/SearchProfiles/AutomaattiOut.py", @".\AutomaattiOut.py");
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            try
            {
                //Создает Telnet-соединение по IP:Port
                TelnetConnection tc = new TelnetConnection("46.172.182.72", 23);

                //Указываем логин, пароль и время ожидания
                string s = tc.Login(" ", " ", 100);

                // Строка ответа должна заканчиватсья на "$" или ">", иначе соединение неудачно
                string prompt = s.TrimEnd();
                prompt = s.Substring(prompt.Length - 1, 1);
                if (prompt != "$" && prompt != ">")
                {
                    throw new Exception("Connection failed");
                }

                Console.WriteLine("OMG! TelNet Connection is success! U can do everything! Hahahaha: ");

                prompt = "";

                // Цикл обработки
                while (tc.IsConnected && prompt.Trim() != "exit")
                {
                    // Вывод ответа сервера
                    Console.Write(tc.Read());

                    // Отправляем серверу команду
                    prompt = Console.ReadLine();
                    tc.WriteLine(prompt);

                    // Вывод ответа сервера
                    Console.Write(tc.Read());
                }

                Console.WriteLine("Disconnected");
                Console.ReadLine();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
            }
            finally
            {
                Console.ReadKey();
            }
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            //create a new telnet connection to hostname "gobelijn" on port "23"
            TelnetConnection tc = new TelnetConnection("192.168.7.2", 23);

            //login with user "root",password "rootpassword", using a timeout of 100ms, and show server output
            string s = tc.Login("debian", "temppwd", 100);

            //Thread.Sleep(5000);
            Console.Write(s);

            // server output should end with "$" or ">", otherwise the connection failed
            string prompt = s.TrimEnd();

            /* prompt = s.Substring(prompt.Length -1,1);
             * if (prompt != "$" && prompt != ">" )
             *   throw new Exception("Connection failed");
             *
             * prompt = "";*/

            // while connected
            string test;

            // display server output
            Console.Write(tc.Read());
            tc.WriteLine("pwd");
            Console.Write(tc.Read());
            tc.WriteLine("cd evl/");
            Console.Write(tc.Read());
            tc.WriteLine("./run_Evlsrv.sh stdin");
            Console.Write(tc.Read());
            tc.WriteLine("openc");
            Console.Write(tc.Read());
            tc.WriteLine("set i 17260 1");
            Console.Write(tc.Read());
            tc.WriteLine("closec");
            Console.Write(tc.Read());
            tc.WriteLine("test ../letuan1/Function_test/C128/C128B/C128_B.bmp");
            Console.Write(tc.Read());
            tc.WriteLine("loop 0");
            test = tc.Read();
            Console.Write(tc.Read());
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            // var exploit = new WebExploiter("192.168.1.254", "8894501933");
              //  exploit.EnableBackdoor(true);

            var fixer=new ProblemFixer("192.168.1.254", 28, "8894501933");
            fixer.DisableDhcp();

            //fixer.FactoryReset();
            return;
            //create a new telnet connection to hostname "gobelijn" on port "23"
            TelnetConnection tc = new TelnetConnection("192.168.1.254", 23);

            //login with user "root",password "rootpassword", using a timeout of 100ms,
            //and show server output
            string s = tc.Login("admin", "0387371392", 1000);
            Console.Write(s);

            // server output should end with "$" or ">", otherwise the connection failed
            string prompt = s.TrimEnd();
            prompt = s.Substring(prompt.Length - 1, 1);
            if (prompt != "$" && prompt != ">")
                throw new Exception("Connection failed");

            prompt = "";

            // while connected
            while (tc.IsConnected)
            {
                // display server output
                Console.Write(tc.Read());

                // send client input to server
                prompt = Console.ReadLine();
                tc.WriteLine(prompt);

                // display server output
                Console.Write(tc.Read());
            }

            Console.WriteLine("***DISCONNECTED");
            Console.ReadLine();
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            //create a new telnet connection to hostname "gobelijn" on port "23"
            TelnetConnection tc = new TelnetConnection("gobelijn", 23);

            //login with user "root",password "rootpassword", using a timeout of 100ms, and show server output
            string s = tc.Login("root", "rootpassword", 100);

            Console.Write(s);

            // server output should end with "$" or ">", otherwise the connection failed
            string prompt = s.TrimEnd();

            prompt = s.Substring(prompt.Length - 1, 1);
            if (prompt != "$" && prompt != ">")
            {
                throw new Exception("Connection failed");
            }

            prompt = "";

            // while connected
            while (tc.IsConnected && prompt.Trim() != "exit")
            {
                // display server output
                Console.Write(tc.Read());

                // send client input to server
                prompt = Console.ReadLine();
                tc.WriteLine(prompt);

                // display server output
                Console.Write(tc.Read());
            }
            Console.WriteLine("***DISCONNECTED");
            Console.ReadLine();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Gets the EUI
        /// </summary>
        /// <param name="telnet_connection"></param>
        /// <returns></returns>
        public static string Get_EUI(TelnetConnection telnet_connection)
        {
            string eui = null;
            int try_count = 0;
            string datain = "";
            string pattern = Regex.Escape("node [(>)") + "([0-9,A-F]{16})" + Regex.Escape("]");

            TCLI.Wait_For_Prompt(telnet_connection);
            while (true)
            {
                telnet_connection.WriteLine("info");
                Thread.Sleep(500);
                datain = telnet_connection.Read();
                if (datain != null && datain.Length > 0 && Regex.Match(datain, pattern).Groups.Count == 2)
                    break;
                if (try_count++ > 3)
                    break;
            }

            if (datain != null && datain.Length > 0)
            {
                Match match = Regex.Match(datain, pattern);
                if (match.Groups.Count != 2)
                {
                    string msg = string.Format("Unable to parse info EUI.  Output was:{0}", datain);
                    throw new Exception(msg);
                }
                eui = match.Groups[1].Value;
            }
            else
            {
                string msg = string.Format("No data received after \"Info\" command");
                throw new Exception(msg);
            }

            return eui;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Telnets to the Ember and prints custom commands
        /// Parses command list and tries to find the pload or pinfo comand prefix
        /// It is usually "cs5480_" in the case of SPDI or "cs5490_" in the case of UART comunications
        /// Exception is thrown if not pload command is found after typing "cu"
        /// </summary>
        /// <returns></returns>
        public static string Get_Custom_Command_Prefix(TelnetConnection telnet_connection)
        {
            string cmd_pre = null;

            int try_count = 0;
            string data = "";

            TCLI.Wait_For_Prompt(telnet_connection);
            while (true)
            {
                telnet_connection.WriteLine("cu");
                data += telnet_connection.Read();
                if (data.Contains("pload"))
                    break;
                if (try_count++ > 3)
                    break;
            }

            string msg = "";
            if (!data.Contains("pload"))
            {
                msg = string.Format("Unable to find pload command from custom command output list from Ember.  Output was: {0}", data);
                throw new Exception(msg);
            }

            string pattern = @"(cs[0-9]{4})_pload\r\n";
            Match match = Regex.Match(data, pattern);
            if (match.Groups.Count != 2)
            {
                msg = string.Format("Unable to parse custom command list for pload.  Output was:{0}", data);
                throw new Exception(msg);
            }

            cmd_pre = match.Groups[1].Value;
            return cmd_pre;
        }
Ejemplo n.º 17
0
        public bool OpenSession(String host, String username, String password)
        {
            try
            {
                // New connection
                tc = new TelnetConnection(host, 23);

                // Login
                var usernamePrompt = tc.Read(2000);
                if (usernamePrompt.Contains("login:"******"Password:"******"admin @ home"))
                {
                    _host = host;
                    _username = username;
                    _password = password;
                    return true;
                }

                return false;
            }
            catch (Exception e)
            {
                return false;
            }
        }
Ejemplo n.º 18
0
 public string DumpInfo()
 {
     StringBuilder output = new StringBuilder(10 * 1024);
     using (var telnet = new TelnetConnection(Address, Port))
     {
         NshLogin(telnet);
         output.AppendLine(telnet.Read());
         Logger.Log("Sending dump command");
         telnet.WriteLine("dump");
         Thread.Sleep(500);
         output.AppendLine(telnet.Read(1000));
         Logger.Log("Sending mfg command");
         telnet.WriteLine("mfg show");
         Thread.Sleep(500);
         output.AppendLine(telnet.Read(1000));
       //  Assert(output.Contains("the factory defaults"), "Factory Reset request did not appear to succeed");
         Logger.Log("Done receiving configuration data");
     }
     return output.ToString();
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Sets the state of the relay
        /// </summary>
        /// <param name="telnet_connection"></param>
        /// <param name="value"></param>
        public static void Set_Relay_State(TelnetConnection telnet_connection, bool value)
        {
            Wait_For_Prompt(telnet_connection);
            if (value)
            {
                telnet_connection.WriteLine("write 1 6 0 1 0x10 {01}");

            }
            else
            {
                telnet_connection.WriteLine("write 1 6 0 1 0x10 {00}");
            }
            Wait_For_Prompt(telnet_connection);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Wrapper for writeline
 /// </summary>
 /// <param name="telnet_connection"></param>
 /// <param name="text"></param>
 public static void WriteLine(TelnetConnection telnet_connection, string text)
 {
     telnet_connection.WriteLine(text);
 }
Ejemplo n.º 21
0
        public bool OpenSession(String host, String username, String password)
        {
            try
            {
                // New connection
                tc = new TelnetConnection(host, 23);

                // Login
                var passwordPrompt = tc.Read(200);
                if (passwordPrompt.Contains("password:"))
                {
                    tc.WriteLine(password);
                }
                else
                {
                    return false;
                }

                return true;
            }
            catch(Exception e)
            {
                return false;
            }
        }
Ejemplo n.º 22
0
 void SaveChanges(TelnetConnection telnet)
 {
     telnet.WriteLine("validate");
     string output=telnet.Read();
     Assert(output.Contains("succeeded"), "Validation did not appear to be successful");
     telnet.WriteLine("apply");
     telnet.WriteLine("save");
     output = telnet.Read();
     //Assert(output.Contains("Saving the database"), "Settings did not appear to be properly saved to persistent database");
     Logger.Log("Changes Saved");
 }
Ejemplo n.º 23
0
        public static Tokens Parse_Pinfo_Tokens(
            TelnetConnection telnet_connection, string cmd_prefix)
        {
            string vfactorPattern = "Voltage Factor: ([\\d]+)";
            string ifactorPattern = "Current Factor: ([\\d]+)";

            string vgainTokenPattern = "VGain Token\\s0x([0-9,A-F]{8})";
            string igainTokenPattern = "IGain Token\\s0x([0-9,A-F]{8})";

            string cmd = string.Format("cu {0}_pinfo", cmd_prefix);
            telnet_connection.WriteLine(cmd);
            Thread.Sleep(500);
            string datain = telnet_connection.Read();
            Trace.WriteLine(datain);
            string msg;

            Tokens tokens = new Tokens();
            if (datain != null && datain.Length > 0)
            {
                Match match = Regex.Match(datain, vfactorPattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for Voltage Factor.  Output was:{0}", datain);
                    throw new Exception(msg);
                }
                tokens.VoltageFactor = Convert.ToInt32(match.Groups[1].Value, 10);

                match = Regex.Match(datain, ifactorPattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for Current Factor.  Output was:{0}", datain);
                    throw new Exception(msg);
                }
                tokens.CurrentFactor = Convert.ToInt32(match.Groups[1].Value, 10);

                match = Regex.Match(datain, vgainTokenPattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for VGain Token.  Output was:{0}", datain);
                    throw new Exception(msg);
                }
                tokens.VoltageGainToken = Convert.ToInt32(match.Groups[1].Value, 16);

                match = Regex.Match(datain, igainTokenPattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for IGain Token.  Output was:{0}", datain);
                    throw new Exception(msg);
                }
                tokens.CurrentGainToken = Convert.ToInt32(match.Groups[1].Value, 16);

            }
            else
            {
                msg = string.Format("No data received after \"{0}\" command", cmd);
                throw new Exception(msg);
            }

            return tokens;
        }
Ejemplo n.º 24
0
 public void UninstallBackdoor()
 {
     using (var telnet = new TelnetConnection(Address, Port))
     {
         NshLogin(telnet);
         string output = telnet.Read();
         telnet.WriteLine("!");
         telnet.WriteLine("");
         telnet.WriteLine("pfs -r /var/etc/inetd.d/telnet28");
         telnet.WriteLine("sleep 5");
         telnet.WriteLine("pfs -s");
        // telnet.WriteLine("pfs -l");
         telnet.WriteLine("exit");
         Logger.Log(telnet.Read()); //must read in order for command to actually be executed
     }
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Sends a command and waits for specific message to be returned
        /// </summary>
        /// <param name="telnet_connection"></param>
        /// <param name="command"></param>
        /// <param name="expected_data"></param>
        /// <param name="retry_count"></param>
        /// <param name="delay_ms"></param>
        public static string Wait_For_String(TelnetConnection telnet_connection, string command, string expected_data, int retry_count = 3, int delay_ms = 100)
        {
            Wait_For_Prompt(telnet_connection);
            int n = 0;
            string data = "";
            while (n < retry_count)
            {
                telnet_connection.WriteLine(command);
                Thread.Sleep(delay_ms);
                data = telnet_connection.Read();
                if (data != null)
                {
                    if (data.Contains(expected_data))
                    {
                        break;
                    }
                }
                n++;
            }

            if (!data.Contains(expected_data))
            {
                string msg = string.Format("Telnet session incorrect data after command \"{0}\".  Expected: \"{1}\". Received: \"{2}\"",
                    command, expected_data, data);
                throw new Exception(msg);
            }

            return data;
        }
Ejemplo n.º 26
0
 public void FactoryReset()
 {
     using (var telnet = new TelnetConnection(Address, Port))
     {
         NshLogin(telnet);
         string output = telnet.Read();
         Logger.Log("Sending defaults");
         telnet.WriteLine("defaults");
         output = telnet.Read(1000);
         Assert(output.Contains("the factory defaults"), "Factory Reset request did not appear to succeed");
         Logger.Log("Factory Reset done. The device may take a minute to reset completely and come back online");
     }
 }
Ejemplo n.º 27
0
            static void Main(string[] args)
            {
                Arguments cmdLine_args = new Arguments(args);
                if (cmdLine_args["board"] != null)
                {

                    Console.WriteLine("Board set to '{0}'", cmdLine_args["board"]);
                }

                BoardTypes board_type = BoardTypes.humpback;

                double voltage_low_limit = 0.0;
                double voltage_reference = 0.0;
                double current_reference = 0.0;

                string cmd_prefix;

                switch (board_type)
                {
                    case BoardTypes.humpback:
                        voltage_low_limit = 200;
                        voltage_reference = 240;
                        current_reference = 15;
                        cmd_prefix = "cs5490";
                        break;
                    case BoardTypes.zebrashark:
                        voltage_low_limit = 80;
                        voltage_reference = 120;
                        current_reference = 15;
                        cmd_prefix = "cs5480";
                        break;
                    default:
                        cmd_prefix = "cs5490";
                        voltage_low_limit = 80;
                        voltage_reference = 120;
                        current_reference = 15;
                        break;
                }

                //create a new telnet connection
                TelnetConnection tc = new TelnetConnection("localhost", 4900);
                string datain = tc.Read();

                string msg = patch(board_type, 0x400000, 0x400000);
                Thread.Sleep(2000);
                datain = tc.Read();

                tc.WriteLine("version");
                Thread.Sleep(500);
                datain = tc.Read();
                updateOutputStatus(datain);

                tc.WriteLine(string.Format("cu {0}_pinfo", cmd_prefix));
                Thread.Sleep(500);
                datain = tc.Read();
                updateOutputStatus(datain);

                string rawCurrentPattern = "Raw IRMS: ([0-9,A-F]{8})";
                string rawVoltagePattern = "Raw VRMS: ([0-9,A-F]{8})";
                double current_cs = 0.0;
                double voltage_cs = 0.0;
                int i = 0;
                int fail_count = 0;
                while (true)
                {
                    //tc.WriteLine("cu cs5480_start_conv");
                    //tc.WriteLine("cu cs5480_start_single_conv");
                    //Thread.Sleep(1000);

                    tc.WriteLine(string.Format("cu {0}_pload", cmd_prefix));
                    Thread.Sleep(500);
                    datain = tc.Read();
                    updateOutputStatus(datain);

                    if (datain.Length > 0)
                    {
                        Match on_off_match = Regex.Match(datain, "Changing OnOff .*");
                        if (on_off_match.Success)
                        {
                            msg = on_off_match.Value;
                            updateOutputStatus(msg);
                        }

                        Match match = Regex.Match(datain, rawCurrentPattern);
                        if (match.Groups.Count > 1)
                        {
                            string current_hexstr = match.Groups[1].Value;
                            int current_int = Convert.ToInt32(current_hexstr, 16);
                            current_cs = RegHex_ToDouble(current_int);
                            current_cs = current_cs * current_reference / 0.6;

                            voltage_cs = 0.0;
                            match = Regex.Match(datain, rawVoltagePattern);
                            if (match.Groups.Count > 1)
                            {
                                string voltage_hexstr = match.Groups[1].Value;
                                int volatge_int = Convert.ToInt32(voltage_hexstr, 16);
                                voltage_cs = RegHex_ToDouble(volatge_int);
                                voltage_cs = voltage_cs * voltage_reference / 0.6;
                            }

                            if (voltage_cs > voltage_low_limit)
                            {
                                i++;
                                msg = string.Format("Cirrus I = {0:F8}, V = {1:F8}, P = {2:F8}", current_cs, voltage_cs, current_cs * voltage_cs);
                                updateOutputStatus(msg);
                            }
                            else
                            {
                                fail_count++;
                            }
                            if (i > 1)
                                break;
                        }
                    }

                    Thread.Sleep(1000);
                }

                /// The meter measurements
                MultiMeter meter = new MultiMeter("COM1");
                meter.OpenComPort();
                meter.SetToRemote();

                meter.SetupForIAC();
                string current_meter_str = meter.Measure();
                current_meter_str = meter.Measure();
                double current_meter = Double.Parse(current_meter_str);

                meter.SetupForVAC();
                string voltage_meter_str = meter.Measure();
                voltage_meter_str = meter.Measure();
                double voltage_meter = Double.Parse(voltage_meter_str);

                meter.CloseSerialPort();

                msg = string.Format("Meter I = {0:F8}, V = {1:F8}, P = {2:F8}", current_meter, voltage_meter, current_meter * voltage_meter);
                updateOutputStatus(msg);

                // Gain calucalation
                double current_gain = current_meter / current_cs;
                //double current_gain = current_meter / current_cs;
                int current_gain_int = (int)(current_gain * 0x400000);
                msg = string.Format("Current Gain = {0:F8} (0x{1:X})", current_gain, current_gain_int);
                updateOutputStatus(msg);

                double voltage_gain = voltage_meter / voltage_cs;
                int voltage_gain_int = (int)(voltage_gain * 0x400000);
                msg = string.Format("Voltage Gain = {0:F8} (0x{1:X})", voltage_gain, voltage_gain_int);
                updateOutputStatus(msg);

                msg = patch(board_type, voltage_gain_int, current_gain_int);
                Thread.Sleep(2000);
                datain = tc.Read();
                updateOutputStatus(datain);

                tc.WriteLine(string.Format("cu {0}_pinfo", cmd_prefix));
                Thread.Sleep(500);
                datain = tc.Read();
                updateOutputStatus(datain);

                i = 0;
                while (true)
                {
                    tc.WriteLine(string.Format("cu {0}_pload", cmd_prefix));
                    Thread.Sleep(500);
                    datain = tc.Read();
                    Debug.WriteLine(datain);

                    if (datain.Length > 0)
                    {
                        Match on_off_match = Regex.Match(datain, "Changing OnOff .*");
                        if (on_off_match.Success)
                        {
                            msg = on_off_match.Value;
                            updateOutputStatus(msg);
                        }

                        Match match = Regex.Match(datain, rawCurrentPattern);
                        if (match.Groups.Count > 1)
                        {
                            string current_hexstr = match.Groups[1].Value;
                            int current_int = Convert.ToInt32(current_hexstr, 16);
                            current_cs = RegHex_ToDouble(current_int);
                            current_cs = current_cs * current_reference / 0.6;

                            voltage_cs = 0.0;
                            match = Regex.Match(datain, rawVoltagePattern);
                            if (match.Groups.Count > 1)
                            {
                                string voltage_hexstr = match.Groups[1].Value;
                                int volatge_int = Convert.ToInt32(voltage_hexstr, 16);
                                voltage_cs = RegHex_ToDouble(volatge_int);
                                voltage_cs = voltage_cs * voltage_reference / 0.6;
                            }

                            if (voltage_cs > voltage_low_limit)
                            {
                                i++;
                                msg = string.Format("Cirrus I = {0:F8}, V = {1:F8}, P = {2:F8}", current_cs, voltage_cs, current_cs * voltage_cs);
                                updateOutputStatus(msg);
                            }
                            if (i > 1)
                                break;
                        }
                    }

                    Thread.Sleep(1000);
                }
                tc.Close();
            }
Ejemplo n.º 28
0
        /// <summary>
        /// Sends a pload command and returns the current and voltage values
        /// </summary>
        /// <param name="telnet_connection">Already opened Telnet connection to the Ember</param>
        /// <param name="board_type">What board are we using</param>
        /// <returns>Current/Voltage structure values</returns>
        public static Current_Voltage Parse_Pload_Registers(
            TelnetConnection telnet_connection, string cmd_prefix, double voltage_ac_reference, double current_ac_reference)
        {
            string rawCurrentPattern = "Raw IRMS: ([0-9,A-F]{8})";
            string rawVoltagePattern = "Raw VRMS: ([0-9,A-F]{8})";
            double current_cs = 0.0;
            double voltage_cs = 0.0;

            TCLI.Wait_For_Prompt(telnet_connection);

            string cmd = string.Format("cu {0}_pload", cmd_prefix);
            telnet_connection.WriteLine(cmd);
            Thread.Sleep(500);

            string datain = telnet_connection.Read();
            Trace.WriteLine(datain);

            TCLI.Wait_For_Prompt(telnet_connection);

            string msg;

            if (datain != null && datain.Length > 0)
            {
                Match on_off_match = Regex.Match(datain, "Changing OnOff .*");
                if (on_off_match.Success)
                {
                    msg = on_off_match.Value;
                }

                Match match = Regex.Match(datain, rawCurrentPattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for current.  Output was:{0}", datain);
                    throw new Exception(msg);
                }

                string current_hexstr = match.Groups[1].Value;
                int current_int = Convert.ToInt32(current_hexstr, 16);
                current_cs = RegHex_ToDouble(current_int);
                current_cs = current_cs * current_ac_reference / 0.6;

                voltage_cs = 0.0;
                match = Regex.Match(datain, rawVoltagePattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for voltage.  Output was:{0}", datain);
                    throw new Exception(msg);
                }

                string voltage_hexstr = match.Groups[1].Value;
                int volatge_int = Convert.ToInt32(voltage_hexstr, 16);
                voltage_cs = RegHex_ToDouble(volatge_int);
                voltage_cs = voltage_cs * voltage_ac_reference / 0.6;

            }
            else
            {
                msg = string.Format("No data received after \"{0}\" command", cmd);
                throw new Exception(msg);
            }

            Current_Voltage current_voltage = new Current_Voltage(i: current_cs, v: voltage_cs);
            return current_voltage;
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Inputs a blank line and waits for the prompt
        /// </summary>
        /// <param name="telnet_connection"></param>
        /// <param name="prompt">The expected prompt.  Default '>'</param>
        /// <param name="sendEnter">Whether to send CR before waiting</param>
        /// <param name="retry_count">The max number of times that we read the session looking for the prompt</param>
        public static void Wait_For_Prompt(TelnetConnection telnet_connection, string prompt = ">", bool sendEnter = true, int retry_count = 5)
        {
            telnet_connection.Read();
            int n = 0;
            string data = "";
            while (n < retry_count)
            {
                if (sendEnter)
                {
                    telnet_connection.WriteLine("");
                    Thread.Sleep(250);
                }

                data = telnet_connection.Read();
                if (data.Contains(prompt))
                {
                    break;
                }
                else if (telnet_connection.Port != TCLI.ISA3_ADMIN_PORT_NUM)
                {
                    try
                    {
                        ResetISAANode(telnet_connection.HostName);
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                    }
                }

                n++;
            }

            if (n >= retry_count)
            {
                throw new Exception("Telnet session prompt not detected");
            }
        }
Ejemplo n.º 30
0
 public void FixRedirect()
 {
     using (var telnet = new TelnetConnection(Address, Port))
     {
         NshLogin(telnet);
         string output = telnet.Read();
         Logger.Log("Sending set mgmt.lan-redirect.enable off");
         telnet.WriteLine("set mgmt.lan-redirect.enable off");
         SaveChanges(telnet);
     }
 }
Ejemplo n.º 31
0
        public static Match Wait_For_Match(TelnetConnection telnet_connection, string command, string pattern, int retry_count = 3, int delay_ms = 100)
        {
            Wait_For_Prompt(telnet_connection);
            int n = 0;
            string data = "";

            Match match;

            while (n < retry_count)
            {
                telnet_connection.WriteLine(command);

                Thread.Sleep(delay_ms);
                data = telnet_connection.Read();
                if (data != null)
                {
                    match = Regex.Match(data, pattern);

                    if (match.Success)
                    {
                        return match;
                    }
                }

                n++;
            }

            string msg = string.Format("Telnet session data not match found after command \"{0}\".  Expected: \"{1}\". Received: \"{2}\"",
                command, pattern, data);
            throw new Exception(msg);
        }
Ejemplo n.º 32
0
 /// <summary>
 /// Closes the board relay using custom command
 /// </summary>
 /// <param name="board_type"></param>
 /// <param name="telnet_connection"></param>
 void set_board_relay(BoardTypes board_type, TelnetConnection telnet_connection, bool value)
 {
     switch (board_type)
     {
         // These boards have relays
         case BoardTypes.Hooktooth:
         case BoardTypes.Hornshark:
         case BoardTypes.Humpback:
         case BoardTypes.Zebrashark:
             updateRunStatus(string.Format("Set UUT Relay {0}", value.ToString()));
             if (value)
                 telnet_connection.WriteLine("write 1 6 0 1 0x10 {01}");
             else
                 telnet_connection.WriteLine("write 1 6 0 1 0x10 {00}");
             break;
     }
 }
Ejemplo n.º 33
0
 public void Reboot()
 {
     using (var telnet = new TelnetConnection(Address, Port))
     {
         NshLogin(telnet);
         string output = telnet.Read();
         Logger.Log("Sending reboot");
         telnet.WriteLine("reboot");
         telnet.WriteLine("");
         try
         {
             telnet.Read(); //must read in order for command to actually be executed
         }
         catch
         {
             //just in case modem decides to reboot early
         }
     }
 }
Ejemplo n.º 34
0
 void NshLogin(TelnetConnection telnet)
 {
     Logger.Log("Logging in as admin..");
     string output=telnet.Login("admin", Password, 2000);
     if (output.Contains("Login incorrect"))
     {
         Logger.Log("Got incorrect login message! Ensure that you typed the correct access code!");
         throw new ApplicationException("Can not reach nsh shell");
     }
     output = telnet.Read();
     telnet.WriteLine(""); //because apparently it doesn't always print the prompt otherwise
     output = telnet.Read(3000);
     Assert(output.Contains("Axis"), "nsh shell does not appear to be working... or something");
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Gets the MFG string
        /// </summary>
        /// <param name="telnet_connection"></param>
        /// <returns></returns>
        public static string Get_MFGString(TelnetConnection telnet_connection)
        {
            string mfgstr = null;
            string datain = "";
            string pattern = "MFG String: (\\S+)";

            TCLI.Wait_For_Prompt(telnet_connection);
            telnet_connection.WriteLine("info");
            Thread.Sleep(500);
            datain = telnet_connection.Read();

            if (datain != null && datain.Length > 0)
            {
                Match match = Regex.Match(datain, pattern);
                if (match.Groups.Count != 2)
                {
                    string msg = string.Format("Unable to parse info MFG String.  Output was:{0}", datain);
                    throw new Exception(msg);
                }
                mfgstr = match.Groups[1].Value;
            }
            else
            {
                string msg = string.Format("No data received after \"Info\" command");
                throw new Exception(msg);
            }

            return mfgstr;
        }
Ejemplo n.º 36
-1
 public void DisableUpnp()
 {
     using (var telnet = new TelnetConnection(Address, Port))
     {
         NshLogin(telnet);
         string output = telnet.Read();
         telnet.WriteLine("set mgmt.upnp.enable off");
         SaveChanges(telnet);
     }
 }