static void gw_oam_pty_sub_thread_entry(gw_uint32 *para) { int length = 0; gw_uint8 *buf = malloc(PTY_BUF_SIZE); gw_uint8 *buf_read = NULL; if(buf == NULL) { gw_printf("in %s, malloc failed\n", __func__); return; } while(1) { memset(buf, 0, PTY_BUF_SIZE); buf[0] = CON_CTL_CODE_DATA; buf_read = &buf[1]; length = read_from_console(buf_read, PTY_BUF_SIZE -2); //buf 的第一位用于存放报文类型,最后一位用于存放结束符'\0' if(length > 0) { buf_read[length] = '\0'; gw_comm_onu_msg_send(CLI_PTY_TRANSMIT, gmCliPtyCtrl.lSerNo++, buf, length+2, gmCliPtyCtrl.bSessionId); } else { //do nothing } //延时 gw_thread_delay(CONSOLE_READ_INTERVAL_TIME); } }
void shell(void) { msg_t msg_struct; msg_t *msg = &msg_struct; while (1) { print_str("deviate> "); g_executed = SHELL_NOTHING; read_from_console(msg); if (msg_type_is_console_input(msg)) { strcpy(g_line, msg_data_get_string(msg)); run(g_line); if (g_executed == SHELL_SPAWN) { uint32_t child_pid = 0; process_state_t state; read_message_by_type(msg, MSG_TYPE_SUPERVISOR_NOTICE_ID, 0); if (msg_type_is(msg, MSG_TYPE_SUPERVISOR_NOTICE_ID)) { child_pid = msg_data_get_integer(msg); } read_message_by_type(msg, MSG_TYPE_SUPERVISOR_NOTICE_STATE, 0); if (msg_type_is(msg, MSG_TYPE_SUPERVISOR_NOTICE_STATE)) { state = msg_data_get_integer(msg); } if (child_pid && (state == PROCESS_STATE_TERMINATED)) { print_str("Process "); print_int(child_pid); print_strln(" quit unexpectedly!"); } } } else { print_strln("Shell: could not read input!"); } } }