diff --git a/common/utils/T/tracer/enb.c b/common/utils/T/tracer/enb.c index a120ba471efa9117f6970e27407e05261a26819c..7d835604fe6514e15d25249ec7ebe3aafe4191d4 100644 --- a/common/utils/T/tracer/enb.c +++ b/common/utils/T/tracer/enb.c @@ -132,7 +132,7 @@ static void enb_main_gui(enb_gui *e, gui *g, event_handler *h, void *database) */ framelog_set_skip(input_signal_log, 10); input_signal_view = new_view_xy(7680*10, 10, - g, input_signal_plot, new_color(g, "#0c0c72")); + g, input_signal_plot, new_color(g, "#0c0c72"), XY_LOOP_MODE); logger_add_view(input_signal_log, input_signal_view); /* downlink/uplink UE DCIs */ diff --git a/common/utils/T/tracer/view/view.h b/common/utils/T/tracer/view/view.h index cbc5e21b73d95fb3b15524977663a6054846fc5f..2173c842ce956929945ef1e38662f64e90e0dcc2 100644 --- a/common/utils/T/tracer/view/view.h +++ b/common/utils/T/tracer/view/view.h @@ -11,10 +11,12 @@ typedef struct view { void (*set)(struct view *this, char *name, ...); } view; +enum xy_mode { XY_LOOP_MODE, XY_FORCED_MODE }; + view *new_view_stdout(void); view *new_view_textlist(int maxsize, float refresh_rate, gui *g, widget *w); view *new_view_xy(int length, float refresh_rate, gui *g, widget *w, - int color); + int color, enum xy_mode mode); view *new_view_tti(float refresh_rate, gui *g, widget *w, int color); view *new_view_time(int number_of_seconds, float refresh_rate, diff --git a/common/utils/T/tracer/view/xy.c b/common/utils/T/tracer/view/xy.c index 1407a16a0e44614c8e86b05569712d738439cfc2..96a44cf5129e41f044cdbf559df32709fb5a8ff2 100644 --- a/common/utils/T/tracer/view/xy.c +++ b/common/utils/T/tracer/view/xy.c @@ -14,6 +14,7 @@ struct xy { float refresh_rate; pthread_mutex_t lock; int length; + int max_length; /* used in XY_FORCED_MODE */ float *x; float *y; int insert_point; @@ -39,7 +40,7 @@ static void clear(view *this) /* TODO */ } -static void append(view *_this, float *x, float *y, int length) +static void append_loop(view *_this, float *x, float *y, int length) { struct xy *this = (struct xy *)_this; int i; @@ -61,6 +62,25 @@ static void append(view *_this, float *x, float *y, int length) if (pthread_mutex_unlock(&this->lock)) abort(); } +static void append_forced(view *_this, float *x, float *y, int length) +{ + struct xy *this = (struct xy *)_this; + + if (length > this->max_length) { + printf("%s:%d:%s: bad length (%d), max allowed is %d\n", + __FILE__, __LINE__, __FUNCTION__, length, this->max_length); + abort(); + } + + if (pthread_mutex_lock(&this->lock)) abort(); + + memcpy(this->x, x, length * sizeof(float)); + memcpy(this->y, y, length * sizeof(float)); + this->length = length; + + if (pthread_mutex_unlock(&this->lock)) abort(); +} + static void set(view *_this, char *name, ...) { struct xy *this = (struct xy *)_this; @@ -89,24 +109,35 @@ static void set(view *_this, char *name, ...) } view *new_view_xy(int length, float refresh_rate, gui *g, widget *w, - int color) + int color, enum xy_mode mode) { struct xy *ret = calloc(1, sizeof(struct xy)); if (ret == NULL) abort(); ret->common.clear = clear; - ret->common.append = (void (*)(view *, ...))append; - ret->common.set = set; + + switch (mode) { + case XY_LOOP_MODE: + ret->common.append = (void (*)(view *, ...))append_loop; + ret->common.set = set; + ret->length = length; + ret->insert_point = 0; + break; + case XY_FORCED_MODE: + ret->common.append = (void (*)(view *, ...))append_forced; + ret->common.set = NULL; + ret->length = 0; + ret->max_length = length; + break; + } ret->refresh_rate = refresh_rate; ret->g = g; ret->w = w; ret->plot = xy_plot_new_plot(g, w, color); - ret->length = length; ret->x = calloc(length, sizeof(float)); if (ret->x == NULL) abort(); ret->y = calloc(length, sizeof(float)); if (ret->y == NULL) abort(); - ret->insert_point = 0; if (pthread_mutex_init(&ret->lock, NULL)) abort();