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