direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
networkThread.h
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 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 NETWORKTHREAD_H
22 #define NETWORKTHREAD_H
23 
24 //-------------------------------------------------------------------
25 #include <QThread>
26 #include <QtNetwork>
27 //-------------------------------------------------------------------
28 
29 class QUdpSocket;
30 
38 class NetworkThread : public QThread
39 {
40  Q_OBJECT
41 
42  public:
43  NetworkThread();
45 
49  void stop();
50 
54  virtual void run();
55 
62  bool init(unsigned int portListen, unsigned int portSend);
63 
67  void swapPorts();
68 
69 
70  public slots:
74  void sendNetworkCommand(QString text);
75 
79  void setNetworkMaster();
80 
84  void setNetworkSlave();
85 
86 
87  signals:
91  void dataReceived(QString text);
92 
96  void heartbeat(unsigned char state);
97 
98 
99  private slots:
104 
105 
106  private:
107  QUdpSocket *udpSocket;
108  volatile bool stopped;
109  unsigned int networkPortListen;
110  unsigned int networkPortSend;
112  bool iAmTheSlave;
113 
114  // Every thread sleeps some time, for having a bit more time fo the other threads!
115  // Time in milliseconds
116  static const unsigned long THREADSLEEPTIME = 1000; // Default: 25 ms (old: 5 ms)
117 
121  static const unsigned char LEDOFF = 0;
122  static const unsigned char RED = 1;
123  static const unsigned char GREEN = 2;
124 };
125 
126 #endif