diff --git a/lib/grading/rpc.c b/lib/grading/rpc.c index 2890653..5857677 100644 --- a/lib/grading/rpc.c +++ b/lib/grading/rpc.c @@ -18,12 +18,12 @@ void grading_rpc_handler_string(const char* string) void grading_rpc_handler_serial_getchar(void) { - DEBUG_PRINTF("grading_rpc_handler_serial_getchar()\n"); + // DEBUG_PRINTF("grading_rpc_handler_serial_getchar()\n"); } void grading_rpc_handler_serial_putchar(char c) { - DEBUG_PRINTF("grading_rpc_handler_serial_putchar(0x%"PRIx8")\n", c); + // DEBUG_PRINTF("grading_rpc_handler_serial_putchar(0x%"PRIx8")\n", c); } void grading_rpc_handler_ram_cap(size_t bytes, size_t alignment) diff --git a/usr/hello/hello.c b/usr/hello/hello.c index 2801872..f17d1d3 100644 --- a/usr/hello/hello.c +++ b/usr/hello/hello.c @@ -185,14 +185,18 @@ int main(int argc, char *argv[]) } if (argc > 1 && !strncmp(argv[1], HELLO_CMD_IO, sizeof(HELLO_CMD_IO))) { - int testInteger; - printf("Hi! Please enter an integer: "); - scanf("%d", &testInteger); - printf("number = %d",testInteger); - char name_input[20]; - printf("Please enter your name: "); - scanf("%s", name_input); - printf("why hello there, %s", name_input); + char input[256]; + printf("Hi! Please enter an input: \n\r"); + fflush(stdout); + input[0] = fgetc(stdin); + fflush(stdin); + printf("input = %s\n\r", input); + printf("Please enter your name: \n\r"); + fflush(stdout); + input[1] = fgetc(stdin); + fflush(stdin); + printf("why hello there, %s\n\r", input); + fflush(stdout); } return EXIT_SUCCESS; diff --git a/usr/shelly/Hakefile b/usr/shelly/Hakefile index 773fa4b..2cf94c6 100644 --- a/usr/shelly/Hakefile +++ b/usr/shelly/Hakefile @@ -14,6 +14,6 @@ { target = "shelly", cFiles = [ "shelly.c" ], - addLibraries = [ "lpuart", "gic_dist", "fs" ] + addLibraries = [ "lpuart", "gic_dist", "fs", "grading" ] } ] diff --git a/usr/shelly/shelly.c b/usr/shelly/shelly.c index 66fdba3..62531fc 100644 --- a/usr/shelly/shelly.c +++ b/usr/shelly/shelly.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "shelly.h" @@ -91,18 +92,6 @@ static void handle_lpuart_interrupt(void * arg) { if (err_is_fail(err)) USER_PANIC_ERR(err, "while trying to put character"); } - if (global_state->current_getchar_request != NULL) { - // a client is waiting for a getchar request, forward it. - if (is_newline(input_char)) { - input_char = '\0'; - } - send_response(global_state->current_getchar_request, SYS_ERR_OK, input_char, 0, NULL); - global_state->current_getchar_request = NULL; - continue; - } - - assert(global_state->current_getchar_request == NULL); - //handle as shell input if (is_newline(input_char)) { global_state->buf[global_state->buffer_i] = '\0'; global_state->buffer_i += 1; @@ -110,13 +99,23 @@ static void handle_lpuart_interrupt(void * arg) { err = shelly_write_str("\n\r"); if (err_is_fail(err)) USER_PANIC_ERR(err, "while trying to write string"); - err = handle_shelly_cmd(global_state->buf, global_state->buffer_i); - if (err_is_fail(err)) shelly_write_str("failed to run command :(\n\r"); + if (global_state->current_getchar_request != NULL) { + //send to client + for (int i = 0; i < global_state->buffer_i; ++i) { + send_response(global_state->current_getchar_request, SYS_ERR_OK, global_state->buf[i], 0, NULL); + } + global_state->current_getchar_request = NULL; + shelly_reset_buffer(); + } else { + //treat as command + err = handle_shelly_cmd(global_state->buf, global_state->buffer_i); + if (err_is_fail(err)) shelly_write_str("failed to run command :(\n\r"); - shelly_reset_buffer(); + shelly_reset_buffer(); - err = shelly_write_str("\n\ryou@windows me > "); - if (err_is_fail(err)) USER_PANIC_ERR(err, "while trying to write string"); + err = shelly_write_str("\n\ryou@windows me > "); + if (err_is_fail(err)) USER_PANIC_ERR(err, "while trying to write string"); + } } else { err = shelly_buffer_append(input_char); if (err_is_fail(err)) { @@ -179,8 +178,11 @@ static void handle_client_request(void *arg, size_t header_size, void *header_bu struct shelly_header * header = (struct shelly_header *) header_buf; if (header->type == SHELLY_MSG_GETCHAR) { + grading_rpc_handler_serial_getchar(); + shelly_reset_buffer(); global_state->current_getchar_request = local_state; } else if (header->type == SHELLY_MSG_PUTCHAR) { + grading_rpc_handler_serial_putchar(header->character); err = lpuart_putchar(global_state->uart_s, header->character); if (err_is_fail(err)) USER_PANIC_ERR(err, "while trying to put character"); if (is_newline(header->character)) {