|
@@ -1,7 +1,10 @@
|
1
|
1
|
#include <QCoreApplication>
|
2
|
2
|
#include <QStringList>
|
|
3
|
+#include <QVariant>
|
3
|
4
|
#include <iostream>
|
4
|
5
|
#include <sysexits.h>
|
|
6
|
+#include <sys/time.h>
|
|
7
|
+#include <unistd.h>
|
5
|
8
|
#include "qcommandlineparser.h"
|
6
|
9
|
#include "mainclass.h"
|
7
|
10
|
#include "gpiomanager.h"
|
|
@@ -13,6 +16,8 @@ MainClass::MainClass(QObject *parent)
|
13
|
16
|
, m_device(Gpio)
|
14
|
17
|
, m_address(QHostAddress::Any)
|
15
|
18
|
, m_port(39415)
|
|
19
|
+ , m_verbose(false)
|
|
20
|
+ , m_lastTime(0)
|
16
|
21
|
{
|
17
|
22
|
}
|
18
|
23
|
|
|
@@ -41,7 +46,30 @@ void MainClass::main()
|
41
|
46
|
}
|
42
|
47
|
|
43
|
48
|
m_input = new InputBusiness(input, m_channels, server);
|
44
|
|
- m_input->readAndSend();
|
|
49
|
+ m_timer = new QTimer(this);
|
|
50
|
+ m_timer->setSingleShot(false);
|
|
51
|
+ m_timer->setInterval(0);
|
|
52
|
+ connect(m_timer, SIGNAL(timeout()), this, SLOT(maySend()));
|
|
53
|
+ m_timer->start();
|
|
54
|
+}
|
|
55
|
+
|
|
56
|
+void MainClass::maySend()
|
|
57
|
+{
|
|
58
|
+ struct timeval time;
|
|
59
|
+ gettimeofday(&time, NULL);
|
|
60
|
+ if (time.tv_usec - m_lastTime < 100)
|
|
61
|
+ usleep(100 - (time.tv_usec - m_lastTime));
|
|
62
|
+ gettimeofday(&time, NULL);
|
|
63
|
+ m_lastTime = time.tv_usec;
|
|
64
|
+ auto values = m_input->readAndSend(time.tv_usec);
|
|
65
|
+ if (m_verbose)
|
|
66
|
+ {
|
|
67
|
+ std::cout << time.tv_usec << ":";
|
|
68
|
+ foreach (auto value, values) {
|
|
69
|
+ std::cout << " " << value.toInt();
|
|
70
|
+ }
|
|
71
|
+ std::cout << std::endl;
|
|
72
|
+ }
|
45
|
73
|
}
|
46
|
74
|
|
47
|
75
|
void MainClass::getOpts()
|
|
@@ -59,6 +87,8 @@ void MainClass::getOpts()
|
59
|
87
|
parser.addOption(address);
|
60
|
88
|
QCommandLineOption port((QStringList() << "p" << "port"), "port to bind socket [1-65535]", "PORT", QString::number(m_port));
|
61
|
89
|
parser.addOption(port);
|
|
90
|
+ QCommandLineOption verbose((QStringList() << "verbose"), "enable verbose mode");
|
|
91
|
+ parser.addOption(verbose);
|
62
|
92
|
|
63
|
93
|
parser.process(*qApp);
|
64
|
94
|
|
|
@@ -95,4 +125,6 @@ void MainClass::getOpts()
|
95
|
125
|
std::cerr << "Invalid port" << std::endl;
|
96
|
126
|
parser.showHelp(EX_USAGE);
|
97
|
127
|
}
|
|
128
|
+
|
|
129
|
+ m_verbose = parser.isSet(verbose);
|
98
|
130
|
}
|