Skip to content

Commit 62ef4fe

Browse files
author
Michal
committed
Merge remote-tracking branch 'origin/dev'
2 parents b54fb9b + f87598a commit 62ef4fe

20 files changed

+3606
-2597
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/mainwindow.cpp.autosave

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Universal serial monitor with data plotting capabilities, based on [Qt](https://
1717
- Resizable UI widgets,
1818
- Data plotter with multiple graphs support and basic data filtering - uses [QCustomPlot](https://www.qcustomplot.com/),
1919
- Printer support, ability to save graph as image,
20-
- Read/write ".txt" data logs,
20+
- Read/write ".csv", ".txt" data logs,
2121
- many more...
2222

2323
<a href="https://github.com/mich-w/QtSerialMonitor/releases/download/v1.4/QtSerialMonitor_1.4_win_x64.zip" download>Download QtSerialMonitor_v1.4_win_x64</a>

src/QtSerialMonitor.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ QT += core gui
88
QT += serialport
99
QT += printsupport
1010
QT += network
11+
QT += 3dcore 3drender 3dquick 3dinput qml quick 3dquickextras quickwidgets
1112
#QT += 3dstudioruntime2
1213

1314
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@@ -69,7 +70,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
6970

7071
DISTFILES += \
7172
QtSM.ico \
72-
TODO
73+
TODO.txt
7374

7475
RESOURCES += \
7576
3dres.qrc

src/TODO

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/TODO.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- void MainWindow::getFileTimeRange(QFile *file) // TODO move to reader !
2+
- if (mode == 0)
3+
sendSerial(ui->comboBoxSend->currentText());
4+
else if (mode == 1)
5+
sendUDPDatagram(ui->comboBoxSend->currentText());
6+
else
7+
{
8+
sendSerial(ui->comboBoxSend->currentText()); // TODO
9+
sendUDPDatagram(ui->comboBoxSend->currentText());
10+
}
11+
12+
- time ref used in logging ?

src/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef CONFIG_H
22
#define CONFIG_H
33

4-
#define VERSION "1.4"
4+
#define VERSION "1.5"
55

66
#define CHANGELOG_TEXT "" //"Changelog - version " VERSION ": \n"
77

src/filereader.cpp

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,6 @@ void FileReader::readLineSendLine()
2020
}
2121
}
2222

23-
bool FileReader::startRead(QFile *fileToRead)
24-
{
25-
if (fileToRead->open(QIODevice::ReadOnly))
26-
{
27-
QTextStream stream(fileToRead);
28-
QString allData = stream.readAll();
29-
fileToRead->close();
30-
31-
readFileSplitLines = allData.split(QRegExp("[\n\r]"), QString::SplitBehavior::SkipEmptyParts);
32-
}
33-
34-
lineReadIterator = 0;
35-
36-
fileReadTimer.start(readInterval);
37-
connect(&fileReadTimer, SIGNAL(timeout()), this, SLOT(readLineSendLine()));
38-
}
39-
4023
bool FileReader::readAllAtOnce(QFile *fileToRead)
4124
{
4225
if (fileToRead->open(QIODevice::ReadOnly))
@@ -53,12 +36,63 @@ bool FileReader::readAllAtOnce(QFile *fileToRead)
5336
return false;
5437
}
5538

56-
void FileReader::setReadInterval(int newVal)
39+
QList<QTime> FileReader::getFileTimeRange(QFile *file)
5740
{
58-
readInterval = newVal;
59-
}
41+
QList<QTime> timeRange = {QTime(), QTime()};
6042

61-
void FileReader::abortRead()
62-
{
63-
fileReadTimer.stop(); // ...
43+
if (file->open(QIODevice::ReadOnly))
44+
{
45+
QString allData = file->readAll();
46+
file->close();
47+
48+
QStringList readFileSplitLines = allData.split(QRegExp("[\\n+\\r+]"), QString::SplitBehavior::SkipEmptyParts);
49+
50+
for (auto i = 0; i < readFileSplitLines.count(); ++i)
51+
{
52+
QStringList inputStringSplitArrayTopLine = readFileSplitLines[i].simplified().split(QRegExp("[\\s+,]"), QString::SplitBehavior::SkipEmptyParts); // rozdzielamy traktująac spacje jako separator
53+
QStringList inputStringSplitArrayButtomLine = readFileSplitLines[readFileSplitLines.count() - 1 - i].simplified().split(QRegExp("[\\s+,]"), QString::SplitBehavior::SkipEmptyParts); // rozdzielamy traktująac spacje jako separator
54+
QStringList searchTimeFormatList = {"hh:mm:ss:zzz", "hh:mm:ss.zzz", "hh:mm:ss.z", "hh:mm:ss"}; // TODO !!!
55+
56+
bool foundTime[2] = {false};
57+
58+
for (auto j = 0; j < inputStringSplitArrayTopLine.count(); ++j)
59+
{
60+
foreach (auto timeFormat, searchTimeFormatList)
61+
{
62+
if (QTime::fromString(inputStringSplitArrayTopLine[j], timeFormat).isValid() && !foundTime[0])
63+
{
64+
timeRange.first() = QTime::fromString(inputStringSplitArrayTopLine[j], timeFormat);
65+
foundTime[0] = true;
66+
break;
67+
}
68+
}
69+
}
70+
71+
for (auto j = 0; j < inputStringSplitArrayButtomLine.count(); ++j)
72+
{
73+
foreach (auto timeFormat, searchTimeFormatList)
74+
{
75+
if (QTime::fromString(inputStringSplitArrayButtomLine[j], timeFormat).isValid() && !foundTime[1])
76+
{
77+
timeRange.last() = (QTime::fromString(inputStringSplitArrayButtomLine[j], timeFormat));
78+
foundTime[1] = true;
79+
80+
break;
81+
}
82+
}
83+
}
84+
85+
if (foundTime[0] && foundTime[1])
86+
return timeRange;
87+
}
88+
}
89+
else
90+
{
91+
qDebug() << "Get file time range - invalid file ?";
92+
return {QTime(), QTime()};
93+
}
6494
}
95+
96+
void FileReader::setReadInterval(int newVal) { readInterval = newVal; }
97+
98+
void FileReader::abortRead() { fileReadTimer.stop(); }

src/filereader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
#include <QObject>
66
#include <QTextStream>
77
#include <QTimer>
8+
#include <QTime>
9+
#include <QDebug>
810

911
class FileReader : public QObject
1012
{
1113
Q_OBJECT
1214
public:
1315
explicit FileReader(QObject *parent = nullptr);
1416
bool readAllAtOnce(QFile *fileToRead);
15-
bool startRead(QFile *fileToRead);
1617
void abortRead();
1718
void setReadInterval(int newVal);
19+
QList<QTime> getFileTimeRange(QFile *file);
1820
signals:
1921
void fileReadFinished();
2022
void lineReady(QString *, int *);

src/infodialog.ui

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
<height>391</height>
1111
</rect>
1212
</property>
13+
<property name="sizePolicy">
14+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
15+
<horstretch>0</horstretch>
16+
<verstretch>0</verstretch>
17+
</sizepolicy>
18+
</property>
1319
<property name="windowTitle">
1420
<string>Application Info</string>
1521
</property>
@@ -50,7 +56,7 @@
5056
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
5157
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
5258
p, li { white-space: pre-wrap; }
53-
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
59+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
5460
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9pt;&quot;&gt;Universal serial monitor with data plotting capabilities, based on &lt;/span&gt;&lt;a href=&quot;https://www.qt.io/&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9pt; text-decoration: underline; color:#0000ff;&quot;&gt;Qt&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9pt;&quot;&gt;. Designed with all sorts of &lt;/span&gt;&lt;a href=&quot;https://www.arduino.cc/&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9pt; text-decoration: underline; color:#0000ff;&quot;&gt;Arduino&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9pt;&quot;&gt; projects in mind, as a handy tool for debugging and experimentation :)&lt;/span&gt;&lt;/p&gt;
5561
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:9pt; font-weight:600;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
5662
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9pt; font-weight:600;&quot;&gt;Author:&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:9pt;&quot;&gt; mich-w&lt;/span&gt;&lt;/p&gt;
@@ -81,7 +87,7 @@ p, li { white-space: pre-wrap; }
8187
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
8288
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
8389
p, li { white-space: pre-wrap; }
84-
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
90+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
8591
&lt;p style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Courier New'; font-size:8pt;&quot;&gt; GNU GENERAL PUBLIC LICENSE&lt;/span&gt;&lt;/p&gt;
8692
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Courier New'; font-size:8pt;&quot;&gt; Version 3, 29 June 2007&lt;/span&gt;&lt;/p&gt;
8793
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Courier New'; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;

src/logger.cpp

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ Logger::Logger(QObject *parent) : QObject(parent)
44
{
55
}
66

7-
void Logger::openFile(QString fileName, bool truncateFile)
7+
bool Logger::openFile(QString fileName, bool trunc)
88
{
9-
if (!fileName.isEmpty())
10-
{
11-
logFile = new QFile;
12-
logFile->setFileName(fileName);
9+
if (fileName.isEmpty())
10+
return false;
1311

14-
if (truncateFile)
15-
logFile->open(QIODevice::OpenModeFlag::Truncate | QFile::OpenModeFlag::ReadWrite | QIODevice::Text);
16-
else
17-
logFile->open(QIODevice::OpenModeFlag::ReadWrite | QIODevice::Text);
18-
}
12+
logFile = new QFile;
13+
logFile->setFileName(fileName);
14+
logFile->open(QFile::OpenModeFlag::ReadWrite | QFile::Text);
15+
16+
if (trunc)
17+
logFile->resize(0);
18+
19+
if (logFile->isOpen())
20+
return true;
21+
else
22+
return false;
1923
}
2024

2125
void Logger::closeFile()
@@ -39,10 +43,18 @@ bool Logger::beginLog(QString path, bool autoLogging, QString fileName, bool tru
3943
qDebug() << "File open";
4044

4145
if (autoLogging)
42-
openFile(path + "/" + QDateTime::currentDateTime().toString("dd.MM.yyyy_hh.mm.ss.zzz_") + "Log" + fileName.right(fileName.length() - fileName.lastIndexOf('.')),truncateFile);
46+
openFile(path + "/" + QDateTime::currentDateTime().toString("dd.MM.yyyy_hh.mm.ss.zzz_") + "Log" + fileName.right(fileName.length() - fileName.lastIndexOf('.')), truncateFile);
4347
else
4448
openFile(path + "/" + fileName, truncateFile);
4549

50+
if (fileName.contains("csv"))
51+
{
52+
csvLabelsBuffer.append(QString(logFile->readLine()).replace("\"", "").split(',', QString::SplitBehavior::SkipEmptyParts));
53+
54+
for (auto i = 0; i < csvLabelsBuffer.count(); ++i)
55+
qDebug() << csvLabelsBuffer[i] + "\n";
56+
}
57+
4658
return true;
4759
}
4860
else
@@ -57,17 +69,14 @@ bool Logger::isOpen()
5769
return logFile != nullptr;
5870
}
5971

60-
void Logger::writeLogLine(QString lineToAppend, bool simplifyText, bool appendDate)
72+
void Logger::writeLogTXTLine(QString lineToAppend, bool simplifyText)
6173
{
6274
QString text = lineToAppend; // + "";
6375

6476
if (simplifyText)
6577
text = text.simplified();
6678

67-
if (appendDate)
68-
text = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss:zzz ") + text;
69-
else
70-
text = QDateTime::currentDateTime().toString("hh:mm:ss:zzz ") + text;
79+
text = QDateTime::currentDateTime().toString("hh:mm:ss:zzz ") + text;
7180

7281
if (logFile != nullptr)
7382
{
@@ -78,7 +87,7 @@ void Logger::writeLogLine(QString lineToAppend, bool simplifyText, bool appendDa
7887
}
7988
}
8089

81-
void Logger::writeLogParsedData(QStringList labelList, QList<double> dataList, bool appendDate)
90+
void Logger::writeLogTXTParsedData(QStringList labelList, QList<double> dataList)
8291
{
8392
QString text;
8493

@@ -89,10 +98,7 @@ void Logger::writeLogParsedData(QStringList labelList, QList<double> dataList, b
8998

9099
text = text.simplified();
91100

92-
if (appendDate)
93-
text = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss:zzz ") + text;
94-
else
95-
text = QDateTime::currentDateTime().toString("hh:mm:ss:zzz ") + text;
101+
text = QDateTime::currentDateTime().toString("hh:mm:ss:zzz ") + text;
96102

97103
if (logFile != nullptr)
98104
{
@@ -103,56 +109,73 @@ void Logger::writeLogParsedData(QStringList labelList, QList<double> dataList, b
103109
}
104110
}
105111

106-
void Logger::writeLogCSV(QStringList labelList, QList<double> dataList, bool appendDate)
112+
void Logger::writeLogCSV(QStringList labelList, QList<double> dataList, bool addTime)
107113
{
108114
QTextStream out(logFile);
109115

116+
if (addTime)
117+
{
118+
if (csvLabelsBuffer.contains("time") == false)
119+
csvLabelsBuffer.insert(0, "time");
120+
}
121+
110122
if (labelList.count() == 0)
123+
{
124+
qDebug() << "Empty label list - abort csv write";
111125
return;
126+
}
112127

113-
bool canAdd = false;
114-
for (auto i = 0; i <= labelList.count() - 1; ++i)
128+
bool canAddLabel = false;
129+
for (auto i = 0; i < labelList.count(); ++i)
115130
{
116-
if(csvLabelsBuffer.count() == 0 || !csvLabelsBuffer.contains(labelList[i]))
117-
canAdd = true;
118-
119-
if (canAdd)
131+
if (csvLabelsBuffer.count() == 0 || csvLabelsBuffer.contains(labelList[i]) == false)
120132
{
121-
csvLabelsBuffer.append(labelList[i].toLatin1());
133+
canAddLabel = true;
134+
csvLabelsBuffer.append(labelList[i]);
135+
}
136+
}
122137

123-
QStringList origFile = out.readAll().split(QRegExp("\r\n"), Qt::SplitBehaviorFlags::SkipEmptyParts);
124-
logFile->resize(0);
138+
if (canAddLabel)
139+
{
140+
canAddLabel = false;
125141

126-
for (auto i = 0; i < csvLabelsBuffer.count(); ++i)
127-
out << "\"" + csvLabelsBuffer[i] + "\",";
142+
QStringList origFile = out.readAll().split(QRegExp("[\r\n]"), Qt::SplitBehaviorFlags::SkipEmptyParts);
128143

129-
out << "\n";
144+
for (auto i = 0; i < csvLabelsBuffer.count(); ++i)
145+
out << "\"" + csvLabelsBuffer[i] + "\",";
130146

131-
for (auto i = 1; i < origFile.count(); ++i) // Start from second line (data without first line which contains labels)
132-
out << origFile[i] + "\r";
147+
out << "\n";
133148

134-
break;
149+
if (origFile.length() > 0)
150+
{
151+
while (origFile.first().contains("\""))
152+
origFile.removeFirst();
135153
}
136-
}
137154

138-
if (canAdd)
139-
out << "\r";
155+
logFile->resize(0); // delete contents !
140156

157+
for (auto i = 0; i < origFile.count(); ++i) // Start from second line (data without first line which contains labels)
158+
out << origFile[i] + "\n";
141159

160+
return;
161+
}
162+
163+
// add Data !
142164
for (auto i = 0; i < csvLabelsBuffer.count(); ++i)
143165
{
144166
out.atEnd(); // ???
145167

146-
int index = labelList.indexOf(csvLabelsBuffer[i]);
168+
int index = labelList.indexOf(csvLabelsBuffer[i]); // TODO
147169
if (index >= 0 && index < dataList.count())
148-
out << QString::number(dataList[index]) + ',';
170+
out << QString::number(dataList[index], 'f') + ',';
171+
else if (csvLabelsBuffer[i] == "time")
172+
out << QTime::currentTime().toString("hh:mm:ss:zzz") + ',';
149173
}
150174

151-
out << "\r";
175+
out << "\n";
152176
}
153177

154178
void Logger::clearWriteBuffer()
155179
{
156180
csvLabelsBuffer.clear();
157181
}
158-

0 commit comments

Comments
 (0)