direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
heartbeat.h
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 #ifndef HEARTBEAT_H
22 #define HEARTBEAT_H
23 
24 //-------------------------------------------------------------------
25 #include "interfaceAvr.h"
26 #include <QThread>
27 #include <QMutex>
28 //-------------------------------------------------------------------
29 
34 class Heartbeat : public QThread
35 {
36  Q_OBJECT
37 
38  public:
39  Heartbeat(InterfaceAvr *i, QMutex *m);
40  ~Heartbeat();
41 
44  void init();
45 
48  bool isConnected(void);
49 
50  void stop();
51  virtual void run();
52 
53 
54  public slots:
59  void setRobotState(bool state);
60 
61 
62  signals:
67  void alarm();
68 
69 
70  private:
71  bool initDone;
72  volatile bool stopped;
73  bool robotIsOn;
74  mutable QMutex *mutex; // make this class thread-safe
76 
77  // Every thread sleeps some time, for having a bit more time for the other threads!
78  // Time in milliseconds
79  static const unsigned long THREADSLEEPTIME = 500; // Default: 500 ms
80 };
81 
82 #endif