direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
heartbeat.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2009 by Markus Knapp *
3  * www.direcs.de *
4  * *
5  * This file is part of direcs. *
6  * *
7  * direcs is free software: you can redistribute it and/or modify it *
8  * under the terms of the GNU General Public License as published *
9  * by the Free Software Foundation, version 3 of the License. *
10  * *
11  * direcs is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with direcs. If not, see <http://www.gnu.org/licenses/>. *
18  * *
19  *************************************************************************/
20 
21 #include "heartbeat.h"
22 
23 
24 Heartbeat::Heartbeat(InterfaceAvr *i, QMutex *m) : QThread()
25 {
26  // copy the pointer from the original object
27  interface1 = i;
28  mutex = m;
29 
30  stopped = false;
31  initDone = false;
32  robotIsOn = false;
33 }
34 
35 
37 {
38 }
39 
40 
42 {
43  stopped = true;
44 }
45 
46 
48 {
49  if (initDone==false)
50  {
51  //init();
52  }
53 
54  //
55  // start "threading"...
56  //
57  while (!stopped)
58  {
59  // Lock the mutex. If another thread has locked the mutex then this call will block until that thread has unlocked it.
60  mutex->lock();
61 
62  //-------------------------------------------------------
63  // Basic init for all the bits on the robot circuit
64  //-------------------------------------------------------
65  if (interface1->sendChar(111) == true)
66  {
67  // Unlock the mutex
68  mutex->unlock();
69  }
70 
71  // Unlock the mutex.
72  mutex->unlock();
73 
74  } // while !stopped
75 
76 
77  stopped = false;
78 }
79 
80 
82 {
83  return robotIsOn;
84 }
85 
86 
88 {
89  //if ( (cameraIsOn == true) && (initDone == false) )
90  if (initDone == false)
91  {
92  // do only *one* init!
93  initDone = true;
94 
95  //-----------------
96  // try to connect
97  //-----------------
98 
99  if (0)
100  {
101  qDebug("INFO: could not initialize blablabla");
102  robotIsOn = false;
103  stopped = true;
104  return;
105  }
106 
107  robotIsOn = true;
108  }
109 }
110 
111 
112 void Heartbeat::setRobotState(bool state)
113 {
114  robotIsOn = state;
115 }