FrelonCamera.h 6.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
22
23
24
25
#ifndef FRELONCAMERA_H
#define FRELONCAMERA_H

#include "FrelonSerialLine.h"
26
#include "FrelonModel.h"
27
#include "FrelonTimingCtrl.h"
28
#include "lima/HwMaxImageSizeCallback.h"
29
30
31
32
33
34
35

namespace lima
{

namespace Frelon
{

ahoms's avatar
ahoms committed
36
class Camera : public HwMaxImageSizeCallbackGen
37
{
38
	DEB_CLASS_NAMESPC(DebModCamera, "Camera", "Frelon");
39

40
 public:
41
	Camera(Espia::SerialLine& espia_ser_line);
42
	~Camera();
43

44
45
46
47
	SerialLine& getSerialLine();

	void writeRegister(Reg reg, int  val);
	void readRegister (Reg reg, int& val);
48
	void readFloatRegister(Reg reg, double& val);
49
50

	void hardReset();
51
	void getVersionStr(std::string& ver);
ahoms's avatar
ahoms committed
52
	void getComplexSerialNb(int& complex_ser_nb);
53
	Model& getModel();
ahoms's avatar
ahoms committed
54

55
56
	TimingCtrl& getTimingCtrl();

57
	bool getDefInputChan(FrameTransferMode ftm, InputChan& input_chan);
ahoms's avatar
ahoms committed
58
59
60
61
62
63
	void setInputChan(InputChan  input_chan);
	void getInputChan(InputChan& input_chan);

	void setFrameTransferMode(FrameTransferMode  ftm);
	void getFrameTransferMode(FrameTransferMode& ftm);

64
65
	static std::string getInputChanModeName(FrameTransferMode ftm, 
						InputChan input_chan);
66

67
	void getMaxFrameDim(FrameDim& max_frame_dim);
ahoms's avatar
ahoms committed
68
69
	void getFrameDim(FrameDim& frame_dim);

70
	bool isChanActive(InputChan curr, InputChan chan);
ahoms's avatar
ahoms committed
71

72
73
74
	void checkFlip(Flip& flip);
	void setFlip(const Flip& flip);
	void getFlip(Flip& flip);
ahoms's avatar
ahoms committed
75

76
	void checkBin(Bin& bin);
ahoms's avatar
ahoms committed
77
78
79
80
81
82
	void setBin(const Bin& bin);
	void getBin(Bin& bin);

	void setRoiMode(RoiMode  roi_mode);
	void getRoiMode(RoiMode& roi_mode);

83
84
85
	void checkRoi(const Roi& set_roi, Roi& hw_roi);
	void setRoi(const Roi& set_roi);
	void getRoi(Roi& hw_roi);
ahoms's avatar
ahoms committed
86

87
88
89
	void setRoiBinOffset(const Point& roi_bin_offset);
	void getRoiBinOffset(Point& roi_bin_offset);

90
91
	void setTrigMode(TrigMode  trig_mode);
	void getTrigMode(TrigMode& trig_mode);
ahoms's avatar
ahoms committed
92
93
94
95
	
	void setExpTime(double  exp_time);
	void getExpTime(double& exp_time);

96
97
98
	void setShutMode(ShutMode  shut_mode);
	void getShutMode(ShutMode& shut_mode);

99
100
101
	void setShutCloseTime(double  shut_time);
	void getShutCloseTime(double& shut_time);

102
103
104
105
106
107
108
	void setUserLatTime(double  lat_time);
	void getUserLatTime(double& lat_time);
	void getReadoutTime(double& readout_time);
	void getTransferTime(double& xfer_time);
	void getDeadTime(double& dead_time);
	void setTotalLatTime(double  lat_time);
	void getTotalLatTime(double& lat_time);
ahoms's avatar
ahoms committed
109
110
111
112

	void setNbFrames(int  nb_frames);
	void getNbFrames(int& nb_frames);

113
114
115
	void setSPB2Config(SPB2Config  spb2_config);
	void getSPB2Config(SPB2Config& spb2_config);

116
117
	static std::string getSPB2ConfigName(SPB2Config spb2_config);

118
119
120
121
122
123
124
125
126
	void setExtSyncEnable(ExtSync  ext_sync_ena);
	void getExtSyncEnable(ExtSync& ext_sync_ena);

	void getStatus(Status& status, bool use_ser_line=false,
		       bool read_spb2=false);
	bool waitStatus(Status& status, Status mask, double timeout,
			bool use_ser_line=false, bool read_spb2=false);

	void getImageCount(unsigned int& img_count, bool only_lsw=false);
127

128
129
	void start();
	void stop();
130
	bool isRunning();
131

ahoms's avatar
ahoms committed
132
133
134
 protected:
	virtual void setMaxImageSizeCallbackActive(bool cb_active);

135
 private:
136
	static const double ResetLinkWaitTime;
137
	static const double UpdateCcdStatusTime;
138
	static const double MaxIdleWaitTime;
139
	static const double MaxBusyRetryTime;
140
141

	Espia::Dev& getEspiaDev();
ahoms's avatar
ahoms committed
142

143
	void sync();
144
	void syncRegs();
145
	void syncRegsGoodHTD();
146
	void syncRegsBadHTD();
147

148
	void sendCmd(Cmd cmd);
149

150
151
	int getModesAvail();

ahoms's avatar
ahoms committed
152
153
154
	void setChanMode(int  chan_mode);
	void getChanMode(int& chan_mode);
	
155
156
157
158
159
	void calcBaseChanMode(FrameTransferMode ftm, int& base_chan_mode);
	void calcChanMode(FrameTransferMode ftm, InputChan input_chan,
			  int& chan_mode);
	void calcFTMInputChan(int chan_mode, FrameTransferMode& ftm, 
			      InputChan& input_chan);
ahoms's avatar
ahoms committed
160
161
162
163

	void setFlipMode(int  flip_mode);
	void getFlipMode(int& flip_mode);

164
165
166
167
168
169
170
171
172
	Flip  getMirror();
	Point getNbChan();
	Size  getCcdSize();
	Size  getChanSize();
        Flip  getRoiInsideMirror();

	void writeChanRoi(const Roi& chan_roi);
	void readChanRoi(Roi& chan_roi);

ahoms's avatar
ahoms committed
173
174
	void xformChanCoords(const Point& point, Point& chan_point, 
			     Corner& ref_corner);
175
176
177
178
179
180
	void calcImageRoi(const Roi& chan_roi, const Flip& roi_inside_mirror,
			  Roi& image_roi, Point& roi_bin_offset);
	void calcFinalRoi(const Roi& image_roi, const Point& roi_offset,
			  Roi& final_roi);
	void calcChanRoi(const Roi& image_roi, Roi& chan_roi,
			 Flip& roi_inside_mirror);
181
182
	void calcChanRoiOffset(const Roi& req_roi, const Roi& image_roi,
			       Point& roi_offset);
ahoms's avatar
ahoms committed
183
        void checkRoiMode(const Roi& roi);
184
185
	void processSetRoi(const Roi& req_roi, Roi& hw_roi, Roi& chan_roi, 
			   Point& roi_offset);
186
187
	void resetRoiBinOffset();
	
188
189
	void setTimeUnitFactor(TimeUnitFactor  time_unit_factor);
	void getTimeUnitFactor(TimeUnitFactor& time_unit_factor);
190
	int  calcTimeUnits(double time_sec, TimeUnitFactor time_unit_factor);
191

192
193
194
195
	double getMaxIdleWaitTime();
	bool waitIdleStatus(Status& status, bool use_ser_line=false,
			    bool read_spb2=false);

196
197
	AutoMutex lock();

198
	SerialLine m_ser_line;
199
	Model m_model;
200
	TimingCtrl m_timing_ctrl;
201
202
	Point m_chan_roi_offset;
	Point m_roi_bin_offset;
203
204
	TrigMode m_trig_mode;
	int m_nb_frames;
ahoms's avatar
ahoms committed
205
	bool m_mis_cb_act;
206
207
	Mutex m_lock;
	bool m_started;
208
209
};

210
inline bool Camera::isChanActive(InputChan curr, InputChan chan)
ahoms's avatar
ahoms committed
211
{
212
	return (curr & chan) == chan;
ahoms's avatar
ahoms committed
213
214
};

215
216
217
218
inline AutoMutex Camera::lock()
{
	return AutoMutex(m_lock);
}
ahoms's avatar
ahoms committed
219

220
221
222
223
224
225
226
227
inline bool Camera::waitIdleStatus(Status& status, bool use_ser_line, 
				   bool read_spb2)
{
	status = Wait;
	return waitStatus(status, StatusMask, getMaxIdleWaitTime(),
			  use_ser_line, read_spb2);
}

228
229
230
231
232
233
234

} // namespace Frelon

} // namespace lima


#endif // FRELONCAMERA_H