Commit 0f0fa90d authored by Cedric Roux's avatar Cedric Roux

xy view to exist in two flavours

XY_LOOP_MODE: replace old points with new ones, using the maximum size
              of the view
XY_FORCE_MODE: append_forced sets those and only those points
               and we crash if we pass too much points
parent 8e458d9c
...@@ -132,7 +132,7 @@ static void enb_main_gui(enb_gui *e, gui *g, event_handler *h, void *database) ...@@ -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); framelog_set_skip(input_signal_log, 10);
input_signal_view = new_view_xy(7680*10, 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); logger_add_view(input_signal_log, input_signal_view);
/* downlink/uplink UE DCIs */ /* downlink/uplink UE DCIs */
......
...@@ -11,10 +11,12 @@ typedef struct view { ...@@ -11,10 +11,12 @@ typedef struct view {
void (*set)(struct view *this, char *name, ...); void (*set)(struct view *this, char *name, ...);
} view; } view;
enum xy_mode { XY_LOOP_MODE, XY_FORCED_MODE };
view *new_view_stdout(void); view *new_view_stdout(void);
view *new_view_textlist(int maxsize, float refresh_rate, gui *g, widget *w); 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, 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, view *new_view_tti(float refresh_rate, gui *g, widget *w,
int color); int color);
view *new_view_time(int number_of_seconds, float refresh_rate, view *new_view_time(int number_of_seconds, float refresh_rate,
......
...@@ -14,6 +14,7 @@ struct xy { ...@@ -14,6 +14,7 @@ struct xy {
float refresh_rate; float refresh_rate;
pthread_mutex_t lock; pthread_mutex_t lock;
int length; int length;
int max_length; /* used in XY_FORCED_MODE */
float *x; float *x;
float *y; float *y;
int insert_point; int insert_point;
...@@ -39,7 +40,7 @@ static void clear(view *this) ...@@ -39,7 +40,7 @@ static void clear(view *this)
/* TODO */ /* 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; struct xy *this = (struct xy *)_this;
int i; int i;
...@@ -61,6 +62,25 @@ static void append(view *_this, float *x, float *y, int length) ...@@ -61,6 +62,25 @@ static void append(view *_this, float *x, float *y, int length)
if (pthread_mutex_unlock(&this->lock)) abort(); 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, ...) static void set(view *_this, char *name, ...)
{ {
struct xy *this = (struct xy *)_this; struct xy *this = (struct xy *)_this;
...@@ -89,24 +109,35 @@ static void set(view *_this, char *name, ...) ...@@ -89,24 +109,35 @@ static void set(view *_this, char *name, ...)
} }
view *new_view_xy(int length, 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)
{ {
struct xy *ret = calloc(1, sizeof(struct xy)); struct xy *ret = calloc(1, sizeof(struct xy));
if (ret == NULL) abort(); if (ret == NULL) abort();
ret->common.clear = clear; ret->common.clear = clear;
ret->common.append = (void (*)(view *, ...))append;
switch (mode) {
case XY_LOOP_MODE:
ret->common.append = (void (*)(view *, ...))append_loop;
ret->common.set = set; 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->refresh_rate = refresh_rate;
ret->g = g; ret->g = g;
ret->w = w; ret->w = w;
ret->plot = xy_plot_new_plot(g, w, color); ret->plot = xy_plot_new_plot(g, w, color);
ret->length = length;
ret->x = calloc(length, sizeof(float)); if (ret->x == NULL) abort(); ret->x = calloc(length, sizeof(float)); if (ret->x == NULL) abort();
ret->y = calloc(length, sizeof(float)); if (ret->y == 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(); if (pthread_mutex_init(&ret->lock, NULL)) abort();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment