-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreflowcontroller.cpp
334 lines (285 loc) · 8.42 KB
/
reflowcontroller.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include "reflowcontroller.h"
int ReflowController::MAX_DATAS_STORED = 16;
int ReflowController::MAX_SIZE_TEMP_LIST=4096;
ReflowController::ReflowController(QObject *parent) : QObject(parent)
{
_phttemp=0;
_phttime=0;
_phtpwr=0;
_soaktemp=0;
_soaktime=0;
_soakpwr=0;
_reflowtemp=0;
_reflowtime=0;
_reflowpwr=0;
_dwelltemp=0;
_dwelltime=0;
_dwellpwr=0;
_tempoffset=0;
_currentTemp=0;
_tempshow=2;
_datas = new QStringList();
_uart = new Uart();
}
void ReflowController::startLearning() {
_uart->send("learn");
}
void ReflowController::updateInformation() {
_uart->send("showall");
}
bool ReflowController::openDevice(string path) {
_uart = new Uart( path );
if ( _uart->openDevice() < 0 )
{
return false;
}
else
{
_uart->setInterfaceAttrib(Uart::BR9600, 0);
_uart->setBlocking(0);
}
return _uart->isDeviceOpen();
}
QStringList* ReflowController::getDatas() {
return _datas;
}
void ReflowController::resetTimeTemps() {
_temps.clear();
_times.clear();
}
void ReflowController::exportCVS(string path, char separator ) {
ofstream cvs_file( path.c_str(), ios::out | ios::trunc);
if(cvs_file)
{
int size = _temps.size();
if ( size == _times.size() ) {
for ( int i=0; i < size ; ++i) {
cvs_file << _times.at( i ) << separator << _temps.at(i) <<endl;
}
}
cvs_file.close();
}
else // sinon
cerr << "Error while opening CVS file " << path << endl;
}
void ReflowController::checkUartDataReady() {
if ( ! _uart->isDeviceOpen() )
{
return;
}
// is some UartData ready ?
if (_uart->readData() ) {
// Is the buffer Full ? (prevent Leak of memory and too much RAM used)
if ( _datas->size() > ReflowController::MAX_DATAS_STORED ) {
for ( int i=5; i>=0 ; i--) {
_datas->removeAt(i);
}
}
_datas->append( QString(_uart->getData().c_str()) );
parseUart( _datas->last().toStdString() );
// Addd uart data ready and delete them from Uart class (see Uart->getData())
}
}
void ReflowController::addTemp(double temp, double time) {
if (_temps.size() >= MAX_SIZE_TEMP_LIST ) {
_temps.remove(0,1);
_times.remove(0,1);
}
_times.append( time );
_temps.append( temp );
if ( _times.first() > time )
resetTimeTemps();
}
void ReflowController::parseUart( string data ) {
QRegExp temp_reg("(OFF|ON|Soak|Preheat|Reflow|Dwell|learn|Learn),\\s*(\\d+),\\s*.(\\d+),\\s*degC");
QRegExp config_reg("([a-z+-]{3,})\\s*(\\d{1,})");
QString d( data.c_str() ) ;
int pos = 0;
//*********TEMP***********
pos = 0;
while ( (pos=temp_reg.indexIn( d , pos )) != -1 ) {
pos += temp_reg.matchedLength();
_currentTemp = temp_reg.cap(3).toInt();
addTemp( (double)(temp_reg.cap(3).toInt()), (double)(temp_reg.cap(2).toInt()) );
state = temp_reg.cap(1).toStdString();
}
//********CONFIG**********
pos = 0;
while ( (pos=config_reg.indexIn( d , pos )) != -1 ) {
pos += config_reg.matchedLength();
string variable_name = config_reg.cap(1).toStdString();
int value = config_reg.cap(2).toInt();
if ( variable_name.compare("phttemp") == 0 )
_phttemp = value;
else if ( variable_name.compare("phttime") == 0 )
_phttime = value;
else if ( variable_name.compare("phtpwr") == 0 )
_phtpwr = value;
else if ( variable_name.compare("soaktemp") == 0 )
_soaktemp = value;
else if ( variable_name.compare("soaktime") == 0 )
_soaktime = value;
else if ( variable_name.compare("soakpwr") == 0 )
_soakpwr = value;
else if ( variable_name.compare("reflowtemp") == 0 )
_reflowtemp = value;
else if ( variable_name.compare("reflowtime") == 0 )
_reflowtime = value;
else if ( variable_name.compare("reflowpwr") == 0 )
_reflowpwr = value;
else if ( variable_name.compare("dwelltemp") == 0 )
_dwelltemp = value;
else if ( variable_name.compare("dwelltime") == 0 )
_dwelltime = value;
else if ( variable_name.compare("dwellpwr") == 0 )
_dwellpwr = value;
else if ( variable_name.compare("tempoffset+") == 0 )
_tempoffset = value;
else if ( variable_name.compare("tempoffset-") == 0 )
_tempoffset = -value;
else if ( variable_name.compare("tempoffset") == 0 )
_tempoffset = value;
}
}
QVector<double>* ReflowController::getTemps() {
return &_temps;
}
QVector<double>* ReflowController::getTimes() {
return &_times;
}
Uart* ReflowController::getUartDevice() {
return _uart;
}
void ReflowController::closeDevice() {
_temps.clear();
_times.clear();
_uart->closeDevice();
}
//******************** SET/GET***********************************************
int ReflowController::getCurrentTemp() {
return _currentTemp;
}
void ReflowController::setPhtTemp( int v ) {
if ( v >= 0 && v <= 254 ) {
_phttemp = v;
_uart->send("phttemp "+QString::number(v).toStdString());
}
}
void ReflowController::setPhtTime( int v ) {
if ( v >= 0 && v <= 65534 ) {
_phttime = v;
_uart->send("phttime "+QString::number(v).toStdString());
}
}
void ReflowController::setPhtPwr( int v ) {
if ( v >= 0 && v <= 100 ) {
_phtpwr = v;
_uart->send("phtpwr "+QString::number(v).toStdString());
}
}
void ReflowController::setSoakTemp( int v ) {
if ( v >= 0 && v <= 254 ) {
_soaktemp = v;
_uart->send("soaktemp "+QString::number(v).toStdString());
}
}
void ReflowController::setSoakTime( int v ) {
if ( v >= 0 && v <= 65534 ) {
_soaktime = v;
_uart->send("soaktime "+QString::number(v).toStdString());
}
}
void ReflowController::setSoakPwr( int v ) {
if ( v >= 0 && v <= 100 ) {
_soakpwr = v;
_uart->send("soaktpwr "+QString::number(v).toStdString());
}
}
void ReflowController::setReflowTemp( int v ) {
if ( v >= 0 && v <= 254 ) {
_reflowtemp = v;
_uart->send("reflowtemp "+QString::number(v).toStdString());
}
}
void ReflowController::setReflowTime( int v ) {
if ( v >= 0 && v <= 65534 ) {
_reflowtime = v;
_uart->send("reflowtime "+QString::number(v).toStdString());
}
}
void ReflowController::setReflowPwr( int v ) {
if ( v >= 0 && v <= 100 ) {
_reflowpwr = v;
_uart->send("reflowpwr "+QString::number(v).toStdString());
}
}
void ReflowController::setDwellTemp( int v ) {
if ( v >= 0 && v <= 254 ) {
_dwelltemp = v;
_uart->send("dwelltemp "+QString::number(v).toStdString());
}
}
void ReflowController::setDwellTime( int v ) {
if ( v >= 0 && v <= 65534 ) {
_dwelltime = v;
_uart->send("dwelltime "+QString::number(v).toStdString());
}
}
void ReflowController::setDwellPwr( int v ) {
if ( v >= 0 && v <= 100 ) {
_dwellpwr = v;
_uart->send("dwellpwr "+QString::number(v).toStdString());
}
}
void ReflowController::setTempoffset( int v ) {
if ( v >= -30 && v <= 30 ) {
_tempoffset = v;
_uart->send("tempoffset "+QString::number(v).toStdString());
}
}
void ReflowController::setTempShow( int v ) {
if ( v >= 0 && v <= 1000 )
_tempshow = v;
}
int ReflowController::getPhtTemp( ) const {
return _phttemp;
}
int ReflowController::getPhtTime( ) const {
return _phttime;
}
int ReflowController::getPhtPwr( ) const {
return _phtpwr;
}
int ReflowController::getSoakTemp( ) const {
return _soaktemp;
}
int ReflowController::getSoakTime( ) const {
return _soaktime;
}
int ReflowController::getSoakPwr( ) const {
return _soakpwr;
}
int ReflowController::getReflowTemp( ) const {
return _reflowtemp;
}
int ReflowController::getReflowTime( ) const {
return _reflowtime;
}
int ReflowController::getReflowPwr( ) const {
return _reflowpwr;
}
int ReflowController::getDwellTemp( ) const {
return _dwelltemp;
}
int ReflowController::getDwellTime( ) const {
return _dwelltime;
}
int ReflowController::getDwellPwr( ) const {
return _dwellpwr;
}
int ReflowController::getTempoffset( ) const {
return _tempoffset;
}
int ReflowController::getTempShow( ) const {
return _tempshow;
}