Line data Source code
1 : #include "wibmod/WIB1/WIB.hh"
2 : #include "wibmod/WIB1/WIBException.hh"
3 : #include "wibmod/WIB1/BNL_UDP_Exception.hh"
4 : #include <stdio.h> //snprintf
5 : #include <iostream>
6 :
7 :
8 :
9 0 : WIB::WIB(std::string const & address, std::string const & WIBAddressTable, std::string const & FEMBAddressTable, bool fullStart):
10 0 : WIBBase(address,WIBAddressTable,FEMBAddressTable),DAQMode(UNKNOWN),FEMBStreamCount(4),FEMBCDACount(2),
11 0 : ContinueOnFEMBRegReadError(false),ContinueOnFEMBSPIError(false),ContinueOnFEMBSyncError(true),
12 0 : ContinueIfListOfFEMBClockPhasesDontSync(true){
13 :
14 :
15 0 : if(fullStart){
16 : //Figure out what kind of WIB firmware we are dealing with
17 0 : FEMBCount = Read("SYSTEM.FEMB_COUNT");
18 0 : DAQLinkCount = Read("SYSTEM.DAQ_LINK_COUNT");
19 : //Hardcoded lookup for RCE and FELIX
20 0 : if((FEMBCount == 4) && (DAQLinkCount == 4)){
21 0 : DAQMode = RCE;
22 0 : }else if((FEMBCount == 4) && (DAQLinkCount == 2)){
23 0 : DAQMode = FELIX;
24 : }
25 : //TODO check FEMBStreamCount and FEMCDACount from registers on the WIB
26 : //TODO create those registers
27 0 : Write("POWER.ENABLE.MASTER_BIAS",1);
28 0 : started = true;
29 : }
30 0 : }
31 :
32 0 : WIB::~WIB(){
33 0 : }
34 :
35 0 : void WIB::FullStart(){
36 : //Figure out what kind of WIB firmware we are dealing with
37 0 : FEMBCount = Read("SYSTEM.FEMB_COUNT");
38 0 : DAQLinkCount = Read("SYSTEM.DAQ_LINK_COUNT");
39 : //Hardcoded lookup for RCE and FELIX
40 0 : if((FEMBCount == 4) && (DAQLinkCount == 4)){
41 0 : DAQMode = RCE;
42 0 : }else if((FEMBCount == 4) && (DAQLinkCount == 2)){
43 0 : DAQMode = FELIX;
44 : }
45 : //TODO check FEMBStreamCount and FEMCDACount from registers on the WIB
46 : //TODO create those registers
47 0 : Write("POWER.ENABLE.MASTER_BIAS",1);
48 0 : started = true;
49 0 : }
50 :
51 0 : void WIB::EnableDAQLink(uint8_t iDAQLink){
52 : //CHeck if we know how to dael with this firmware
53 0 : if(!((DAQMode == RCE)||(DAQMode == FELIX))){
54 : //Not RCE or FELIX firmware, return
55 0 : BUException::WIB_FEATURE_NOT_SUPPORTED e;
56 0 : e.Append("Automatic DAQLink configuration not supported with this firmware.\n");
57 0 : throw e;
58 0 : }
59 :
60 : //Build the base string for this DAQLINK
61 0 : std::string base("DAQ_LINK_");
62 0 : base.push_back(GetDAQLinkChar(iDAQLink));
63 0 : base.append(".CONTROL.");
64 0 : printf("%s\n",base.c_str());
65 :
66 : //set the CD stream enable mask from that
67 : uint32_t enable_mask = 0;
68 0 : for(size_t iStream = 0; iStream < (4 * FEMBCount/DAQLinkCount);iStream++){
69 : enable_mask <<= 0x1;
70 : }
71 :
72 0 : Write(base+"ENABLE_CDA_STREAM",enable_mask);
73 :
74 0 : Write(base+"ENABLE",0x1);
75 0 : }
76 :
77 0 : void WIB::EnableDAQLink_Lite(uint8_t iDAQLink, uint8_t enable){
78 : //CHeck if we know how to dael with this firmware
79 0 : if(!((DAQMode == RCE)||(DAQMode == FELIX))){
80 : //Not RCE or FELIX firmware, return
81 0 : BUException::WIB_FEATURE_NOT_SUPPORTED e;
82 0 : e.Append("Automatic DAQLink configuration not supported with this firmware.\n");
83 0 : throw e;
84 0 : }
85 :
86 : //Build the base string for this DAQLINK
87 0 : std::string base("DAQ_LINK_");
88 0 : base.push_back(GetDAQLinkChar(iDAQLink));
89 0 : base.append(".CONTROL.");
90 :
91 0 : uint8_t stream = 0;
92 0 : if(enable){
93 0 : if(DAQMode == RCE) stream = 0xF;
94 0 : else stream = 0xFF;
95 : }
96 :
97 0 : Write(base+"ENABLE_CDA_STREAM",stream);
98 0 : Write(base+"ENABLE",enable);
99 0 : }
100 :
101 : /*void WIB::DisableDAQLink_Lite(uint8_t iDAQLink, uint8_t enable){
102 : //CHeck if we know how to dael with this firmware
103 : if(!((DAQMode == RCE)||(DAQMode == FELIX))){
104 : //Not RCE or FELIX firmware, return
105 : BUException::WIB_FEATURE_NOT_SUPPORTED e;
106 : e.Append("Automatic DAQLink configuration not supported with this firmware.\n");
107 : throw e;
108 : }
109 :
110 : //Build the base string for this DAQLINK
111 : std::string base("DAQ_LINK_");
112 : base.push_back(GetDAQLinkChar(iDAQLink));
113 : base.append(".CONTROL.");
114 :
115 : uint8_t stream = 0;
116 : if(DAQMode == RCE) stream = 0xF;
117 : else stream = 0xFF;
118 :
119 : if(enable){
120 : Write(base+"ENABLE_CDA_STREAM",stream);
121 :
122 : Write(base+"ENABLE",enable);
123 : }
124 : else{
125 : Write(base+"ENABLE_CDA_STREAM",0);
126 : Write(base+"ENABLE",0);
127 : }
128 : }*/
129 :
130 0 : void WIB::InitializeWIB(){
131 : //run resets
132 0 : Write("SYSTEM.RESET",0xFF);
133 : //Set clock settings
134 0 : Write("POWER.ENABLE.MASTER_BIAS",0x1);//Turn on DC/DC converter
135 0 : }
136 :
137 : //void WIB::ResetWIB(bool cntrlRegister=true, bool global=false, bool daq_path=false, bool udp=false){
138 0 : void WIB::ResetWIB(bool reset_udp){
139 :
140 0 : if(reset_udp){
141 : //Resetting the UDP will stop the reply packet which will cause an error.
142 0 : try{
143 0 : Write("SYSTEM.RESET.UDP_RESET",1);
144 0 : }catch(BUException::BAD_REPLY & e){
145 : //do nothing
146 0 : }
147 : //Since we don't know this happened since we lack a udp response, do it again.
148 : //This could be extended to read register REG
149 0 : usleep(10000);
150 0 : try{
151 0 : Write("SYSTEM.RESET.UDP_RESET",1);
152 0 : }catch(BUException::BAD_REPLY & e){
153 : //do nothing
154 0 : }
155 0 : usleep(10000);
156 : }
157 :
158 :
159 : //Reset the control register
160 0 : WriteWithRetry("SYSTEM.RESET.CONTROL_REGISTER_RESET",1);
161 0 : usleep(1000);
162 :
163 : //If this is felix, make sure we configure the SI5342
164 0 : if(DAQMode == FELIX){
165 0 : Write("DAQ.SI5342.RESET",1);
166 0 : usleep(10000);
167 0 : Write("DAQ.SI5342.RESET",0);
168 0 : usleep(10000);
169 0 : printf("Configuring SI5342 for FELIX\n");
170 0 : LoadConfigDAQ_SI5342("default"); //use the default config file for the SI5342
171 0 : usleep(10000); // Wait for
172 0 : SelectSI5342(1, // Set input to be local oscillator for FELIX clock
173 : 1); // enable the output of the SI5342
174 : }
175 :
176 : //Reset the Eventbuilder PLL
177 0 : Write("SYSTEM.RESET.EB_PLL_RESET",1);
178 0 : usleep(10000);
179 :
180 : //Reset the DAQ path
181 0 : Write("SYSTEM.RESET.DAQ_PATH_RESET",1);
182 :
183 0 : usleep(10000);
184 :
185 : //Set clock settings
186 0 : Write("DTS.CMD_COUNT_RESET", 0xFFFFFFFF);
187 0 : Write("DTS.CMD_COUNT_RESET", 0);
188 :
189 : //Halt signals
190 0 : Write("DTS.CONVERT_CONTROL.HALT", 1);
191 0 : Write("DTS.CONVERT_CONTROL.ENABLE", 0);
192 :
193 : //Make sure DC/DC is on
194 0 : Write("POWER.ENABLE.MASTER_BIAS",1);
195 0 : }
196 :
197 0 : void WIB::ResetWIBAndCfgDTS(uint8_t localClock, uint8_t PDTS_TGRP, uint8_t PDTSsource, uint32_t PDTSAlignment_timeout){
198 0 : if(DAQMode == UNKNOWN){
199 0 : BUException::WIB_DAQMODE_UNKNOWN e;
200 0 : throw e;
201 0 : }
202 0 : if(localClock > 1){
203 0 : BUException::WIB_BAD_ARGS e;
204 0 : e.Append("localClock > 1; must be 0 (for DTS) or 1 (for local clock)\n");
205 0 : throw e;
206 0 : }
207 0 : if(PDTSsource > 1){
208 0 : BUException::WIB_BAD_ARGS e;
209 0 : e.Append("PDTSsource > 1; must be 0 (for backplane) or 1 (for front panel)\n");
210 0 : throw e;
211 0 : }
212 0 : if(16 <= PDTS_TGRP){
213 0 : BUException::WIB_BAD_ARGS e;
214 0 : e.Append("PDTS TGRP > 15; must be 0 to 15\n");
215 0 : throw e;
216 0 : }
217 :
218 : // get this register so we can leave it in the state it started in
219 0 : uint32_t slow_control_dnd = Read("SYSTEM.SLOW_CONTROL_DND");
220 :
221 0 : ResetWIB();
222 0 : Write("SYSTEM.SLOW_CONTROL_DND",1);
223 0 : sleep(1);
224 :
225 0 : for (size_t iFEMB=1; iFEMB<=4; iFEMB++){
226 0 : FEMBPower(iFEMB,0);
227 : }
228 :
229 : //make sure everything DTS is off
230 0 : Write("DTS.CONVERT_CONTROL.HALT",1);
231 0 : Write("DTS.CONVERT_CONTROL.ENABLE",0);
232 0 : Write("DTS.CONVERT_CONTROL.START_SYNC",0);
233 0 : sleep(1);
234 :
235 0 : if(localClock > 0){
236 0 : printf("Configuring local clock\n");
237 : //Configure the SI5344 to use the local oscillator instead of the PDTS
238 0 : LoadConfigDTS_SI5344("default");
239 0 : sleep(1);
240 0 : SelectSI5344(1,1);
241 0 : sleep(1);
242 0 : Write("DTS.CONVERT_CONTROL.EN_FAKE",1);
243 0 : Write("DTS.CONVERT_CONTROL.LOCAL_TIMESTAMP",1);
244 0 : Write("FEMB_CNC.CNC_CLOCK_SELECT",1);
245 : // Write("FEMB_CNC.ENABLE_DTS_CMDS",1);
246 0 : sleep(1);
247 : }
248 : else {
249 : //Configure the clocking for the PDTS (assumes the PDTS is sending idle or something)
250 0 : printf("Configuring DTS\n");
251 0 : Write("DTS.PDTS_TGRP",PDTS_TGRP);
252 0 : printf("Using timing group 0x%X\n",PDTS_TGRP);
253 0 : InitializeDTS(PDTSsource,0,PDTSAlignment_timeout);
254 0 : sleep(1);
255 0 : Write("FEMB_CNC.CNC_CLOCK_SELECT",1);
256 0 : sleep(1);
257 : //We are ready for the PDTS, start searching
258 0 : Write("DTS.PDTS_ENABLE",1);
259 0 : sleep(1);
260 : }
261 :
262 : //Now we have the 128MHz clock
263 0 : Write("FEMB1.DAQ.ENABLE",0);
264 0 : Write("FEMB2.DAQ.ENABLE",0);
265 0 : Write("FEMB3.DAQ.ENABLE",0);
266 0 : Write("FEMB4.DAQ.ENABLE",0);
267 :
268 0 : Write("SYSTEM.SLOW_CONTROL_DND",slow_control_dnd);
269 :
270 0 : }
271 :
272 0 : void WIB::CheckedResetWIBAndCfgDTS(uint8_t localClock, uint8_t PDTS_TGRP, uint8_t PDTSsource, uint32_t PDTSAlignment_timeout){
273 0 : if(DAQMode == UNKNOWN){
274 0 : BUException::WIB_DAQMODE_UNKNOWN e;
275 0 : throw e;
276 0 : }
277 0 : if(localClock > 1){
278 0 : BUException::WIB_BAD_ARGS e;
279 0 : e.Append("localClock > 1; must be 0 (for DTS) or 1 (for local clock)\n");
280 0 : throw e;
281 0 : }
282 0 : if(PDTSsource > 1){
283 0 : BUException::WIB_BAD_ARGS e;
284 0 : e.Append("PDTSsource > 1; must be 0 (for backplane) or 1 (for front panel)\n");
285 0 : throw e;
286 0 : }
287 0 : if(16 <= PDTS_TGRP){
288 0 : BUException::WIB_BAD_ARGS e;
289 0 : e.Append("PDTS TGRP > 15; must be 0 to 15\n");
290 0 : throw e;
291 0 : }
292 :
293 :
294 0 : bool reset_check = false;
295 : // Check if we are already in a good state
296 0 : if(localClock > 0){
297 0 : printf("Checking if locked on local clock\n");
298 0 : reset_check = ( (Read("DTS.CONVERT_CONTROL.EN_FAKE") != 1)
299 0 : || (Read("DTS.CCONVERT_CONTROL.LOCAL_TIMESTAMP") != 1)
300 0 : || (Read("FEMB_CNC.CNC_CLOCK_SELECT") != 1)
301 : // || (Read("FEMB_CNC.ENABLE_DTS_CMDS") != 1)
302 0 : || (Read("DTS.SI5344.INPUT_SELECT") != 1)
303 0 : || (Read("DTS.SI5344.ENABLE") != 1) );
304 0 : if(!reset_check){
305 0 : printf("Already in a good state\n");
306 : }
307 : else{
308 0 : printf("Need to reset for local clocking\n");
309 : }
310 : }
311 : else{
312 0 : printf("Checking if locked on PDTS\n");
313 0 : reset_check = ( (Read("DTS.PDTS_TGRP") != PDTS_TGRP)
314 0 : || (Read("FEMB_CNC.CNC_CLOCK_SELECT") != 1)
315 0 : || (Read("DTS.PDTS_ENABLE") != 1)
316 0 : || (Read("DTS.CDS.LOL") != 0)
317 0 : || (Read("DTS.CDS.LOS") != 0)
318 0 : || (ReadWithRetry("DTS.SI5344.INPUT_SELECT") != 0)
319 0 : || (ReadWithRetry("DTS.SI5344.LOS") != 0)
320 0 : || (ReadWithRetry("DTS.SI5344.LOL") != 0)
321 0 : || (ReadWithRetry("DTS.SI5344.ENABLE") != 1)
322 0 : || (ReadWithRetry("DTS.PDTS_STATE") != 0x8) );
323 0 : if(!reset_check){
324 0 : printf("Already in a good state\n");
325 : }
326 : else{
327 0 : printf("Need to reset for PDTS\n");
328 : }
329 : }
330 :
331 : //Check the SI5342 if we're attached to FELIX
332 0 : if(DAQMode == FELIX){
333 :
334 0 : if(
335 0 : (Read("DAQ.SI5342.ENABLE") == 0)
336 0 : || (Read("DAQ.SI5342.INPUT_SELECT") != 1)
337 0 : || (Read("DAQ.SI5342.LOL") == 1)
338 0 : || (Read("DAQ.SI5342.LOS_XAXB") == 1)
339 0 : || (Read("DAQ.SI5342.LOS_2") == 1) ){
340 0 : printf("Need to reset for SI5342\n");
341 0 : reset_check = true;
342 : }
343 : else{
344 0 : printf("SI5342 in good state\n");
345 : }
346 : }
347 :
348 0 : if(reset_check){
349 : // get this register so we can leave it in the state it started in
350 0 : uint32_t slow_control_dnd = Read("SYSTEM.SLOW_CONTROL_DND");
351 :
352 0 : ResetWIB();
353 0 : Write("SYSTEM.SLOW_CONTROL_DND",1);
354 :
355 0 : for (size_t iFEMB=1; iFEMB<=4; iFEMB++){
356 0 : FEMBPower(iFEMB,0);
357 : }
358 :
359 : //make sure everything DTS is off
360 0 : Write("DTS.CONVERT_CONTROL.HALT",1);
361 0 : Write("DTS.CONVERT_CONTROL.ENABLE",0);
362 0 : Write("DTS.CONVERT_CONTROL.START_SYNC",0);
363 0 : sleep(1);
364 :
365 0 : if(localClock > 0){
366 0 : printf("Configuring local clock\n");
367 : //Configure the SI5344 to use the local oscillator instead of the PDTS
368 0 : LoadConfigDTS_SI5344("default");
369 0 : sleep(1);
370 0 : SelectSI5344(1,1);
371 0 : sleep(1);
372 0 : Write("DTS.CONVERT_CONTROL.EN_FAKE",1);
373 0 : Write("DTS.CONVERT_CONTROL.LOCAL_TIMESTAMP",1);
374 0 : Write("FEMB_CNC.CNC_CLOCK_SELECT",1);
375 : // Write("FEMB_CNC.ENABLE_DTS_CMDS",1);
376 0 : sleep(1);
377 : }
378 : else {
379 : //Configure the clocking for the PDTS (assumes the PDTS is sending idle or something)
380 0 : printf("Configuring DTS\n");
381 0 : Write("DTS.PDTS_TGRP",PDTS_TGRP);
382 0 : printf("Using timing group 0x%X\n",PDTS_TGRP);
383 0 : InitializeDTS(PDTSsource,0,PDTSAlignment_timeout);
384 0 : sleep(1);
385 0 : Write("FEMB_CNC.CNC_CLOCK_SELECT",1);
386 0 : sleep(1);
387 : //We are ready for the PDTS, start searching
388 0 : Write("DTS.PDTS_ENABLE",1);
389 0 : sleep(1);
390 : }
391 :
392 :
393 0 : Write("SYSTEM.SLOW_CONTROL_DND",slow_control_dnd);
394 : }
395 : //Now we have the 128MHz clock
396 0 : std::cout << "Resetting DAQ Links" << std::endl;
397 0 : size_t nLinks = 4;
398 0 : if(DAQMode == FELIX){ nLinks = 2; }
399 0 : for (size_t iLink=1; iLink <= nLinks; ++iLink){
400 0 : std::cout << iLink << std::endl;
401 0 : EnableDAQLink_Lite(iLink, 0);
402 : }
403 :
404 0 : Write("FEMB1.DAQ.ENABLE",0);
405 0 : Write("FEMB2.DAQ.ENABLE",0);
406 0 : Write("FEMB3.DAQ.ENABLE",0);
407 0 : Write("FEMB4.DAQ.ENABLE",0);
408 :
409 0 : }
410 :
411 0 : void WIB::StartStreamToDAQ(bool link1_enabled, bool link2_enabled, bool link3_enabled, bool link4_enabled ){
412 0 : if(DAQMode == UNKNOWN){
413 0 : BUException::WIB_DAQMODE_UNKNOWN e;
414 0 : throw e;
415 0 : }
416 0 : WriteWithRetry("DTS.CONVERT_CONTROL.HALT",1);
417 0 : WriteWithRetry("DTS.CONVERT_CONTROL.ENABLE",0);
418 :
419 :
420 : // get this register so we can leave it in the state it started in
421 0 : uint32_t slow_control_dnd = Read("SYSTEM.SLOW_CONTROL_DND");
422 0 : Write("SYSTEM.SLOW_CONTROL_DND",1);
423 :
424 0 : sleep(1);
425 0 : Write("FEMB_CNC.FEMB_STOP",1);
426 0 : sleep(1);
427 0 : Write("SYSTEM.RESET.DAQ_PATH_RESET",1);
428 0 : sleep(1);
429 :
430 : // Enable DAQ links
431 0 : if (DAQMode == FELIX){
432 0 : if(link1_enabled) EnableDAQLink_Lite(1,1);
433 0 : if(link2_enabled) EnableDAQLink_Lite(2,1);
434 : }
435 : else {
436 0 : if(link3_enabled) EnableDAQLink_Lite(3,1);
437 0 : if(link4_enabled) EnableDAQLink_Lite(4,1);
438 : }
439 :
440 : // Enable the FEMB to align to idle and wait for convert
441 0 : Write("FEMB1.DAQ.ENABLE",0xF);
442 0 : Write("FEMB2.DAQ.ENABLE",0xF);
443 0 : Write("FEMB3.DAQ.ENABLE",0xF);
444 0 : Write("FEMB4.DAQ.ENABLE",0xF);
445 :
446 : // Start sending characters from the FEMB
447 0 : Write("FEMB_CNC.ENABLE_DTS_CMDS",1);
448 0 : StartSyncDTS();
449 : // Write("FEMB_CNC.TIMESTAMP_RESET",1);
450 : //Write("FEMB_CNC.FEMB_START",1);
451 : // Write("SYSTEM.RESET.FEMB_COUNTER_RESET",1);
452 :
453 0 : Write("SYSTEM.SLOW_CONTROL_DND",slow_control_dnd);
454 0 : }
455 :
456 0 : void WIB::FEMBPower(uint8_t iFEMB,bool turnOn){
457 0 : std::string reg = "POWER.ENABLE.FEMB";
458 0 : reg.push_back(GetFEMBChar(iFEMB));
459 0 : if(turnOn){
460 0 : Write(reg,0x1F);
461 : }else{
462 0 : Write(reg,0x0);
463 : }
464 0 : }
465 :
466 : //void WIB::PowerOnFEMB(uint8_t iFEMB){
467 : // //Turn on power
468 : // std::string reg = "POWER.ENABLE.FEMB";
469 : // reg.push_back(GetFEMBChar(iFEMB));
470 : //
471 : //
472 : // const int REG_COUNT = 6;
473 : // uint8_t mon_reg_val = 0x1+REG_COUNT*(iFEMB-1); // starts at 0x1 and there are 6 per FEMB
474 : //
475 : // for(uint8_t iReg=0;iReg < REG_COUNT;iReg++){
476 : // //Go measure the reg value
477 : // // int iTries = 0;
478 : // // const int NUM_TRIES = 100;
479 : // //Set the value to be read
480 : // Write("POWER.MON_CONTROL.ADDRESS",mon_reg_val+iReg);
481 : // //Wait till the output is valid
482 : //// for(;iTries < NUM_TRIES;iTries++){
483 : //// sleep(1);
484 : //// if(0x1 == Read("POWER.MON_CONTROL.VALID")){
485 : //// break;
486 : //// }
487 : //// }
488 : //// if (NUM_TRIES == iTries){
489 : //// printf("Timeout on reading FEMB: %d power reg %d\n",iFEMB,iReg);
490 : //// }else{
491 : // uint32_t reg_val = Read("POWER.MON_VALUE.MEASUREMENT");
492 : // printf("Reg %u 0x%04X 0x%04X\n",iReg,reg_val >> 16,reg_val&0xFFFF);
493 : // // }
494 : // }
495 : //
496 : //}
497 : //
498 0 : void WIB::EnableFEMBCNC(){
499 : //Enable the clock and control stream to the FEMBs
500 0 : Write("FEMB_CNC.CNC_CLOCK_SELECT",1);
501 0 : Write("FEMB_CNC.CNC_COMMAND_SELECT",1);
502 0 : }
503 0 : void WIB::DisableFEMBCNC(){
504 : //Enable the clock and control stream to the FEMBs
505 0 : Write("FEMB_CNC.CNC_CLOCK_SELECT",0);
506 0 : Write("FEMB_CNC.CNC_COMMAND_SELECT",0);
507 0 : }
508 :
509 0 : bool WIB::CheckDAQLinkInRange(uint8_t iDAQLink){
510 0 : if(!((iDAQLink > 0) && (iDAQLink <= DAQLinkCount))){
511 0 : BUException::WIB_INDEX_OUT_OF_RANGE e;
512 0 : e.Append("DAQ Link\n");
513 0 : throw e;
514 0 : }
515 0 : return true;
516 : }
517 :
518 0 : char WIB::GetDAQLinkChar(uint8_t iDAQLink){
519 0 : char c = '0';
520 : //Check if the link is in range given DAQLinkCount (throws)
521 0 : CheckDAQLinkInRange(iDAQLink);
522 : //Convert the numeric daq link number to a char
523 0 : switch (iDAQLink){
524 : case 1:
525 : c = '1';
526 : break;
527 : case 2:
528 : c = '2';
529 : break;
530 : case 3:
531 : c = '3';
532 : break;
533 : case 4:
534 : c = '4';
535 : break;
536 0 : default:
537 0 : BUException::WIB_INDEX_OUT_OF_RANGE e;
538 0 : e.Append("DAQ Link\n");
539 0 : char estr[] = "0";
540 0 : estr[0] = c;
541 0 : e.Append(estr);
542 0 : throw e;
543 : }
544 0 : return c;
545 : }
546 :
547 0 : bool WIB::CheckFEMBInRange(uint8_t iFEMB){
548 0 : if(!((iFEMB > 0) && (iFEMB <= FEMBCount))){
549 0 : BUException::WIB_INDEX_OUT_OF_RANGE e;
550 0 : e.Append("FEMB\n");
551 0 : throw e;
552 0 : }
553 0 : return true;
554 : }
555 :
556 0 : char WIB::GetFEMBChar(uint8_t iFEMB){
557 0 : char c = '0';
558 : //Check if the link is in range given FEMBCount (throws)
559 0 : CheckFEMBInRange(iFEMB);
560 : //Convert the numeric daq link number to a char
561 0 : switch (iFEMB){
562 : case 1:
563 : c = '1';
564 : break;
565 : case 2:
566 : c = '2';
567 : break;
568 : case 3:
569 : c = '3';
570 : break;
571 : case 4:
572 : c = '4';
573 : break;
574 0 : default:
575 0 : BUException::WIB_INDEX_OUT_OF_RANGE e;
576 0 : e.Append("FEMB\n");
577 0 : char estr[] = "0";
578 0 : estr[0] = c;
579 0 : e.Append(estr);
580 0 : throw e;
581 : }
582 0 : return c;
583 : }
584 :
585 0 : bool WIB::CheckFEMBStreamInRange(uint8_t iStream){
586 0 : if(!((iStream > 0) && (iStream <= FEMBStreamCount))){
587 0 : BUException::WIB_INDEX_OUT_OF_RANGE e;
588 0 : e.Append("FEMB Stream");
589 0 : throw e;
590 0 : }
591 0 : return true;
592 : }
593 :
594 0 : bool WIB::CheckFEMBCDInRange(uint8_t iCDA){
595 0 : if(!((iCDA > 0) && (iCDA <= FEMBCDACount))){
596 0 : BUException::WIB_INDEX_OUT_OF_RANGE e;
597 0 : e.Append("FEMB CDA");
598 0 : throw e;
599 0 : }
600 0 : return true;
601 : }
602 :
603 0 : char WIB::GetFEMBCDChar(uint8_t iCD){
604 0 : char c = '0';
605 : //Check if the link is in range given FEMBCount (throws)
606 0 : CheckFEMBCDInRange(iCD);
607 : //Convert the numeric daq link number to a char
608 0 : switch (iCD){
609 : case 1:
610 : c = '1';
611 : break;
612 0 : case 2:
613 0 : c = '2';
614 0 : break;
615 0 : default:
616 0 : BUException::WIB_INDEX_OUT_OF_RANGE e;
617 0 : e.Append("FEMB CDA\n");
618 0 : char estr[] = "0";
619 0 : estr[0] = c;
620 0 : e.Append(estr);
621 0 : throw e;
622 : }
623 0 : return c;
624 : }
625 :
626 0 : void WIB::SourceFEMB(uint64_t iFEMB, uint64_t real){
627 0 : if(iFEMB < 1){
628 0 : printf("FEMB index out of range < 1\n");
629 0 : return;
630 : }
631 :
632 : /* if(DAQMode == RCE && iFEMB > 4){
633 : printf("FEMB index out of range > 4 (RCE) \n");
634 : return;}
635 : if(DAQMode == FELIX && iFEMB > 2){
636 : printf("FEMB index out of range > 2 (FELIX) \n");
637 : return;}
638 : */
639 0 : std::string address("FEMB");
640 0 : address.push_back(GetFEMBChar(iFEMB));
641 0 : address.append(".DAQ.FAKE_CD.FAKE_SOURCE");
642 0 : Write(address,real);
643 0 : }
|