1 #ifndef _TWR_DATA_STREAM_H
2 #define _TWR_DATA_STREAM_H
4 #include <twr_common.h>
12 #define TWR_DATA_STREAM_FLOAT_BUFFER(NAME, NUMBER_OF_SAMPLES) \
13 float NAME##_feed[NUMBER_OF_SAMPLES]; \
14 float NAME##_sort[NUMBER_OF_SAMPLES]; \
15 twr_data_stream_buffer_t NAME = { \
16 .feed = NAME##_feed, \
17 .sort = NAME##_sort, \
18 .number_of_samples = NUMBER_OF_SAMPLES, \
19 .type=TWR_DATA_STREAM_TYPE_FLOAT \
24 #define TWR_DATA_STREAM_INT_BUFFER(NAME, NUMBER_OF_SAMPLES) \
25 int NAME##_feed[NUMBER_OF_SAMPLES]; \
26 int NAME##_sort[NUMBER_OF_SAMPLES]; \
27 twr_data_stream_buffer_t NAME = { \
28 .feed = NAME##_feed, \
29 .sort = NAME##_sort, \
30 .number_of_samples = NUMBER_OF_SAMPLES, \
31 .type=TWR_DATA_STREAM_TYPE_INT \
36 #define TWR_DATA_STREAM_FLOAT_ARRAY(NAME, COUNT, NUMBER_OF_SAMPLES) \
37 static float NAME##_feed[(COUNT)][(NUMBER_OF_SAMPLES)]; \
38 static float NAME##_sort[(NUMBER_OF_SAMPLES)]; \
39 static twr_data_stream_buffer_t NAME##_buffer[(COUNT)]; \
40 static twr_data_stream_t NAME[(COUNT)];
44 #define TWR_DATA_STREAM_FLOAT_ARRAY_INIT(NAME, COUNT, MIN_NUMBER_OF_SAMPLES) \
45 for (size_t i = 0; i < (COUNT); i++) \
47 NAME##_buffer[i].feed = NAME##_feed[i]; \
48 NAME##_buffer[i].sort = NAME##_sort; \
49 NAME##_buffer[i].number_of_samples = (sizeof(NAME##_feed[i]) / sizeof(float)); \
50 NAME##_buffer[i].type=TWR_DATA_STREAM_TYPE_FLOAT; \
51 twr_data_stream_init(&NAME[i], (MIN_NUMBER_OF_SAMPLES), &NAME##_buffer[i]); \
58 TWR_DATA_STREAM_TYPE_FLOAT = 0,
59 TWR_DATA_STREAM_TYPE_INT = 1
69 int number_of_samples;
85 int _min_number_of_samples;
bool twr_data_stream_get_nth(twr_data_stream_t *self, int n, void *result)
Get nth value in data stream.
int twr_data_stream_get_number_of_samples(twr_data_stream_t *self)
Get buffer number_of_samples.
bool twr_data_stream_get_max(twr_data_stream_t *self, void *result)
Get max value.
struct twr_data_stream_t twr_data_stream_t
Data stream instance.
bool twr_data_stream_get_min(twr_data_stream_t *self, void *result)
Get min value.
twr_data_stream_type_t twr_data_stream_get_type(twr_data_stream_t *self)
Get type.
void twr_data_stream_reset(twr_data_stream_t *self)
Reset data stream.
bool twr_data_stream_get_first(twr_data_stream_t *self, void *result)
Get first value in data stream.
void twr_data_stream_init(twr_data_stream_t *self, int min_number_of_samples, twr_data_stream_buffer_t *buffer)
Initialize data stream instance.
int twr_data_stream_get_counter(twr_data_stream_t *self)
Get counter.
int twr_data_stream_get_length(twr_data_stream_t *self)
Get length.
twr_data_stream_type_t
Data stream type.
bool twr_data_stream_get_median(twr_data_stream_t *self, void *result)
Get median value of data stream.
bool twr_data_stream_get_average(twr_data_stream_t *self, void *result)
Get average value of data stream.
bool twr_data_stream_get_last(twr_data_stream_t *self, void *result)
Get last value in data stream.
void twr_data_stream_feed(twr_data_stream_t *self, void *data)
Feed data into stream instance.