The VisAO Camera
libvisao.h
Go to the documentation of this file.
1 /************************************************************
2 * libvisao.h
3 *
4 * Author: Jared R. Males (jrmales@as.arizona.edu)
5 *
6 * VisAO software utilitites, declarations
7 *
8 ************************************************************/
9 
10 /** \file libvisao.h
11  * \author Jared R. Males
12  * \brief VisAO software utilitites, declarations
13  *
14 */
15 
16 #ifndef __libvisao_h__
17 #define __libvisao_h__
18 
19 #include "time.h"
20 #include "sys/time.h"
21 
22 #include <sys/shm.h>
23 
24 #include "fifoutils.h"
25 
26 /// The real-time scheduling policy used by the VisAO system.
27 #define VISAO_SCHED_POLICY SCHED_FIFO
28 
29 #define PROMPT_UP 1
30 #define PROMPT_DOWN 2
31 #define PROMPT_INT 3
32 
33 #define FTYPE_NORMAL 0
34 #define FTYPE_SDI 1
35 #define FTYPE_CORON 2
36 
37 #define RTSIGTIMEOUT (RTSIGPING + 1)
38 
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif //__cplusplus
43 
44 ///Number of physical processors in the system
45 #define SYS_N_CORES 6
46 
47 ///Number of virtual processors in the system
48 #define SYS_N_VCORES 12
49 
50 ///Number of physical drives in the system
51 #define SYS_N_DRV 2
52 
53 ///Number of logical drives in the system
54 #define SYS_N_LOGDRV 6
55 
56 
57 ///A global error reporting function, arguments are the report, file, and line.
58 /** This is used by various library functions and classes that aren't derived from one of the Apps.
59  */
60 extern void (*global_error_report)(const char*, const char*, int);
61 
62 ///Macro for declaring and setting the error reporting global.
63 #define set_global_error_report(er) void (*global_error_report)(const char*, const char*, int) = er
64 
65 ///A global info logging function.
66 /** This is used by various library functions and classes that aren't derived from one of the Apps.
67  */
68 extern void (*global_log_info)(const char*);
69 
70 ///Macro for declaring and setting the info logging global.
71 #define set_global_log_info(li) void (*global_log_info)(const char*) = li
72 
73 
74 /// The fifoutils error reporting function.
75 /** This passes the ERRMSG macro in fifoutils out to the global_error_report.
76  */
77 void fifo_error_message(const char *, const char *, int);
78 
79 /// Fills in the properly formatted dioserver channel fifo names
80 int get_dio_fnames(char *fout, char *fin, char *fbase, int ch);
81 
82 /// Convert a timespec structure to double seconds.
83 double ts_to_curr_time(struct timespec *tsp);
84 
85 /// Convert a timeval structure to double seconds.
86 double tv_to_curr_time(struct timeval *tvp);
87 
88 /// Gets the current CLOCK_REALTIME time, returns it in seconds to double precision.
89 double get_curr_time(void);
90 
91 
92 /// Create a shared memory buffer
93 int create_shmem(int * shmemid, key_t mkey, size_t sz);
94 
95 /// Attach to a shared memory buffer and get its size.
96 void * attach_shm(size_t *sz, key_t mkey, int shmemid);
97 
98 /// Calculate frame rate given Little Joe program parameters
99 double ComputeFramerate(double delay_base, double delay_inc, int rep);
100 
101 int ComputeRepsFrameRate(double delay_base, double delay_inc, double fr);
102 
103 int ComputeRepsExpTime(double delay_base, double delay_inc, double et);
104 
105 
106 /// Signal proof sleep function.
107 /** Sleeps for at least secs seconds, even if interrupted by a handled signal.
108  * May sleep for longer if signal handling takes a long time.
109  * Monitors the integer pointed by dienow and exits if it becomes 1
110  * set dienow to 0 to ignore.
111  */
112 int sigproof_sleep(double secs, int *dienow);
113 
114 #ifdef __cplusplus
115 } //extern "C"
116 #endif //__cplusplus
117 
118 
119 #ifdef __cplusplus
120 
121 #include <iostream>
122 #include <string>
123 #include <fstream>
124 #include <sstream>
125 #include <vector>
126 #include <cstdlib>
127 
128 /// Read /proc/mdstat and parse for status of the 2 RAID 1 arrays.
129 int visao_mdstat(char dstat[SYS_N_LOGDRV]);
130 
131 ///Save a preset file for, e.g., the focus or gimbal
132 /** \param calname is the name of the directory in calib/visao where the presets directory for this device is
133  * \param fw1pos is the current position of F/W 1 position, which will be rounded to the nearest integer
134  * \param wollstat is the current status of the wollaston.
135  * \param fw2pos is the current position of F/W 2, which will be rounded to the nearest integer
136  * \param fw3pos is the current position of F/W 3, which will be rounded to the nearest integer
137  * \param vec is a pointer to a vector containing the presets. The number of presets read from the file is determined by the size of vec.
138  * \retval -1 if the file can't be created or saved
139  * \retval 0 on success.
140  */
141 int save_preset(std::string calname, double fw1pos, int wollstat, double fw2pos, double fw3pos, std::vector<double> *vec);
142 
143 ///Read the focus calibration
144 /** \param fcal [output] is the read focus position
145  * \retval -1 if the file doesn't exist or can't be opened
146  * \retval 0 on success.
147  */
148 int get_focuscal(double * fcal);
149 
150 ///Read a preset file for, e.g., the focus or gimbal
151 /** \param calname is the name of the directory in calib/visao where the presets directory for this device is
152  * \param fw1pos is the current position of F/W 1 position, which will be rounded to the nearest integer
153  * \param wollstat is the current status of the wollaston.
154  * \param fw2pos is the current position of F/W 2, which will be rounded to the nearest integer
155  * \param fw3pos is the current position of F/W 3, which will be rounded to the nearest integer
156  * \param vec is a pointer to an allocated vector to return the presets in. The number of presets read from the file is determined by the size of vec.
157  * \param presetf is a string that will be filled with the preset file name
158  * \retval -1 if the file doesn't exist or can't be opened
159  * \retval 0 on success.
160  */
161 int get_preset(std::string calname, double fw1pos, int wollstat, double fw2pos, double fw3pos, std::vector<double> *vec, std::string &presetf);
162 
163 
164 
165 #endif //__cplusplus
166 
167 
168 #endif //__libvisao_h__
double get_curr_time(void)
Gets the current CLOCK_REALTIME time, returns it in seconds to double precision.
Definition: libvisaoc.c:40
double ComputeFramerate(double delay_base, double delay_inc, int rep)
Calculate frame rate given Little Joe program parameters.
Definition: libvisaoc.c:142
int sigproof_sleep(double secs, int *dienow)
Signal proof sleep function.
Definition: libvisaoc.c:161
void fifo_error_message(const char *, const char *, int)
The fifoutils error reporting function.
Definition: libvisaoc.c:18
void * attach_shm(size_t *sz, key_t mkey, int shmemid)
Attach to a shared memory buffer and get its size.
Definition: libvisaoc.c:90
void(* global_error_report)(const char *, const char *, int)
A global error reporting function, arguments are the report, file, and line.
void(* global_log_info)(const char *)
A global info logging function.
Declarations for linux fifo utilities.
double ts_to_curr_time(struct timespec *tsp)
Convert a timespec structure to double seconds.
Definition: libvisaoc.c:30
#define SYS_N_LOGDRV
Number of logical drives in the system.
Definition: libvisao.h:54
double tv_to_curr_time(struct timeval *tvp)
Convert a timeval structure to double seconds.
Definition: libvisaoc.c:35
int create_shmem(int *shmemid, key_t mkey, size_t sz)
Create a shared memory buffer.
Definition: libvisaoc.c:49
int get_dio_fnames(char *fout, char *fin, char *fbase, int ch)
Fills in the properly formatted dioserver channel fifo names.
Definition: libvisaoc.c:23