private void sensor1type_SelectedIndexChanged(object sender, EventArgs e) { config.sensorType[0] = NXT_ROVER_CONTROL.sensorTypes[sensor1type.SelectedIndex]; //update NXT_ROVER_CONTROL.setSensors(); }
private void timer2_Tick(object sender, EventArgs e) { if (config.sensor_auto_on_off) { string temp, sql; TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)); double unixTime = ts.TotalSeconds; //send commands nxt_result[] cmd = new nxt_result[4]; temp = ""; if (sensor1type.SelectedIndex != -1) { cmd[0] = NXT_ROVER_CONTROL.command_translation("cmd sensor value 1"); temp += "Sensor 1: " + cmd[0].value + "\n"; } if (sensor2type.SelectedIndex != -1) { cmd[1] = NXT_ROVER_CONTROL.command_translation("cmd sensor value 2"); temp += "Sensor 2: " + cmd[1].value + "\n"; } if (sensor3type.SelectedIndex != -1) { cmd[2] = NXT_ROVER_CONTROL.command_translation("cmd sensor value 3"); temp += "Sensor 3: " + cmd[2].value + "\n"; } if (sensor4type.SelectedIndex != -1) { cmd[3] = NXT_ROVER_CONTROL.command_translation("cmd sensor value 4"); temp += "Sensor 4: " + cmd[3].value + "\n"; } //update database sql = "INSERT INTO `rover`.`sensors` (`ID`, `when`, `result`) VALUES (NULL, '" + unixTime.ToString().Replace(',', '.') + "', '" + temp + "');"; mysql.QueryCommand(sql); //show if (temp.Length < 5) { status.Text = "Please select type of sensor below."; } else { status.Text = temp; } } }
public static void check() { TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)); double unixTime = ts.TotalSeconds; mysql_results res = new mysql_results(); nxt_result result = new nxt_result(); //check mysql conntection if (mysql.connection.State == ConnectionState.Open || mysql.connection.State == ConnectionState.Connecting) { res = mysql.QueryCommand("SELECT `ID`,`message`,`when` FROM `log_current_session` WHERE `status`='' AND `when`< '" + unixTime.ToString().Replace(',', '.') + "' AND `when`> '" + (unixTime - 100).ToString().Replace(',', '.') + "' AND `type`='cmd' ORDER BY `when` ASC LIMIT 0,1"); if (res.result) { IrcBot.log += DateTime.Now + "checking(" + res.msg + ")..."; result = NXT_ROVER_CONTROL.command_translation(res.msg); if (result.result) { //true cmd.CommandText = "UPDATE `log_current_session` SET `status`='" + result.value + "', `when`='" + unixTime.ToString().Replace(',', '.') + "' WHERE `ID`=" + res.ID; cmd.CommandType = CommandType.Text; MySqlDataReader reader = cmd.ExecuteReader(); reader.Close(); IrcBot.log += "succed\n"; } else { //false cmd.CommandText = "UPDATE `log_current_session` SET `status`='" + result.value + "' WHERE `ID`=" + res.ID; cmd.CommandType = CommandType.Text; MySqlDataReader reader = cmd.ExecuteReader(); reader.Close(); IrcBot.log += "faild\n"; } } } else { //make connecion IrcBot.log += "Mysql connection faild"; mysql.connect(); } }
private void send_command_Click(object sender, EventArgs e) { command.Text = NXT_ROVER_CONTROL.command_translation(command.Text).value; }
public static void run_irc() { NetworkStream stream; TcpClient irc; string inputLine; StreamReader reader; try { irc = new TcpClient(SERVER, PORT); stream = irc.GetStream(); reader = new StreamReader(stream); writer = new StreamWriter(stream); // Start PingSender thread //PingSender ping = new PingSender (); //ping.Start(); inputLine = reader.ReadLine(); log += inputLine + "\n"; //MessageBox.Show(inputLine); ident(); IrcBot.log += "IRC chat ready\n"; nxt_result result = new nxt_result(); while (true) { while ((inputLine = reader.ReadLine()) != null) { //log += inputLine + "\n"; if (inputLine.Contains("PING")) { // inputLine.Split(' '); //MessageBox.Show(inputLine); //MessageBox.Show(inputLine.Substring(inputLine.IndexOf(" ") + 2)); //log += "send: " + "PONG " + inputLine.Substring(inputLine.IndexOf(" ") + 2) + "\n"; writer.WriteLine("PONG " + inputLine.Substring(inputLine.IndexOf(" ") + 2)); writer.Flush(); } if (inputLine.Contains("Register first.")) { ident(); } if (inputLine.Contains(CHANNEL + " :")) { //echo // :[email protected] PRIVMSG #control :hello mes_buffer = inputLine.Substring(inputLine.IndexOf(CHANNEL + " :") + CHANNEL.Length + 2); log += mes_buffer + "\n"; if (mes_buffer.StartsWith("cmd ")) { result = NXT_ROVER_CONTROL.command_translation(mes_buffer); if (result.result) { writer.WriteLine(":" + NICK + "! PRIVMSG " + CHANNEL + " :Result " + result.value); writer.Flush(); } else { writer.WriteLine(":" + NICK + "! PRIVMSG " + CHANNEL + " :Result faild"); writer.Flush(); } } else { writer.WriteLine(":" + NICK + "! PRIVMSG " + CHANNEL + " :Result false, Not a command"); writer.Flush(); } } } // Close all streams writer.Close(); reader.Close(); irc.Close(); } } catch (Exception e) { // Show the exception, sleep for a while and try to establish a new connection to irc server log += e.Message.ToString() + "\n"; timesleep *= 2; Thread.Sleep(timesleep); run_irc(); } }