Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeThreadWd.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // File: laeThreadWd.cxx
6 //
7 /*! \file
8  *
9  * $LastChangedDate: 2015-08-07 14:25:35 -0600 (Fri, 07 Aug 2015) $
10  * $Rev: 4051 $
11  *
12  * \brief Laelaps watchdog thread class implementation.
13  *
14  * \author Robin Knight (robin.knight@roadnarrows.com)
15  *
16  * \par Copyright
17  * \h_copy 2015-2018. RoadNarrows LLC.\n
18  * http://www.roadnarrows.com\n
19  * All Rights Reserved
20  */
21 /*
22  * @EulaBegin@
23  *
24  * Unless otherwise stated explicitly, all materials contained are copyrighted
25  * and may not be used without RoadNarrows LLC's written consent,
26  * except as provided in these terms and conditions or in the copyright
27  * notice (documents and software) or other proprietary notice provided with
28  * the relevant materials.
29  *
30  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
31  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
32  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
33  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
34  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
35  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
38  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
39  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
40  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
41  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
42  *
43  * @EulaEnd@
44  */
45 ////////////////////////////////////////////////////////////////////////////////
46 
47 #include <sys/types.h>
48 #include <sys/time.h>
49 #include <time.h>
50 #include <pthread.h>
51 
52 #include <string>
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/log.h"
56 
57 #include "Laelaps/laelaps.h"
58 #include "Laelaps/laeUtils.h"
59 #include "Laelaps/laeTune.h"
60 
61 #include "Laelaps/laeBatt.h"
62 #include "Laelaps/laeAlarms.h"
63 #include "Laelaps/laeWatchDog.h"
64 #include "Laelaps/laeWd.h"
65 
66 #include "Laelaps/laeThread.h"
67 #include "Laelaps/laeThreadWd.h"
68 
69 using namespace std;
70 using namespace laelaps;
71 
72 //------------------------------------------------------------------------------
73 // LaeThreadWd Class
74 //------------------------------------------------------------------------------
75 
76 const double LaeThreadWd::ThreadWdPrioDft = 50; ///< default priority
77 const double LaeThreadWd::ThreadWdHzDft = 1.0; ///< default run rate
78 
79 double LaeThreadWd::optimizeHz(const double fWatchDogTimeout)
80 {
81  double t;
82 
83  t = fWatchDogTimeout / 2.0 - 0.001;
84  if( t > LaeThreadWd::ThreadWdHzDft )
85  {
86  t = LaeThreadWd::ThreadWdHzDft;
87  }
88  return t;
89 }
90 
91 LaeThreadWd::LaeThreadWd(LaeWd &hwif) : LaeThread("WatchDog"), m_hwif(hwif)
92 {
93 }
94 
96 {
97 }
98 
99 int LaeThreadWd::reload(const LaeTunes &tunes)
100 {
101  int rc;
102 
103  lock();
104 
105  rc = m_hwif.reload(tunes);
106 
107  unlock();
108 
109  return rc;
110 }
111 
113 {
114  m_hwif.exec();
115  m_battery.update();
116  m_alarms.update();
117 }
Laelaps thread base class interface.
virtual void update()
Update alarm and warning state.
Definition: laeAlarms.cxx:105
LaeWd & m_hwif
hardware interface
Definition: laeThreadWd.h:122
void unlock()
Unlock the I2C bus.
Definition: laeThread.h:235
Laelaps tuning data class.
Definition: laeTune.h:566
Laelaps battery management and energy monitoring class interface.
void lock()
Lock the I2C bus.
Definition: laeThread.h:221
Laelaps WatchDog software class interface.
LaeBattery m_battery
battery and energy monitor
Definition: laeThreadWd.h:124
int reload(const LaeTunes &tunes)
Reload tunable paramaters.
Definition: laeThreadWd.cxx:99
virtual void exec()
Execute watchdog task within scheduled cycle.
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
Laelaps common utilities.
Laelaps tuning.
virtual void exec()
Execute cycle to pet/read/update Watchdog sub-processor.
Definition: laeWd.cxx:188
LaeAlarms m_alarms
alarm monitor
Definition: laeThreadWd.h:125
Laelaps built-in Arduino sub-processor.
Laelaps watchdog thread class interface.
Laelaps alarm monitoring class interface.
virtual void update()
Update the energy state for all of the robot&#39;s subsystems.
Definition: laeBatt.cxx:373
virtual ~LaeThreadWd()
Destructor.
Definition: laeThreadWd.cxx:95
virtual int reload(const LaeTunes &tunes)
Reload with new configuration.
Definition: laeWd.cxx:182
Top-level package include file.