int do_pipe() { int n; char buf[1024]; n = read(pipe_out, buf, 1024); write_tty(buf, n); return 0; }
/** * write command * @return answer or NULL if error occured (or no answer) */ static char *write_cmd(const char *cmd){ DBG("Write %s", cmd); if(write_tty(cmd, strlen(cmd))) return NULL; double t0 = dtime(); static char *ans; while(dtime() - t0 < T_POLLING_TMOUT){ // read answer if((ans = read_string())){ // parse new data DBG("got answer: %s", ans); return ans; } } return NULL; }
int send_command(char *cmd){ int L = strlen(cmd); size_t R = 0; char ans[256]; write_tty(cmd, L); R = read_ctrl_command(ans, 255); // DBG("readed: %s (cmd: %s, R = %zd, L = %d)\n", ans, cmd, R, L); if(!R || (strncmp(ans, cmd, L) != 0)){ fprintf(stderr, "Error: controller doesn't respond (answer: %s)\n", ans); return 0; } R = read_ctrl_command(ans, 255); // DBG("readed: %s\n", ans); if(!R){ // controller is running or error fprintf(stderr, "Controller doesn't answer!\n"); return 0; } return parse_ctrlr_ans(ans); }