Cat
SpecsInterface.cpp
Go to the documentation of this file.
1 //$Id: SpecsInterface.cpp,v 1.15 2006/10/04 19:53:25 fmachefe Exp $
2 //-----------------------------------------------------------------------------
3 //
4 // Package : SpecsInterface
5 //
6 // Description:
7 //
8 // Author(s) : F. Machefert -
9 // Date : 18 January 2004
10 //
11 //-----------------------------------------------------------------------------
12 
13 // Include files
14 //#include "Tools.h"
15 #include "SpecsMaster.h"
16 #include "SpecsSlave.h"
17 
18 // local
19 #include "SpecsInterface.h"
20 
22  m_address=0;
23  m_outputSelect=0x0;
24  setId(0);
25 
26 
27 }
28 
29 void SpecsInterface::setAddress(unsigned char address){
31 }
32 
33 unsigned char SpecsInterface::address() {
34  return m_address;
35 }
36 
39 }
40 
42  return m_outputSelect;
43 }
44 
45 //=========================================================================
46 //
47 //=========================================================================
48 
50  if (0!=parent()){
51  SpecsInterface* tmp = dynamic_cast <SpecsInterface*> (parent());
52  if ( 0 != tmp ) return tmp->specsSlave();
53  }
54  return (SpecsSlave*)NULL;
55 }
56 
58  if (0!=parent()){
59  SpecsInterface* tmp = dynamic_cast <SpecsInterface*> (parent());
60  if ( 0 != tmp ) return tmp->specsMaster();
61  }
62  return (SpecsMaster*)NULL;
63 }
64 
65 #ifndef _NODEVICE_
67  if (0!=parent()){
68  SpecsInterface* tmp = dynamic_cast <SpecsInterface*> (parent());
69  if ( 0 != tmp ) return tmp->specsSlaveDevice();
70  }
71  return (SPECSSLAVE*)NULL;
72 }
73 #endif
74 
75 #ifndef _NODEVICE_
77  if (0!=parent()){
78  SpecsInterface* tmp = dynamic_cast <SpecsInterface*> (parent());
79  if ( 0 != tmp ) return tmp->specsMasterDevice();
80  }
81  return (SPECSMASTER*)NULL;
82 }
83 #endif
84 
85 bool SpecsInterface::specsWriteI2c(unsigned char i2cAdd,
86  unsigned char nWord,
87  U8* data){
88 #ifndef _NODEVICE_
89  SPECSSLAVE *specsSlv=specsSlaveDevice();
90  if ( 0==specsSlv ){
91  warning("Could not reach proper Specs Master and/or Slave.","SpecsInterface::specsWriteI2c");
92  return false;
93  }
94  SpecsError status = specs_i2c_write ( specsSlv, outputSelect() , i2cAdd , nWord , data );
95  if (0!=status){
96  warning("failure at address " + itos (i2cAdd) + "[code=" + itos(status) + "]" ,
97  "specsWriteI2c");
98  // specsMaster() -> reset();
99  }
100  else {
101  verbose(itos(nWord) + " words written at address " + itos(i2cAdd),
102  "SpecsWriteI2c");
103  }
104 #else
105  verbose("Compilation in _NODEVICE_ mode.","SpecsInterface::specsWriteI2c");
106 #endif
107  return true;
108 }
109 
110 
112  std::vector<U8> data ){
113 
114  unsigned char nword = static_cast<unsigned int>( data.size() );
115  if ( nword == 0 ) {
116  warning("Request to write data of size 0","SpecsInterface::specsWriteI2c");
117  return false;
118  }
119  unsigned char* new_data = new unsigned char[nword];
120  for(unsigned int i=0; i<data.size(); ++i) new_data[i] = data[i];
121 
122  bool status = specsWriteI2c(address, nword, new_data);
123  delete [] new_data;
124  return status;
125 
126  return true;
127 }
128 
129 bool SpecsInterface::specsWriteI2c( unsigned char i2cAdd ,
130  unsigned char subAdd ,
131  unsigned char nWord ,
132  U8* data ){
133 #ifndef _NODEVICE_
134  SPECSSLAVE *specsSlv=specsSlaveDevice();
135  if ( 0==specsSlv ){
136  warning("Could not reach proper Specs Master and/or Slave.","SpecsInterface::specsWriteI2c");
137  return false;
138  }
139  SpecsError status = specs_i2c_write_sub ( specsSlv, outputSelect() , i2cAdd , subAdd , nWord , data );
140  if (0!=status){
141  warning("failure at address " + itos (i2cAdd) + "/ subAddress " + itos(subAdd) +
142  " [code=" + itos(status) + "]","specsWriteI2c");
143  // specsMaster() -> reset();
144  }
145  else {
146  verbose(itos(nWord) +
147  " words written at address " +
148  itos(i2cAdd) +
149  "/ subAddress " +
150  itos(subAdd),
151  "SpecsWriteI2c");
152  }
153 #else
154  verbose("Compilation in _NODEVICE_ mode.","SpecsInterface::specsWriteI2c");
155 #endif
156  return true;
157 }
158 
159 bool SpecsInterface::specsWriteI2c( unsigned char i2cAdd ,
160  unsigned char outputSel,
161  unsigned char subAdd ,
162  unsigned char nWord ,
163  U8* data ){
164 #ifndef _NODEVICE_
165  SPECSSLAVE *specsSlv=specsSlaveDevice();
166  if ( 0==specsSlv ){
167  warning("Could not reach proper Specs Master and/or Slave.",
168  "SpecsInterface::specsWriteI2c");
169  return false;
170  }
171  SpecsError status = specs_i2c_write_sub ( specsSlv, outputSel ,
172  i2cAdd , subAdd ,
173  nWord , data );
174  if (0!=status){
175  warning("failure at address " + itos (i2cAdd) + "/ subAddress " + itos(subAdd) +
176  " [code=" + itos(status) + "]" ,
177  "specsWriteI2c");
178  // specsMaster() -> reset();
179  }
180  else {
181  verbose(itos(nWord) + " words written at address " + itos(i2cAdd) +
182  "/ subAddress " + itos(subAdd),
183  "SpecsWriteI2c");
184  }
185 #else
186  verbose("Compilation in _NODEVICE_ mode.","SpecsInterface::specsWriteI2c");
187 #endif
188  return true;
189 }
190 
191 bool SpecsInterface::specsReadI2c(unsigned char i2cAdd,
192  unsigned char nOctets,
193  U8* i2cWords ){
194 #ifndef _NODEVICE_
195  SPECSSLAVE *specsSlv=specsSlaveDevice();
196  if ( 0==specsSlv ){
197  warning("Could not reach proper Specs Master and/or Slave.",
198  "SpecsInterface::specsReadI2c");
199  return false;
200  }
201  SpecsError status = specs_i2c_read ( specsSlv, outputSelect() , i2cAdd , nOctets , i2cWords );
202  if (0!=status){
203  warning("failure at address " + itos (i2cAdd) + "[code=" + itos(status) + "]",
204  "specsReadI2c" );
205  // specsMaster() -> reset();
206  }
207  else {
208  verbose(itos(nOctets) + " words read at address " + itos(i2cAdd),"SpecsReadI2c");
209  }
210 #else
211  verbose("Compilation in _NODEVICE_ mode.","SpecsInterface::specsReadI2c");
212 #endif
213  return true;
214 }
215 
217  std::vector<unsigned char>& specsWords ){
218 
219  int nOctets = specsWords.size();
220  if( nOctets==0) {
221  warning("The vector of data to read should have a non-zero size",
222  "SpecsInterface::specsReadI2c");
223  return false;
224  }
225 
226  U8 BufferSource[50];
227 
228  bool status = specsReadI2c(address, nOctets, BufferSource);
229 
230  for(int j=0; j<nOctets; ++j) specsWords[j] = static_cast<unsigned char>(BufferSource[j]);
231 
232  return status;
233 }
234 
235 bool SpecsInterface::specsReadI2c(unsigned char i2cAdd,
236  unsigned char subAdd,
237  unsigned char nOctets,
238  U8* i2cWords){
239 #ifndef _NODEVICE_
240  SPECSSLAVE *specsSlv=specsSlaveDevice();
241  if ( 0==specsSlv ){
242  warning("Could not reach proper Specs Master and/or Slave.","SpecsInterface::specsReadI2c");
243  return false;
244  }
245  SpecsError status = specs_i2c_read_sub ( specsSlv, outputSelect() , i2cAdd , subAdd , nOctets , i2cWords );
246  if (0!=status){
247  warning("failure at address " + itos (i2cAdd) + "/ subAddress " + itos(subAdd) +
248  " [code=" + itos(status) + "]" ,
249  "specsReadI2c");
250  // specsMaster() -> reset();
251  }
252  else {
253  verbose(itos(nOctets) + " words read at address " + itos(i2cAdd) +
254  "/ subAddress " + itos(subAdd),
255  "SpecsReadI2c");
256  }
257 #else
258  verbose("Compilation in _NODEVICE_ mode.","SpecsInterface::specsReadI2c");
259 #endif
260  return true;
261 }
262 
263 bool SpecsInterface::specsReadI2c(unsigned char i2cAdd,
264  unsigned char outputSel,
265  unsigned char subAdd,
266  unsigned char nOctets,
267  U8* i2cWords){
268 #ifndef _NODEVICE_
269  SPECSSLAVE *specsSlv=specsSlaveDevice();
270  if ( 0==specsSlv ){
271  warning("Could not reach proper Specs Master and/or Slave.",
272  "SpecsInterface::specsReadI2c");
273  return false;
274  }
275  SpecsError status = specs_i2c_read_sub ( specsSlv, outputSel ,
276  i2cAdd , subAdd ,
277  nOctets , i2cWords );
278  if (0!=status){
279  warning("failure at address " + itos (i2cAdd) + "/ subAddress " + itos(subAdd) +
280  " [code=" + itos(status) + "]",
281  "specsReadI2c" );
282  // specsMaster() -> reset();
283  }
284  else {
285  verbose(itos(nOctets) + " words read at address " + itos(i2cAdd) +
286  "/ subAddress " + itos(subAdd),
287  "SpecsReadI2c");
288  }
289 #else
290  verbose("Compilation in _NODEVICE_ mode.","SpecsInterface::specsReadI2c");
291 #endif
292  return true;
293 }
294 
296  U16 value){
297 #ifndef _NODEVICE_
298  SPECSSLAVE *specsSlv=specsSlaveDevice();
299  if ( 0==specsSlv ){
300  warning("Could not reach proper Specs Master and/or Slave.",
301  "SpecsInterface::specsWriteParallel");
302  return false;
303  }
304  SpecsError status = specs_parallel_write( specsSlv , add , 1 , &value );
305  if (0!=status){
306  warning("failure at address " + itos (add) +
307  " [code=" + itos(status) + "]" ,
308  "specsWriteParallel");
309  // specsMaster() -> reset();
310  }
311  else {
312  verbose("Word " + itos( value ) +
313  " successfully written at address " + itos(add),
314  "SpecsWriteParallel");
315  }
316 #else
317  verbose("Compilation in _NODEVICE_ mode.",
318  "SpecsWriteParallel");
319 #endif
320  return true;
321 }
322 
324  U16 &parallelBus){
325 #ifndef _NODEVICE_
326  SPECSSLAVE *specsSlv=specsSlaveDevice();
327  if ( 0==specsSlv ){
328  warning("Could not reach proper SpecsSlave/Master.","SpecsInterface::specsReadI2c");
329  return false;
330  }
331  SpecsError status = specs_parallel_read( specsSlv , add , 1 , &parallelBus );
332  if (0!=status){
333  warning("failure at address " + itos (add) +
334  " [code=" + itos(status) + "]",
335  "specsReadParallel" );
336  // specsMaster() -> reset();
337  }
338  else {
339  verbose("Word " + itos(parallelBus) +
340  " successfully read at address " + itos(add),
341  "SpecsReadParallel");
342  }
343 #else
344  verbose("Compilation in _NODEVICE_ mode.",
345  "SpecsReadParallel");
346 #endif
347  return true;
348 }
349 
350 
351 bool SpecsInterface::specsWriteRegister(unsigned char reg,
352  unsigned short value){
353 #ifndef _NODEVICE_
354  SPECSSLAVE *specsSlv=specsSlaveDevice();
355 
356  if ( 0==specsSlv ){
357  warning("Could not reach proper SpecsSlave/Master.",
358  "SpecsInterface::specsWriteRegister");
359  return false;
360  }
361 
362  SpecsError status ;
363  status = specs_register_write ( specsSlv , reg , value );
364  if ( 0 != status ){
365  warning("failure at register " + itos (reg) +
366  " [code=" + itos(status) + "]" ,
367  "specsWriteRegister");
368  // specsMaster() -> reset();
369  return false;
370  }
371  else {
372  verbose("register " + itos(reg) +
373  " successfully written with value " + itos (value),
374  "SpecsWriteRegister");
375  }
376 #else
377  verbose("Compilation in _NODEVICE_ mode.",
378  "SpecsInterface::specsWriteRegister");
379 #endif
380  return true;
381 }
382 
383 bool SpecsInterface::specsReadRegister(unsigned char reg,
384  U16 & value){
385 #ifndef _NODEVICE_
386  SPECSSLAVE *specsSlv=specsSlaveDevice();
387 
388  if ( 0==specsSlv ){
389  warning("Could not reach proper SpecsSlave/Master.",
390  "SpecsInterface::specsReadRegister");
391  return false;
392  }
393 
394  SpecsError status ;
395  status = specs_register_read ( specsSlv , reg , &value );
396  if (0!=status){
397  warning("failure at register " + itos (reg) +
398  " [code=" + itos(status) + "]" ,
399  "specsReadRegister");
400  // specsMaster() -> reset();
401  return false;
402  }
403  else {
404  verbose("register " + itos(reg) +
405  " successfully read with value " + itos(value),
406  "SpecsReadRegister");
407  }
408 #else
409  verbose("Compilation in _NODEVICE_ mode.",
410  "SpecsInterface::specsReadRegister");
411 #endif
412  return true;
413 }
std::string itos(int)
Definition: Tools.cpp:46
void verbose(std::string mymsg)
Definition: Object.h:36
virtual SpecsMaster * specsMaster()
void add(int attribut)
Definition: Attrib.h:67
bool specsReadI2c(unsigned char address, unsigned char nOctects, U8 *i2cWords)
bool specsReadParallel(unsigned char address, U16 &data)
bool specsWriteI2c(unsigned char address, unsigned char nData, U8 *data)
Hierarchy * parent()
Definition: Hierarchy.h:28
unsigned char address()
bool specsWriteRegister(unsigned char, unsigned short)
unsigned char U8
Definition: ICECALv3.h:55
void setId(unsigned char id)
Definition: Object.h:53
def data(object, stream=None)
Definition: shell.py:150
unsigned char m_address
virtual SPECSSLAVE * specsSlaveDevice()
unsigned char m_outputSelect
bool specsWriteParallel(unsigned char address, unsigned short data)
virtual SPECSMASTER * specsMasterDevice()
virtual SpecsSlave * specsSlave()
unsigned char outputSelect()
unsigned short U16
Definition: ICECALv3.h:54
void warning(std::string mymsg)
Definition: Object.h:39
void setOutputSelect(unsigned char)
void setAddress(unsigned char)
bool specsReadRegister(unsigned char, U16 &)