SlsDetectorReceiver.h 3.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
22
23
24
25
//###########################################################################
// 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/>.
//###########################################################################

#ifndef __SLS_DETECTOR_RECEIVER_H
#define __SLS_DETECTOR_RECEIVER_H

26
#include "SlsDetectorFrameMap.h"
27
#include "SlsDetectorModel.h"
28

29
30
31
32
33
34
#include "sls/sls_detector_defs.h"

namespace sls
{
class Receiver;
}
35
36
37
38
39
40
41
42
43
44
45
46
47
48

namespace lima 
{

namespace SlsDetector
{

class Camera;

class Receiver 
{
	DEB_CLASS_NAMESPC(DebModCamera, "Receiver", "SlsDetector");

public:
49
50
	typedef slsDetectorDefs::sls_detector_header sls_detector_header;
	typedef slsDetectorDefs::sls_receiver_header sls_receiver_header;
51

52
53
	class ImagePackets {
	public:
54
		FrameType frame;
55
56
57
		sls_receiver_header header;
		int numberOfPorts;
		std::bitset<MAX_NUM_PORTS> validPortData;
58

59
		virtual ~ImagePackets() {}
60
61

		uint64_t detFrame() { return header.detHeader.frameNumber; }
62
63
64
65
66
67
68
69
70
71
72

		bool assemble(char *buf)
		{ return recv->asmImagePackets(this, buf); }

	protected:
		friend class Receiver;

		ImagePackets(Receiver *r) : frame(-1), numberOfPorts(0), recv(r)
		{ header.detHeader.frameNumber = -1; }

		Receiver *recv;
73
	};
74

75
76
77
78
	Receiver(Camera *cam, int idx, int rx_port);
	~Receiver();

	void start();
79

80
81
82
	void setGapPixelsEnable(bool enable)
	{ m_gap_pixels_enable = enable; }

83
84
	void prepareAcq();

85
86
	void setCPUAffinity(const RecvCPUAffinity& recv_affinity);

87
88
89
90
	ImagePackets *readImagePackets();

	void fillBadFrame(char *buf);

91
92
	SlsDetector::Stats& getStats()
	{ return m_stats.stats; }
93

94
	void clearAllBuffers();
95

96
97
private:
	friend class Camera;
98
	friend class ImagePackets;
99

100
101
102
103
104
105
106
107
108
	struct Stats {
		SlsDetector::Stats stats;
		Timestamp last_t0;
		Timestamp last_t1;
		void reset()
		{
			stats.reset();
			last_t0 = last_t1 = Timestamp();
		}
109
	};
110

111
112
	struct AssemblerImpl;

113
114
	bool asmImagePackets(ImagePackets *image_data, char *buffer);
	AutoPtr<ImagePackets> readSkippableImagePackets();
115

116
117
118
119
	Camera *m_cam;
	int m_idx;
	int m_rx_port;
	Args m_args;
120
121
	bool m_gap_pixels_enable;
	AutoPtr<sls::Receiver> m_recv;
122
	AssemblerImpl *m_asm_impl;
123
	Stats m_stats;
124
	bool m_last_skipped;
125
126
}; 

127
128
129
130
typedef std::map<int, AutoPtr<Receiver::ImagePackets>> DetImagePackets;
typedef std::map<FrameType, DetImagePackets> FramePacketMap;
typedef FramePacketMap::value_type DetFrameImagePackets;

131
132
133
134
135
136
137

} // namespace SlsDetector

} // namespace lima


#endif // __SLS_DETECTOR_RECEIVER_H