Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laelaps_diag.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // Program: laelaps_diag
6 //
7 // File: laelaps_diag.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2016-02-01 15:14:45 -0700 (Mon, 01 Feb 2016) $
12  * $Rev: 4289 $
13  *
14  * \brief Diagnotics header file.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \par Copyright
19  * \h_copy 2015-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #ifndef _LAELAPS_DIAG_H
50 #define _LAELAPS_DIAG_H
51 
52 #include <unistd.h>
53 #include <termios.h>
54 #include <string.h>
55 #include <stdio.h>
56 #include <stdlib.h>
57 #include <stdarg.h>
58 
59 #include <iostream>
60 #include <fstream>
61 #include <string>
62 #include <vector>
63 
64 #include "rnr/rnrconfig.h"
65 #include "rnr/log.h"
66 #include "rnr/opts.h"
67 #include "rnr/pkg.h"
68 
69 // common
70 #include "Laelaps/laelaps.h"
71 #include "Laelaps/laeUtils.h"
72 #include "Laelaps/laeDesc.h"
73 
74 // hardware
75 #include "Laelaps/laeSysDev.h"
76 #include "Laelaps/laeI2C.h"
77 #include "Laelaps/laeI2CMux.h"
78 #include "Laelaps/laeWd.h"
79 
80 
81 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82 // External Data
83 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
84 
85 //
86 // Shared interfaces used by diagnostics
87 //
88 extern laelaps::LaeDesc RobotDesc;
89 extern laelaps::LaeI2C I2CBus;
90 extern laelaps::LaeI2CMux I2CMux;
91 extern laelaps::LaeWd WatchDog;
92 
93 //
94 // Diagnostic Tags
95 //
96 extern char PassTag[];
97 extern char WarnTag[];
98 extern char FailTag[];
99 extern char WaitTag[];
100 extern char YNTag[];
101 extern char FatalTag[];
102 
103 /*!
104  * \brief Simple diagnostics statistics class.
105  */
107 {
108 public:
109  int passCnt; // diagnostic test pass count
110  int testCnt; // diagnostic test count
111  bool fatal; // diagnoistics can [not] continue
112 
113  /*!
114  * \brief Constructor.
115  */
117  {
118  zero();
119  }
120 
121  /*!
122  * \brief Destructor.
123  */
125  {
126  }
127 
128  /*!
129  * \brief Zero statistics.
130  */
131  void zero()
132  {
133  passCnt = 0;
134  testCnt = 0;
135  fatal = false;
136  }
137 
138  /*!
139  * \brief Compound assignment operator.
140  *
141  * A compound assignment (does not need to be a member, but often is, to
142  * modify any private members). The addition of rhs to *this takes place
143  * here.
144  *
145  * \param rhs Right hand side object.
146  *
147  * \return *this.
148  */
150  {
151  passCnt += rhs.passCnt;
152  testCnt += rhs.testCnt;
153  fatal = rhs.fatal;
154  return *this;
155  }
156 
157  /*!
158  * \brief Addition operator.
159  *
160  * Friends defined inside class body are inline and are hidden from
161  * non-ADL lookup (Argument-Dependent Lookup). Passing lhs by value helps
162  * optimize chained a+b+c. Otherwise, both parameters may be const references.
163  *
164  * \param lhs Left hand side lvalue.
165  * \param rhs Right hand side object.
166  *
167  * \return *this.
168  */
170  const DiagStats& rhs)
171  {
172  lhs += rhs; // reuse compound assignment
173  return lhs;
174  }
175 };
176 
177 
178 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
179 // Top-Level Diagnostics
180 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
181 
182 extern DiagStats runCpuDiagnostics();
183 
184 extern DiagStats runProductDiagnostics();
185 
186 extern DiagStats runMotorsDiagnostics(bool bTestMotion);
187 
188 extern DiagStats runToFDiagnostics(bool bAnyKey);
189 
190 extern DiagStats runImuDiagnostics(bool bAnyKey);
191 
192 extern DiagStats runWatchDogDiagnostics();
193 
194 extern DiagStats runCamDiagnostics();
195 
196 extern DiagStats runBatteryDiagnostics(bool bAnyKey);
197 
198 
199 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
200 // Utilities
201 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
202 
203 extern void setTags(bool bColor);
204 
205 extern void printHdr(std::string strDiag);
206 
207 extern void printSubHdr(std::string strName);
208 
209 extern void printTestResult(const char *sTag, const char *sFmt, ...);
210 
211 extern void printSubTotals(DiagStats &stats);
212 
213 extern void printTotals(DiagStats &stats);
214 
215 extern void printGrandTotals(DiagStats &stats);
216 
217 extern int kbblock();
218 
219 extern int kbhit();
220 
221 extern long findProc(const std::string &strName);
222 
223 #endif // _LAELAPS_DIAG_H
224 
Laelaps robotic mobile platform full description class.
Definition: laeDesc.h:451
control register mask
Definition: laeI2CMux.h:100
DiagStats & operator+=(const DiagStats &rhs)
Compound assignment operator.
Definition: laelaps_diag.h:149
DiagStats()
Constructor.
Definition: laelaps_diag.h:116
Laelaps WatchDog software class interface.
Laelaps PCA9548A I2C multiplexer switch interface.
Laelaps I2C class interface.
void zero()
Zero statistics.
Definition: laelaps_diag.h:131
Laelaps robotic base mobile platform description class interface.
friend DiagStats operator+(DiagStats lhs, const DiagStats &rhs)
Addition operator.
Definition: laelaps_diag.h:169
Simple diagnostics statistics class.
Definition: laelaps_diag.h:106
Laelaps common utilities.
Laelaps system devices.
~DiagStats()
Destructor.
Definition: laelaps_diag.h:124
Top-level package include file.