Cat
Public Member Functions | Protected Attributes | Private Attributes | List of all members
SpecsSlave Class Reference

#include <SpecsSlave.h>

Inheritance diagram for SpecsSlave:
SpecsInterface Interface Element Hierarchy Object Attrib SpecsGlue SpecsMezzanine

Public Member Functions

 SpecsSlave ()
 
 ~SpecsSlave ()
 
void addI2c (Hierarchy *)
 
void setAddress (unsigned char)
 
SPECSSLAVE * specsSlaveDevice ()
 
bool detect ()
 
StatusCode init ()
 
void recursiveInitCommunications ()
 
void resetInternal ()
 
void reset ()
 
- Public Member Functions inherited from SpecsInterface
 SpecsInterface ()
 
virtual ~SpecsInterface ()
 
virtual void help ()
 
virtual void update ()
 
void setAddress (unsigned char)
 
unsigned char address ()
 
void setOutputSelect (unsigned char)
 
unsigned char outputSelect ()
 
virtual SpecsSlave * specsSlave ()
 
virtual SpecsMaster * specsMaster ()
 
virtual SPECSMASTER * specsMasterDevice ()
 
virtual StatusCode read (IOdata *io)
 
virtual StatusCode write (IOdata *io)
 
bool specsWriteI2c (unsigned char address, unsigned char nData, U8 *data)
 
bool specsWriteI2c (unsigned char address, std::vector< U8 > data)
 
bool specsReadI2c (unsigned char address, unsigned char nOctects, U8 *i2cWords)
 
bool specsReadI2c (unsigned char address, std::vector< unsigned char > &specsWords)
 
bool specsWriteI2c (unsigned char address, unsigned char subAddress, unsigned char nData, U8 *data)
 
bool specsWriteI2c (unsigned char address, unsigned char outputSel, unsigned char subAddress, unsigned char nData, U8 *data)
 
bool specsReadI2c (unsigned char address, unsigned char subAddress, unsigned char nOctets, U8 *i2cWords)
 
bool specsReadI2c (unsigned char address, unsigned char outputSel, unsigned char subAddress, unsigned char nOctets, U8 *i2cWords)
 
bool specsWriteParallel (unsigned char address, unsigned short data)
 
bool specsReadParallel (unsigned char address, U16 &data)
 
bool specsWriteRegister (unsigned char, unsigned short)
 
bool specsReadRegister (unsigned char, U16 &)
 
- Public Member Functions inherited from Interface
 Interface ()
 Standard constructor. More...
 
virtual ~Interface ()
 Destructor. More...
 
- Public Member Functions inherited from Element
 Element ()
 Standard constructor. More...
 
virtual ~Element ()
 Destructor. More...
 
void recursiveInitElement ()
 
void recursiveInitCommunications ()
 
StatusCode setConnection (Hierarchy *)
 
Hierarchy * connection ()
 
- Public Member Functions inherited from Hierarchy
 Hierarchy ()
 Standard constructor. More...
 
virtual ~Hierarchy ()
 Destructor. More...
 
void clear ()
 
void setParent (Hierarchy *parent)
 
Hierarchy * parent ()
 
Hierarchy * parent (std::string)
 
Hierarchy * origin ()
 
virtual void addChild (Hierarchy *element)
 
std::vector< Hierarchy * > children ()
 
Hierarchy * child (std::string)
 
Hierarchy * childTyped (std::string)
 
unsigned long numberOfChildren ()
 
bool hasChildren ()
 
void delChild (Hierarchy *)
 
void delChild (std::string)
 
std::string path (std::string=std::string(""))
 
std::string pathTyped (std::string=std::string(""))
 
void tree (std::string indent=std::string(""))
 
void tree ()
 
- Public Member Functions inherited from Object
 Object ()
 Standard constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
std::string name () const
 
std::string type ()
 
unsigned char id ()
 
std::string title ()
 
void msgSvc (int level, std::string msg, std::string name)
 
void msg (std::string mymsg)
 
void verbose (std::string mymsg)
 
void debug (std::string mymsg)
 
void info (std::string mymsg)
 
void warning (std::string mymsg)
 
void error (std::string mymsg)
 
void fatal (std::string mymsg)
 
void msg (std::string mymsg, std::string name)
 
void verbose (std::string mymsg, std::string name)
 
void debug (std::string mymsg, std::string name)
 
void info (std::string mymsg, std::string name)
 
void warning (std::string mymsg, std::string name)
 
void error (std::string mymsg, std::string name)
 
void fatal (std::string mymsg, std::string name)
 
void setName (std::string name)
 
void setType (std::string type)
 
void setId (unsigned char id)
 
void setTitle (std::string title)
 
void setDllName (std::string dllName)
 
std::string dllName ()
 
- Public Member Functions inherited from Attrib
 Attrib ()
 Standard constructor. More...
 
virtual ~Attrib ()
 Destructor. More...
 
bool is (int attribut)
 
void add (int attribut)
 
void remove (int attribut)
 
std::string attributs ()
 

Protected Attributes

SpecsI2c * i2c
 
- Protected Attributes inherited from SpecsInterface
unsigned char m_address
 
unsigned char m_outputSelect
 
- Protected Attributes inherited from Element
Hierarchy * m_connection
 
- Protected Attributes inherited from Attrib
std::string m_attribString [10]
 

Private Attributes

SPECSSLAVE specsSlave
 

Additional Inherited Members

- Public Types inherited from Attrib
enum  Attribut {
  UNDEFINED, PASSIVE, ACTIVE, INTERFACE,
  IO, IODATA, ELEMENT, HARDWARE,
  PROCESSUS, SOFTWARE
}
 

Detailed Description

Definition at line 21 of file SpecsSlave.h.

Constructor & Destructor Documentation

◆ SpecsSlave()

SpecsSlave::SpecsSlave ( )

Definition at line 32 of file SpecsSlave.cpp.

References Attrib::add(), Object::debug(), Attrib::ELEMENT, Attrib::HARDWARE, setAddress(), Object::setId(), and Object::setType().

32  {
33  debug("SpecsSlave built.","SpecsSlave::SpecsSlave");
34 
35  setAddress(0x0);
36  setType("SpecsSlave");
37  setId(0);
39 }
void add(int attribut)
Definition: Attrib.h:67
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
void setAddress(unsigned char)
Definition: SpecsSlave.cpp:50

◆ ~SpecsSlave()

SpecsSlave::~SpecsSlave ( )

Definition at line 44 of file SpecsSlave.cpp.

44  {
45 }

Member Function Documentation

◆ addI2c()

void SpecsSlave::addI2c ( Hierarchy *  element)

Definition at line 175 of file SpecsSlave.cpp.

References Hierarchy::addChild(), Object::debug(), i2c, Object::name(), and Hierarchy::setParent().

Referenced by BOOST_PYTHON_MODULE(), and SpecsMezzanine::SpecsMezzanine().

175  {
176  element->setParent(i2c);
177  i2c->addChild(element);
178  debug(element->name()+" added to the i2c child tree.","SpecsSlave::addI2c");
179 }
SpecsI2c * i2c
Definition: SpecsSlave.h:28
void setParent(Hierarchy *parent)
Definition: Hierarchy.cpp:67
void debug(std::string mymsg)
Definition: Object.h:37
std::string name() const
Definition: Object.h:28
virtual void addChild(Hierarchy *element)
Definition: Hierarchy.cpp:83

◆ detect()

bool SpecsSlave::detect ( )

Detect connection with the SpecsSlave by trying a register read

detect a SpecsSlave at a certain address

Parameters
addaddress of the specs slave looked at

Definition at line 119 of file SpecsSlave.cpp.

References SpecsInterface::address(), Object::debug(), Object::info(), itos(), Object::name(), SpecsMaster::reset(), SpecsInterface::specsMaster(), SpecsInterface::specsMasterDevice(), SpecsInterface::specsSlave(), specsSlaveDevice(), and Object::warning().

Referenced by BOOST_PYTHON_MODULE().

119  {
120 #ifndef _NODEVICE_
121  SPECSMASTER* master=specsMasterDevice();
122  if (0!=master){
123  SpecsError status = specs_slave_open ( master, address() , &specsSlave );
124  if (0!=status){
125  info("SpecsSlave "+name()+"could not be initialized correctly [code:"+
126  itos(status) + "].","initSpecs");
127  return false;
128  }
129  else{
130  SPECSSLAVE *specsSlv=specsSlaveDevice();
131  if ( 0==specsSlv ){
132  warning("Could not reach proper Specs Master and/or Slave.",
133  "SpecsElement::specsWriteI2c");
134  return false;
135  }
136 
137  U16 value ;
138  U8 reg = 8 ;
139  status = specs_register_read ( specsSlv , reg , &value );
140 
141  if (0!=status){
142  debug("No SpecsSlave detected at address " +
143  itos (address()) + "[code=" + itos(status) + "]",
144  "specsSlave::detect");
145  specsMaster()->reset();
146  return false;
147  }
148  else {
149  info("SpecsSlave detected at address " +
150  itos (address()) + "[date=" + itos(value)+"]",
151  "specsSlave::detect");
152  return true;
153  }
154  }
155  }
156 #endif
157  return false;
158 }
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
virtual SpecsMaster * specsMaster()
unsigned char address()
unsigned char U8
Definition: ICECALv3.h:55
void debug(std::string mymsg)
Definition: Object.h:37
SPECSSLAVE * specsSlaveDevice()
Definition: SpecsSlave.cpp:61
virtual SPECSMASTER * specsMasterDevice()
virtual SpecsSlave * specsSlave()
std::string name() const
Definition: Object.h:28
unsigned short U16
Definition: ICECALv3.h:54
void warning(std::string mymsg)
Definition: Object.h:39

◆ init()

StatusCode SpecsSlave::init ( )
virtual

init the component

Returns
void

Reimplemented from SpecsInterface.

Definition at line 69 of file SpecsSlave.cpp.

References SpecsInterface::address(), Object::debug(), StatusCode::FAILURE, Object::fatal(), Object::info(), itos(), Object::name(), reset(), resetInternal(), SpecsInterface::specsMasterDevice(), SpecsInterface::specsSlave(), StatusCode::SUCCESS, and Object::warning().

Referenced by BOOST_PYTHON_MODULE(), and recursiveInitCommunications().

69  {
70 #ifndef _NODEVICE_
71  SPECSMASTER* master=specsMasterDevice();
72  if (0!=master){
73  SpecsError status = specs_slave_open ( master, address() , &specsSlave );
74  if (0!=status){
75  warning("SpecsSlave " + name() + "could not be initialized correctly [code:" +
76  itos(status) + "].","SpecsSlave::initSpecs");
77  return StatusCode::FAILURE;
78  }
79  else{
80  int nAttempts = 10;
81  for (int i=0 ; i<nAttempts ; ++i){
82  U16 rd;
83  U16 wr = (U16)(rand()&&0xFFFC);
84  // specsWriteRegister(3,wr);
85  // specsReadRegister (3,rd);
86  rd=wr;
87  if (wr!=rd){
88  warning("Specs Slave "+name()+" [Add="+itos (address())+"] : wrong connection [attempt "+
89  itos(i)+"/"+itos (nAttempts)+"]. Further use of this slave is hazardeous.",
90  "SpecsSlave::init");
91  return StatusCode::FAILURE;
92  }
93  }
94  info("SpecsSlave "+name()+" initialized and connected to master.","SpecsSlave::init");
95  }
96  }
97  else{
98  fatal("Could not initialize SpecsSlave "+name()+".","SpecsSlave::init");
99  return StatusCode::FAILURE;
100  }
101 #else
102  debug("Compilation in the _NODEVICE_ mode.","SpecsSlave::init");
103 #endif
104  resetInternal();
105  reset();
106  return StatusCode::SUCCESS;
107 }
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
void reset()
Definition: SpecsSlave.cpp:204
void fatal(std::string mymsg)
Definition: Object.h:41
unsigned char address()
void resetInternal()
Definition: SpecsSlave.cpp:184
void debug(std::string mymsg)
Definition: Object.h:37
virtual SPECSMASTER * specsMasterDevice()
virtual SpecsSlave * specsSlave()
std::string name() const
Definition: Object.h:28
unsigned short U16
Definition: ICECALv3.h:54
void warning(std::string mymsg)
Definition: Object.h:39

◆ recursiveInitCommunications()

void SpecsSlave::recursiveInitCommunications ( )

Definition at line 163 of file SpecsSlave.cpp.

References Hierarchy::children(), and init().

163  {
164  init();
165  std::vector<Hierarchy*> list = this->children();
166  std::vector<Hierarchy*>::iterator iter;
167  for (iter=list.begin() ; iter!=list.end() ; ++iter){
168  dynamic_cast<Element*>((*iter))->recursiveInitCommunications();
169  }
170 }
void recursiveInitCommunications()
Definition: SpecsSlave.cpp:163
std::vector< Hierarchy * > children()
Definition: Hierarchy.h:33
StatusCode init()
Definition: SpecsSlave.cpp:69

◆ reset()

void SpecsSlave::reset ( )
virtual

External Reset of the Slave

Reimplemented from SpecsInterface.

Definition at line 204 of file SpecsSlave.cpp.

References SpecsInterface::address(), Object::debug(), itos(), Object::name(), specsSlaveDevice(), and Object::warning().

Referenced by SpecsMezzanine::cmdline(), and init().

204  {
205 #ifndef _NODEVICE_
206  SPECSSLAVE *specsSlv=specsSlaveDevice();
207  SpecsError status = specs_slave_external_reset ( specsSlv );
208  if (0!=status){
209  warning("SpecsSlave " + name() +
210  ": failure in performing the SpecsSlave reset [code:" +
211  itos(status) + "].",
212  "SpecsSlave::reset" ); }
213  else{
214  debug("reset of the specs slave "+
215  name()+" "+" [address="+itos(address())+"]." ,
216  "SpecsSlave::reset");
217  }
218 #endif
219 }
std::string itos(int)
Definition: Tools.cpp:46
unsigned char address()
void debug(std::string mymsg)
Definition: Object.h:37
SPECSSLAVE * specsSlaveDevice()
Definition: SpecsSlave.cpp:61
std::string name() const
Definition: Object.h:28
void warning(std::string mymsg)
Definition: Object.h:39

◆ resetInternal()

void SpecsSlave::resetInternal ( )

Internal Reset of the Slave

Definition at line 184 of file SpecsSlave.cpp.

References SpecsInterface::address(), Object::info(), itos(), Object::name(), specsSlaveDevice(), and Object::warning().

Referenced by BOOST_PYTHON_MODULE(), SpecsMezzanine::cmdline(), and init().

184  {
185 #ifndef _NODEVICE_
186  SPECSSLAVE *specsSlv=specsSlaveDevice();
187  SpecsError status = specs_slave_internal_reset ( specsSlv );
188  if (0!=status){
189  warning("SpecsSlave " + name() +
190  ": failure in performing the internal reset [code:" +
191  itos(status) + "].",
192  "SpecsSlave::reset" ); }
193  else{
194  info("internal reset of the specs slave "+
195  name()+" "+" [address="+itos(address())+"].",
196  "SpecsSlave::resetInternal");
197  }
198 #endif
199 }
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
unsigned char address()
SPECSSLAVE * specsSlaveDevice()
Definition: SpecsSlave.cpp:61
std::string name() const
Definition: Object.h:28
void warning(std::string mymsg)
Definition: Object.h:39

◆ setAddress()

void SpecsSlave::setAddress ( unsigned char  add)

Definition at line 50 of file SpecsSlave.cpp.

References Attrib::add(), SpecsInterface::m_address, and SpecsInterface::specsSlave().

Referenced by BOOST_PYTHON_MODULE(), SpecsMezzanine::cmdline(), SpecsGlue::SpecsGlue(), SpecsMezzanine::SpecsMezzanine(), and SpecsSlave().

50  {
51  m_address=add;
52 #ifndef _NODEVICE_
53  specsSlave.SpecsslaveAdd=add;
54 #endif
55 }
void add(int attribut)
Definition: Attrib.h:67
unsigned char m_address
virtual SpecsSlave * specsSlave()

◆ specsSlaveDevice()

SPECSSLAVE * SpecsSlave::specsSlaveDevice ( )
virtual

Get the closest slave in the element hierarchy

Returns
SPECSSLAVE*

Reimplemented from SpecsInterface.

Definition at line 61 of file SpecsSlave.cpp.

References SpecsInterface::specsSlave().

Referenced by detect(), reset(), and resetInternal().

61  {
62  return &specsSlave;
63 }
virtual SpecsSlave * specsSlave()

Member Data Documentation

◆ i2c

SpecsI2c* SpecsSlave::i2c
protected

Definition at line 28 of file SpecsSlave.h.

Referenced by addI2c().

◆ specsSlave

SPECSSLAVE SpecsSlave::specsSlave
private

Definition at line 24 of file SpecsSlave.h.


The documentation for this class was generated from the following files: