diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-05-26 12:42:34 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-05-26 12:42:34 +0200 |
commit | f353e78916a57fe21084fe34fd80c13ae4844d32 (patch) | |
tree | 392a8d6bfccad7beb70e253ad7c1786934d5657b /robot | |
parent | 54b69efe150e1a102faafb4e214159c92abbb841 (diff) |
implement info command
Diffstat (limited to 'robot')
-rw-r--r-- | robot/hypervisor.c | 17 | ||||
-rw-r--r-- | robot/hypervisor.h | 6 | ||||
-rw-r--r-- | robot/makefile | 2 | ||||
-rw-r--r-- | robot/sercomm.c | 26 | ||||
-rw-r--r-- | robot/setup.c | 3 |
5 files changed, 50 insertions, 4 deletions
diff --git a/robot/hypervisor.c b/robot/hypervisor.c index c4e7aba..0baa406 100644 --- a/robot/hypervisor.c +++ b/robot/hypervisor.c @@ -1,11 +1,17 @@ #include "hypervisor.h" +#include "../shared/util.h" #include "errcatch.h" #include "io.h" #include "modes.h" #include "orangutan_shim.h" #include "sercomm.h" -uint64_t g_w2_hypervisor_cycles = 0; +uint64_t g_w2_hypervisor_cycles = 0; +uint64_t g_w2_hypervisor_uptime_ms = 0; +unsigned long g_w2_hypervisor_ema_sercomm_ms = 0; +unsigned long g_w2_hypervisor_ema_errcatch_ms = 0; +unsigned long g_w2_hypervisor_ema_io_ms = 0; +unsigned long g_w2_hypervisor_ema_mode_ms = 0; void w2_hypervisor_main() { #ifdef W2_SIM @@ -13,6 +19,7 @@ void w2_hypervisor_main() { if (DBG_ENABLE_CYCLEINFO) siminfo("cycle start\n"); #endif + g_w2_hypervisor_uptime_ms += get_ms(); time_reset(); w2_sercomm_main(); @@ -24,6 +31,14 @@ void w2_hypervisor_main() { w2_modes_main(); unsigned long mode_time = get_ms() - io_time; + // calculate exponential moving averages + g_w2_hypervisor_ema_sercomm_ms = + w2_util_exp_mov_avg(g_w2_hypervisor_ema_sercomm_ms, sercomm_time); + g_w2_hypervisor_ema_errcatch_ms = + w2_util_exp_mov_avg(g_w2_hypervisor_ema_errcatch_ms, errcatch_time); + g_w2_hypervisor_ema_io_ms = w2_util_exp_mov_avg(g_w2_hypervisor_ema_io_ms, io_time); + g_w2_hypervisor_ema_mode_ms = w2_util_exp_mov_avg(g_w2_hypervisor_ema_mode_ms, mode_time); + if (mode_time > W2_MAX_MODULE_CYCLE_MS) w2_errcatch_throw(W2_E_WARN_CYCLE_EXPIRED); #ifdef W2_SIM diff --git a/robot/hypervisor.h b/robot/hypervisor.h index 35fa64c..5008c8f 100644 --- a/robot/hypervisor.h +++ b/robot/hypervisor.h @@ -3,6 +3,12 @@ #include <stdint.h> extern uint64_t g_w2_hypervisor_cycles; +extern uint64_t g_w2_hypervisor_uptime_ms; + +extern unsigned long g_w2_hypervisor_ema_sercomm_ms; +extern unsigned long g_w2_hypervisor_ema_errcatch_ms; +extern unsigned long g_w2_hypervisor_ema_io_ms; +extern unsigned long g_w2_hypervisor_ema_mode_ms; /** * backbone of all other modules diff --git a/robot/makefile b/robot/makefile index 6de886c..a6e96ee 100644 --- a/robot/makefile +++ b/robot/makefile @@ -32,7 +32,7 @@ OBJ2HEX=$(PREFIX)objcopy # debug build info string BUILD_STR=$(shell git update-index -q --refresh; git describe --tags --dirty='*' --broken='x' | cut -c1-20) -CFLAGS += -DW2_BUILD_STR="$(BUILD_STR)" +CFLAGS += -DW2_BUILD_STR=\"$(BUILD_STR)\" clean:: rm -f *.o out.hex a.out diff --git a/robot/sercomm.c b/robot/sercomm.c index 293e3c6..a3ccdb0 100644 --- a/robot/sercomm.c +++ b/robot/sercomm.c @@ -3,6 +3,7 @@ #include "../shared/bin.h" #include "../shared/serial_parse.h" +#include "hypervisor.h" #include "orangutan_shim.h" #include "sercomm.h" @@ -53,7 +54,7 @@ void w2_cmd_ping_rx(w2_s_bin *data) { size_t return_size = sizeof(w2_s_cmd_ping_tx); w2_s_cmd_ping_tx *return_message = malloc(return_size); - return_message->opcode = (message->opcode & W2_CMD_DIRECTION_MASK) | W2_CMDDIR_TX; + return_message->opcode = W2_CMD_PING | W2_CMDDIR_TX; return_message->id = message->id; w2_s_bin *return_message_bin = w2_bin_s_alloc(return_size, (uint8_t *)return_message); @@ -81,7 +82,28 @@ void w2_cmd_mcfg_rx(w2_s_bin *data) { return; } void w2_cmd_sens_rx(w2_s_bin *data) { return; } -void w2_cmd_info_rx(w2_s_bin *data) { return; } +void w2_cmd_info_rx(w2_s_bin *data) { + w2_s_cmd_info_rx *message = malloc(w2_cmd_sizeof(data->data, data->bytes)); + memcpy(message, data->data, data->bytes); + + size_t return_size = sizeof(w2_s_cmd_info_tx); + w2_s_cmd_info_tx *return_message = malloc(return_size); + return_message->opcode = W2_CMD_INFO | W2_CMDDIR_TX; + strncpy((char *)return_message->build_str, W2_BUILD_STR, sizeof(return_message->build_str)); + return_message->errcatch_ms = (uint8_t)g_w2_hypervisor_ema_errcatch_ms; + return_message->io_ms = (uint8_t)g_w2_hypervisor_ema_io_ms; + return_message->sercomm_ms = (uint8_t)g_w2_hypervisor_ema_sercomm_ms; + return_message->mode_ms = (uint8_t)g_w2_hypervisor_ema_mode_ms; + return_message->uptime_s = w2_bin_hton32((uint32_t)(g_w2_hypervisor_uptime_ms / 1e3)); + + w2_s_bin *return_message_bin = w2_bin_s_alloc(return_size, (uint8_t *)return_message); + + w2_sercomm_append_msg(return_message_bin); + + free(message); + free(return_message); + free(return_message_bin); +} void w2_cmd_disp_rx(w2_s_bin *data) { return; } diff --git a/robot/setup.c b/robot/setup.c index f8468bf..d075c41 100644 --- a/robot/setup.c +++ b/robot/setup.c @@ -29,6 +29,9 @@ void w2_setup_main() { serial_set_baud_rate(W2_SERIAL_BAUD); serial_receive_ring(g_w2_serial_buffer, W2_SERIAL_READ_BUFFER_SIZE); + // reset timer + time_reset(); + // indicate startup done play("L50 c>c"); } |