-
Notifications
You must be signed in to change notification settings - Fork 0
/
remoteDataAnalysisThread.cpp
131 lines (112 loc) · 3.32 KB
/
remoteDataAnalysisThread.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
/*
* remoteDataAnalysisThread.cpp
*
* Created on: 02.06.2010
* Author: cyborg-x1
*/
#include "remoteDataAnalysisThread.h"
remoteDataAnalysisThread::remoteDataAnalysisThread()
{
// TODO Auto-generated constructor stub
pReset=false;
sReset=false;
}
remoteDataAnalysisThread::~remoteDataAnalysisThread()
{
//Wait for thread to terminate
wait();
}
void remoteDataAnalysisThread::run()
{
//Create an new Timer
this->timer_analysis = new QTimer();
//Connect the Timer to analysis thread
connect(timer_analysis, SIGNAL(timeout()),this,SLOT(analysis()));
//Start it with calling the function each 500 ms,
//should be enough because the multimeter is only
//capable of sending 2 data sets each sec
timer_analysis->start(500);
exec();
}
void remoteDataAnalysisThread::analysis()
{
static long numberDataSet;
QString priValue,priMin,priMax,priAvg,secValue,secMin,secMax,secAvg;
Fluke::Fluke189::RCT_QD0 current;
lock.lockForRead();
//have a look if user wants to reset min,max,avg
bool sReset=this->sReset;
bool pReset=this->pReset;
//Usually this function should be faster than the logthread
//But otherwise it will not leave out any value
//each time it is called it checks if there is a new container
//if there is it will get the next, if not it returns
if(this->qd0Data.count() > (signed)numberDataSet)
{
current=this->qd0Data[numberDataSet];
numberDataSet++;
lock.unlock();
}
else
{
lock.unlock();
return;
}
if(pReset)
{
Logger.reset_primary();
}
if(sReset) Logger.reset_secondary();
if(pReset || sReset)
{
//Clear class member
lock.lockForWrite();
this->pReset=false;
this->sReset=false;
lock.unlock();
}
Logger.addContainer(current);
priValue=QString::fromUtf8(Logger.get_Primary_ValueAndUnit_String().c_str());
priMin=QString::fromUtf8(Logger.get_Primary_Min_ValueAndUnit_String().c_str());
priMax=QString::fromUtf8(Logger.get_Primary_Max_ValueAndUnit_String().c_str());
priAvg=QString::fromUtf8(Logger.get_Primary_Avg_ValueAndUnit_String().c_str());
secValue=QString::fromUtf8(Logger.get_Secondary_ValueAndUnit_String().c_str());
secMin=QString::fromUtf8(Logger.get_Secondary_Min_ValueAndUnit_String().c_str());
secMax=QString::fromUtf8(Logger.get_Secondary_Max_ValueAndUnit_String().c_str());
secAvg=QString::fromUtf8(Logger.get_Secondary_Avg_ValueAndUnit_String().c_str());
emit updateCurrentValues(priValue,priMin,priMax,priAvg,secValue,secMin,secMax,secAvg);
if(!Fluke::Fluke189DataResponseAnalyzer(current)[0]->hasErrorPRIdisplay())
emit setGraph(current.Data()->I_Time0, current.Data()->I_Time1,
this->Logger.get_Primary_Value(),
this->Logger.get_Primary_Maximum(),
this->Logger.get_Primary_Minimum(),
this->Logger.get_Primary_Average(),
this->Logger.get_Secondary_Value(),
this->Logger.get_Secondary_Maximum(),
this->Logger.get_Secondary_Minimum(),
this->Logger.get_Secondary_Average());
}
void remoteDataAnalysisThread::stop()
{
quit();
}
void remoteDataAnalysisThread::getFluke189_QD0(Fluke::Fluke189::RCT_QD0 container)
{
lock.lockForWrite();
this->qd0Data.append(container);
lock.unlock();
}
void remoteDataAnalysisThread::reset_primary()
{
lock.lockForWrite();
pReset=true;
lock.unlock();
emit primary_reset();
}
void remoteDataAnalysisThread::reset_secondary()
{
lock.lockForWrite();
sReset=true;
lock.unlock();
emit secondary_reset();
}