SlsDetectorReceiver.h 3.12 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
28
#include "SlsDetectorCPUAffinity.h"
#include "SlsDetectorArgs.h"
29

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

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

namespace lima 
{

namespace SlsDetector
{

class Camera;

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

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

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

60
		virtual ~ImagePackets() {}
61
62

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

		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;
74
	};
75

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

	void start();
80

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

84
85
	void prepareAcq();

86
87
	void setCPUAffinity(const RecvCPUAffinity& recv_affinity);

88
89
90
91
	ImagePackets *readImagePackets();

	void fillBadFrame(char *buf);

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

95
	void clearAllBuffers();
96

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

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

112
113
	struct AssemblerImpl;

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

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

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

132
133
134
135
136
137
138

} // namespace SlsDetector

} // namespace lima


#endif // __SLS_DETECTOR_RECEIVER_H