Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekateros::HekSysBoard Class Reference

Public Member Functions

 HekSysBoard ()
 Default constructor.
 
virtual ~HekSysBoard ()
 Destructor.
 
virtual int open (const std::string &dev=HekI2CDevice)
 Open all interfaces monitoring hardware. More...
 
virtual int close ()
 Close all interfaces to monitoring hardware. More...
 
virtual int scan ()
 Scan and initialize hardware. More...
 
virtual int cmdReadFwVersion (int &ver)
 Command to read firmware version. More...
 
virtual byte_t cmdReadLimits ()
 Command to read limit bit state. More...
 
virtual byte_t cmdReadAux ()
 Command to read auxilliary bit state. More...
 
virtual int cmdReadPin (int id)
 Command to read one I/O pin. More...
 
virtual int cmdWritePin (int id, int val)
 Command to write value to an I/O pin. More...
 
virtual int cmdConfigPin (int id, char dir)
 Command to configure direction of an I/O pin. More...
 
virtual int cmdSetAlarmLED (int val)
 Command to set Alarm LED. More...
 
virtual int cmdSetStatusLED (int val)
 Command to set Status LED. More...
 
virtual int cmdSetHaltingState ()
 Command to set monitoring state to halting. More...
 

Protected Member Functions

byte_t readIOExp (byte_t byCmd)
 Read I/O expander byte. More...
 
byte_t readIOExpPort0 ()
 Read I/O expander port 0. More...
 
byte_t readIOExpPort1 ()
 Read I/O expander port 1. More...
 
int writeIOExp (byte_t byCmd, byte_t byVal)
 Write byte to I/O expander. More...
 

Protected Attributes

i2c_struct m_i2c
 i2c bus
 

Detailed Description

Definition at line 67 of file hekSysBoard.h.

Member Function Documentation

int HekSysBoard::close ( )
virtual

Close all interfaces to monitoring hardware.

Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 122 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

123 {
124  if( m_i2c.fd >= 0 )
125  {
126  i2c_close(&m_i2c);
127  m_i2c.fd = -1;
128  m_i2c.addr = 0;
129  }
130 
131  return HEK_OK;
132 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
i2c_struct m_i2c
i2c bus
Definition: hekSysBoard.h:192
int HekSysBoard::cmdConfigPin ( int  id,
char  dir 
)
virtual

Command to configure direction of an I/O pin.

Parameters
idPin identifier.
dirPin direction 'i' or 'o'.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 254 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

255 {
256  // TODO
257  return HEK_OK;
258 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
byte_t HekSysBoard::cmdReadAux ( )
virtual

Command to read auxilliary bit state.

Auxillary bits are usually End Effector GPIO, but allows room for additional bits.

Returns
Returns auxilliary switches state as a bit packed byte.

Definition at line 162 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

163 {
164  byte_t cmd = HekIOExpCmdInput1;
165  byte_t val = 0;
166 
167 #ifdef TGT_EMBEDDED
168  if(i2c_transfer(&m_i2c, HekIOExpI2CAddr, &cmd, 1, &val, 1) < 0)
169  {
170  LOGSYSERROR("i2c_transfer: %s: addr=0x%.02x, command=%u.",
172  }
173 #endif // TGT_EMBEDDED
174 
175  return val;
176 }
static const byte_t HekIOExpI2CAddr
i2c 7-bit address
Definition: hekOptical.h:69
const char *const HekI2CDevice
i2c device name
Definition: hekateros.h:382
static const byte_t HekIOExpCmdInput1
read port 1 command
Definition: hekOptical.h:73
i2c_struct m_i2c
i2c bus
Definition: hekSysBoard.h:192
int HekSysBoard::cmdReadFwVersion ( int &  ver)
virtual

Command to read firmware version.

param [out] ver Version number.

Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 139 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

140 {
141  ver = 0;
142 
143  return HEK_OK;
144 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
byte_t HekSysBoard::cmdReadLimits ( )
virtual

Command to read limit bit state.

Returns
Returns limit switches state as a bit packed byte.

Definition at line 146 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

147 {
148  byte_t cmd = HekIOExpCmdInput0;
149  byte_t val = 0;
150 
151 #ifdef TGT_EMBEDDED
152  if(i2c_transfer(&m_i2c, HekIOExpI2CAddr, &cmd, 1, &val, 1) < 0)
153  {
154  LOGSYSERROR("i2c_transfer: %s: addr=0x%.02x, command=%u.",
156  }
157 #endif // TGT_EMBEDDED
158 
159  return val;
160 }
static const byte_t HekIOExpI2CAddr
i2c 7-bit address
Definition: hekOptical.h:69
const char *const HekI2CDevice
i2c device name
Definition: hekateros.h:382
static const byte_t HekIOExpCmdInput0
read port 0 command
Definition: hekOptical.h:72
i2c_struct m_i2c
i2c bus
Definition: hekSysBoard.h:192
int HekSysBoard::cmdReadPin ( int  id)
virtual

Command to read one I/O pin.

Parameters
idPin identifier.
Returns
Return pin state 0 or 1.

Definition at line 178 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

179 {
180  byte_t cmd;
181  int shift;
182  byte_t mask;
183  byte_t bits = 0;
184  int val = 0;
185 
186  if( id < 8 )
187  {
188  cmd = HekIOExpCmdInput0;
189  shift = id;
190  }
191  else
192  {
193  cmd = HekIOExpCmdInput1;
194  shift = id - 8;
195  }
196 
197  mask = 0x01 << shift;
198 
199 #ifdef TGT_EMBEDDED
200  if(i2c_transfer(&m_i2c, HekIOExpI2CAddr, &cmd, 1, &bits, 1) < 0)
201  {
202  LOGSYSERROR("i2c_transfer: %s: addr=0x%.02x, command=%u.",
204  }
205  else if( bits & mask )
206  {
207  val = 1;
208  }
209 #endif // TGT_EMBEDDED
210 
211  return val;
212 }
static const byte_t HekIOExpI2CAddr
i2c 7-bit address
Definition: hekOptical.h:69
const char *const HekI2CDevice
i2c device name
Definition: hekateros.h:382
static const byte_t HekIOExpCmdInput0
read port 0 command
Definition: hekOptical.h:72
static const byte_t HekIOExpCmdInput1
read port 1 command
Definition: hekOptical.h:73
i2c_struct m_i2c
i2c bus
Definition: hekSysBoard.h:192
int HekSysBoard::cmdSetAlarmLED ( int  val)
virtual

Command to set Alarm LED.

Parameters
valLED 0==off or 1==on value.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 260 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

261 {
262  // TODO overio gpio
263  return HEK_OK;
264 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
int HekSysBoard::cmdSetHaltingState ( )
virtual

Command to set monitoring state to halting.

Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 272 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

273 {
274  // not supported
275  return HEK_OK;
276 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
int HekSysBoard::cmdSetStatusLED ( int  val)
virtual

Command to set Status LED.

Parameters
valLED 0==off or 1==on value.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 266 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

267 {
268  // not supported
269  return HEK_OK;
270 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
int HekSysBoard::cmdWritePin ( int  id,
int  val 
)
virtual

Command to write value to an I/O pin.

Parameters
idPin identifier.
valPin state 0 or 1.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 214 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

215 {
216  byte_t cmd;
217  int shift;
218  byte_t mask;
219  byte_t bits;
220  byte_t buf[2];
221 
222  if( id < 8 )
223  {
224  cmd = HekIOExpCmdInput0;
225  shift = id;
226  bits = cmdReadLimits();
227  }
228  else
229  {
230  cmd = HekIOExpCmdInput0;
231  shift = id;
232  bits = cmdReadAux();
233  }
234 
235  mask = 0x01 << shift;
236  bits = (bits & ~mask) | (val & mask);
237 
238  buf[0] = cmd;
239  buf[1] = bits;
240 
241 #ifdef TGT_EMBEDDED
242  if(i2c_write(&m_i2c, HekIOExpI2CAddr, buf, 2) < 0)
243  {
244  LOGSYSERROR("i2c_write: %s: addr=0x%.02x, command=%u.",
246  return -HEK_ECODE_SYS;
247  }
248 #endif // TGT_EMBEDDED
249 
250  return HEK_OK;
251 
252 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
static const byte_t HekIOExpI2CAddr
i2c 7-bit address
Definition: hekOptical.h:69
const char *const HekI2CDevice
i2c device name
Definition: hekateros.h:382
virtual byte_t cmdReadLimits()
Command to read limit bit state.
virtual byte_t cmdReadAux()
Command to read auxilliary bit state.
static const int HEK_ECODE_SYS
system (errno) error
Definition: hekateros.h:73
static const byte_t HekIOExpCmdInput0
read port 0 command
Definition: hekOptical.h:72
i2c_struct m_i2c
i2c bus
Definition: hekSysBoard.h:192
int HekSysBoard::open ( const std::string &  dev = HekI2CDevice)
virtual

Open all interfaces monitoring hardware.

< off hekateros target

Parameters
devI2C device.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 72 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

73 {
74  byte_t val;
75  int rc;
76 
77  m_i2c.fd = -1;
78  m_i2c.addr = HekIOExpI2CAddr;
79 
80 #ifdef TGT_EMBEDDED
81 
82  // open i2c device
83  if( i2c_open(&m_i2c, dev.c_str()) < 0 )
84  {
85  LOGSYSERROR("%s.", dev.c_str());
86  return -HEK_ECODE_NO_DEV;
87  }
88 
89  LOGDIAG3("Hekateros i2c bus hardware initialized successfully.");
90 
91  //
92  // Set required i/o expansion configuration.
93  //
94 
95  // port 0 polarity
97 
98  if( val != HekIOExpConstPolarity0 )
99  {
101  {
102  return rc;
103  }
104  }
105 
106  // port 0 input/output direction
108 
109  if( val != HekIOExpConstConfig0 )
110  {
112  {
113  return rc;
114  }
115  }
116 
117 #endif // TGT_EMBEDDED
118 
119  return HEK_OK;
120 }
static const byte_t HekIOExpConstPolarity0
port 0 not inverted
Definition: hekOptical.h:85
static const int HEK_ECODE_NO_DEV
device not found error
Definition: hekateros.h:81
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
static const byte_t HekIOExpI2CAddr
i2c 7-bit address
Definition: hekOptical.h:69
static const byte_t HekIOExpCmdPolarity0
polarity inversion port 0
Definition: hekOptical.h:76
byte_t readIOExp(byte_t byCmd)
Read I/O expander byte.
static const byte_t HekIOExpConstConfig0
port 0 all input
Definition: hekOptical.h:86
int writeIOExp(byte_t byCmd, byte_t byVal)
Write byte to I/O expander.
static const byte_t HekIOExpCmdConfig0
configuration port 0 cmd
Definition: hekOptical.h:78
i2c_struct m_i2c
i2c bus
Definition: hekSysBoard.h:192
byte_t HekSysBoard::readIOExp ( byte_t  byCmd)
protected

Read I/O expander byte.

Parameters
byCmdI/O expander command.
Returns
Byte value.

Definition at line 278 of file hekSysBoard.cxx.

Referenced by readIOExpPort0(), and readIOExpPort1().

279 {
280  byte_t byVal = 0;
281 
282 #ifdef TGT_EMBEDDED
283  if(i2c_transfer(&m_i2c, HekIOExpI2CAddr, &byCmd, 1, &byVal, 1) < 0)
284  {
285  LOGSYSERROR("i2c_transfer: %s: addr=0x%.02x, command=%u.",
286  HekI2CDevice, HekIOExpI2CAddr, byCmd);
287  }
288 #endif // TGT_EMBEDDED
289 
290  return byVal;
291 }
static const byte_t HekIOExpI2CAddr
i2c 7-bit address
Definition: hekOptical.h:69
const char *const HekI2CDevice
i2c device name
Definition: hekateros.h:382
i2c_struct m_i2c
i2c bus
Definition: hekSysBoard.h:192
byte_t hekateros::HekSysBoard::readIOExpPort0 ( )
inlineprotected

Read I/O expander port 0.

All optical limit switches are tied to port 0.

Returns
Port 0 byte value.

Definition at line 210 of file hekSysBoard.h.

References hekateros::HekIOExpCmdInput0, and readIOExp().

211  {
213  }
static const byte_t HekIOExpCmdInput0
read port 0 command
Definition: hekOptical.h:72
byte_t readIOExp(byte_t byCmd)
Read I/O expander byte.
byte_t hekateros::HekSysBoard::readIOExpPort1 ( )
inlineprotected

Read I/O expander port 1.

All end effector i/o are tied to port 1.

Returns
Port 1 byte value.

Definition at line 222 of file hekSysBoard.h.

References hekateros::HekIOExpCmdInput1, readIOExp(), and writeIOExp().

223  {
225  }
static const byte_t HekIOExpCmdInput1
read port 1 command
Definition: hekOptical.h:73
byte_t readIOExp(byte_t byCmd)
Read I/O expander byte.
int HekSysBoard::scan ( )
virtual

Scan and initialize hardware.

Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 134 of file hekSysBoard.cxx.

Referenced by ~HekSysBoard().

135 {
136  return HEK_OK;
137 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
int HekSysBoard::writeIOExp ( byte_t  byCmd,
byte_t  byVal 
)
protected

Write byte to I/O expander.

Parameters
byCmdI/O expander command.
Bytevalue.
Returns
On success, HEK_OK is returned.
On error, the appropriate < 0 negated Hekateros Error Code is returned.

Definition at line 293 of file hekSysBoard.cxx.

Referenced by readIOExpPort1().

294 {
295  byte_t buf[2];
296 
297  buf[0] = byCmd;
298  buf[1] = byVal;
299 
300 #ifdef TGT_EMBEDDED
301  if(i2c_write(&m_i2c, HekIOExpI2CAddr, buf, 2) < 0)
302  {
303  LOGSYSERROR("i2c_write: %s: addr=0x%.02x, command=%u.",
304  HekI2CDevice, HekIOExpI2CAddr, byCmd);
305  return -HEK_ECODE_SYS;
306  }
307 #endif // TGT_EMBEDDED
308 
309  return HEK_OK;
310 }
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
static const byte_t HekIOExpI2CAddr
i2c 7-bit address
Definition: hekOptical.h:69
const char *const HekI2CDevice
i2c device name
Definition: hekateros.h:382
static const int HEK_ECODE_SYS
system (errno) error
Definition: hekateros.h:73
i2c_struct m_i2c
i2c bus
Definition: hekSysBoard.h:192

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