This repository has been archived by the owner on Feb 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
COREMOD_memory.h
835 lines (614 loc) · 18.6 KB
/
COREMOD_memory.h
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
/**
* @file COREMOD_memory.h
* @brief Function prototypes for milk memory functions
*
* Functions to handle images and streams
*
*
*/
#ifndef _COREMODMEMORY_H
#define _COREMODMEMORY_H
/* the number of images in the data structure is kept NB_IMAGES_BUFFER above the number of used images prior to the execution of any function. It means that no function should create more than 100 images. */
#define NB_IMAGES_BUFFER 500
/* when the number of free images in the data structure is below NB_IMAGES_BUFFER, it is increased by NB_IMAGES_BUFFER */
#define NB_IMAGES_BUFFER_REALLOC 600
/* the number of variables in the data structure is kept NB_VARIABLES_BUFFER above the number of used variables prior to the execution of any function. It means that no function should create more than 100 variables. */
#define NB_VARIABLES_BUFFER 100
/* when the number of free variables in the data structure is below NB_VARIABLES_BUFFER, it is increased by NB_VARIABLES_BUFFER */
#define NB_VARIABLES_BUFFER_REALLOC 150
/*void print_sys_mem_info();*/
typedef long imageID;
/** data logging of shared memory image stream
*
*/
typedef struct
{
char iname[100];
char fname[200];
int partial; // 1 if partial cube
long cubesize; // size of the cube
int saveascii;
// 0 : Not saving ascii
// 1 : Saving ascii: arraycnt0, arraycnt1, arraytime
// 2 : ???
char fnameascii[200]; // name of frame to be saved
uint64_t *arrayindex;
uint64_t *arraycnt0;
uint64_t *arraycnt1;
double *arraytime;
} STREAMSAVE_THREAD_MESSAGE;
typedef struct
{
int on; /**< 1 if logging, 0 otherwise */
long long cnt;
long long filecnt;
long interval; /**< log every x frames (default = 1) */
int logexit; /**< toggle to 1 when exiting */
char fname[200];
} LOGSHIM_CONF;
typedef struct
{
long cnt0;
long cnt1;
} TCP_BUFFER_METADATA;
void __attribute__((constructor)) libinit_COREMOD_memory();
//int ImageCreateSem(IMAGE *image, long NBsem);
//int ImageCreate(IMAGE *image, const char *name, long naxis, uint32_t *size, uint8_t datatype, int shared, int NBkw);
errno_t COREMOD_MEMORY_testfunc();
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 1. MANAGE MEMORY AND IDENTIFIERS
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
errno_t memory_monitor(
const char *termttyname
);
long compute_nb_image();
long compute_nb_variable();
long long compute_image_memory();
long compute_variable_memory();
imageID image_ID(
const char *name
);
imageID image_ID_noaccessupdate(
const char *name
);
variableID variable_ID(
const char *name
);
imageID next_avail_image_ID();
variableID next_avail_variable_ID();
errno_t delete_image_ID(
const char *imname
);
errno_t delete_image_ID_prefix(
const char *prefix
);
errno_t delete_variable_ID(
const char *varname
);
variableID create_variable_long_ID(
const char *name,
long value
);
variableID create_variable_string_ID(
const char *name,
const char *value
);
imageID create_image_ID(
const char *name,
long naxis,
uint32_t *size,
uint8_t datatype,
int shared,
int nbkw
);
errno_t clearall();
void *save_fits_function(
void *ptr
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 2. KEYWORDS
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
long image_write_keyword_L(
const char *IDname,
const char *kname,
long value, const
char *comment
);
long image_write_keyword_D(
const char *IDname,
const char *kname,
double value,
const char *comment
);
long image_write_keyword_S(
const char *IDname,
const char *kname,
const char *value,
const char *comment
);
long image_list_keywords(
const char *IDname
);
long image_read_keyword_D(
const char *IDname,
const char *kname,
double *val
);
long image_read_keyword_L(
const char *IDname,
const char *kname,
long *val
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 3. READ SHARED MEM IMAGE AND SIZE
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
imageID read_sharedmem_image_size(
const char *name,
const char *fname
);
imageID read_sharedmem_image(
const char *name
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 4. CREATE IMAGE
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
imageID create_1Dimage_ID(
const char *ID_name,
uint32_t xsize
);
imageID create_1DCimage_ID(
const char *ID_name,
uint32_t xsize
);
imageID create_2Dimage_ID(
const char *ID_name,
uint32_t xsize,
uint32_t ysize
);
imageID create_2Dimage_ID_double(
const char *ID_name,
uint32_t xsize,
uint32_t ysize
);
imageID create_2DCimage_ID(
const char *ID_name,
uint32_t xsize,
uint32_t ysize
);
imageID create_2DCimage_ID_double(
const char *ID_name,
uint32_t xsize,
uint32_t ysize
);
imageID create_3Dimage_ID(
const char *ID_name,
uint32_t xsize,
uint32_t ysize,
uint32_t zsize
);
imageID create_3Dimage_ID_double(
const char *ID_name,
uint32_t xsize,
uint32_t ysize,
uint32_t zsize
);
imageID create_3DCimage_ID(
const char *ID_name,
uint32_t xsize,
uint32_t ysize,
uint32_t zsize
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 5. CREATE VARIABLE
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
variableID create_variable_ID(
const char *name,
double value
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 6. COPY IMAGE
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
imageID copy_image_ID(
const char *name,
const char *newname,
int shared
);
imageID chname_image_ID(
const char *ID_name,
const char *new_name
);
errno_t COREMOD_MEMORY_cp2shm(
const char *IDname,
const char *IDshmname
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 7. DISPLAY / LISTS
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
errno_t init_list_image_ID_ncurses(
const char *termttyname
);
void close_list_image_ID_ncurses();
errno_t list_image_ID_ncurses();
errno_t list_image_ID_ofp(
FILE *fo
);
errno_t list_image_ID_ofp_simple(
FILE *fo
);
errno_t list_image_ID();
errno_t list_image_ID_file(
const char *fname
);
errno_t list_variable_ID();
errno_t list_variable_ID_file(
const char *fname
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 8. TYPE CONVERSIONS TO AND FROM COMPLEX
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
errno_t mk_complex_from_reim(
const char *re_name,
const char *im_name,
const char *out_name,
int sharedmem
);
errno_t mk_complex_from_amph(
const char *am_name,
const char *ph_name,
const char *out_name,
int sharedmem
);
errno_t mk_reim_from_complex(
const char *in_name,
const char *re_name,
const char *im_name,
int sharedmem
);
errno_t mk_amph_from_complex(
const char *in_name,
const char *am_name,
const char *ph_name,
int sharedmem
);
errno_t mk_reim_from_amph(
const char *am_name,
const char *ph_name,
const char *re_out_name,
const char *im_out_name,
int sharedmem
);
errno_t mk_amph_from_reim(
const char *re_name,
const char *im_name,
const char *am_out_name,
const char *ph_out_name,
int sharedmem
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 9. VERIFY SIZE
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
int check_2Dsize(
const char *ID_name,
uint32_t xsize,
uint32_t ysize
);
int check_3Dsize(
const char *ID_name,
uint32_t xsize,
uint32_t ysize,
uint32_t zsize
);
int COREMOD_MEMORY_check_2Dsize(
const char *IDname,
uint32_t xsize,
uint32_t ysize
);
int COREMOD_MEMORY_check_3Dsize(
const char *IDname,
uint32_t xsize,
uint32_t ysize,
uint32_t zsize
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 10. COORDINATE CHANGE
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
errno_t rotate_cube(const char *ID_name, const char *ID_out_name,
int orientation);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 11. SET IMAGE FLAGS / COUNTERS
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
errno_t COREMOD_MEMORY_image_set_status(
const char *IDname,
int status
);
errno_t COREMOD_MEMORY_image_set_cnt0(
const char *IDname,
int cnt0
);
errno_t COREMOD_MEMORY_image_set_cnt1(
const char *IDname,
int cnt1
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 12. MANAGE SEMAPHORES
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
imageID COREMOD_MEMORY_image_set_createsem(
const char *IDname,
long NBsem
);
imageID COREMOD_MEMORY_image_seminfo(
const char *IDname
);
imageID COREMOD_MEMORY_image_set_sempost(
const char *IDname,
long index
);
imageID COREMOD_MEMORY_image_set_sempost_byID(
imageID ID,
long index
);
imageID COREMOD_MEMORY_image_set_sempost_excl_byID(
imageID ID,
long index
);
imageID COREMOD_MEMORY_image_set_sempost_loop(
const char *IDname,
long index,
long dtus
);
imageID COREMOD_MEMORY_image_set_semwait(
const char *IDname,
long index
);
void *waitforsemID(
void *ID
);
errno_t COREMOD_MEMORY_image_set_semwait_OR_IDarray(
imageID *IDarray,
long NB_ID
);
errno_t COREMOD_MEMORY_image_set_semflush_IDarray(
imageID *IDarray,
long NB_ID
);
imageID COREMOD_MEMORY_image_set_semflush(
const char *IDname,
long index
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 13. SIMPLE OPERATIONS ON STREAMS
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
/** @brief Poke stream at regular intervals
*/
imageID COREMOD_MEMORY_streamPoke(
const char *IDstream_name,
long usperiod
);
/** @brief Difference between two streams
*/
imageID COREMOD_MEMORY_streamDiff(
const char *IDstream0_name,
const char *IDstream1_name,
const char *IDstreammask_name,
const char *IDstreamout_name,
long semtrig
);
/** @brief Paste two equal size 2D streams into an output 2D stream
*/
imageID COREMOD_MEMORY_streamPaste(
const char *IDstream0_name,
const char *IDstream1_name,
const char *IDstreamout_name,
long semtrig0,
long semtrig1,
int master
);
/** difference between two halves of stream image
*/
imageID COREMOD_MEMORY_stream_halfimDiff(
const char *IDstream_name,
const char *IDstreamout_name,
long semtrig
);
/** @brief Averages frames in stream
*
* @param[in] IDstream_name Input stream
* @param[in] NBave Number of consecutive frames to be averaged together
* @param[in] mode 1: Perform average once, exit when completed and write output to local image
* 2: Run forever, write output to shared mem stream
* @param[out] IDout_name output stream name
*
*/
imageID COREMOD_MEMORY_streamAve(
const char *IDstream_name,
int NBave,
int mode,
const char *IDout_name
);
/**
* @brief takes a 3Dimage (circular buffer) and writes slices to a 2D image with time interval specified in us */
imageID COREMOD_MEMORY_image_streamupdateloop(
const char *IDinname,
const char *IDoutname,
long usperiod,
long NBcubes,
long period,
long offsetus,
const char *IDsync_name,
int semtrig,
int timingmode
);
/**
* @brief takes a 3Dimage (circular buffer) and writes slices to a 2D image synchronized with an image semaphore
*
*
* @param[in] IDinname 3D circular buffer of frames to be written
* @param[out] IDoutname 2D output stream
* @param[in] period number of semaphore waits required to advance to next slice in the circular buffer
* @param[in] offsetus fixed time offset between trigger stream and output write
* @param[in] IDsync_name trigger stream
* @param[in] smmtrig semaphore index for trigger
* @param[in] timingmode
*/
imageID COREMOD_MEMORY_image_streamupdateloop_semtrig(
const char *IDinname,
const char *IDoutname,
long period,
long offsetus,
const char *IDsync_name,
int semtrig,
int timingmode
);
errno_t COREMOD_MEMORY_streamDelay_FPCONF(
char *fpsname,
uint32_t CMDmode
);
imageID COREMOD_MEMORY_streamDelay_RUN(
char *fpsname
);
errno_t COREMOD_MEMORY_streamDelay(
const char *IDin_name,
const char *IDout_name,
long delayus,
long dtus
);
errno_t COREMOD_MEMORY_SaveAll_snapshot(
const char *dirname
);
errno_t COREMOD_MEMORY_SaveAll_sequ(
const char *dirname,
const char *IDtrig_name,
long semtrig,
long NBframes
);
errno_t COREMOD_MEMORY_testfunction_semaphore(
const char *IDname,
int semtrig,
int testmode
);
imageID COREMOD_MEMORY_image_NETWORKtransmit(
const char *IDname,
const char *IPaddr,
int port,
int mode,
int RT_priority
);
imageID COREMOD_MEMORY_image_NETWORKreceive(
int port,
int mode,
int RT_priority
);
imageID COREMOD_MEMORY_PixMapDecode_U(
const char *inputstream_name,
uint32_t xsizeim,
uint32_t ysizeim,
const char *NBpix_fname,
const char *IDmap_name,
const char *IDout_name,
const char *IDout_pixslice_fname
);
///@}
/* =============================================================================================== */
/* =============================================================================================== */
/** @name 14. DATA LOGGING
*
*/
///@{
/* =============================================================================================== */
/* =============================================================================================== */
errno_t COREMOD_MEMORY_logshim_printstatus(
const char *IDname
);
errno_t COREMOD_MEMORY_logshim_set_on(
const char *IDname,
int setv
);
errno_t COREMOD_MEMORY_logshim_set_logexit(
const char *IDname,
int setv
);
errno_t COREMOD_MEMORY_sharedMem_2Dim_log(
const char *IDname,
uint32_t zsize,
const char *logdir,
const char *IDlogdata_name
);
///@}
#endif