Cat
SpecsMaster.cpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 //
3 // Package : SpecsMaster
4 //
5 // Description:
6 //
7 // Author(s) : F. Machefert -
8 // Date : 12 February 2004
9 //
10 //------------------------------------------------------------------------------
11 
12 // include files
13 //#include <stdlib.h>
14 #include <algorithm>
15 
16 #include "SpecsMaster.h"
17 
18 //=============================================================================
19 //
20 //=============================================================================
22  setPciDevID(1);
23  setMasterDevID(1);
24  setName("SpecsMaster");
25  setType("SpecsMaster");
26  setId(0);
27  m_speed=0;
28  m_specsMasterOpen = false;
30  debug("SpecsMaster built.","SpecsMaster::SpecsMaster");
31 }
32 
33 //=============================================================================
34 //
35 //=============================================================================
37 #ifndef _NODEVICE_
38  if (m_specsMasterOpen) specs_master_close ( &m_specsMaster );
39  m_specsMasterOpen = false;
40 #endif
41 }
42 
43 //=============================================================================
44 //
45 //=============================================================================
47  return this;
48 }
49 
50 //=============================================================================
51 //
52 //=============================================================================
53 #ifndef _NODEVICE_
55  return &m_specsMaster;
56 }
57 #endif
58 
59 //=============================================================================
60 //
61 //=============================================================================
63  info("Specs Slave SpecsElement help","SpecsMaster::help");
64 }
65 
66 //=============================================================================
67 //
68 //=============================================================================
70 #ifndef _NODEVICE_
71  DEVICE_INVENT DeviceList[MAX_CARD];
72  U8 DevIndex;
73  // List all cards connected to the PC
74  DevIndex = specs_master_card_select(DeviceList);
75  info("Number of devices connected : " + itos (DevIndex),"SpecsMaster::initSpecs");
76 
77  if (m_pciDevID > DevIndex){
78  error("The requested device [" + itos(m_pciDevID) +
79  "] doesn't exist.\n" + itos(DevIndex) + " boards are seen.",
80  "SpecsMaster::initSpecs");
81  return StatusCode::FAILURE;
82  }
83 
84  if (specs_master_open(DeviceList[m_pciDevID-1],
86  &m_specsMaster) == SpecsSuccess) {
87  info("Init SpecsMaster ["+itos(m_masterDevID)+"] on device "+itos(m_pciDevID),
88  "SpecsMaster::initSpecs"
89  );
90  m_specsMasterOpen = true;
91  reset();
92  }
93  else {
94  error("Cannot Initialize correctly the SpecsMaster "+name()+
95  " - Abort execution",
96  "SpecsMaster::initSpecs");
97  return StatusCode::FAILURE;
98  }
99 
100 #else
101  debug("PciDevID = "+itos(m_pciDevID),"SpecsMaster::initSpecs");
102  debug("MasterDevID = "+itos(m_masterDevID),"SpecsMaster::initSpecs");
103  debug("Compilation in the _NODEVICE_ mode. ","SpecsMaster::initSpecs");
104 #endif
105 
106  reset();
107  return StatusCode::SUCCESS;
108 }
109 
110 /*
111 
112 //=============================================================================
113 //
114 //=============================================================================
115 void SpecsMaster::recursiveInitCommunications(){
116  init();
117  reset();
118  std::vector<Hierarchy*> list = this->children();
119  std::vector<Hierarchy*>::iterator iter;
120  for (iter=list.begin() ; iter!=list.end() ; ++iter){
121  dynamic_cast<Element*>((*iter))->recursiveInitCommunications();
122  }
123 }
124 
125 */
126 
127 //=============================================================================
128 //
129 //=============================================================================
131 #ifndef _NODEVICE_
132  SpecsError status = specs_master_reset ( &m_specsMaster );
133  if (0!=status){
134  warning("SpecsMaster " + name() + " : reset failed [code=" + itos(status) + "]","reset");
135  }
136  else {
137  info("Reset SpecsMaster "+name()+".","SpecsMaster::reset");
138  }
139 #else
140  debug("Compilation in the _NODEVICE_ mode.","SpecsMaster::reset");
141 #endif
142  setSpeed(m_speed);
143 }
144 
145 
146 //=============================================================================
147 //
148 //=============================================================================
149 void SpecsMaster::setSpeed(unsigned char speed){
150  m_speed=speed;
151  if ( 3 != speed ){
152  warning("Having a speed higher than 3 may cause problem.",
153  "SpecsMaster::setSpeed");
154  }
155  debug("SpecsMaster "+name()+" : Speed Reduction -> 2^"+itos(m_speed),"SpecsMaster::setSpeed");
156 #ifndef _NODEVICE_
157  // unsigned int value ;
158  // value = ( ( m_speed ) & 0x7 ) ;
159  SpecsmasterCtrlWrite(&m_specsMaster,m_speed);
160 #endif
161 }
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
unsigned char m_speed
Definition: SpecsMaster.h:71
void add(int attribut)
Definition: Attrib.h:67
void setName(std::string name)
Definition: Object.h:51
SpecsMaster * specsMaster()
Definition: SpecsMaster.cpp:46
void setType(std::string type)
Definition: Object.h:52
bool m_specsMasterOpen
Definition: SpecsMaster.h:72
unsigned char U8
Definition: ICECALv3.h:55
StatusCode init()
Definition: SpecsMaster.cpp:69
void error(std::string mymsg)
Definition: Object.h:40
void setId(unsigned char id)
Definition: Object.h:53
void debug(std::string mymsg)
Definition: Object.h:37
void setSpeed(unsigned char)
SPECSMASTER m_specsMaster
Definition: SpecsMaster.h:74
unsigned char speed()
Definition: SpecsMaster.h:64
unsigned char m_pciDevID
Definition: SpecsMaster.h:69
SPECSMASTER * specsMasterDevice()
Definition: SpecsMaster.cpp:54
void setMasterDevID(unsigned char masterDevID)
Definition: SpecsMaster.h:38
void setPciDevID(unsigned char pciDevID)
Definition: SpecsMaster.h:30
std::string name() const
Definition: Object.h:28
void warning(std::string mymsg)
Definition: Object.h:39
unsigned char m_masterDevID
Definition: SpecsMaster.h:70