diff --git a/errors/errno.fugu b/errors/errno.fugu index 005c0ad..db22626 100755 --- a/errors/errno.fugu +++ b/errors/errno.fugu @@ -1437,4 +1437,6 @@ errors sdhc SDHCD_ERR_ { errors shelly SHELLY_ERR_ { failure BUFFER_OVERFLOW "Buffer limits reached", failure WRITE "String write failed", + failure SPAWN_RPC "Spawn RPC failed", + failure PS_RPC "ps RPC failed", }; \ No newline at end of file diff --git a/lib/aos/ump_chan.c b/lib/aos/ump_chan.c index c9fd08f..c28ccd2 100644 --- a/lib/aos/ump_chan.c +++ b/lib/aos/ump_chan.c @@ -287,6 +287,7 @@ static void ump_worker_schedule(struct ump_worker_context *worker_context) { // this is supposed to be called single threaded and only upon event trigger // hence this cannot be a reregister and thus not fail assert(err_is_ok(err)); + thread_yield(); } /** diff --git a/usr/shelly/shelly.c b/usr/shelly/shelly.c index 3ad4d53..487fb3d 100644 --- a/usr/shelly/shelly.c +++ b/usr/shelly/shelly.c @@ -81,20 +81,20 @@ static void handle_lpuart_interrupt(void * arg) { global_state->buf[global_state->buffer_i] = '\0'; global_state->buffer_i += 1; - err = shelly_write_str("\n\xd"); + 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)) USER_PANIC_ERR(err, "while running command"); + if (err_is_fail(err)) DEBUG_ERR(err, "while running command"); shelly_reset_buffer(); - err = shelly_write_str("\n\xd>"); + err = shelly_write_str("\n\r>"); 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)) { - err = shelly_write_str("shelly buffer full! resetting...\n"); + err = shelly_write_str("shelly buffer full! resetting...\n\r"); if (err_is_fail(err)) USER_PANIC_ERR(err, "while trying to write string"); } } @@ -147,6 +147,8 @@ static void handle_client_request(void *arg, size_t header_size, void *header_bu assert(local_state); assert(global_state); + // SHELLY_DEBUG("[handle_client_request] client_id=%d\n", local_state->client_id); + struct shelly_header * header = (struct shelly_header *) header_buf; if (header->type == SHELLY_MSG_GETCHAR) { @@ -272,7 +274,7 @@ int main(int argc, char *argv[]) SHELLY_DEBUG("registered as shelly server\n"); - err = shelly_write_str("welcome to Shelly(TM)(TM)!\n"); + err = shelly_write_str("Welcome to Shelly(TM)(TM)!\n\r"); if (err_is_fail(err)) USER_PANIC_ERR(err, "while trying to write welcome message"); while (true) { diff --git a/usr/shelly/shelly_cmd.c b/usr/shelly/shelly_cmd.c index eb8e8e7..99d2f02 100644 --- a/usr/shelly/shelly_cmd.c +++ b/usr/shelly/shelly_cmd.c @@ -28,25 +28,32 @@ static errval_t shelly_cmd_run(char * line) { domainid_t pid; struct aos_rpc * rpc = aos_rpc_get_process_channel(); err = aos_rpc_process_spawn(rpc, line, 0, &pid); - if (err_is_fail(err)) USER_PANIC_ERR(err, "Failed to spawn process"); - SHELLY_DEBUG("[shelly_cmd_run] spawned process\n"); + if (err == SPAWN_ERR_FIND_MODULE) { + err = shelly_write_str("[run]:couldn't find module:\n\r"); + if (err_is_fail(err)) return err; + err = shelly_write_str(line); + if (err_is_fail(err)) return err; + err = shelly_write_str("\n\r"); + if (err_is_fail(err)) return err; + } else if (err_is_fail(err)) return err_push(err, SHELLY_ERR_SPAWN_RPC); - // // get process name - // char *name; - // err = aos_rpc_process_get_name(rpc, pid, &name); - // if (err_is_fail(err)) USER_PANIC_ERR(err, "Failed to get process name"); - // printf("Process Name: %s\n", name); + return SYS_ERR_OK; +} - // // get all PIDs - // domainid_t *pids; - // size_t pid_count; - // err = aos_rpc_process_get_all_pids(rpc, &pids, &pid_count); - // if (err_is_fail(err)) USER_PANIC_ERR(err, "Failed to get all PIDs"); - // printf("PIDs:\n"); - // for(size_t i = 0; i < pid_count; ++i) { - // printf(" %lu\n", pids[i]); - // } +static errval_t shelly_cmd_ps(char * line) { + errval_t err; + domainid_t *pids; + size_t pid_count; + struct aos_rpc * rpc = aos_rpc_get_process_channel(); + err = aos_rpc_process_get_all_pids(rpc, &pids, &pid_count); + if (err_is_fail(err)) return err_push(err, SHELLY_ERR_PS_RPC); + shelly_write_str("PIDs:\n\r"); + char buf[256]; + for(size_t i = 0; i < pid_count; ++i) { + snprintf(buf, 256, " %lu\n\r", pids[i]); + shelly_write_str(buf); + } return SYS_ERR_OK; } @@ -66,9 +73,11 @@ static errval_t handle_shelly_cmd(char* line, size_t len) { return shelly_cmd_echo(remaining_line); } else if (strcmp(cmd, "run") == 0) { return shelly_cmd_run(remaining_line); + } else if (strcmp(cmd, "ps") == 0) { + return shelly_cmd_ps(remaining_line); } else { char buf[256]; - snprintf(buf, 256, "unknown command %s\n", cmd); + snprintf(buf, 256, "unknown command \"%s\"\n\r", cmd); shelly_write_str(buf); }