diff --git a/src/conf/buffer.c b/src/conf/buffer.c index 187f8509..c266b008 100644 --- a/src/conf/buffer.c +++ b/src/conf/buffer.c @@ -40,6 +40,14 @@ uint16_t to_float16(float x) { return (b&0x80000000)>>16 | (e>112)*((((e-112)<<10)&0x7C00)|m>>13) | ((e<113)&(e>101))*((((0x007FF000+m)>>(125-e))+1)>>1) | (e>143)*0x7FFF; } +float from_float16(uint16_t x) { + const float sign = x & 0x8000u ? -1.0f : 1.0f; + const uint16_t exponent = (x >> 10) & 0x1fu; + const uint16_t mantissa = x & 0x03ffu; + return sign * (exponent ? ldexpf(1024.0f + mantissa, exponent - 25) + : ldexpf(mantissa, -24)); +} + // clang-format on #pragma GCC diagnostic pop diff --git a/src/conf/buffer.h b/src/conf/buffer.h index f8ef8108..400300ce 100644 --- a/src/conf/buffer.h +++ b/src/conf/buffer.h @@ -21,6 +21,7 @@ #include uint16_t to_float16(float x); +float from_float16(uint16_t x); void buffer_append_int16(uint8_t *buffer, int16_t number, int32_t *index); void buffer_append_uint16(uint8_t *buffer, uint16_t number, int32_t *index); diff --git a/src/data_recorder.c b/src/data_recorder.c index 62cde126..451584a8 100644 --- a/src/data_recorder.c +++ b/src/data_recorder.c @@ -131,12 +131,13 @@ void data_recorder_sample(DataRecord *dr, const Data *d, time_t time) { } static void send_point_vt_experiment(const void *item, void *data) { - unused(data); + const time_t start_time = *(const time_t *) data; - Sample *sample = (Sample *) item; + const Sample *sample = (const Sample *) item; + const float time = (sample->time - start_time) * (1.0f / SYSTEM_TICK_RATE_HZ); for (uint8_t i = 0; i < ITEMS_COUNT_REC(RT_DATA_ALL_ITEMS); ++i) { VESC_IF->plot_set_graph(i); - VESC_IF->plot_send_points(sample->time, sample->values[i]); + VESC_IF->plot_send_points(time, from_float16(sample->values[i])); } } @@ -151,7 +152,9 @@ void data_recorder_send_experiment_plot(DataRecord *dr) { VISIT_REC(RT_DATA_ALL_ITEMS, ADD_GRAPH); #undef ADD_GRAPH - circular_buffer_iterate(&dr->buffer, &send_point_vt_experiment, 0); + Sample first_sample = {0}; + circular_buffer_get(&dr->buffer, 0, &first_sample); + circular_buffer_iterate(&dr->buffer, &send_point_vt_experiment, &first_sample.time); } typedef enum {