-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSerialSamplingThread.cpp
More file actions
61 lines (56 loc) · 1.31 KB
/
SerialSamplingThread.cpp
File metadata and controls
61 lines (56 loc) · 1.31 KB
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
#include "SerialSamplingThread.h"
#include "signaldata.h"
#include <qwt_math.h>
#include <QTextStream>
#if QT_VERSION < 0x040600
#define qFastSin(x) ::sin(x)
#endif
SerialSamplingThread::SerialSamplingThread(QObject *parent,
RecvDatabBase *recvData,
const QString &txt) :
QwtSamplingThread(parent),
d_frequency( 5.0 ),
d_amplitude( 20.0 )
{
i = 0;
recv = recvData;
m_file = new QFile(txt);
if(!m_file->open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "file open false";
}
else
{
qDebug() << "file open";
}
in.setDevice(m_file);
}
SerialSamplingThread::~SerialSamplingThread()
{
recv = NULL;
m_file = NULL;
}
void SerialSamplingThread::sample(double elapsed)
{
in.flush();
if ( d_frequency > 0.0 )
{
if(!in.atEnd())
{
i++;
float data = in.readLine().toFloat();
const QPointF s(elapsed,data);
SignalData::instance().append(s);
qDebug() << QString("ĎÔĘžľÚ %1 ĐĐĘýžÝ %2").arg(i).arg(data);
}
else
{
usleep(10);
}
}
}
double SerialSamplingThread::value(double timeStamp) const
{
const double v = timeStamp;
return v;
}