-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAOloopControl_IOtools.c
315 lines (197 loc) · 13 KB
/
AOloopControl_IOtools.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/**
* @file AOloopControl_IOtools.c
* @brief Adaptive Optics Control loop engine I/O tools
*
* AO engine uses stream data structure
*
* @bug No known bugs.
*
*
*/
#define _GNU_SOURCE
// uncomment for test print statements to stdout
//#define _PRINT_TEST
/* =============================================================================================== */
/* =============================================================================================== */
/* HEADER FILES */
/* =============================================================================================== */
/* =============================================================================================== */
#include <string.h>
#include "CommandLineInterface/CLIcore.h"
#include "AOloopControl/AOloopControl.h"
#include "AOloopControl_IOtools/AOloopControl_IOtools.h"
/* =============================================================================================== */
/* =============================================================================================== */
/* DEFINES, MACROS */
/* =============================================================================================== */
/* =============================================================================================== */
# ifdef _OPENMP
# include <omp.h>
#define OMP_NELEMENT_LIMIT 1000000
# endif
/* =============================================================================================== */
/* =============================================================================================== */
/* GLOBAL DATA DECLARATION */
/* =============================================================================================== */
/* =============================================================================================== */
static sem_t AOLCOMPUTE_TOTAL_ASYNC_sem_name;
static long long imtotalcnt;
static int AOLCOMPUTE_DARK_SUBTRACT_THREADinit = 0;
static int COMPUTE_DARK_SUBTRACT_NBTHREADS = 1;
static sem_t AOLCOMPUTE_DARK_SUBTRACT_sem_name[32];
static sem_t AOLCOMPUTE_DARK_SUBTRACT_RESULT_sem_name[32];
static int avcamarraysInit = 0;
static unsigned short *arrayutmp;
static char Average_cam_frames_dname[200];
static long Average_cam_frames_IDdark = -1;
static long Average_cam_frames_nelem = 1;
static float *arrayftmp;
// TIMING
static struct timespec tnow;
static struct timespec tdiff;
static double tdiffv;
//extern int aoloopcontrol_var.PIXSTREAM_SLICE;
static long ti; // thread index
static int AOLCOMPUTE_TOTAL_ASYNC_THREADinit = 0;
static int AOLCOMPUTE_TOTAL_INIT = 0; // toggles to 1 AFTER total for first image is computed
//extern float aoloopcontrol_var.normfloorcoeff;
//extern float aoloopcontrol_var.GPU_alpha;
//extern float aoloopcontrol_var.GPU_beta;
/* =============================================================================================== */
/* MAIN DATA STRUCTURES */
/* =============================================================================================== */
static int INITSTATUS_AOloopControl_IOtools = 0;
extern long LOOPNUMBER; // current loop index
extern AOLOOPCONTROL_CONF *AOconf; // declared in AOloopControl.c
extern AOloopControl_var aoloopcontrol_var; // declared in AOloopControl.c
// CLI commands
//
// function CLI_checkarg used to check arguments
// CLI_checkarg ( CLI argument index , type code )
//
// type codes:
// 1: float
// 2: long
// 3: string, not existing image
// 4: existing image
// 5: string
//
/* =============================================================================================== */
/* =============================================================================================== */
/** @name AOloopControl_IOtools - 1. CAMERA INPUT
* Read camera imates */
/* =============================================================================================== */
/* =============================================================================================== */
/** @brief CLI function for AOloopControl_camimage_extract2D_sharedmem_loop */
int_fast8_t AOloopControl_IOtools_camimage_extract2D_sharedmem_loop_cli() {
if(CLI_checkarg(1,4)+CLI_checkarg(2,5)+CLI_checkarg(3,3)+CLI_checkarg(4,2)+CLI_checkarg(5,2)+CLI_checkarg(6,2)+CLI_checkarg(7,2)==0) {
AOloopControl_IOtools_camimage_extract2D_sharedmem_loop(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, data.cmdargtoken[3].val.string , data.cmdargtoken[4].val.numl, data.cmdargtoken[5].val.numl, data.cmdargtoken[6].val.numl, data.cmdargtoken[7].val.numl);
return 0;
}
else return 1;
}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name AOloopControl_IOtools - 2. LOAD DATA STREAMS
* Load 2D and 3D shared memory images */
/* =============================================================================================== */
/* =============================================================================================== */
// No command line hooks to functions in this section
/* =============================================================================================== */
/* =============================================================================================== */
/** @name AOloopControl_IOtools - 3. DATA STREAMS PROCESSING
* Data streams real-time processing */
/* =============================================================================================== */
/* =============================================================================================== */
/** @brief CLI function for AOloopControl_AveStream */
int_fast8_t AOloopControl_IOtools_AveStream_cli() {
if(CLI_checkarg(1,4)+CLI_checkarg(2,1)+CLI_checkarg(3,3)+CLI_checkarg(4,3)+CLI_checkarg(5,3)==0) {
AOloopControl_IOtools_AveStream(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numf, data.cmdargtoken[3].val.string, data.cmdargtoken[4].val.string, data.cmdargtoken[5].val.string);
return 0;
}
else return 1;
}
/** @brief Aligns data stream */
int_fast8_t AOloopControl_IOtools_imAlignStream_cli() {
if(CLI_checkarg(1,4)+CLI_checkarg(2,2)+CLI_checkarg(3,2)+CLI_checkarg(4,4)+CLI_checkarg(5,3)+CLI_checkarg(6,2)==0) {
AOloopControl_IOtools_imAlignStream(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.numl, data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.string, data.cmdargtoken[5].val.string, data.cmdargtoken[6].val.numl);
return 0;
}
else return 1;
}
/** @brief CLI function for AOloopControl_frameDelay */
int_fast8_t AOloopControl_IOtools_frameDelay_cli()
{
if(CLI_checkarg(1,4)+CLI_checkarg(2,4)+CLI_checkarg(3,5)+CLI_checkarg(4,2)==0) {
AOloopControl_IOtools_frameDelay(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, data.cmdargtoken[3].val.string, data.cmdargtoken[4].val.numl);
return 0;
}
else return 1;
}
/** @brief CLI function for AOloopControl_stream3Dto2D */
int_fast8_t AOloopControl_IOtools_stream3Dto2D_cli() {
if(CLI_checkarg(1,4)+CLI_checkarg(2,3)+CLI_checkarg(3,2)+CLI_checkarg(4,2)==0) {
AOloopControl_IOtools_stream3Dto2D(data.cmdargtoken[1].val.string, data.cmdargtoken[2].val.string, data.cmdargtoken[3].val.numl, data.cmdargtoken[4].val.numl);
return 0;
}
else return 1;
}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name AOloopControl_IOtools - 4. SAVE REAL-TIME TELEMETRY BUFFER
* Save to disk telemetry packaged in alternate buffers */
/* =============================================================================================== */
/* =============================================================================================== */
/** @brief Save telemetry */
int_fast8_t AOloopControl_IOtools_RTLOGsave_cli() {
if(CLI_checkarg(1,2)+CLI_checkarg(2,5)+CLI_checkarg(3,5)==0) {
AOloopControl_IOtools_RTLOGsave(data.cmdargtoken[1].val.numl, data.cmdargtoken[2].val.string, data.cmdargtoken[3].val.string);
return 0;
}
else return 1;
}
/* =============================================================================================== */
/* =============================================================================================== */
/* FUNCTIONS SOURCE CODE */
/* =============================================================================================== */
/* =============================================================================================== */
/** @name AOloopControl_IOtools functions */
void __attribute__ ((constructor)) libinit_AOloopControl_IOtools()
{
if ( INITSTATUS_AOloopControl_IOtools == 0)
{
init_AOloopControl_IOtools();
RegisterModule(__FILE__, "cacao", "AO loop control IO tools");
INITSTATUS_AOloopControl_IOtools = 1;
}
}
int_fast8_t init_AOloopControl_IOtools()
{
/* =============================================================================================== */
/* =============================================================================================== */
/** @name AOloopControl_IOtools - 1. CAMERA INPUT
* Read camera imates */
/* =============================================================================================== */
/* =============================================================================================== */
RegisterCLIcommand("cropshim", __FILE__, AOloopControl_IOtools_camimage_extract2D_sharedmem_loop_cli, "crop shared mem image", "<input image> <optional dark> <output image> <sizex> <sizey> <xstart> <ystart>" , "cropshim imin null imout 32 32 153 201", "int AOloopControl_IOtools_camimage_extract2D_sharedmem_loop(char *in_name, const char *dark_name, char *out_name, long size_x, long size_y, long xstart, long ystart)");
/* =============================================================================================== */
/* =============================================================================================== */
/** @name AOloopControl_IOtools - 3. DATA STREAMS PROCESSING
* Data streams real-time processing */
/* =============================================================================================== */
/* =============================================================================================== */
RegisterCLIcommand("aveACshmim", __FILE__, AOloopControl_IOtools_AveStream_cli, "average and AC shared mem image", "<input image> <coeff> <output image ave> <output AC> <output RMS>" , "aveACshmim imin 0.01 outave outAC outRMS", "int AOloopControl_IOtools_AveStream(char *IDname, double alpha, char *IDname_out_ave, char *IDname_out_AC, char *IDname_out_RMS)");
RegisterCLIcommand("alignshmim", __FILE__, AOloopControl_IOtools_imAlignStream_cli, "align image stream to reference", "<input stream> <box x offset> <box y offset> <ref stream> <output stream> <sem index>" , "alignshmim imin 100 100 imref imout 3", "int_fast8_t AOloopControl_IOtools_imAlignStream(const char *IDname, int xbox0, int ybox0, const char *IDref_name, const char *IDout_name, int insem)");
RegisterCLIcommand("aolframedelay", __FILE__, AOloopControl_IOtools_frameDelay_cli, "introduce temporal delay", "<in> <temporal kernel> <out> <sem index>","aolframedelay in kern out 0","long AOloopControl_IOtools_frameDelay(const char *IDin_name, const char *IDkern_name, const char *IDout_name, int insem)");
RegisterCLIcommand("aolstream3Dto2D", __FILE__, AOloopControl_IOtools_stream3Dto2D_cli, "remaps 3D cube into 2D image", "<input 3D stream> <output 2D stream> <# cols> <sem trigger>" , "aolstream3Dto2D in3dim out2dim 4 1", "long AOloopControl_IOtools_stream3Dto2D(const char *in_name, const char *out_name, int NBcols, int insem)");
/* =============================================================================================== */
/* =============================================================================================== */
/** @name AOloopControl_IOtools - 4. SAVE REAL-TIME TELEMETRY BUFFER
* Save to disk telemetry packaged in alternate buffers */
/* =============================================================================================== */
/* =============================================================================================== */
RegisterCLIcommand("aolrtlogbuffsave", __FILE__, AOloopControl_IOtools_RTLOGsave_cli, "log realtime buffer stream", "<loopnumber> <streamname> <dirname>", "aolrtlogbuffsave modeval \"/media/data/\"", "int_fast8_t AOloopControl_IOtools_RTLOGsave(long loop, const char *streamname, const char *dirname)");
// add atexit functions here
// atexit((void*) myfunc);
return 0;
}