FrelonInterface.cpp 20.5 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
SyncCtrlObj::SyncCtrlObj(Acq& acq, Camera& cam)
	: HwSyncCtrlObj(), m_acq(acq), m_cam(cam)
270
{
271
	DEB_CONSTRUCTOR();
272
273
274
275
}

SyncCtrlObj::~SyncCtrlObj()
{
276
	DEB_DESTRUCTOR();
277
278
}

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
bool SyncCtrlObj::checkTrigMode(TrigMode trig_mode)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(trig_mode);

	bool valid_mode;
	switch (trig_mode) {
	case IntTrig:
	case ExtTrigSingle:
	case ExtTrigMult:
	case ExtGate:
		valid_mode = true;
		break;

	default:
		valid_mode = false;
	}

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

301
302
void SyncCtrlObj::setTrigMode(TrigMode trig_mode)
{
303
	DEB_MEMBER_FUNCT();
304
305
306
307

	if (!checkTrigMode(trig_mode))
		THROW_HW_ERROR(InvalidValue) << "Invalid " 
					     << DEB_VAR1(trig_mode);
308
309
310
311
312
	m_cam.setTrigMode(trig_mode);
}

void SyncCtrlObj::getTrigMode(TrigMode& trig_mode)
{
313
	DEB_MEMBER_FUNCT();
314
315
316
317
318
	m_cam.getTrigMode(trig_mode);
}

void SyncCtrlObj::setExpTime(double exp_time)
{
319
	DEB_MEMBER_FUNCT();
320
321
322
323
324
	m_cam.setExpTime(exp_time);
}

void SyncCtrlObj::getExpTime(double& exp_time)
{
325
	DEB_MEMBER_FUNCT();
326
327
328
329
330
	m_cam.getExpTime(exp_time);
}

void SyncCtrlObj::setLatTime(double lat_time)
{
331
	DEB_MEMBER_FUNCT();
332
333
334
335
336
	m_cam.setLatTime(lat_time);
}

void SyncCtrlObj::getLatTime(double& lat_time)
{
337
	DEB_MEMBER_FUNCT();
338
339
340
	m_cam.getLatTime(lat_time);
}

341
void SyncCtrlObj::setNbHwFrames(int nb_frames)
342
{
343
344
345
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(nb_frames);

346
	m_acq.setNbFrames(nb_frames);
347
348
349

	int cam_nb_frames = nb_frames;
	if (cam_nb_frames > MaxRegVal) {
350
		DEB_TRACE() << "Too many frames: setting camera endless acq";
351
		cam_nb_frames = 0;
352
	}
353
354

	m_cam.setNbFrames(cam_nb_frames);
355
356
}

357
void SyncCtrlObj::getNbHwFrames(int& nb_frames)
358
{
359
	DEB_MEMBER_FUNCT();
360
361
362
363
364
	m_acq.getNbFrames(nb_frames);
}

void SyncCtrlObj::getValidRanges(ValidRangesType& valid_ranges)
{
365
366
	DEB_MEMBER_FUNCT();

ahoms's avatar
ahoms committed
367
368
369
370
371
372
373
374
375
376
377
378
379
380
	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;

	valid_ranges.min_lat_time = 0 * LatTimeUnit;
	valid_ranges.max_lat_time = MaxRegVal * LatTimeUnit;

	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);
381
382
383
}


384
385
386
387
/*******************************************************************
 * \brief BinCtrlObj constructor
 *******************************************************************/

388
389
390
391
392
393
394
395
396
397
398
399
400
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);
}

401
BinCtrlObj::BinCtrlObj(Camera& cam)
402
	: m_cam(cam), m_bin_chg_cb(NULL)
403
{
404
	DEB_CONSTRUCTOR();
405
406
407
408
}

BinCtrlObj::~BinCtrlObj()
{
409
	DEB_DESTRUCTOR();
410
411
	if (m_bin_chg_cb)
		m_bin_chg_cb->m_bin_ctrl_obj = NULL;
412
413
414
415
}

void BinCtrlObj::setBin(const Bin& bin)
{
416
	DEB_MEMBER_FUNCT();
417
	m_cam.setBin(bin);
418
419
420
421
422
423
424

	if (m_bin_chg_cb) {
		DEB_TRACE() << "Firing change callback";
		Bin hw_bin;
		getBin(hw_bin);
		m_bin_chg_cb->hwBinChanged(hw_bin);
	}
425
426
427
428
}

void BinCtrlObj::getBin(Bin& bin)
{
429
	DEB_MEMBER_FUNCT();
430
431
432
433
434
	m_cam.getBin(bin);
}

void BinCtrlObj::checkBin(Bin& bin)
{
435
	DEB_MEMBER_FUNCT();
436
437
438
	m_cam.checkBin(bin);
}

439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
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;
}

468
469
470
471
472

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

473
474
475
476
477
478
479
480
481
482
483
484
485
486
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);
}

487
488
RoiCtrlObj::RoiCtrlObj(Espia::Acq& acq, Camera& cam)
	: m_acq(acq), m_cam(cam), m_roi_chg_cb(NULL)
489
{
490
	DEB_CONSTRUCTOR();
491
492
493
494
}

RoiCtrlObj::~RoiCtrlObj()
{
495
	DEB_DESTRUCTOR();
496
497
498

	if (m_roi_chg_cb)
		m_roi_chg_cb->m_roi_ctrl_obj = NULL;
499
500
501
502
}

void RoiCtrlObj::checkRoi(const Roi& set_roi, Roi& hw_roi)
{
503
	DEB_MEMBER_FUNCT();
504
	m_cam.checkRoi(set_roi, hw_roi);
505
506
507
508

	Size det_frame_size;
	Roi espia_roi;
	checkEspiaRoi(set_roi, hw_roi, det_frame_size, espia_roi);
509
510
}

511
void RoiCtrlObj::setRoi(const Roi& set_roi)
512
{
513
	DEB_MEMBER_FUNCT();
514
515
516
517
518
519
520
	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);
521
522
523
524
525

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

528
void RoiCtrlObj::getRoi(Roi& hw_roi)
529
{
530
	DEB_MEMBER_FUNCT();
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
	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();

556
	bool sg_roi = (!set_roi.isEmpty() && (hw_roi != set_roi));
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
	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);
572
573
}

574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
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;
}

603

604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/*******************************************************************
 * \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);
}


638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
/*******************************************************************
 * \brief ShutterCtrlObj constructor
 *******************************************************************/

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

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

653
bool ShutterCtrlObj::checkMode(ShutterMode shut_mode) const
654
655
{
	DEB_MEMBER_FUNCT();
656
	DEB_PARAM() << DEB_VAR1(shut_mode);
657
658

	bool valid_mode;
659
	switch (shut_mode) {
660
661
	case ShutterManual:
	case ShutterAutoFrame:
662
663
664
665
666
667
668
669
670
671
		valid_mode = true;
		break;
	default:
		valid_mode = false;
	}

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

672
673
674
675
676
677
678
679
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)
680
681
{
	DEB_MEMBER_FUNCT();
682
	DEB_PARAM() << DEB_VAR1(shut_mode);
683

684
	if (!checkMode(shut_mode))
685
		THROW_HW_ERROR(NotSupported) << "Invalid (not supported) " 
686
					     << DEB_VAR1(shut_mode);
687
688

	ShutMode cam_mode;
689
690
	cam_mode = (shut_mode == ShutterAutoFrame) ? Frelon::AutoFrame : 
	  					     Frelon::Off;
691
692
693
	m_cam.setShutMode(cam_mode);
}

694
void ShutterCtrlObj::getMode(ShutterMode& shut_mode) const
695
696
697
698
699
{
	DEB_MEMBER_FUNCT();

	ShutMode cam_mode;
	m_cam.getShutMode(cam_mode);
700
701
	shut_mode = (cam_mode == Frelon::AutoFrame) ? ShutterAutoFrame : 
	  					      ShutterManual;
702
	DEB_RETURN() << DEB_VAR1(shut_mode);
703
704
705
706
707
708
709
}

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

710
	ShutterMode mode;
711
	getMode(mode);
712
	if (mode != ShutterManual)
713
		THROW_HW_ERROR(NotSupported) << "Not in manual shutter mode";
714
715
716
717
718
	else if (open)
		THROW_HW_ERROR(NotSupported) << "Manual shutter open "
					        "not supported";
}

719
void ShutterCtrlObj::getState(bool& open) const
720
721
722
{
	DEB_MEMBER_FUNCT();

723
	ShutterMode mode;
724
	getMode(mode);
725
	if (mode != ShutterManual)
726
		THROW_HW_ERROR(NotSupported) << "Not in manual shutter mode";
727
728
729
730
731
732
733
734
735
736
737

	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)
738
739
		THROW_HW_ERROR(NotSupported) << "Shutter open time not "
						"supported";
740
741
}

742
void ShutterCtrlObj::getOpenTime(double& shut_open_time) const
743
744
745
746
747
748
749
750
751
752
753
754
{
	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);
}

755
void ShutterCtrlObj::getCloseTime(double& shut_close_time) const
756
757
758
759
760
761
{
	DEB_MEMBER_FUNCT();
	m_cam.getShutCloseTime(shut_close_time);
}


762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
/*******************************************************************
 * \brief ShutterCtrlObj constructor
 *******************************************************************/

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

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


777
778
779
780
/*******************************************************************
 * \brief Hw Interface constructor
 *******************************************************************/

781
Interface::Interface(Espia::Acq& acq, BufferCtrlMgr& buffer_mgr,
782
		     Camera& cam)
783
	: m_acq(acq), m_buffer_mgr(buffer_mgr), m_cam(cam),
784
	  m_det_info(cam), m_buffer(buffer_mgr), m_sync(acq, cam), 
785
786
	  m_bin(cam), m_roi(acq, cam), m_flip(cam), m_shutter(cam),
	  m_acq_end_cb(cam), m_event_cb(m_event)
787
{
788
789
	DEB_CONSTRUCTOR();

790
	m_acq.registerAcqEndCallback(m_acq_end_cb);
791
	m_acq.registerEventCallback(m_event_cb);
792

793
794
795
796
797
798
799
800
801
802
803
804
	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));

805
806
807
	HwRoiCtrlObj *roi = &m_roi;
	m_cap_list.push_back(HwCap(roi));

808
809
810
	HwFlipCtrlObj *flip = &m_flip;
	m_cap_list.push_back(HwCap(flip));

811
812
813
	HwShutterCtrlObj *shutter = &m_shutter;
	m_cap_list.push_back(HwCap(shutter));

814
815
816
	HwEventCtrlObj *event = &m_event;
	m_cap_list.push_back(HwCap(event));

817
818
819
820
821
	reset(SoftReset);
}

Interface::~Interface()
{
822
	DEB_DESTRUCTOR();
823
824
}

825
void Interface::getCapList(HwInterface::CapList &cap_list) const
826
{
827
	DEB_MEMBER_FUNCT();
828
	cap_list = m_cap_list;
829
830
831
832
}

void Interface::reset(ResetLevel reset_level)
{
833
834
835
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(reset_level);

ahoms's avatar
ahoms committed
836
	stopAcq();
837

838
839
	if (reset_level == HardReset) {
		DEB_TRACE() << "Performing camera hard reset";
840
		m_cam.hardReset();
841
	}
842
843

	m_cam.setFrameTransferMode(FFM);
844
845
846
	InputChan input_chan;
	m_cam.getDefInputChan(FFM, input_chan);
	m_cam.setInputChan(input_chan);
847
848

	m_flip.setFlip(Flip(false));
849
850
851
852
853
854

	m_sync.setNbFrames(1);
	m_sync.setExpTime(1.0);
	m_sync.setLatTime(0.0);
	m_sync.setTrigMode(IntTrig);

855
856
	m_shutter.setMode(ShutterAutoFrame);
	m_shutter.setCloseTime(0.0);
857

858
	m_cam.setRoiBinOffset(Point(0));
859
	m_bin.setBin(Bin(1));
860
	m_roi.setRoi(Roi());
861
862
863
864
865
866
867
868
869
870
871
872
873
874
	
	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()
{
875
	DEB_MEMBER_FUNCT();
876
877
878
879
}

void Interface::startAcq()
{
880
	DEB_MEMBER_FUNCT();
881

882
	m_buffer_mgr.setStartTimestamp(Timestamp::now());
883
	m_acq.start();
884
885
886
887
888
889
	try {
		m_cam.start();
	} catch (...) {
		m_acq.stop();
		throw;
	}
890
891
892
893
}

void Interface::stopAcq()
{
894
	DEB_MEMBER_FUNCT();
895
896
897
898
899
900
	m_cam.stop();
	m_acq.stop();
}

void Interface::getStatus(StatusType& status)
{
901
	DEB_MEMBER_FUNCT();
902
903

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

905
906
907
908
	static const DetStatus det_mask = 
		(DetWaitForTrigger | DetExposure    | DetShutterClose   | 
		 DetChargeShift    | DetReadout     | DetLatency);

909
910
911
912
913
	status.det_mask = det_mask;
	status.det = DetIdle;
	Frelon::Status cam;
	m_cam.getStatus(cam);
	if (cam & Frelon::Wait)
914
		status.det |= DetWaitForTrigger;
915
	if (cam & Frelon::Exposure)
916
		status.det |= DetExposure;
917
	if (cam & Frelon::Shutter)
918
		status.det |= DetShutterClose;
919
	if (cam & Frelon::Transfer)
920
		status.det |= DetChargeShift;
921
	if (cam & Frelon::Readout)
922
		status.det |= DetReadout;
923
	if (cam & Frelon::Latency)
924
		status.det |= DetLatency;
925
926

	DEB_RETURN() << DEB_VAR1(status);
927
928
}

929
int Interface::getNbHwAcquiredFrames()
930
{
931
	DEB_MEMBER_FUNCT();
932
933
	Acq::Status acq_status;
	m_acq.getStatus(acq_status);
934
935
936
	int nb_hw_acq_frames = acq_status.last_frame_nb + 1;
	DEB_RETURN() << DEB_VAR1(nb_hw_acq_frames);
	return nb_hw_acq_frames;
937
938
939
}