Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekUno.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekUno.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2013-07-11 10:45:27 -0600 (Thu, 11 Jul 2013) $
12  * $Rev: 3111 $
13  *
14  * \brief \h_hek Arduino Uno compatible I/O board class interface.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  * \author Daniel Packard (daniel@roadnarrows.com)
18  *
19  * \copyright
20  * \h_copy 2013-2017. RoadNarrows LLC.\n
21  * http://www.roadnarrows.com\n
22  * All Rights Reserved
23  */
24 /*
25  * @EulaBegin@
26  *
27  * Unless otherwise stated explicitly, all materials contained are copyrighted
28  * and may not be used without RoadNarrows LLC's written consent,
29  * except as provided in these terms and conditions or in the copyright
30  * notice (documents and software) or other proprietary notice provided with
31  * the relevant materials.
32  *
33  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
34  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
35  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
36  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
37  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
38  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
41  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
42  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
43  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
44  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
45  *
46  * @EulaEnd@
47  */
48 ////////////////////////////////////////////////////////////////////////////////
49 
50 #ifndef _HEK_UNO_H
51 #define _HEK_UNO_H
52 
53 #include <string>
54 
55 #include "rnr/rnrconfig.h"
56 #include "rnr/log.h"
57 
58 #include "Hekateros/hekateros.h"
59 #include "Hekateros/hekOptical.h"
60 
61 namespace hekateros
62 {
63  class HekUno
64  {
65  public:
66 
67  /*!
68  * \brief Default constructor.
69  */
70  HekUno();
71 
72  /*!
73  * \brief Destructor.
74  */
75  virtual ~HekUno();
76 
77  /*!
78  * \brief Open all interfaces monitoring hardware.
79  *
80  * \param uHekHwVer \h_hek hardware version.
81  * \param dev Arduino compatible device.
82  * \param baud Baud rate.
83  *
84  * \copydoc doc_return_std
85  */
86  virtual int open(uint_t uHekHwVer,
87  const std::string& dev = HekDevArduino,
88  int baud = HekBaudRateArduino);
89 
90  /*!
91  * \brief Close all interfaces to monitoring hardware.
92  *
93  * \copydoc doc_return_std
94  */
95  virtual int close();
96 
97  /*!
98  * \brief Scan and initialize hardware.
99  *
100  * \copydoc doc_return_std
101  */
102  virtual int scan();
103 
104  /*!
105  * \brief Command to read firmware version.
106  *
107  * param [out] ver Version number.
108  *
109  * \copydoc doc_return_std
110  */
111  virtual int cmdReadFwVersion(int &ver);
112 
113  /*!
114  * \brief Command to read limit bit state.
115  *
116  * \return Returns limit switches state as a bit packed byte.
117  */
118  virtual byte_t cmdReadLimits();
119 
120  /*!
121  * \brief Command to read auxilliary bit state.
122  *
123  * Auxillary bits are usually End Effector GPIO, but allows room for
124  * additional bits.
125  *
126  * \return Returns auxilliary switches state as a bit packed byte.
127  */
128  virtual byte_t cmdReadAux();
129 
130  /*!
131  * \brief Command to read one I/O pin.
132  *
133  * \param id Pin identifier.
134  *
135  * \return Return pin state 0 or 1.
136  */
137  virtual int cmdReadPin(int id);
138 
139  /*!
140  * \brief Command to write value to an I/O pin.
141  *
142  * \param id Pin identifier.
143  * \param val Pin state 0 or 1.
144  *
145  * \copydoc doc_return_std
146  */
147  virtual int cmdWritePin(int id, int val);
148 
149  /*!
150  * \brief Command to configure direction of an I/O pin.
151  *
152  * \param id Pin identifier.
153  * \param dir Pin direction 'i' or 'o'.
154  *
155  * \copydoc doc_return_std
156  */
157  virtual int cmdConfigPin(int id, char dir);
158 
159  /*!
160  * \brief Command to set Alarm LED.
161  *
162  * \param val LED 0==off or 1==on value.
163  *
164  * \copydoc doc_return_std
165  */
166  virtual int cmdSetAlarmLED(int val);
167 
168  /*!
169  * \brief Command to set Status LED.
170  *
171  * \param val LED 0==off or 1==on value.
172  *
173  * \copydoc doc_return_std
174  */
175  virtual int cmdSetStatusLED(int val);
176 
177  /*!
178  * \brief Command to set monitoring state to halted.
179  *
180  * \copydoc doc_return_std
181  */
182  virtual int cmdSetHaltedState();
183 
184  /*!
185  * \brief Test serial interface command.
186  *
187  * \copydoc doc_return_std
188  */
189  virtual int cmdTestInterface();
190 
191  /*!
192  * \brief Null command.
193  *
194  * \copydoc doc_return_std
195  */
196  virtual int cmdNull();
197 
198  protected:
199  int m_fd; ///< open arduino file descriptor
200  uint_t m_uHekHwVer; ///< hekateros hardware version
201  int m_nFwVer; ///< arduino firmware version
202 
203  // test serial interface
204  int m_nFwOpState; ///< firmware operational state
205  int m_nFwSeqNum; ///< expected test sequence number modulo 256
206 
207  /*!
208  * \brief Send command to Arduino.
209  *
210  * \param buf Buffer of bytes.
211  * \param nBytes Number of bytes in buffer to write.
212  * \param timeout Send timeout (usec).
213  *
214  * \copydoc doc_return_std
215  */
216  int sendCommand(char *buf, size_t nBytes, uint_t timeout=50000);
217 
218  /*!
219  * \brief Receive response from Arduino.
220  *
221  * \param buf Receiving character buffer.
222  * \param count Maximum number of bytes to read.
223  * \param timeout Receive timeout (usec).
224  *
225  * \copydoc doc_return_std
226  */
227  int recvResponse(char buf[], size_t count, uint_t timeout=100000);
228 
229  /*!
230  * \brief Unpack hex characters to byte.
231  *
232  * Format: hh
233  *
234  * \param buf Buffer of hex characters
235  *
236  * \return Returns unpacked byte.
237  */
238  byte_t unpackHex(char buf[]);
239  };
240 
241 } // namespace hekateros
242 
243 
244 #endif // _HEK_UNO_H
int m_fd
open arduino file descriptor
Definition: hekUno.h:199
int sendCommand(char *buf, size_t nBytes, uint_t timeout=50000)
Send command to Arduino.
Definition: hekUno.cxx:418
virtual ~HekUno()
Destructor.
Definition: hekUno.cxx:76
virtual byte_t cmdReadLimits()
Command to read limit bit state.
Definition: hekUno.cxx:162
virtual int cmdSetAlarmLED(int val)
Command to set Alarm LED.
Definition: hekUno.cxx:283
HekUno()
Default constructor.
Definition: hekUno.cxx:66
virtual int cmdSetHaltedState()
Command to set monitoring state to halted.
Definition: hekUno.cxx:335
<b><i>Hekateros</i></b> optical limit switches.
virtual int cmdConfigPin(int id, char dir)
Command to configure direction of an I/O pin.
Definition: hekUno.cxx:248
int m_nFwSeqNum
expected test sequence number modulo 256
Definition: hekUno.h:205
virtual int scan()
Scan and initialize hardware.
Definition: hekUno.cxx:115
virtual int cmdNull()
Null command.
Definition: hekUno.cxx:405
virtual int cmdSetStatusLED(int val)
Command to set Status LED.
Definition: hekUno.cxx:309
virtual int close()
Close all interfaces to monitoring hardware.
Definition: hekUno.cxx:103
Top-level package include file.
virtual int cmdWritePin(int id, int val)
Command to write value to an I/O pin.
Definition: hekUno.cxx:227
virtual byte_t cmdReadAux()
Command to read auxilliary bit state.
Definition: hekUno.cxx:188
virtual int open(uint_t uHekHwVer, const std::string &dev=HekDevArduino, int baud=HekBaudRateArduino)
Open all interfaces monitoring hardware.
Definition: hekUno.cxx:81
virtual int cmdTestInterface()
Test serial interface command.
Definition: hekUno.cxx:360
uint_t m_uHekHwVer
hekateros hardware version
Definition: hekUno.h:200
int recvResponse(char buf[], size_t count, uint_t timeout=100000)
Receive response from Arduino.
Definition: hekUno.cxx:425
const int HekBaudRateArduino
arduino baudrate
Definition: hekateros.h:456
int m_nFwOpState
firmware operational state
Definition: hekUno.h:204
const char *const HekDevArduino
arduino device name
Definition: hekateros.h:447
byte_t unpackHex(char buf[])
Unpack hex characters to byte.
Definition: hekUno.cxx:445
virtual int cmdReadPin(int id)
Command to read one I/O pin.
Definition: hekUno.cxx:207
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56
virtual int cmdReadFwVersion(int &ver)
Command to read firmware version.
Definition: hekUno.cxx:138
int m_nFwVer
arduino firmware version
Definition: hekUno.h:201