FrelonInterface.cpp 21.7 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
26
27
28
29
#include "FrelonInterface.h"
#include <algorithm>

using namespace lima;
using namespace lima::Espia;
using namespace lima::Frelon;
using namespace std;

30
31
32
33
34
/*******************************************************************
 * \brief AcqEndCallback constructor
 *******************************************************************/

Frelon::AcqEndCallback::AcqEndCallback(Camera& cam) 
35
	: m_cam(cam)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{
	DEB_CONSTRUCTOR();
}

Frelon::AcqEndCallback::~AcqEndCallback()
{
	DEB_DESTRUCTOR();
}

void Frelon::AcqEndCallback::acqFinished(const HwFrameInfoType& /*finfo*/)
{
	DEB_MEMBER_FUNCT();
	m_cam.stop();
}


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************
 * \brief EventCallback constructor
 *******************************************************************/

Frelon::EventCallback::EventCallback(HwEventCtrlObj& ctrl_obj) 
	: m_ctrl_obj(ctrl_obj)
{
	DEB_CONSTRUCTOR();
}

Frelon::EventCallback::~EventCallback()
{
	DEB_DESTRUCTOR();
}

void Frelon::EventCallback::processEvent(Event *event)
{
	DEB_MEMBER_FUNCT();
	m_ctrl_obj.reportEvent(event);
}


74
75
76
77
78
79
80
/*******************************************************************
 * \brief DetInfoCtrlObj constructor
 *******************************************************************/

DetInfoCtrlObj::DetInfoCtrlObj(Camera& cam)
	: m_cam(cam)
{
81
	DEB_CONSTRUCTOR();
82
83
84
85
}

DetInfoCtrlObj::~DetInfoCtrlObj()
{
86
	DEB_DESTRUCTOR();
87
88
89
90
}

void DetInfoCtrlObj::getMaxImageSize(Size& max_image_size)
{
91
	DEB_MEMBER_FUNCT();
92
93
94
95
96
97
98
	FrameDim max_frame_dim;
	m_cam.getFrameDim(max_frame_dim);
	max_image_size = max_frame_dim.getSize();
}

void DetInfoCtrlObj::getDetectorImageSize(Size& det_image_size)
{
99
	DEB_MEMBER_FUNCT();
100
101
102
	FrameDim max_frame_dim;
	m_cam.getMaxFrameDim(max_frame_dim);
	det_image_size = max_frame_dim.getSize();
103
104
105
106
}

void DetInfoCtrlObj::getDefImageType(ImageType& def_image_type)
{
107
	DEB_MEMBER_FUNCT();
108
109
110
	FrameDim max_frame_dim;
	m_cam.getMaxFrameDim(max_frame_dim);
	def_image_type = max_frame_dim.getImageType();
111
112
113
114
}

void DetInfoCtrlObj::getCurrImageType(ImageType& curr_image_type)
{
115
	DEB_MEMBER_FUNCT();
116
117
118
119
120
121
122
	FrameDim max_frame_dim;
	m_cam.getFrameDim(max_frame_dim);
	curr_image_type = max_frame_dim.getImageType();
}

void DetInfoCtrlObj::setCurrImageType(ImageType curr_image_type)
{
123
	DEB_MEMBER_FUNCT();
124
125
	ImageType unique_image_type;
	getCurrImageType(unique_image_type);
126
127
128
	if (curr_image_type != unique_image_type)
		THROW_HW_ERROR(InvalidValue) 
			<< "Only " << DEB_VAR1(unique_image_type) << "allowed";
129
130
}

131
void DetInfoCtrlObj::getPixelSize(double& x_size, double& y_size)
132
{
133
	DEB_MEMBER_FUNCT();
134
	Model& model = m_cam.getModel();
135
136
	x_size = y_size = model.getPixelSize();
	DEB_RETURN() << DEB_VAR2(x_size, y_size);
137
138
139
140
}

void DetInfoCtrlObj::getDetectorType(std::string& det_type)
{
141
	DEB_MEMBER_FUNCT();
142
	det_type = "Frelon";
143
	DEB_RETURN() << DEB_VAR1(det_type);
144
145
146
147
}

void DetInfoCtrlObj::getDetectorModel(std::string& det_model)
{
148
	DEB_MEMBER_FUNCT();
149
150
	Model& model = m_cam.getModel();
	det_model = model.getName();
151
	DEB_RETURN() << DEB_VAR1(det_model);
152
153
}

ahoms's avatar
ahoms committed
154
155
void DetInfoCtrlObj::registerMaxImageSizeCallback(
					HwMaxImageSizeCallback& cb)
156
{
157
	DEB_MEMBER_FUNCT();
ahoms's avatar
ahoms committed
158
159
	m_cam.registerMaxImageSizeCallback(cb);
}
160

ahoms's avatar
ahoms committed
161
162
163
164
165
void DetInfoCtrlObj::unregisterMaxImageSizeCallback(
					HwMaxImageSizeCallback& cb)
{
	DEB_MEMBER_FUNCT();
	m_cam.unregisterMaxImageSizeCallback(cb);
166
167
168
169
170
171
172
173
174
175
}


/*******************************************************************
 * \brief BufferCtrlObj constructor
 *******************************************************************/

BufferCtrlObj::BufferCtrlObj(BufferCtrlMgr& buffer_mgr)
	: m_buffer_mgr(buffer_mgr)
{
176
	DEB_CONSTRUCTOR();
177
178
179
180
}

BufferCtrlObj::~BufferCtrlObj()
{
181
	DEB_DESTRUCTOR();
182
183
184
185
}

void BufferCtrlObj::setFrameDim(const FrameDim& frame_dim)
{
186
	DEB_MEMBER_FUNCT();
187
188
189
	m_buffer_mgr.setFrameDim(frame_dim);
}

190
void BufferCtrlObj::getFrameDim(FrameDim& frame_dim)
191
{
192
	DEB_MEMBER_FUNCT();
193
194
195
196
197
	m_buffer_mgr.getFrameDim(frame_dim);
}

void BufferCtrlObj::setNbBuffers(int nb_buffers)
{
198
	DEB_MEMBER_FUNCT();
199
200
201
202
203
	m_buffer_mgr.setNbBuffers(nb_buffers);
}

void BufferCtrlObj::getNbBuffers(int& nb_buffers)
{
204
	DEB_MEMBER_FUNCT();
205
206
207
208
209
	m_buffer_mgr.getNbBuffers(nb_buffers);
}

void BufferCtrlObj::setNbConcatFrames(int nb_concat_frames)
{
210
	DEB_MEMBER_FUNCT();
211
212
213
214
215
	m_buffer_mgr.setNbConcatFrames(nb_concat_frames);
}

void BufferCtrlObj::getNbConcatFrames(int& nb_concat_frames)
{
216
	DEB_MEMBER_FUNCT();
217
218
219
220
221
	m_buffer_mgr.getNbConcatFrames(nb_concat_frames);
}

void BufferCtrlObj::getMaxNbBuffers(int& max_nb_buffers)
{
222
	DEB_MEMBER_FUNCT();
223
224
225
226
227
228
	m_buffer_mgr.getMaxNbBuffers(max_nb_buffers);

}

void *BufferCtrlObj::getBufferPtr(int buffer_nb, int concat_frame_nb)
{
229
	DEB_MEMBER_FUNCT();
230
231
232
233
234
	return m_buffer_mgr.getBufferPtr(buffer_nb, concat_frame_nb);
}

void *BufferCtrlObj::getFramePtr(int acq_frame_nb)
{
235
	DEB_MEMBER_FUNCT();
236
237
238
239
240
	return m_buffer_mgr.getFramePtr(acq_frame_nb);
}

void BufferCtrlObj::getStartTimestamp(Timestamp& start_ts)
{
241
	DEB_MEMBER_FUNCT();
242
243
244
245
246
	m_buffer_mgr.getStartTimestamp(start_ts);
}

void BufferCtrlObj::getFrameInfo(int acq_frame_nb, HwFrameInfoType& info)
{
247
	DEB_MEMBER_FUNCT();
248
249
250
251
252
	m_buffer_mgr.getFrameInfo(acq_frame_nb, info);
}

void BufferCtrlObj::registerFrameCallback(HwFrameCallback& frame_cb)
{
253
	DEB_MEMBER_FUNCT();
254
255
256
257
258
	m_buffer_mgr.registerFrameCallback(frame_cb);
}

void BufferCtrlObj::unregisterFrameCallback(HwFrameCallback& frame_cb)
{
259
	DEB_MEMBER_FUNCT();
260
261
262
263
264
265
266
267
	m_buffer_mgr.unregisterFrameCallback(frame_cb);
}


/*******************************************************************
 * \brief SyncCtrlObj constructor
 *******************************************************************/

268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
SyncCtrlObj::DeadTimeChangedCallback::DeadTimeChangedCallback(SyncCtrlObj *sync)
	: m_sync(sync)
{
	DEB_CONSTRUCTOR();
}

void SyncCtrlObj::DeadTimeChangedCallback::deadTimeChanged(double dead_time)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(dead_time);

	if (!m_sync)
		return;

	ValidRangesType valid_ranges;
	m_sync->getValidRanges(valid_ranges);
	m_sync->validRangesChanged(valid_ranges);
}
	
287
SyncCtrlObj::SyncCtrlObj(Acq& acq, Camera& cam)
288
	: HwSyncCtrlObj(), m_acq(acq), m_cam(cam), m_dead_time_cb(this)
289
{
290
	DEB_CONSTRUCTOR();
291
	m_cam.registerDeadTimeChangedCallback(m_dead_time_cb);
292
293
294
295
}

SyncCtrlObj::~SyncCtrlObj()
{
296
	DEB_DESTRUCTOR();
297
	m_dead_time_cb.m_sync = NULL;
298
299
}

300
301
302
303
304
305
306
307
bool SyncCtrlObj::checkTrigMode(TrigMode trig_mode)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(trig_mode);

	bool valid_mode;
	switch (trig_mode) {
	case IntTrig:
308
	case IntTrigMult:
309
310
311
312
313
314
315
316
317
318
319
320
321
322
	case ExtTrigSingle:
	case ExtTrigMult:
	case ExtGate:
		valid_mode = true;
		break;

	default:
		valid_mode = false;
	}

	DEB_RETURN() << DEB_VAR1(valid_mode);
	return valid_mode;
}

323
324
void SyncCtrlObj::setTrigMode(TrigMode trig_mode)
{
325
	DEB_MEMBER_FUNCT();
326
327
328
329

	if (!checkTrigMode(trig_mode))
		THROW_HW_ERROR(InvalidValue) << "Invalid " 
					     << DEB_VAR1(trig_mode);
330
331
332
333
334
	m_cam.setTrigMode(trig_mode);
}

void SyncCtrlObj::getTrigMode(TrigMode& trig_mode)
{
335
	DEB_MEMBER_FUNCT();
336
337
338
339
340
	m_cam.getTrigMode(trig_mode);
}

void SyncCtrlObj::setExpTime(double exp_time)
{
341
	DEB_MEMBER_FUNCT();
342
343
344
345
346
	m_cam.setExpTime(exp_time);
}

void SyncCtrlObj::getExpTime(double& exp_time)
{
347
	DEB_MEMBER_FUNCT();
348
349
350
351
352
	m_cam.getExpTime(exp_time);
}

void SyncCtrlObj::setLatTime(double lat_time)
{
353
	DEB_MEMBER_FUNCT();
354
	m_cam.setTotalLatTime(lat_time);
355
356
357
358
}

void SyncCtrlObj::getLatTime(double& lat_time)
{
359
	DEB_MEMBER_FUNCT();
360
	m_cam.getTotalLatTime(lat_time);
361
362
}

363
void SyncCtrlObj::setNbHwFrames(int nb_frames)
364
{
365
366
367
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(nb_frames);

368
	m_acq.setNbFrames(nb_frames);
369
370
371

	int cam_nb_frames = nb_frames;
	if (cam_nb_frames > MaxRegVal) {
372
		DEB_TRACE() << "Too many frames: setting camera endless acq";
373
		cam_nb_frames = 0;
374
	}
375
376

	m_cam.setNbFrames(cam_nb_frames);
377
378
}

379
void SyncCtrlObj::getNbHwFrames(int& nb_frames)
380
{
381
	DEB_MEMBER_FUNCT();
382
383
384
385
386
	m_acq.getNbFrames(nb_frames);
}

void SyncCtrlObj::getValidRanges(ValidRangesType& valid_ranges)
{
387
388
	DEB_MEMBER_FUNCT();

ahoms's avatar
ahoms committed
389
390
391
392
393
394
395
	const double MinTimeUnit = TimeUnitFactorMap[Microseconds];
	const double MaxTimeUnit = TimeUnitFactorMap[Milliseconds];
	const double LatTimeUnit = TimeUnitFactorMap[Milliseconds];

	valid_ranges.min_exp_time = 1 * MinTimeUnit;
	valid_ranges.max_exp_time = MaxRegVal * MaxTimeUnit;

396
397
398
399
	double dead_time;
	m_cam.getDeadTime(dead_time);
	valid_ranges.min_lat_time = dead_time;
	valid_ranges.max_lat_time = dead_time + MaxRegVal * LatTimeUnit;
ahoms's avatar
ahoms committed
400
401
402
403
404

	DEB_RETURN() << DEB_VAR2(valid_ranges.min_exp_time, 
				 valid_ranges.max_exp_time);
	DEB_RETURN() << DEB_VAR2(valid_ranges.min_lat_time, 
				 valid_ranges.max_lat_time);
405
406
407
}


408
409
410
411
/*******************************************************************
 * \brief BinCtrlObj constructor
 *******************************************************************/

412
413
414
415
416
417
418
419
420
421
422
423
424
BinChangedCallback::BinChangedCallback()
	: m_bin_ctrl_obj(NULL)
{
	DEB_CONSTRUCTOR();
}

BinChangedCallback::~BinChangedCallback()
{
	DEB_DESTRUCTOR();
	if (m_bin_ctrl_obj != NULL)
		m_bin_ctrl_obj->unregisterBinChangedCallback(*this);
}

425
BinCtrlObj::BinCtrlObj(Camera& cam)
426
	: m_cam(cam), m_bin_chg_cb(NULL)
427
{
428
	DEB_CONSTRUCTOR();
429
430
431
432
}

BinCtrlObj::~BinCtrlObj()
{
433
	DEB_DESTRUCTOR();
434
435
	if (m_bin_chg_cb)
		m_bin_chg_cb->m_bin_ctrl_obj = NULL;
436
437
438
439
}

void BinCtrlObj::setBin(const Bin& bin)
{
440
	DEB_MEMBER_FUNCT();
441
	m_cam.setBin(bin);
442
443
444
445
446
447
448

	if (m_bin_chg_cb) {
		DEB_TRACE() << "Firing change callback";
		Bin hw_bin;
		getBin(hw_bin);
		m_bin_chg_cb->hwBinChanged(hw_bin);
	}
449
450
451
452
}

void BinCtrlObj::getBin(Bin& bin)
{
453
	DEB_MEMBER_FUNCT();
454
455
456
457
458
	m_cam.getBin(bin);
}

void BinCtrlObj::checkBin(Bin& bin)
{
459
	DEB_MEMBER_FUNCT();
460
461
462
	m_cam.checkBin(bin);
}

463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
void BinCtrlObj::registerBinChangedCallback(BinChangedCallback& bin_chg_cb)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR2(&bin_chg_cb, m_bin_chg_cb);

	if (m_bin_chg_cb != NULL)
		THROW_HW_ERROR(InvalidValue) << "a cb is already registered";

	m_bin_chg_cb = &bin_chg_cb;
	bin_chg_cb.m_bin_ctrl_obj = this;

	DEB_TRACE() << "Firing first callback for update";
	Bin hw_bin;
	getBin(hw_bin);
	m_bin_chg_cb->hwBinChanged(hw_bin);
}

void BinCtrlObj::unregisterBinChangedCallback(BinChangedCallback& bin_chg_cb)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR2(&bin_chg_cb, m_bin_chg_cb);

	if (&bin_chg_cb != m_bin_chg_cb)
		THROW_HW_ERROR(InvalidValue) << "cb is not registered";

	m_bin_chg_cb = NULL;
	bin_chg_cb.m_bin_ctrl_obj = NULL;
}

492
493
494
495
496

/*******************************************************************
 * \brief RoiCtrlObj constructor
 *******************************************************************/

497
498
499
500
501
502
503
504
505
506
507
508
509
510
RoiChangedCallback::RoiChangedCallback()
	: m_roi_ctrl_obj(NULL)
{
	DEB_CONSTRUCTOR();
}

RoiChangedCallback::~RoiChangedCallback()
{
	DEB_DESTRUCTOR();

	if (m_roi_ctrl_obj != NULL)
		m_roi_ctrl_obj->unregisterRoiChangedCallback(*this);
}

511
512
RoiCtrlObj::RoiCtrlObj(Espia::Acq& acq, Camera& cam)
	: m_acq(acq), m_cam(cam), m_roi_chg_cb(NULL)
513
{
514
	DEB_CONSTRUCTOR();
515
516
517
518
}

RoiCtrlObj::~RoiCtrlObj()
{
519
	DEB_DESTRUCTOR();
520
521
522

	if (m_roi_chg_cb)
		m_roi_chg_cb->m_roi_ctrl_obj = NULL;
523
524
525
526
}

void RoiCtrlObj::checkRoi(const Roi& set_roi, Roi& hw_roi)
{
527
	DEB_MEMBER_FUNCT();
528
	m_cam.checkRoi(set_roi, hw_roi);
529
530
531
532

	Size det_frame_size;
	Roi espia_roi;
	checkEspiaRoi(set_roi, hw_roi, det_frame_size, espia_roi);
533
534
}

535
void RoiCtrlObj::setRoi(const Roi& set_roi)
536
{
537
	DEB_MEMBER_FUNCT();
538
539
540
541
542
543
544
	m_cam.setRoi(set_roi);

	Roi hw_roi, espia_roi;
	m_cam.getRoi(hw_roi);
	Size det_frame_size;
	checkEspiaRoi(set_roi, hw_roi, det_frame_size, espia_roi);
	m_acq.setSGRoi(det_frame_size, espia_roi);
545
546
547
548
549

	if (m_roi_chg_cb) {
		DEB_TRACE() << "Firing change callback";
		m_roi_chg_cb->hwRoiChanged(hw_roi);
	}
550
551
}

552
void RoiCtrlObj::getRoi(Roi& hw_roi)
553
{
554
	DEB_MEMBER_FUNCT();
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
	m_cam.getRoi(hw_roi);

	Size det_frame_size;
	Roi espia_roi;
	m_acq.getSGRoi(det_frame_size, espia_roi);
	if (!espia_roi.isEmpty()) {
		if (det_frame_size != hw_roi.getSize())
			THROW_HW_ERROR(Error) << "Camera/Espia roi mismatch: "
					      << DEB_VAR2(det_frame_size, 
							  hw_roi);
		Roi final_hw_roi = hw_roi.subRoiRel2Abs(espia_roi);
		hw_roi = final_hw_roi;
	}

	DEB_RETURN() << DEB_VAR1(hw_roi);
}
 
void RoiCtrlObj::checkEspiaRoi(const Roi& set_roi, Roi& hw_roi, 
			       Size& det_frame_size, Roi& espia_roi)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR2(set_roi, hw_roi);

	det_frame_size = hw_roi.getSize();

580
	bool sg_roi = (!set_roi.isEmpty() && (hw_roi != set_roi));
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
	if (sg_roi) {
		espia_roi = hw_roi.subRoiAbs2Rel(set_roi);
		int width = set_roi.getSize().getWidth();
		bool horz_match = ((espia_roi.getTopLeft().x == 0) && 
				   (espia_roi.getSize().getWidth() == width));
		sg_roi = (horz_match && ((width % 4) == 0));
	}

	if (sg_roi) {
		DEB_TRACE() << "Horz. aligned roi qualifies for Espia SG!";
		hw_roi = set_roi;
	} else
		espia_roi.reset();

	DEB_RETURN() << DEB_VAR3(hw_roi, det_frame_size, espia_roi);
596
597
}

598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
void RoiCtrlObj::registerRoiChangedCallback(RoiChangedCallback& roi_chg_cb)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR2(&roi_chg_cb, m_roi_chg_cb);

	if (m_roi_chg_cb != NULL)
		THROW_HW_ERROR(InvalidValue) << "a cb is already registered";

	m_roi_chg_cb = &roi_chg_cb;
	roi_chg_cb.m_roi_ctrl_obj = this;

	DEB_TRACE() << "Firing first callback for update";
	Roi hw_roi;
	getRoi(hw_roi);
	m_roi_chg_cb->hwRoiChanged(hw_roi);
}

void RoiCtrlObj::unregisterRoiChangedCallback(RoiChangedCallback& roi_chg_cb)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR2(&roi_chg_cb, m_roi_chg_cb);

	if (&roi_chg_cb != m_roi_chg_cb)
		THROW_HW_ERROR(InvalidValue) << "cb is not registered";

	m_roi_chg_cb = NULL;
	roi_chg_cb.m_roi_ctrl_obj = NULL;
}

627

628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
/*******************************************************************
 * \brief FlipCtrlObj constructor
 *******************************************************************/

FlipCtrlObj::FlipCtrlObj(Camera& cam)
	: m_cam(cam)
{
	DEB_CONSTRUCTOR();
}

FlipCtrlObj::~FlipCtrlObj()
{
	DEB_DESTRUCTOR();
}

void FlipCtrlObj::setFlip(const Flip& flip)
{
	DEB_MEMBER_FUNCT();
	m_cam.setFlip(flip);
}

void FlipCtrlObj::getFlip(Flip& flip)
{
	DEB_MEMBER_FUNCT();
	m_cam.getFlip(flip);
}

void FlipCtrlObj::checkFlip(Flip& flip)
{
	DEB_MEMBER_FUNCT();
	m_cam.checkFlip(flip);
}


662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
/*******************************************************************
 * \brief ShutterCtrlObj constructor
 *******************************************************************/

ShutterCtrlObj::ShutterCtrlObj(Camera& cam)
	: m_cam(cam)
{
	DEB_CONSTRUCTOR();
}

ShutterCtrlObj::~ShutterCtrlObj()
{
	DEB_DESTRUCTOR();
}

677
bool ShutterCtrlObj::checkMode(ShutterMode shut_mode) const
678
679
{
	DEB_MEMBER_FUNCT();
680
	DEB_PARAM() << DEB_VAR1(shut_mode);
681
682

	bool valid_mode;
683
	switch (shut_mode) {
684
685
	case ShutterManual:
	case ShutterAutoFrame:
686
687
688
689
690
691
692
693
694
695
		valid_mode = true;
		break;
	default:
		valid_mode = false;
	}

	DEB_RETURN() << DEB_VAR1(valid_mode);
	return valid_mode;
}

696
697
698
699
700
701
702
703
void ShutterCtrlObj::getModeList(ShutterModeList& mode_list) const
{
	DEB_MEMBER_FUNCT();
	mode_list.push_back(lima::ShutterManual);
	mode_list.push_back(lima::ShutterAutoFrame);	
}

void ShutterCtrlObj::setMode(ShutterMode shut_mode)
704
705
{
	DEB_MEMBER_FUNCT();
706
	DEB_PARAM() << DEB_VAR1(shut_mode);
707

708
	if (!checkMode(shut_mode))
709
		THROW_HW_ERROR(NotSupported) << "Invalid (not supported) " 
710
					     << DEB_VAR1(shut_mode);
711
712

	ShutMode cam_mode;
713
714
	cam_mode = (shut_mode == ShutterAutoFrame) ? Frelon::AutoFrame : 
	  					     Frelon::Off;
715
716
717
	m_cam.setShutMode(cam_mode);
}

718
void ShutterCtrlObj::getMode(ShutterMode& shut_mode) const
719
720
721
722
723
{
	DEB_MEMBER_FUNCT();

	ShutMode cam_mode;
	m_cam.getShutMode(cam_mode);
724
725
	shut_mode = (cam_mode == Frelon::AutoFrame) ? ShutterAutoFrame : 
	  					      ShutterManual;
726
	DEB_RETURN() << DEB_VAR1(shut_mode);
727
728
729
730
731
732
733
}

void ShutterCtrlObj::setState(bool open)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(open);

734
	ShutterMode mode;
735
	getMode(mode);
736
	if (mode != ShutterManual)
737
		THROW_HW_ERROR(NotSupported) << "Not in manual shutter mode";
738
739
740
741
742
	else if (open)
		THROW_HW_ERROR(NotSupported) << "Manual shutter open "
					        "not supported";
}

743
void ShutterCtrlObj::getState(bool& open) const
744
745
746
{
	DEB_MEMBER_FUNCT();

747
	ShutterMode mode;
748
	getMode(mode);
749
	if (mode != ShutterManual)
750
		THROW_HW_ERROR(NotSupported) << "Not in manual shutter mode";
751
752
753
754
755
756
757
758
759
760
761

	open = false;
	DEB_RETURN() << DEB_VAR1(open);
}

void ShutterCtrlObj::setOpenTime(double shut_open_time)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(shut_open_time);

	if (shut_open_time != 0)
762
763
		THROW_HW_ERROR(NotSupported) << "Shutter open time not "
						"supported";
764
765
}

766
void ShutterCtrlObj::getOpenTime(double& shut_open_time) const
767
768
769
770
771
772
773
774
775
776
777
778
{
	DEB_MEMBER_FUNCT();
	shut_open_time = 0;
	DEB_RETURN() << DEB_VAR1(shut_open_time);
}

void ShutterCtrlObj::setCloseTime(double shut_close_time)
{
	DEB_MEMBER_FUNCT();
	m_cam.setShutCloseTime(shut_close_time);
}

779
void ShutterCtrlObj::getCloseTime(double& shut_close_time) const
780
781
782
783
784
785
{
	DEB_MEMBER_FUNCT();
	m_cam.getShutCloseTime(shut_close_time);
}


786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
/*******************************************************************
 * \brief ShutterCtrlObj constructor
 *******************************************************************/

EventCtrlObj::EventCtrlObj()
{
	DEB_CONSTRUCTOR();
}

EventCtrlObj::~EventCtrlObj()
{
	DEB_DESTRUCTOR();
}


801
802
803
804
/*******************************************************************
 * \brief Hw Interface constructor
 *******************************************************************/

805
Interface::Interface(Espia::Acq& acq, BufferCtrlMgr& buffer_mgr,
806
		     Camera& cam)
807
	: m_acq(acq), m_buffer_mgr(buffer_mgr), m_cam(cam),
808
	  m_det_info(cam), m_buffer(buffer_mgr), m_sync(acq, cam), 
809
810
	  m_bin(cam), m_roi(acq, cam), m_flip(cam), m_shutter(cam),
	  m_acq_end_cb(cam), m_event_cb(m_event)
811
{
812
813
	DEB_CONSTRUCTOR();

814
	m_acq.registerAcqEndCallback(m_acq_end_cb);
815
	m_acq.registerEventCallback(m_event_cb);
816

817
818
819
820
821
822
823
824
825
826
827
828
	HwDetInfoCtrlObj *det_info = &m_det_info;
	m_cap_list.push_back(HwCap(det_info));

	HwBufferCtrlObj *buffer = &m_buffer;
	m_cap_list.push_back(HwCap(buffer));

	HwSyncCtrlObj *sync = &m_sync;
	m_cap_list.push_back(HwCap(sync));

	HwBinCtrlObj *bin = &m_bin;
	m_cap_list.push_back(HwCap(bin));

829
830
831
	HwRoiCtrlObj *roi = &m_roi;
	m_cap_list.push_back(HwCap(roi));

832
833
834
	HwFlipCtrlObj *flip = &m_flip;
	m_cap_list.push_back(HwCap(flip));

835
836
837
	HwShutterCtrlObj *shutter = &m_shutter;
	m_cap_list.push_back(HwCap(shutter));

838
839
840
	HwEventCtrlObj *event = &m_event;
	m_cap_list.push_back(HwCap(event));

841
	reset(SoftReset);
842
	resetDefaults();
843
844
845
846
}

Interface::~Interface()
{
847
	DEB_DESTRUCTOR();
848
849
}

850
void Interface::getCapList(HwInterface::CapList &cap_list) const
851
{
852
	DEB_MEMBER_FUNCT();
853
	cap_list = m_cap_list;
854
855
856
857
}

void Interface::reset(ResetLevel reset_level)
{
858
859
860
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(reset_level);

ahoms's avatar
ahoms committed
861
	stopAcq();
862

863
864
	if (reset_level == HardReset) {
		DEB_TRACE() << "Performing camera hard reset";
865
		m_cam.hardReset();
866
867

		resetDefaults();
868
	}
869
870
871
872
873
874
875
876
}

void Interface::resetDefaults()
{
	DEB_MEMBER_FUNCT();
	DEB_TRACE() << "Setting default configuration";

	stopAcq();
877

878
	FrameTransferMode ftm;
879
	InputChan input_chan;
880
881
882
883
	if (!m_cam.getDefInputChan(ftm=FFM, input_chan)	&&
	    !m_cam.getDefInputChan(ftm=FTM, input_chan))
		THROW_HW_ERROR(Error) << "Cannot find default input channel!!";
	m_cam.setFrameTransferMode(ftm);
884
	m_cam.setInputChan(input_chan);
885
886

	m_flip.setFlip(Flip(false));
887
888
889
890

	m_sync.setNbFrames(1);
	m_sync.setExpTime(1.0);
	m_sync.setTrigMode(IntTrig);
891
	m_cam.setUserLatTime(0.0);
892

893
894
	m_shutter.setMode(ShutterAutoFrame);
	m_shutter.setCloseTime(0.0);
895

896
	m_cam.setRoiBinOffset(Point(0));
897
	m_bin.setBin(Bin(1));
898
	m_roi.setRoi(Roi());
899
900
901
902
903
904
905
906
907
908
909
910
911
912
	
	Size image_size;
	m_det_info.getMaxImageSize(image_size);
	ImageType image_type;
	m_det_info.getDefImageType(image_type);
	FrameDim frame_dim(image_size, image_type);
	m_buffer.setFrameDim(frame_dim);

	m_buffer.setNbConcatFrames(1);
	m_buffer.setNbBuffers(1);
}

void Interface::prepareAcq()
{
913
	DEB_MEMBER_FUNCT();
914
915
916
917
}

void Interface::startAcq()
{
918
	DEB_MEMBER_FUNCT();
919

920
921
	TrigMode trig_mode;
	m_cam.getTrigMode(trig_mode);
922
923
	bool was_running = (trig_mode == IntTrigMult) && m_cam.isRunning();
	if (!was_running) {
924
925
926
927
		m_buffer_mgr.setStartTimestamp(Timestamp::now());
		m_acq.start();
	}

928
929
930
	try {
		m_cam.start();
	} catch (...) {
931
		if (!was_running)
932
			m_acq.stop();
933
934
		throw;
	}
935
936
937
938
}

void Interface::stopAcq()
{
939
	DEB_MEMBER_FUNCT();
940
941
942
943
944
945
	m_cam.stop();
	m_acq.stop();
}

void Interface::getStatus(StatusType& status)
{
946
	DEB_MEMBER_FUNCT();
947
948

	status.acq = m_cam.isRunning() ? AcqRunning : AcqReady;
949

950
951
952
953
	static const DetStatus det_mask = 
		(DetWaitForTrigger | DetExposure    | DetShutterClose   | 
		 DetChargeShift    | DetReadout     | DetLatency);

954
955
956
957
958
	status.det_mask = det_mask;
	status.det = DetIdle;
	Frelon::Status cam;
	m_cam.getStatus(cam);
	if (cam & Frelon::Wait)
959
		status.det |= DetWaitForTrigger;
960
	if (cam & Frelon::Exposure)
961
		status.det |= DetExposure;
962
	if (cam & Frelon::Shutter)
963
		status.det |= DetShutterClose;
964
	if (cam & Frelon::Transfer)
965
		status.det |= DetChargeShift;
966
	if (cam & Frelon::Readout)
967
		status.det |= DetReadout;
968
	if (cam & Frelon::Latency)
969
		status.det |= DetLatency;
970

971
972
973
974
975
	TrigMode trig_mode;
	m_cam.getTrigMode(trig_mode);
	if ((trig_mode == IntTrigMult) && (status.det == DetWaitForTrigger))
		status.det = DetIdle;

976
	DEB_RETURN() << DEB_VAR1(status);
977
978
}

979
int Interface::getNbHwAcquiredFrames()
980
{
981
	DEB_MEMBER_FUNCT();
982
983
	Acq::Status acq_status;
	m_acq.getStatus(acq_status);
984
985
986
	int nb_hw_acq_frames = acq_status.last_frame_nb + 1;
	DEB_RETURN() << DEB_VAR1(nb_hw_acq_frames);
	return nb_hw_acq_frames;
987
988
989
}