Cat
DCU.cpp
Go to the documentation of this file.
1 // $Id: DCU.cpp,v 1.6 2007/10/11 11:06:55 fmachefe Exp $
2 
3 // include files
4 #include <algorithm>
5 #include <sstream>
6 
7 // Include files
8 #include "Element.h"
9 #include "Tools.h"
10 
11 // local
12 #include "DCU.h"
13 
14 #if defined(_DEBUG) && !defined(USE_ROOT) && defined(WIN32)
15 #define new DEBUG_NEW
16 #endif
17 
18 //-----------------------------------------------------------------------------
19 // Implementation file for class : DCU
20 //
21 // 2005-05-31 : Frédéric Machefert
22 //-----------------------------------------------------------------------------
23 
24 //=============================================================================
25 // Standard constructor, initializes variables
26 //=============================================================================
28  setType( "DCU" ) ;
29  setId( 0 ) ;
30  debug("DCU::DCU" , "DCU built" ) ;
31  m_outputSelect = 0xF ;
32 }
33 //=============================================================================
34 // Destructor
35 //=============================================================================
36 DCU::~DCU( ) { }
37 
38 /*
39 bool DCU::cmdline(std::vector <std::string> cmd){
40  if ( 0==cmd.size() ){
41  char line[200];
42  std::string tmp;
43 
44  U8 dcumode = 0 ;
45  readMode ( dcumode );
46  if ( 0 == dcumode ) {
47  msgSvc (INFO,"cmdline","DCU Mode : HIR");
48  }
49  else {
50  msgSvc (INFO,"cmdline","DCU Mode : LIR");
51  }
52 
53  U16 data [7];
54  double value[7];
55  for (int i = 0 ; i < 7 ; ++i ) {
56  acquire ( i , data[i] , value[i] );
57  }
58 
59  sprintf(line,"Raw Data %6i %6i %6i %6i %6i %6i %6i",
60  data[0], data[1],
61  data[2], data[3],
62  data[4], data[5],
63  data[6]);
64  msgSvc(INFO,"cmdline",line);
65 
66  sprintf(line,"Value (v) %6.3lf %6.3lf %6.3lf %6.3lf %6.3lf %6.3lf %6.3lf",
67  value[0],value[1],
68  value[2],value[3],
69  value[4],value[5],
70  value[6]);
71  msgSvc(INFO,"cmdline",line);
72  return true;
73  }
74 
75  transform(cmd[0].begin(),cmd[0].end(),cmd[0].begin(),tolower);
76 
77  if (cmd[0].compare("reset")==0){
78  reset();
79  return true;
80  }
81 
82  if (cmd[0].compare("lir")==0){
83  setLIR();
84  return true;
85  }
86 
87  if (cmd[0].compare("hir")==0){
88  setHIR();
89  return true;
90  }
91  return false;
92 }
93 */
94 
95 //=============================================================================
96 // perform acqUsition on a DCU channel
97 //=============================================================================
98 bool DCU::acquire( U8 channel , U16 & data , double & value ) {
99 #ifndef _NODEVICE_
100  SPECSSLAVE *specsSlv=specsSlaveDevice();
101  if ( 0==specsSlv ){
102  warning("DCU::acquire",
103  "Could not reach proper Specs Master and/or Slave.");
104  return false;
105  }
106 
107  SpecsError status = specs_dcu_acquire (specsSlv
108 #ifdef _OLDSPECSLIB_
109  ,address()
110 #endif
111  ,channel,
112  &data,
113  &value);
114 
115  if (0!=status){
116  warning("DCU::acquire","Acquisition failure channel " +
117  itos (channel) +
118  "[code=" + itos(status) + "]" );
119  return false;
120  }
121  else {
122  verbose("DCU::acquire","Channel " + itos (channel) +
123  " -> Acquisition : " + itos(data) );
124  }
125 #else
126  verbose("DCU::acquire","Compilation in _NODEVICE_ mode.");
127 #endif
128  return true;
129 }
130 
131 // ============================================================================
132 // Reset DCU
133 // ============================================================================
134 void DCU::reset( ) {
135 #ifndef _NODEVICE_
136  SPECSSLAVE *specsSlv=specsSlaveDevice();
137  if ( 0==specsSlv ){
138  warning"DCU::reset","Could not reach proper Specs Master and/or Slave.");
139  return;
140  }
141  SpecsError status = specs_dcu_reset (specsSlv
142 #ifdef _OLDSPECSLIB_
143  ,address()
144 #endif
145 );
146  if (0!=status){
147  warning("DCU::reset","Could not properly reset the DCU.");
148  return;
149  }
150  else {
151  verbose("DCU::reset","DCU reset.");
152  }
153 #else
154 verbose("DCU::reset","Compilation in _NODEVICE_ mode.");
155 #endif
156 }
157 
158 // ============================================================================
159 // Initialize DCU
160 // ============================================================================
162 #ifndef _NODEVICE_
163  SPECSSLAVE *specsSlv=specsSlaveDevice();
164  if ( 0==specsSlv ){
165  warning("DCU::init",
166  "Could not reach proper Specs Master and/or Slave.");
167  return StatusCode::FAILURE;
168  }
169  SpecsError status = specs_dcu_initialize (specsSlv
170 #ifdef _OLDSPECSLIB_
171  ,address()
172 #endif
173 );
174  if (0!=status){
175  warning("DCU::init","Could not properly init the DCU.");
176  return StatusCode::FAILURE;
177  }
178  else {
179  verbose("DCU::init","DCU init.");
180  }
181 #else
182  verbose("DCU::init","Compilation in _NODEVICE_ mode.");
183 #endif
184  return StatusCode::SUCCESS;
185 }
186 
187 // ============================================================================
188 // set LIR Mode
189 // ============================================================================
190 bool DCU::setLIR( ) {
191 #ifndef _NODEVICE_
192  SPECSSLAVE *specsSlv=specsSlaveDevice();
193  if ( 0==specsSlv ){
194  warning("DCU::setLIR",
195  "Could not reach proper Specs Master and/or Slave.");
196  return false;
197  }
198  SpecsError status = specs_dcu_set_LIR (specsSlv
199 #ifdef _OLDSPECSLIB_
200  ,address()
201 #endif
202 );
203  if (0!=status){
204  msgSvc( WARNING, "DCU::setLIR","Could not properly set LIR Mode");
205  return false;
206  }
207  else {
208  verbose("DCU::setLIR","DCU LIR Mode set");
209  }
210 #else
211  verbose("DCU::setLIR",
212  "Compilation in _NODEVICE_ mode.");
213 #endif
214  return true;
215 }
216 
217 // ============================================================================
218 // set HIR Mode
219 // ============================================================================
220 bool DCU::setHIR( ) {
221 #ifndef _NODEVICE_
222  SPECSSLAVE *specsSlv=specsSlaveDevice();
223  if ( 0==specsSlv ){
224  warning("DCU::setHIR",
225  "Could not reach proper Specs Master and/or Slave.");
226  return false;
227  }
228  SpecsError status = specs_dcu_set_HIR (specsSlv
229 #ifdef _OLDSPECSLIB_
230  ,address()
231 #endif
232 );
233  if (0!=status){
234  msgSvc( WARNING, "DCU::setHIR","Could not properly set HIR Mode");
235  return false;
236  }
237  else {
238  verbose("DCU::setHIR","DCU HIR Mode set");
239  }
240 #else
241  verbose("DCU::setHIR",
242  "Compilation in _NODEVICE_ mode.");
243 #endif
244  return true;
245 }
246 
247 //=============================================================================
248 // Read DCU Mode
249 //=============================================================================
250 bool DCU::readMode( U8 & mode ){
251 #ifndef _NODEVICE_
252  SPECSSLAVE *specsSlv=specsSlaveDevice();
253  if ( 0==specsSlv ){
254  warning("DCU::readMode",
255  "Could not reach proper Specs Master and/or Slave.");
256  return false;
257  }
258 
259  SpecsError status = specs_dcu_read_mode (specsSlv
260 #ifdef _OLDSPECSLIB_
261  ,address()
262 #endif
263  ,&mode);
264 
265  if (0!=status){
266  msgSvc( WARNING, "DCU::readMode","Could not properly read DCU Mode");
267  return false;
268  }
269  else {
270  switch (mode){
271  case 0:
272  verbose("DCU::readMode","DCU read Mode HIR" );
273  break;
274  default:
275  verbose("DCU::readMode","DCU read Mode LIR" );
276  }
277  }
278 #else
279  verbose("DCU::readMode",
280  "Compilation in _NODEVICE_ mode.");
281 #endif
282  return true;
283 }
284 
285 //=============================================================================
286 // Convert input value
287 //=============================================================================
288 bool DCU::convert( std::string & output_value ,
289  U16 input_value ,
290  U8 channel ){
291  U8 mode = 0 ;
292  if ( ! ( readMode( mode ) ) ) {
293  warning("DCU::convertInputValueViaI2c","Cannot read mode" ) ;
294  return false ;
295  }
296 
297  std::string unit = "V" ;
298 
299  if ( channel == 7 ) unit = "C" ;
300 
301  double value ;
302 
303  if ( channel == 7 )
304  value = ( (double) ( input_value - 2469 ) ) / 9.22 + 25. ;
305  else
306  if ( mode == 1 )
307  value = input_value * 0.0003052 ;
308  else if ( mode == 0 )
309  value = 2.5 - input_value * 0.0003052 ;
310 
311  std::ostringstream outstr ;
312  outstr << value << " " << unit ;
313 
314  output_value = outstr.str() ;
315 
316  return true ;
317 }
318 
std::string itos(int)
Definition: Tools.cpp:46
bool readMode(U8 &mode)
Definition: DCU.cpp:250
void verbose(std::string mymsg)
Definition: Object.h:36
bool setHIR()
Definition: DCU.cpp:220
bool acquire(U8, U16 &, double &)
Definition: DCU.cpp:98
unsigned char U8
Definition: DCU.h:19
U8 m_outputSelect
Definition: DCU.h:60
void setType(std::string type)
Definition: Object.h:52
void setId(unsigned char id)
Definition: Object.h:53
void debug(std::string mymsg)
Definition: Object.h:37
def data(object, stream=None)
Definition: shell.py:150
bool convert(std::string &converted_value, U16 input_value, U8 channel)
Definition: DCU.cpp:288
StatusCode init()
Definition: DCU.cpp:161
DCU()
Constructor.
Definition: DCU.cpp:27
unsigned short U16
Definition: DCU.h:18
U8 address()
Definition: DCU.h:50
~DCU()
Destructor.
Definition: DCU.cpp:36
void msgSvc(int level, std::string msg, std::string name)
Definition: Object.h:33
bool setLIR()
Definition: DCU.cpp:190
void warning(std::string mymsg)
Definition: Object.h:39
void reset()
Definition: DCU.cpp:134