FrelonModel.cpp 7.47 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
#include "FrelonModel.h"
23
#include "lima/RegExUtils.h"
24

25
26
#include <stdlib.h>

27
28
29
30
using namespace lima;
using namespace lima::Frelon;
using namespace std;

31
const Firmware Firmware::v2_0c("2.0c");
32
33
const Firmware Firmware::v2_1b("2.1b");
const Firmware Firmware::v3_0i("3.0i");
34
const Firmware Firmware::v3_1c("3.1c");
35

36
Firmware::Firmware()
37
38
39
40
41
42
{
	DEB_CONSTRUCTOR();

	reset();
}

43
44
45
46
47
48
49
50
51
52
53
54

Firmware::Firmware(const string& ver)
{
	DEB_CONSTRUCTOR();
	DEB_PARAM() << DEB_VAR1(ver);

	reset();
	setVersionStr(ver);
}


Firmware::~Firmware()
55
56
{
	DEB_DESTRUCTOR();
57
58
59
60
61
62
63
64
65
66
67

	reset();
}


void Firmware::reset()
{
	DEB_MEMBER_FUNCT();

	m_major = m_minor = 0;
	m_rel.clear();
68
69
}

70
void Firmware::setVersionStr(const string& ver)
71
72
73
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(ver);
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

	RegEx re("(?P<major>[0-9]+)\\.(?P<minor>[0-9]+)(?P<rel>[a-z]+)?");
	RegEx::FullNameMatchType match;

	if (!re.matchName(ver, match))
		THROW_HW_ERROR(InvalidValue) << "Invalid firmware "
					     << DEB_VAR1(ver);

	m_major = atoi(string(match["major"]).c_str());
	m_minor = atoi(string(match["minor"]).c_str());
	m_rel = match["rel"];

	if (!isValid()) {
		reset();
		THROW_HW_ERROR(InvalidValue) << "Invalid firmware "
					     << DEB_VAR1(ver);
	}
91
92
}

93
void Firmware::getVersionStr(string& ver) const
94
95
{
	DEB_MEMBER_FUNCT();
96
97
98
99
100
101
102
103

	ostringstream os;
	if (isValid())
		os << m_major << "." << m_minor << m_rel;
	else
		os << "Unknown";

	ver = os.str();
104
105
106
	DEB_RETURN() << DEB_VAR1(ver);
}

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
bool Firmware::isValid() const
{
	DEB_MEMBER_FUNCT();

	bool valid = (m_major > 0) || (m_minor > 0);
	DEB_RETURN() << DEB_VAR1(valid);
	return valid;
}

int Firmware::getMajor() const
{
	return m_major;
}

int Firmware::getMinor() const
{
	return m_minor;
}

string Firmware::getRelease() const
{
	return m_rel;
}

void Firmware::checkValid()
{
	DEB_MEMBER_FUNCT();

	if (!isValid())
		THROW_HW_ERROR(InvalidValue) 
			<< "Frelon Firmware not fully initialised yet";
}

Model::Model()
{
	DEB_CONSTRUCTOR();

	reset();
}

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

void Model::setVersionStr(const std::string& ver)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(ver);
156
157

	m_valid = false;
158
	m_firmware.setVersionStr(ver);
159
	update();
160
161
}

162
const Firmware& Model::getFirmware()
163
164
165
166
{
	return m_firmware;
}

167
168
169
void Model::setComplexSerialNb(int complex_ser_nb)
{
	DEB_MEMBER_FUNCT();
170
	DEB_PARAM() << DEB_VAR1(DEB_HEX(complex_ser_nb));
171

172
	m_complex_ser_nb = complex_ser_nb;
173
	update();
174
175
176
177
178
179
}

void Model::getComplexSerialNb(int& complex_ser_nb)
{
	DEB_MEMBER_FUNCT();
	complex_ser_nb = m_complex_ser_nb;
180
	DEB_RETURN() << DEB_VAR1(DEB_HEX(complex_ser_nb));
181
182
183
184
185
186
}

void Model::reset()
{
	DEB_MEMBER_FUNCT();

187
	m_firmware.reset();
188
	m_complex_ser_nb = 0;
189
	update();
190
191
}

192
void Model::update()
193
194
195
{
	DEB_MEMBER_FUNCT();

196
197
198
199
200
201
202
203
204
205
	m_valid = (m_complex_ser_nb > 0) && m_firmware.isValid();
	DEB_TRACE() << DEB_VAR1(m_valid);
	if (!m_valid)
		return;

	bool is_spb2 = isSPB2();
	if (is_spb2)
		m_chip_type = ChipType(getSerialNbParam(SPB2Type) >> 12);
	else
		m_chip_type = bool(getSerialNbParam(SPB1Kodak)) ? Kodak : Atmel;
206
	m_is_hama = (m_chip_type == Hama);
207

208
209
210
	bool firm_v2_0c = (is_spb2 && (m_firmware >= Firmware::v2_0c));
	m_htd_cmd = firm_v2_0c;

211
212
213
214
215
216
	bool firm_v2_1b = (is_spb2 && (m_firmware >= Firmware::v2_1b));
	m_modes_avail = m_time_calc = firm_v2_1b;

	bool firm_v3_0i = (is_spb2 && (m_firmware >= Firmware::v3_0i));
	m_good_htd = firm_v3_0i;

217
218
	bool firm_v3_1c = (is_spb2 && (m_firmware >= Firmware::v3_1c));
	m_images_per_eof = firm_v3_1c;
219

220
221
	DEB_TRACE() << DEB_VAR6(m_chip_type, m_is_hama, m_modes_avail, 
				m_time_calc, m_good_htd, m_images_per_eof);
222
223
224
225
226
227
228
}

bool Model::isValid()
{
	DEB_MEMBER_FUNCT();
	DEB_RETURN() << DEB_VAR1(m_valid);
	return m_valid;
229
230
231
232
233
234
}

void Model::checkValid()
{
	DEB_MEMBER_FUNCT();

235
	if (!m_valid)
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
		THROW_HW_ERROR(InvalidValue) 
			<< "Frelon model not fully initialised yet";
}

int Model::getSerialNbParam(SerNbParam param)
{
	DEB_MEMBER_FUNCT();
	DEB_PARAM() << DEB_VAR1(DEB_HEX(param));

	int val = m_complex_ser_nb & int(param);
	DEB_RETURN() << DEB_VAR1(val);
	return val;
}

int Model::getSerialNb()
{
	DEB_MEMBER_FUNCT();
	checkValid();

	int ser_nb = getSerialNbParam(SerNb);
	DEB_RETURN() << DEB_VAR1(ser_nb);
	return ser_nb;
}

bool Model::isSPB1()
{
	DEB_MEMBER_FUNCT();

	bool frelon_spb1 = !isSPB2();
	DEB_RETURN() << DEB_VAR1(frelon_spb1);
	return frelon_spb1;
}
	
bool Model::isSPB2()
{
	DEB_MEMBER_FUNCT();
	checkValid();

	bool frelon_spb2 = bool(getSerialNbParam(SPB2Sign));
	DEB_RETURN() << DEB_VAR1(frelon_spb2);
	return frelon_spb2;
}
	
int Model::getAdcBits()
{
	DEB_MEMBER_FUNCT();

	int adc_bits;
	if (isSPB1())
		adc_bits = bool(getSerialNbParam(SPB1Adc16)) ? 16 : 14;
	else
		adc_bits = 16;
	DEB_RETURN() << DEB_VAR1(adc_bits);
	return adc_bits;
}

ChipType Model::getChipType()
{
	DEB_MEMBER_FUNCT();

296
297
298
299
	checkValid();

	DEB_RETURN() << DEB_VAR1(m_chip_type);
	return m_chip_type;
300
301
}

302
303
304
305
306
307
308
309
310
311
bool Model::isHama()
{
	DEB_MEMBER_FUNCT();

	checkValid();

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

312
313
314
315
316
317
318
319
320
bool Model::hasTaper()
{
	DEB_MEMBER_FUNCT();

	bool taper = bool(getSerialNbParam(Taper));
	DEB_RETURN() << DEB_VAR1(taper);
	return taper;
}

321
322
323
324
bool Model::hasModesAvail()
{
	DEB_MEMBER_FUNCT();

325
326
327
328
	checkValid();

	DEB_RETURN() << DEB_VAR1(m_modes_avail);
	return m_modes_avail;
329
330
331
332
333
334
}

bool Model::hasTimeCalc()
{
	DEB_MEMBER_FUNCT();

335
336
337
338
	checkValid();

	DEB_RETURN() << DEB_VAR1(m_time_calc);
	return m_time_calc;
339
340
}

341
342
343
344
345
346
347
348
349
350
bool Model::hasHTDCmd()
{
	DEB_MEMBER_FUNCT();

	checkValid();

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

351
352
353
354
bool Model::hasGoodHTD()
{
	DEB_MEMBER_FUNCT();

355
356
357
358
	checkValid();

	DEB_RETURN() << DEB_VAR1(m_good_htd);
	return m_good_htd;
359
360
}

361
bool Model::hasImagesPerEOF()
362
363
364
365
366
{
	DEB_MEMBER_FUNCT();

	checkValid();

367
368
	DEB_RETURN() << DEB_VAR1(m_images_per_eof);
	return m_images_per_eof;
369
370
}

371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
double Model::getPixelSize()
{
	DEB_MEMBER_FUNCT();

	ChipType chip_type = getChipType();
	double pixel_size = ChipPixelSizeMap[chip_type];
	DEB_RETURN() << DEB_VAR1(pixel_size);
	return pixel_size;
}

string Model::getName()
{
	DEB_MEMBER_FUNCT();
	checkValid();

386
387
388
389
390
391
392
393
	string chip_model;
	switch (getChipType()) {
	case Atmel:        chip_model = "A7899";   break;
	case Kodak:        chip_model = "K4320";   break;
	case E2V_2k:       chip_model = "E230-42"; break;
	case E2V_2kNotMPP: chip_model = "E231-42"; break;
	case E2V_4k:       chip_model = "E230-84"; break;
	case E2V_4kNotMPP: chip_model = "E231-84"; break;
394
	case Hama:         chip_model = "Hama";    break;
395
396
	default:           chip_model = "Unknown";
	}
397
398

	string hd = isSPB2() ? "HD " : "";
399
	string name = hd + chip_model;
400
401
402
403
404
405
406
407
408
409

	if (isSPB1() && (getAdcBits() == 16))
		name += " 16bit";

	if (hasTaper())
		name += "T";

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