CAENPhaDriver.cpp 7.58 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Nomad Instrument Control Software
 *
 * Copyright 2011 Institut Laue-Langevin
 *
 * Licensed under the EUPL, Version 1.1 only (the "License");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 *
 * http://joinup.ec.europa.eu/software/page/eupl
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and
 * limitations under the Licence.
 */

#include "CAENPhaDef.h"
#include "CAENPhaState.h"
#include "CAENPhaDriver.h"
#include "PerfectCAENPhaDriver.h"
#include "RealCAENPhaDriver.h"
#include "drivers/global/DriversCommands.h"

namespace caen_pha {

const std::string CAENPhaDriver::TYPE = "caen_pha";

const std::string CAENPhaDriver::WRITE_PARAMETERS_COMMAND = "writeParam";
const std::string CAENPhaDriver::SET_MODE_COMMAND = "setAcqMode";
const std::string CAENPhaDriver::RESET_COMMAND = "reset";
const std::string CAENPhaDriver::CLEAR_COMMAND = "clear";

/*
 * Constructor
 */
CAENPhaDriver::CAENPhaDriver(const string& name) {

	driver::Vme::init(name);

	registerStates(new RealCAENPhaDriver(this), new PerfectCAENPhaDriver(this), new PerfectCAENPhaDriver(this));

	// Global properties
	nbChannels.init(this, SAVE, "nb_channels");
	nbBits.init(this, SAVE, "nb_bits");
    model.init(this, NOSAVE, "model");
    channels.init(this, NOSAVE, "channels");
    serialNumber.init(this, NOSAVE, "serial_number");
    modelName.init(this, NOSAVE, "model_name");
    rocFirmware.init(this, NOSAVE, "roc_firmware");
    amcFirmware.init(this, NOSAVE, "amc_firmware");

    // Board properties
    linkType.init(this, SAVE, "link_type");
    acqMode.init(this, SAVE, "acq_mode");
    dppAcqMode.init(this, SAVE, "dpp_acq_mode");
    dppAcqModeStr.init(this, NOSAVE, "dpp_acq_mode_str");
    saveMode.init(this, SAVE, "save_mode");
    saveModeStr.init(this, NOSAVE, "save_mode_str");
    recordLength.init(this, SAVE, "record_length");
    ioLevel.init(this, SAVE, "io_level");
    triggerMode.init(this, SAVE, "trigger_mode");
    channelMask.init(this, SAVE, "channel_mask");

Paolo Mutti's avatar
Paolo Mutti committed
66
67
68
69
70
71
	enableCoincidence.init(this, NOSAVE, "enable_coincidence");
	coincidenceWindow.init(this, NOSAVE, "coincidence_window");
	coincidenceMask.init(this, NOSAVE, "coincidence_mask");

    usePn1Coincidence.init(this, SAVE, "use_Pn1_Coincidence");

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
	// Channels properties
	signalDecayTime.init(this, SAVE, "decay_time");
	trapezoidFlatTop.init(this, SAVE, "trapezoid_flat");
	trapezoidRiseTime.init(this, SAVE, "trapezoid_rise");
	flatTopDelay.init(this, SAVE, "flat_top");
	triggerSmoothing.init(this, SAVE, "trigger_smoothing");
	signalRiseTime.init(this, SAVE, "rise_time");
	triggerThreshold.init(this, SAVE, "trigger_threshold");
	baselineMean.init(this, SAVE, "base_mean");
	peakMean.init(this, SAVE, "peak_mean");
	peakHoldOff.init(this, SAVE, "peak_holdoff");
	baselineHoldOff.init(this, SAVE, "base_holdoff");
	triggerHoldOff.init(this, SAVE, "trigger_holdoff");
	triggerWindowSize.init(this, SAVE, "trigger_window_size");
	triggerWindowEnable.init(this, SAVE, "trigger_window_enable");
	digitalGain.init(this, SAVE, "digital_gain");
	trapezoidGain.init(this, SAVE, "trapezoid_gain");
	decimation.init(this, SAVE, "decimation");

	channelActive.init(this, SAVE, "channel_active");
	channelActiveStr.init(this, NOSAVE, "channel_active_str");
	dcOffset.init(this, SAVE, "dc_offset");
	preTrigger.init(this, SAVE, "pre_trigger");
	pulsePolarity.init(this, SAVE, "pulse_polarity");
	pulsePolarityStr.init(this, NOSAVE, "pulse_polarity_str");
	useFirstDerivative.init(this, SAVE, "use_first_derivative");

	// Init the device command list
	initCommand(driver::INIT_COMMAND);
	initCommand(driver::READ_INFOS_COMMAND);
	initCommand(WRITE_PARAMETERS_COMMAND);
	initCommand(SET_MODE_COMMAND);
	initCommand(RESET_COMMAND);
	initCommand(CLEAR_COMMAND);

	// Init functions
	registerFunction(NONE_FUNCTION);

	addressType.update(driver::Vme::A32_ACCESS);
	deviceType = LEAF_DEVICE_TYPE_DEVICE_CONTAINER;

	registerRefresher(nbChannels, &CAENPhaDriver::refreshNbChannelsProperty, this);
	registerRefresher(dppAcqMode, &CAENPhaDriver::refreshDppAcqModeProperty, this);
	registerRefresher(saveMode, &CAENPhaDriver::refreshSaveModeProperty, this);
	registerRefresher(channelActive, &CAENPhaDriver::refreshChannelActiveProperty, this);
	registerRefresher(pulsePolarity, &CAENPhaDriver::refreshPulsePolarityProperty, this);
}

/*
 * Destructor
 */
CAENPhaDriver::~CAENPhaDriver() {

}

/*
 * execute
 */
void CAENPhaDriver::execute(const std::string& aCommand) {

	if ((aCommand != driver::STOP_COMMAND) && (aCommand != driver::STATUS_COMMAND)
			&& (aCommand != driver::READ_COMMAND)) {
		commandProgression = PROGRESSION_UNKNOWNSTATE_DEVICE_CONTAINER;
	}

	CAENPhaState* currentState = dynamic_cast<CAENPhaState*>(getCurrentState());
	// Check command
	if (aCommand == driver::INIT_COMMAND) {
		// Init command
		currentState->init();
	} else if (aCommand == WRITE_PARAMETERS_COMMAND) {
		// writeParam command
		currentState->writeParam();
		commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
	} else if (aCommand == SET_MODE_COMMAND) {
		// clear command
		currentState->setAcqMode();
		commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
	} else if (aCommand == CLEAR_COMMAND) {
		// clear command
		currentState->clear();
		commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
	} else if (aCommand == RESET_COMMAND) {
		// clear command
		currentState->reset();
		commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
	} else if (aCommand == driver::READ_INFOS_COMMAND) {
		// Info command
		currentState->readInfos();
		commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
	} else {
		//Error bad command
		//Todo , normaly it will be detect it device action driver
	}
}

void CAENPhaDriver::refreshNbChannelsProperty(int32 aValue)  throw (CannotSetValue){

	signalDecayTime.resize(aValue);
	trapezoidFlatTop.resize(aValue);
	trapezoidRiseTime.resize(aValue);
	flatTopDelay.resize(aValue);
	triggerSmoothing.resize(aValue);
	signalRiseTime.resize(aValue);
	triggerThreshold.resize(aValue);
	baselineMean.resize(aValue);
	peakMean.resize(aValue);
	peakHoldOff.resize(aValue);
	baselineHoldOff.resize(aValue);
	triggerHoldOff.resize(aValue);
	triggerWindowSize.resize(aValue);
	triggerWindowEnable.resize(aValue);
	digitalGain.resize(aValue);
	trapezoidGain.resize(aValue);
	decimation.resize(aValue);

	channelActive.resize(aValue);
	channelActiveStr.resize(aValue);
	dcOffset.resize(aValue);
	preTrigger.resize(aValue);
	pulsePolarity.resize(aValue);
	pulsePolarityStr.resize(aValue);
	useFirstDerivative.resize(aValue);
}

void CAENPhaDriver::refreshDppAcqModeProperty(int32 aValue) throw (CannotSetValue) {

	switch (aValue) {
	case 0:
		dppAcqModeStr = "Oscilloscope";
		break;
	case 1:
		dppAcqModeStr = "Histogram";
		break;
	}
}

void CAENPhaDriver::refreshSaveModeProperty(int32 aValue) throw (CannotSetValue) {

	switch (aValue) {
	case 0:
		saveModeStr = "Energy";
		break;
	case 1:
		saveModeStr = "Time";
		break;
	case 2:
		saveModeStr = "Energy&Time";
		break;
	}
}

void CAENPhaDriver::refreshChannelActiveProperty(int32 index, int32 aValue) throw (CannotSetValue) {

	switch (aValue) {
	case 0:
		channelActiveStr.set(index, "Inactive");
		break;
	case 1:
		channelActiveStr.set(index, "Active");
		break;
	}
}

void CAENPhaDriver::refreshPulsePolarityProperty(int32 index, int32 aValue) throw (CannotSetValue) {

	switch (aValue) {
	case 0:
		pulsePolarityStr.set(index, "Positive");
		break;
	case 1:
		pulsePolarityStr.set(index, "Negative");
		break;
	}
}

}