1 /**
2  * Copyright (C) 2012-2013 Analog Devices, Inc.
3  *
4  * Licensed under the GPL-2.
5  *
6  **/
7 #ifndef __DATA_TYPES__
8 #define __DATA_TYPES__
9 
10 #include <glib.h>
11 #include <gtk/gtk.h>
12 #include <gtkdatabox.h>
13 #include <errno.h>
14 #include <stdbool.h>
15 #include <fftw3.h>
16 
17 #include <iio.h>
18 
19 #define INITIAL_UPDATE TRUE
20 #define NORMAL_UPDATE FALSE
21 
22 struct detachable_plugin {
23 	const struct osc_plugin *plugin;
24 	gboolean detached_state;
25 	GtkWidget *detach_attach_button;
26 	GtkWidget *window;
27 	gint xpos;
28 	gint ypos;
29 };
30 
31 /* Types of transforms */
32 enum {
33 	NO_TRANSFORM_TYPE,
34 	TIME_TRANSFORM,
35 	FFT_TRANSFORM,
36 	CONSTELLATION_TRANSFORM,
37 	COMPLEX_FFT_TRANSFORM,
38 	CROSS_CORRELATION_TRANSFORM,
39 	FREQ_SPECTRUM_TRANSFORM,
40 	TRANSFORMS_TYPES_COUNT
41 };
42 
43 enum plot_channel_constraints {
44 	CONSTR_CHN_INITIAL_ENABLED = 1 << 0,  /* The channel initial state is owerwritten to ENABLE state */
45 	CONSTR_CHN_UNTOGGLEABLE = 1 << 1,     /* The channel state cannot be changed and is displayed as grey-out */
46 };
47 
48 typedef struct _transform Transform;
49 typedef struct _tr_list TrList;
50 
51 struct extra_info {
52 	struct iio_device *dev;
53 	gfloat *data_ref;
54 	off_t offset;
55 	int shadow_of_enabled;
56 	bool may_be_enabled;
57 	double lo_freq;
58 	unsigned int constraints;
59 };
60 
61 struct extra_dev_info {
62 	bool input_device;
63 	struct iio_buffer *buffer;
64 	unsigned int sample_count;
65 	unsigned int buffer_size;
66 	unsigned int channel_trigger;
67 	bool channel_trigger_enabled;
68 	bool trigger_falling_edge;
69 	float trigger_value;
70 	double adc_freq;
71 	char adc_scale;
72 	gfloat **channels_data_copy;
73 	GSList *plots_sample_counts;
74 	gfloat plugin_fft_corr;
75 };
76 
77 struct buffer {
78 	void *data;
79 	void *data_copy;
80 	unsigned int available;
81 	unsigned int size;
82 };
83 
84 struct plot_params{
85 	int plot_id;
86 	unsigned int sample_count;
87 };
88 
89 struct _fft_alg_data{
90 	gfloat fft_corr;
91 	double *in;
92 	double *win;
93 	int m;			/* size of fft; -1 if not initialized */
94 	fftw_complex *in_c;
95 	fftw_complex *out;
96 	fftw_plan plan_forward;
97 	int cached_fft_size;
98 	int cached_num_active_channels;
99 	int num_active_channels;
100 };
101 
102 struct _transform {
103 	GtkDataboxGraph *graph;
104 	int type_id;
105 	GSList *plot_channels;
106 	int plot_channels_type;
107 	gfloat *x_axis;
108 	gfloat *y_axis;
109 	unsigned x_axis_size;
110 	unsigned y_axis_size;
111 	bool destroy_x_axis;
112 	bool destroy_y_axis;
113 	GdkColor *graph_color;
114 	bool has_the_marker;
115 	void *settings;
116 	bool (*transform_function)(Transform *tr, gboolean init_transform);
117 };
118 
119 struct _tr_list {
120 	Transform **transforms;
121 	int size;
122 };
123 
124 struct _time_settings {
125 	gfloat *data_source;
126 	unsigned int num_samples;
127 	gfloat max_x_axis;
128 	gboolean apply_inverse_funct;
129 	gboolean apply_multiply_funct;
130 	gboolean apply_add_funct;
131 	gfloat multiply_value;
132 	gfloat add_value;
133 };
134 
135 struct _fft_settings {
136 	gfloat *real_source;
137 	gfloat *imag_source;
138 	unsigned int fft_size;
139 	gchar *fft_win;
140 	unsigned int fft_avg;
141 	gfloat fft_pwr_off;
142 	struct _fft_alg_data fft_alg_data;
143 	struct marker_type *markers;
144 	struct marker_type **markers_copy;
145 	GMutex *marker_lock;
146 	enum marker_types *marker_type;
147 };
148 
149 struct _constellation_settings {
150 	gfloat *x_source;
151 	gfloat *y_source;
152 	unsigned int num_samples;
153 };
154 
155 struct _cross_correlation_settings {
156 	gfloat *i0_source;
157 	gfloat *q0_source;
158 	gfloat *i1_source;
159 	gfloat *q1_source;
160 	unsigned int num_samples;
161 	gfloat max_x_axis;
162 	unsigned int avg;
163 	int revert_xcorr;
164 	fftw_complex *signal_a;
165 	fftw_complex *signal_b;
166 	fftw_complex *xcorr_data;
167 	struct marker_type *markers;
168 	struct marker_type **markers_copy;
169 	GMutex *marker_lock;
170 	enum marker_types *marker_type;
171 };
172 
173 struct _freq_spectrum_settings {
174 	gfloat *real_source;
175 	gfloat *imag_source;
176 	gfloat *freq_axis_source;
177 	gfloat *magn_axis_source;
178 	gchar *fft_win;
179 	unsigned freq_axis_size;
180 	unsigned magn_axis_size;
181 	unsigned fft_index;
182 	unsigned fft_count;
183 	double freq_sweep_start;
184 	double filter_bandwidth;
185 	unsigned int fft_size;
186 	unsigned int fft_avg;
187 	gfloat fft_pwr_off;
188 	unsigned fft_lower_clipping_limit;
189 	unsigned fft_upper_clipping_limit;
190 	struct _fft_alg_data *ffts_alg_data;
191 	gfloat fft_corr;
192 	unsigned int *maxXaxis;
193 	gfloat *maxYaxis;
194 	struct marker_type *markers;
195 	struct marker_type **markers_copy;
196 	GMutex *marker_lock;
197 	enum marker_types *marker_type;
198 };
199 
200 Transform* Transform_new(int tr_type);
201 void Transform_destroy(Transform *tr);
202 void Transform_resize_x_axis(Transform *tr, int new_size);
203 void Transform_resize_y_axis(Transform *tr, int new_size);
204 gfloat* Transform_get_x_axis_ref(Transform *tr);
205 gfloat* Transform_get_y_axis_ref(Transform *tr);
206 void Transform_attach_settings(Transform *tr, void *settings);
207 void Transform_attach_function(Transform *tr, bool (*f)(Transform *tr , gboolean init_transform));
208 void Transform_setup(Transform *tr);
209 bool Transform_update_output(Transform *tr);
210 
211 TrList* TrList_new(void);
212 void TrList_destroy(TrList *list);
213 void TrList_add_transform(TrList *list, Transform *tr);
214 void TrList_remove_transform(TrList *list, Transform *tr);
215 
216 #endif /* __DATA_TYPES__ */
217