FrelonCamera.h 6.09 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"
ahoms's avatar
ahoms committed
28
#include "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
48
49
	SerialLine& getSerialLine();

	void writeRegister(Reg reg, int  val);
	void readRegister (Reg reg, int& val);

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

54
55
	TimingCtrl& getTimingCtrl();

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

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

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

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

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

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

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

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

82
83
84
	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
85

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

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

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

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

ahoms's avatar
ahoms committed
101
102
103
104
105
106
	void setLatTime(double  lat_time);
	void getLatTime(double& lat_time);

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

107
108
109
	void setSPB2Config(SPB2Config  spb2_config);
	void getSPB2Config(SPB2Config& spb2_config);

110
111
	static std::string getSPB2ConfigName(SPB2Config spb2_config);

112
113
114
115
116
117
118
119
120
	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);
121

122
123
	void start();
	void stop();
124
	bool isRunning();
125

ahoms's avatar
ahoms committed
126
127
128
 protected:
	virtual void setMaxImageSizeCallbackActive(bool cb_active);

129
 private:
130
	static const double ResetLinkWaitTime;
131
	static const double UpdateCcdStatusTime;
132
	static const double MaxIdleWaitTime;
133
	static const double MaxBusyRetryTime;
134
135

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

137
	void sync();
138
	void syncRegs();
139
	void syncRegsGoodHTD();
140
	void syncRegsBadHTD();
141

142
	void sendCmd(Cmd cmd);
143

144
145
	int getModesAvail();

ahoms's avatar
ahoms committed
146
147
148
	void setChanMode(int  chan_mode);
	void getChanMode(int& chan_mode);
	
149
150
151
152
153
	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
154
155
156
157

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

158
159
160
161
162
163
164
165
166
	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
167
168
	void xformChanCoords(const Point& point, Point& chan_point, 
			     Corner& ref_corner);
169
170
171
172
173
174
	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);
175
176
	void calcChanRoiOffset(const Roi& req_roi, const Roi& image_roi,
			       Point& roi_offset);
ahoms's avatar
ahoms committed
177
        void checkRoiMode(const Roi& roi);
178
179
	void processSetRoi(const Roi& req_roi, Roi& hw_roi, Roi& chan_roi, 
			   Point& roi_offset);
180
181
	void resetRoiBinOffset();
	
182
183
	void setTimeUnitFactor(TimeUnitFactor  time_unit_factor);
	void getTimeUnitFactor(TimeUnitFactor& time_unit_factor);
184
	int  calcTimeUnits(double time_sec, TimeUnitFactor time_unit_factor);
185

186
187
188
189
	double getMaxIdleWaitTime();
	bool waitIdleStatus(Status& status, bool use_ser_line=false,
			    bool read_spb2=false);

190
191
	AutoMutex lock();

192
	SerialLine m_ser_line;
193
	Model m_model;
194
	TimingCtrl m_timing_ctrl;
195
196
	Point m_chan_roi_offset;
	Point m_roi_bin_offset;
197
198
	TrigMode m_trig_mode;
	int m_nb_frames;
ahoms's avatar
ahoms committed
199
	bool m_mis_cb_act;
200
201
	Mutex m_lock;
	bool m_started;
202
203
};

204
inline bool Camera::isChanActive(InputChan curr, InputChan chan)
ahoms's avatar
ahoms committed
205
{
206
	return (curr & chan) == chan;
ahoms's avatar
ahoms committed
207
208
};

209
210
211
212
inline AutoMutex Camera::lock()
{
	return AutoMutex(m_lock);
}
ahoms's avatar
ahoms committed
213

214
215
216
217
218
219
220
221
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);
}

222
223
224
225
226
227
228

} // namespace Frelon

} // namespace lima


#endif // FRELONCAMERA_H