$write = array(); $except = array(); $result = stream_select($read, $write, $except, 0); if ($result === false) { throw new Exception('stream_select failed'); } if ($result === 0) { return false; } $data = stream_get_line($fd, 1); return true; } $flag = 1; while (!feof($sensors)) { $x = ""; if (non_block_read(STDIN, $x) && $x == 'q' || trim(file_get_contents('/tmp/controller.run')) != '1') { //stop(); $exec = '@q#'; $serial->deviceOpen(); // sleep(0.5); $serial->sendMessage($exec); // sleep(0.1); $serial->deviceClose(); // sleep(1); //sleep(1); break; } // Quit on F10 //sleep(0.01); refreshDIYData($sensors); carscript();
if ($num_changed_sockets > 0) { foreach ($read as $sock) { if ($r = socket_read($sock, 1, PHP_NORMAL_READ)) { $r = str_ireplace("\n", '', $r); $r = str_ireplace("\r", '', $r); $read_buffer .= $r; $start = stripos($read_buffer, '__JSON__START__'); $end = stripos($read_buffer, '__JSON__END__'); if ($start !== false && $end !== false) { print "\rnoobhub> " . substr($read_buffer, $start + 15, $end - ($start + 15)) . " \n"; $read_buffer = substr($read_buffer, 0, $start) . substr($read_buffer, $end + 13); } } } } if (non_block_read(STDIN, $x)) { $command .= $x; if (stripos($command, "\n") !== false || stripos($command, "\r") !== false) { $command = str_ireplace("\n", '', $command); socket_write($socket, $msg = "__JSON__START__" . json_encode($command) . "__JSON__END__", strlen($msg)); $command = ''; } } } function non_block_read($fd, &$data) { $read = array($fd); $write = array(); $except = array(); $result = stream_select($read, $write, $except, 0); if ($result === false) {