ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcdcsEXPDRV.hpp
Go to the documentation of this file.
1
7#ifndef ngcdcsEXPDRV_H
8#define ngcdcsEXPDRV_H
9
10
11#ifndef __cplusplus
12#error This is a C++ include file and cannot be used from plain C
13#endif
14
15#include <stdlib.h>
16#include <stdio.h>
17#include <stdarg.h>
18#include <string.h>
19#include <unistd.h>
20#include <errno.h>
21
22#include <ngc/core/ngcbOBJ.hpp>
25
29class ngcdcsEXPDRV: public ngcbOBJ
30{
31public:
33 char name[64];
34
36 int state;
37
39 int acqId;
40
42 unsigned int expId;
43
46
49
52
54 explicit ngcdcsEXPDRV(const ngcb_fb_t &fb) : fb_(fb) {Init_();}
55
57 virtual ~ngcdcsEXPDRV() {
58 if (fb_.automatic && (fb_.chan != NULL))
59 {
60 fclose(fb_.chan); fb_.chan = NULL;
61 }
62 }
63
65 int Initialized() {return (initialized_);}
66
68 FILE *FeedBackStream() {return (fb_.chan);}
69
71 int ImgProcessor() {return (imgProcessor_ || (state > 0));}
72
74 virtual int Configure(ngcbPARAM_LIST *cfg) {USE(cfg); return (ngcbSUCCESS);}
75
77 void GetCfg(ngcbPARAM_LIST *cfg) {cfg->Clear(); CfgStatus(cfg);}
78
80 int Active() {return (active_);}
81
83 int NewSetup() {return ((setupList.First() != NULL));}
84
86 void Init() {state = 0; expId = 0; FeedBack("\n<INIT!>\n");}
87
89 int Next() {
90 int result;
91 setupList.Clear();
92 delay_ = 0;
93 active_ = 1;
94 ErrMsg()[0] = '\0';
95 result = Exec();
96 if (result == ngcbFAILURE) state = -1;
97 return (result);
98 }
99
101 void Terminate(int status=0) {
102 setupList.Clear();
103 if (Active())
104 {
105 Exit(status);
106 active_ = 0;
107 if (status == ngcbABORTED) FeedBack("\n<ABORTED!>\n");
108 else if (status == ngcbFAILURE) FeedBack("\n<FAILURE!>\n");
109 else FeedBack("\n<SUCCESS!>\n");
110 }
111 }
112
114 int Delay() {return (delay_);}
115
117 virtual int Process(void *buffer, ngcdcs_finfo_t *finfo) {
118 USE(buffer); USE(finfo);
119 return (ngcbSUCCESS);
120 }
121
123 virtual int MergeFits(ngcbFITS *hdr) {USE(hdr); return (ngcbSUCCESS);}
124
125protected:
127 void Initialized(int flag) {
128 if (flag) initialized_ = 1;
129 else initialized_ = 0;
130 }
131
133 void ImgProcessorOn() {imgProcessor_ = 1;}
134
136 void Delay(int ms) {delay_ = ms;}
137
139 int Status(const char *paramName, char *value) {
140 if (paramList != NULL)
141 {
142 /*
143 * Check global list first
144 */
145 if (paramList->ValString(paramName, value) == ngcbSUCCESS)
146 {
147 return (ngcbSUCCESS);
148 }
149 }
150
151 if (services != NULL)
152 {
153 /*
154 * An external hook is defined - check if this
155 * resolves our parameter.
156 */
157 if (services->ParamLookup(paramName, value))
158 {
159 return (ngcbSUCCESS);
160 }
161 }
162
163 /*
164 * Parameter is unknown within this scope
165 */
166 sprintf(ErrMsg(), "unknown parameter");
167 return (ngcbFAILURE);
168 }
169
171 virtual int Exec() {return (ngcbSUCCESS);}
172
174 virtual void Exit(int status) {USE(status);}
175
177 virtual void CfgStatus(ngcbPARAM_LIST *cfg) {USE(cfg);}
178
180 void SendFeedBack(const char *msg) {
181 if (fb_.chan != NULL)
182 {
183 if ((verboseLevel <= 0) || (fb_.chan != stdout))
184 {
185 if (fprintf(fb_.chan, "%s", msg) < 0)
186 {
187 if (fb_.automatic) fclose(fb_.chan);
188 fb_.chan = NULL; // don't use anymore
189 }
190 if (fflush(fb_.chan) != 0)
191 {
192 if (fb_.automatic) fclose(fb_.chan);
193 fb_.chan = NULL; // don't use anymore
194 }
195 }
196 }
197
198 if ((strcmp(msg, "\n<ABORTED!>\n") == 0) ||
199 (strcmp(msg, "\n<FAILURE!>\n") == 0) ||
200 (strcmp(msg, "\n<SUCCESS!>\n") == 0))
201 {
202 return;
203 }
204 else
205 {
206 Verbose("ngcdcsEXPDRV: %s", msg);
207 }
208 }
209
210private:
212 int initialized_;
213
215 int delay_;
216
218 int active_;
219
221 ngcb_fb_t fb_;
222
224 int imgProcessor_;
225
227 void Init_() {
228 initialized_ = 0;
229
230 if ((fb_.chan == NULL) && fb_.automatic)
231 {
232 fb_.chan = ngcbDebugOpen(static_cast<char *>(NULL));
233 }
234
235 delay_ = 0;
236 state = 0;
237 acqId = 0;
238 expId = 0;
239 paramList = NULL;
240 name[0] = '\0';
241 active_ = 0;
242 imgProcessor_ = 0;
243 initialized_ = 1;
244 }
245};
246
247#endif
Definition ngcbFITS.hpp:24
int verboseLevel
Verbose level.
Definition ngcbOBJ.hpp:45
virtual void virtual void virtual void virtual void virtual void void FeedBack(const char *format,...) __attribute__((format(printf
Feed-back function.
Definition ngcbOBJ.cpp:205
ngcbOBJ()
Constructor.
Definition ngcbOBJ.cpp:34
virtual void Verbose(int level, const char *format,...) __attribute__((format(printf
Verbose message if verbose level exceeds level.
Definition ngcbOBJ.cpp:73
virtual char * ErrMsg()
Error message.
Definition ngcbOBJ.cpp:65
ngcbSERVICE * services
System services.
Definition ngcbOBJ.hpp:42
Definition ngcbPARAM.hpp:200
void Clear()
Remove all parameters.
Definition ngcbPARAM_LIST.cpp:135
virtual int Process(void *buffer, ngcdcs_finfo_t *finfo)
Processing call-back.
Definition ngcdcsEXPDRV.hpp:117
int Delay()
Get delay (milliseconds) to be applied before next exposure.
Definition ngcdcsEXPDRV.hpp:114
virtual ~ngcdcsEXPDRV()
Destructor.
Definition ngcdcsEXPDRV.hpp:57
void GetCfg(ngcbPARAM_LIST *cfg)
Get current configuration.
Definition ngcdcsEXPDRV.hpp:77
void Initialized(int flag)
Set initialization flag.
Definition ngcdcsEXPDRV.hpp:127
int Active()
Return active flag.
Definition ngcdcsEXPDRV.hpp:80
int Initialized()
Return initialization flag.
Definition ngcdcsEXPDRV.hpp:65
int NewSetup()
New setup available.
Definition ngcdcsEXPDRV.hpp:83
void Init()
Initiate exposure sequence.
Definition ngcdcsEXPDRV.hpp:86
virtual int Configure(ngcbPARAM_LIST *cfg)
Configuration call-back.
Definition ngcdcsEXPDRV.hpp:74
ngcbPARAM_LIST * paramList
Global parameter list.
Definition ngcdcsEXPDRV.hpp:48
char name[64]
Exposure driver name.
Definition ngcdcsEXPDRV.hpp:33
int Next()
Execute next step in the exposure sequence.
Definition ngcdcsEXPDRV.hpp:89
virtual void Exit(int status)
Exposure sequence exit function.
Definition ngcdcsEXPDRV.hpp:174
void ImgProcessorOn()
Connect image-processor to all exposures.
Definition ngcdcsEXPDRV.hpp:133
void Delay(int ms)
Set a delay (milliseconds) to be applied before next exposure.
Definition ngcdcsEXPDRV.hpp:136
virtual int MergeFits(ngcbFITS *hdr)
FITS-header completion call-back.
Definition ngcdcsEXPDRV.hpp:123
virtual void CfgStatus(ngcbPARAM_LIST *cfg)
Configuration status call-back.
Definition ngcdcsEXPDRV.hpp:177
int Status(const char *paramName, char *value)
Get status value of a system parameter.
Definition ngcdcsEXPDRV.hpp:139
void SendFeedBack(const char *msg)
Feed-back function.
Definition ngcdcsEXPDRV.hpp:180
FILE * FeedBackStream()
Return feed-back stream.
Definition ngcdcsEXPDRV.hpp:68
unsigned int expId
Exposure id.
Definition ngcdcsEXPDRV.hpp:42
ngcdcsEXPDRV(const ngcb_fb_t &fb)
Constructor with feed-back channel.
Definition ngcdcsEXPDRV.hpp:54
ngcbPARAM_LIST setupList
Setup parameter list.
Definition ngcdcsEXPDRV.hpp:45
int ImgProcessor()
Return image-processor flag.
Definition ngcdcsEXPDRV.hpp:71
ngcbFITS fits
Driver specific FITS-header.
Definition ngcdcsEXPDRV.hpp:51
void Terminate(int status=0)
Terminate the exposure sequence.
Definition ngcdcsEXPDRV.hpp:101
int state
State variable.
Definition ngcdcsEXPDRV.hpp:36
virtual int Exec()
Execution-block call-back.
Definition ngcdcsEXPDRV.hpp:171
int acqId
Associated acquisition module id.
Definition ngcdcsEXPDRV.hpp:39
FILE * ngcbDebugOpen(char *erms)
Definition ngcbDebug.c:28
#define USE(x)
Definition ngcb.h:28
#define ngcbABORTED
Definition ngcb.h:138
#define ngcbSUCCESS
Definition ngcb.h:137
#define ngcbFAILURE
Definition ngcb.h:139
Definition ngcbSTREAM.hpp:27
int automatic
Automatic open/close.
Definition ngcbSTREAM.hpp:32
FILE * chan
Stream channel.
Definition ngcbSTREAM.hpp:29
Definition ngcdcsFINFO.hpp:462