public static void Main(string[] args) { ConsoleOutputLogger.verbose = true; ConsoleOutputLogger.writeLogfile = true; Console.WriteLine("ELV MAX! Debug Tool version 1 (C) Daniel Kirstenpfad 2012"); Console.WriteLine(); // not enough paramteres given, display help if (args.Length < 2) { Console.WriteLine("Syntax:"); Console.WriteLine(); Console.WriteLine("\tmaxdebug <hostname/ip> <port (e.g. 62910)> [commands]"); Console.WriteLine(); return; } ConsoleOutputLogger.LogToFile("--------------------------------------"); MAXMonitoringThread _Thread = new MAXMonitoringThread(args[0], Convert.ToInt32(args[1]), 5000); Thread MAXMonitoring = new Thread(new ThreadStart(_Thread.Run)); MAXMonitoring.Start(); while (_Thread.running) { Thread.Sleep(100); } }
public static void Main(string[] args) { House thisHouse = new House(); ConsoleOutputLogger.verbose = true; ConsoleOutputLogger.writeLogfile = true; Console.WriteLine("ELV MAX! Debug Tool version 1 (C) Daniel Kirstenpfad 2012"); Console.WriteLine(); // not enough paramteres given, display help if (args.Length < 2) { Console.WriteLine("Syntax:"); Console.WriteLine(); Console.WriteLine("\tmaxdebug <hostname/ip> <port (e.g. 62910)> [commands]"); Console.WriteLine(); return; } ConsoleOutputLogger.LogToFile("--------------------------------------"); // we obviously have enough paramteres, go on and try to connect TcpClient client = new TcpClient(); client.Connect(args[0], Convert.ToInt32(args[1])); NetworkStream stream = client.GetStream(); // the read buffer (chosen quite big) byte[] myReadBuffer = new byte[4096 * 8]; List <String> Messages = new List <string>(); // to build the complete message StringBuilder myCompleteMessage = new StringBuilder(); int numberOfBytesRead = 0; MAXEncodeDecode DecoderEncoder = new MAXEncodeDecode(); // Incoming message may be larger than the buffer size. do { myCompleteMessage = new StringBuilder(); stream.ReadTimeout = 1000; try { numberOfBytesRead = stream.Read(myReadBuffer, 0, myReadBuffer.Length); myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead)); Messages.Add(myCompleteMessage.ToString()); } catch (Exception) { //Console.WriteLine("Exception: "+e.Message); keepRunning = false; } }while(keepRunning); List <String> PreProcessedMessages = new List <string>(); // preprocess foreach (String _Message in Messages) { if (_Message.Remove(_Message.Length - 2).Contains("\r\n")) { String[] PMessages = _Message.Remove(_Message.Length - 2).Split(new char[1] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (String pmessage in PMessages) { PreProcessedMessages.Add(pmessage.Replace("\r", "") + "\r\n"); } } else { PreProcessedMessages.Add(_Message); } } // Analyze and Output Messages foreach (String _Message in PreProcessedMessages) { IMAXMessage Message = DecoderEncoder.ProcessMessage(_Message.ToString(), thisHouse); if (Message != null) { //ConsoleOutputLogger.WriteLine(_Message.ToString()); ConsoleOutputLogger.WriteLine(Message.ToString()); //ConsoleOutputLogger.WriteLine(""); } } // some writing if (args.Length > 2) { System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); byte[] args_data_buffer = enc.GetBytes(args[2] + "\r\n"); ConsoleOutputLogger.WriteLine("Sending Command: " + args[2]); stream.Write(args_data_buffer, 0, args_data_buffer.Length); keepRunning = true; Messages = new List <string>(); do { myCompleteMessage = new StringBuilder(); stream.ReadTimeout = 1000; try { numberOfBytesRead = stream.Read(myReadBuffer, 0, myReadBuffer.Length); myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead)); Messages.Add(myCompleteMessage.ToString()); } catch (Exception) { //jConsole.WriteLine("Exception: "+e.Message); keepRunning = false; } }while(keepRunning); PreProcessedMessages = new List <string>(); // preprocess foreach (String _Message in Messages) { if (_Message.Remove(_Message.Length - 2).Contains("\r\n")) { String[] PMessages = _Message.Remove(_Message.Length - 2).Split(new char[1] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (String pmessage in PMessages) { PreProcessedMessages.Add(pmessage.Replace("\r", "") + "\r\n"); } } else { PreProcessedMessages.Add(_Message); } } foreach (String _Message in PreProcessedMessages) { IMAXMessage Message = DecoderEncoder.ProcessMessage(_Message, thisHouse); if (Message != null) { ConsoleOutputLogger.WriteLine(Message.ToString()); ConsoleOutputLogger.LogToFile(""); } } } stream.Close(); client.Close(); }
private static void StartClient(String[] args) { ConsoleOutputLogger.verbose = true; ConsoleOutputLogger.writeLogfile = true; Console.WriteLine("ELV MAX! Debug Tool version 1 (C) Daniel Kirstenpfad 2012"); Console.WriteLine(); // not enough paramteres given, display help if (args.Length < 2) { Console.WriteLine("Syntax:"); Console.WriteLine(); Console.WriteLine("\tmaxdebug <hostname/ip> <port (e.g. 62910)> [commands]"); Console.WriteLine(); return; } ConsoleOutputLogger.LogToFile("--------------------------------------"); // Connect to a remote device. try { // Establish the remote endpoint for the socket. // The name of the // remote device is "host.contoso.com". IPHostEntry ipHostInfo = Dns.Resolve(args[0]); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint remoteEP = new IPEndPoint(ipAddress, Convert.ToInt32(args[1])); // Create a TCP/IP socket. Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Connect to the remote endpoint. client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client); connectDone.WaitOne(); client.ReceiveTimeout = 1000; // Receive the response from the remote device. Receive(client); receiveDone.WaitOne(); #region execute command from commandline if (args.Length > 2) { // Send test data to the remote device. Send(client, args[2] + "\r\n"); sendDone.WaitOne(); // Receive the response from the remote device. Receive(client); receiveDone.WaitOne(); } #endregion // Release the socket. client.Shutdown(SocketShutdown.Both); client.Close(); // take the response and split it into it's lines String[] SplittedResponse = response.Replace("\r", "").Split(new char[1] { '\n' }, StringSplitOptions.RemoveEmptyEntries); MAXEncodeDecode DecoderEncoder = new MAXEncodeDecode(); // Analyze and Output Messages foreach (String _Message in SplittedResponse) { IMAXMessage Message = DecoderEncoder.ProcessMessage(_Message.ToString()); if (Message != null) { ConsoleOutputLogger.WriteLine(Message.ToString()); ConsoleOutputLogger.WriteLine(""); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } }