-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlaserrangefinder20hzv2messagemonitorform.cpp
182 lines (142 loc) · 7.18 KB
/
laserrangefinder20hzv2messagemonitorform.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
laserrangefinder20hzv2messagemonitorform.cpp (part of GNSS-Stylus)
Copyright (C) 2019-2021 Pasi Nuutinmaki (gnssstylist<at>sci<dot>fi)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @file laserrangefinder20hzv2messagemonitorform.cpp
* @brief Declaration for a form that shows some data about messages sent by "20hz high Accuracy 80m Laser Sensor Range finder Distance measuring module".
*/
#include <QTime>
#include "laserrangefinder20hzv2messagemonitorform.h"
#include "ui_laserrangefinder20hzv2messagemonitorform.h"
LaserRangeFinder20HzV2MessageMonitorForm::LaserRangeFinder20HzV2MessageMonitorForm(QWidget *parent, const QString& title) :
QWidget(parent),
ui(new Ui::LaserRangeFinder20HzV2MessageMonitorForm)
{
ui->setupUi(this);
this->setWindowTitle(title);
}
LaserRangeFinder20HzV2MessageMonitorForm::~LaserRangeFinder20HzV2MessageMonitorForm()
{
delete ui;
}
void LaserRangeFinder20HzV2MessageMonitorForm::addLogLine(const QString& line)
{
QTime currentTime = QTime::currentTime();
QString timeString = currentTime.toString("hh:mm:ss:zzz");
ui->plainTextEdit_Output->setMaximumBlockCount(ui->spinBox_MaxLines->value());
ui->plainTextEdit_Output->setCenterOnScroll(ui->checkBox_PagedScroll->isChecked());
ui->plainTextEdit_Output->setWordWrapMode(QTextOption::NoWrap);
ui->plainTextEdit_Output->appendPlainText(timeString + ": " + line);
}
void LaserRangeFinder20HzV2MessageMonitorForm::errorMessage(const QString& errorMessage)
{
addLogLine(QString("Serial thread error: ") + errorMessage);
}
void LaserRangeFinder20HzV2MessageMonitorForm::warningMessage(const QString& warningMessage)
{
addLogLine(QString("Serial thread warning: ") + warningMessage);
}
void LaserRangeFinder20HzV2MessageMonitorForm::infoMessage(const QString& infoMessage)
{
addLogLine(QString("Serial thread info: ") + infoMessage);
}
void LaserRangeFinder20HzV2MessageMonitorForm::distanceReceived(const double& distance, qint64 startTime, qint64 endTime)
{
if ((!ui->checkBox_SuspendOutput->checkState()) && (ui->checkBox_Distance->checkState()))
{
addLogLine(QString("New distance received: ") + QString::number(distance, 'f', 4) + "m. " + getTimeDifferenceString(startTime, endTime));
}
updateStartAndEndTimes(startTime, endTime);
}
void LaserRangeFinder20HzV2MessageMonitorForm::errorReceived(const QString& errorString, qint64 startTime, qint64 endTime)
{
if ((!ui->checkBox_SuspendOutput->checkState()) && (ui->checkBox_Errors->checkState()))
{
addLogLine(QString("Error received: \"") + errorString + "\". " + getTimeDifferenceString(startTime, endTime));
}
updateStartAndEndTimes(startTime, endTime);
}
void LaserRangeFinder20HzV2MessageMonitorForm::unidentifiedDataReceived(const QByteArray& data, qint64 startTime, qint64 endTime)
{
if ((!ui->checkBox_SuspendOutput->checkState()) && (ui->checkBox_UnidentifiedData->checkState()))
{
QString dataString;
for (int i = 0; i < data.length(); i++)
{
if (i != 0)
{
dataString += ", ";
}
if (!(data[i] & 0xF0))
{
dataString += "0";
}
dataString += QString::number(static_cast<unsigned char>(data[i]), 16);
}
addLogLine(QString("Unidentified data received. Num of bytes: ") + QString::number(data.length()) +
", Data(hex): " + dataString + " (as string: " + data + ")." +
getTimeDifferenceString(startTime, endTime));
}
updateStartAndEndTimes(startTime, endTime);
}
void LaserRangeFinder20HzV2MessageMonitorForm::connectSerialThreadSlots(LaserRangeFinder20HzV2SerialThread* serThread)
{
connect(serThread, &LaserRangeFinder20HzV2SerialThread::infoMessage,
this, &LaserRangeFinder20HzV2MessageMonitorForm::infoMessage);
connect(serThread, &LaserRangeFinder20HzV2SerialThread::warningMessage,
this, &LaserRangeFinder20HzV2MessageMonitorForm::warningMessage);
connect(serThread, &LaserRangeFinder20HzV2SerialThread::errorMessage,
this, &LaserRangeFinder20HzV2MessageMonitorForm::errorMessage);
connect(serThread, &LaserRangeFinder20HzV2SerialThread::distanceReceived,
this, &LaserRangeFinder20HzV2MessageMonitorForm::distanceReceived);
connect(serThread, &LaserRangeFinder20HzV2SerialThread::errorReceived,
this, &LaserRangeFinder20HzV2MessageMonitorForm::errorReceived);
connect(serThread, &LaserRangeFinder20HzV2SerialThread::unidentifiedDataReceived,
this, &LaserRangeFinder20HzV2MessageMonitorForm::unidentifiedDataReceived);
}
void LaserRangeFinder20HzV2MessageMonitorForm::disconnectSerialThreadSlots(LaserRangeFinder20HzV2SerialThread* serThread)
{
disconnect(serThread, &LaserRangeFinder20HzV2SerialThread::infoMessage,
this, &LaserRangeFinder20HzV2MessageMonitorForm::infoMessage);
disconnect(serThread, &LaserRangeFinder20HzV2SerialThread::warningMessage,
this, &LaserRangeFinder20HzV2MessageMonitorForm::warningMessage);
disconnect(serThread, &LaserRangeFinder20HzV2SerialThread::errorMessage,
this, &LaserRangeFinder20HzV2MessageMonitorForm::errorMessage);
disconnect(serThread, &LaserRangeFinder20HzV2SerialThread::distanceReceived,
this, &LaserRangeFinder20HzV2MessageMonitorForm::distanceReceived);
disconnect(serThread, &LaserRangeFinder20HzV2SerialThread::errorReceived,
this, &LaserRangeFinder20HzV2MessageMonitorForm::errorReceived);
disconnect(serThread, &LaserRangeFinder20HzV2SerialThread::unidentifiedDataReceived,
this, &LaserRangeFinder20HzV2MessageMonitorForm::unidentifiedDataReceived);
}
void LaserRangeFinder20HzV2MessageMonitorForm::on_pushButton_ClearAll_clicked()
{
ui->plainTextEdit_Output->clear();
}
QString LaserRangeFinder20HzV2MessageMonitorForm::getTimeDifferenceString(const qint64 startTime, const qint64 endTime)
{
qint64 startTimeDifference = startTime - lastStartTime;
qint64 burstDuration = endTime - startTime;
qint64 idleTime = startTime - lastEndTime;
QString retval = "Start time difference: ";
retval += QString::number(startTimeDifference);
retval += ", burst duration: " + QString::number(burstDuration);
retval += ", idle time: " + QString::number(idleTime);
return retval;
}
void LaserRangeFinder20HzV2MessageMonitorForm::updateStartAndEndTimes(const qint64 startTime, const qint64 endTime)
{
lastStartTime = startTime;
lastEndTime = endTime;
}