fileprocessdlg.cpp
19.9 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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#include <QTimer>
#include <unistd.h>
#include "fileprocessdlg.h"
#include "ui_fileprocessdlg.h"
#include "fileprocessor.h"
#include "ovenstatics.h"
#include "stringer.h"
#include <QDebug>
#define ERROR_LOG_FILE_TOP "/GasErrorHistoryTop.csv"
#define ERROR_LOG_FILE_STEAM "/GasErrorHistorySteam.csv"
#define ERROR_LOG_FILE_BOTTOM "/GasErrorHistoryBottom.csv"
#define ERROR_LOG_FILE_TOTAL "/TotalError.csv"
#define SERVICE_DATA_FILE "/ServiceData.csv"
FileProcessDlg::FileProcessDlg(QWidget *parent, ConfigType type, bool isDown) :
QDialog(parent),
ui(new Ui::FileProcessDlg)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::FramelessWindowHint);
ui->ctrWjProcess->setMinimum(0);
ui->ctrWjProcess->setMaximum(100);
if(isDown){
QPixmap pxmap;
pxmap.load(":/images/config/102_usb_upload_icon.png");
ui->label_2->setPixmap(pxmap);
}
switch(type){
case config_info_data_download:
QTimer::singleShot(100,this,SLOT(infodataDownload()));
break;
case config_service_data_download:
QTimer::singleShot(100,this,SLOT(servicedataDownload()));
break;
case config_program_download:
QTimer::singleShot(100,this,SLOT(programDownload()));
break;
case config_program_upload:
QTimer::singleShot(100,this,SLOT(programUpload()));
break;
case config_set_download:
QTimer::singleShot(100,this,SLOT(configDownload()));
break;
case config_set_upload:
QTimer::singleShot(100,this,SLOT(configUpload()));
break;
default:
QTimer::singleShot(200,this,SLOT(deleteLater()));
break;
}
}
FileProcessDlg::~FileProcessDlg()
{
delete ui;
}
void FileProcessDlg::on_ctrBtnCancel_clicked()
{
close();
}
void FileProcessDlg::saveHistoryLineData(QTextStream &out, uint16_t i, uint16_t fired_cnt, time_t first_fired, time_t last_fried){
QString strLine;
QDateTime dt;
//for(int i =0;i<m_arrErrorMaxIdx[(uint16_t)type];i++){
// err_item = &(ovenst->srvdata->err_log.values[m_arrErrorIdxs[type][i]]);
strLine = tr("erro%1,").arg(i);
if(first_fired == 0){
strLine += "-,0,-";
}
else{
dt.setTime_t(first_fired);
strLine+= Stringer::DateTimeString(dt,Stringer::datetime_string_type_oneline) + ",";
strLine += QString("%1").arg(fired_cnt) + ",";
dt.setTime_t(last_fried);
strLine += Stringer::DateTimeString(dt,Stringer::datetime_string_type_oneline) + ",";
}
out << strLine << "\n";
qDebug() << strLine;
//}
}
void FileProcessDlg::saveHistoryTotalData(QTextStream &out){
int i = 0;
error_item *item;
time_t firsttimebuf=0,lasttimebuf=0;
uint16_t firecntbuf=0;
QString strLine;
QDateTime dt;
OvenStatistics *ovenst = OvenStatistics::getInstance();
//01 상부 점화 장치 데이터 초기화
// for(i=0;i<m_arrErrorMaxIdx[ERROR_HISTORY_UPPERBUNNER];i++){
// item = &(ovenst->srvdata->err_log.values[m_arrErrorIdxs[ERROR_HISTORY_UPPERBUNNER][i]]);
// if(i==0) {firsttimebuf = item->first_fired;lasttimebuf = item->last_fried;firecntbuf=item->fired_cnt;}
// else{
// if( firsttimebuf > item->first_fired && item->first_fired != 0 ) firsttimebuf = item->first_fired;
// if( lasttimebuf < item->last_fried ) lasttimebuf = item->last_fried;
// firecntbuf += item->fired_cnt;
// }
// }
// total_items[0].fired_cnt = firecntbuf;
// total_items[0].first_fired = firsttimebuf;
// total_items[0].last_fried = lasttimebuf;
}
void FileProcessDlg::infodataDownload(){
QString strUsbPath;
QString strFile;
QFile file;
error_item *item;
OvenStatistics *ovenst = OvenStatistics::getInstance();
time_t firsttimebuf=0,lasttimebuf=0;
uint16_t firecntbuf=0;
uint16_t erridx = 0;
int i;
if(FileProcessor::detectUSB(strUsbPath)){
//Top
strFile = strUsbPath + ERROR_LOG_FILE_TOP;
qDebug() << strUsbPath;
file.setFileName(strFile);
if(file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)){
QTextStream out(&file);
out << tr("Gas Error History\n") << "Top Ignition Box" <<"\n";
out << tr("no,") << tr("First Appearance,") << tr("Counter,") << tr("Last Appearance\n");
for(i =0;i<m_arrErrorMaxIdx[ERROR_HISTORY_UPPERBUNNER];i++){
item = &(ovenst->srvdata->err_log.values[m_arrErrorIdxs[ERROR_HISTORY_UPPERBUNNER][i]]);
saveHistoryLineData(out,i+1,item->fired_cnt,item->first_fired,item->last_fried);
}
file.close();
}
ui->ctrWjProcess->setValue(25);
ui->ctrLbRemainTime->setText(tr("남은 예상 시간 : 1초"));
//Bottom
strFile = strUsbPath + ERROR_LOG_FILE_BOTTOM;
qDebug() << strUsbPath;
file.setFileName(strFile);
if(file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)){
QTextStream out(&file);
out << tr("Gas Error History\n") << "Bottom Ignition Box" <<"\n";
out << tr("no,") << tr("First Appearance,") << tr("Counter,") << tr("Last Appearance\n");
for(i =0;i<m_arrErrorMaxIdx[ERROR_HISTORY_LOWERBUNNER];i++){
item = &(ovenst->srvdata->err_log.values[m_arrErrorIdxs[ERROR_HISTORY_LOWERBUNNER][i]]);
saveHistoryLineData(out,i+1,item->fired_cnt,item->first_fired,item->last_fried);
}
file.close();
}
ui->ctrWjProcess->setValue(50);
ui->ctrLbRemainTime->setText(tr("남은 예상 시간 : 1초"));
//Steam
strFile = strUsbPath + ERROR_LOG_FILE_STEAM;
qDebug() << strUsbPath;
file.setFileName(strFile);
if(file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)){
QTextStream out(&file);
out << tr("Gas Error History\n") << "Steam Ignition Box" <<"\n";
out << tr("no,") << tr("First Appearance,") << tr("Counter,") << tr("Last Appearance\n");
for(i =0;i<m_arrErrorMaxIdx[ERROR_HISTORY_STEAMBUNNER];i++){
item = &(ovenst->srvdata->err_log.values[m_arrErrorIdxs[ERROR_HISTORY_STEAMBUNNER][i]]);
saveHistoryLineData(out,i+1,item->fired_cnt,item->first_fired,item->last_fried);
}
file.close();
}
ui->ctrWjProcess->setValue(75);
ui->ctrLbRemainTime->setText(tr("남은 예상 시간 : 1초"));
//Total
strFile = strUsbPath + ERROR_LOG_FILE_TOTAL;
qDebug() << strUsbPath;
file.setFileName(strFile);
if(file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)){
QTextStream out(&file);
out << tr("Service Error History\n\n");
out << tr("no,") << tr("First Appearance,") << tr("Counter,") << tr("Last Appearance\n");
//01 상부 점화 장치 데이터 초기화
firecntbuf = 0;firsttimebuf = 0; lasttimebuf=0;
for(i=0;i<m_arrErrorMaxIdx[ERROR_HISTORY_UPPERBUNNER];i++){
item = &(ovenst->srvdata->err_log.values[m_arrErrorIdxs[ERROR_HISTORY_UPPERBUNNER][i]]);
if(i==0) {firsttimebuf = item->first_fired;lasttimebuf = item->last_fried;firecntbuf=item->fired_cnt;}
else{
if( (firsttimebuf > item->first_fired && item->first_fired != 0) || firsttimebuf == 0 ) firsttimebuf = item->first_fired;
if( lasttimebuf < item->last_fried ) lasttimebuf = item->last_fried;
firecntbuf += item->fired_cnt;
}
}
saveHistoryLineData(out,erridx+1, firecntbuf,firsttimebuf,lasttimebuf);erridx++;
//02 스팀 점화 장치 데이터 초기화
firecntbuf = 0;firsttimebuf = 0; lasttimebuf=0;
for(i=0;i<m_arrErrorMaxIdx[ERROR_HISTORY_STEAMBUNNER];i++){
item = &(ovenst->srvdata->err_log.values[m_arrErrorIdxs[ERROR_HISTORY_STEAMBUNNER][i]]);
if(i==0) {firsttimebuf = item->first_fired;lasttimebuf = item->last_fried;firecntbuf=item->fired_cnt;}
else{
if((firsttimebuf > item->first_fired && item->first_fired != 0) || firsttimebuf == 0 ) firsttimebuf = item->first_fired;
if( lasttimebuf < item->last_fried ) lasttimebuf = item->last_fried;
firecntbuf += item->fired_cnt;
}
}
saveHistoryLineData(out, erridx,firecntbuf,firsttimebuf,lasttimebuf);erridx++;
//03 하부 점화 장치 데이터 초기화
firecntbuf = 0;firsttimebuf = 0; lasttimebuf=0;
for(i=0;i<m_arrErrorMaxIdx[ERROR_HISTORY_LOWERBUNNER];i++){
item = &(ovenst->srvdata->err_log.values[m_arrErrorIdxs[ERROR_HISTORY_LOWERBUNNER][i]]);
if(i==0) {firsttimebuf = item->first_fired;lasttimebuf = item->last_fried;firecntbuf=item->fired_cnt;}
else{
if((firsttimebuf > item->first_fired && item->first_fired != 0) || firsttimebuf == 0 ) firsttimebuf = item->first_fired;
if( lasttimebuf < item->last_fried ) lasttimebuf = item->last_fried;
firecntbuf += item->fired_cnt;
}
}
saveHistoryLineData(out, erridx,firecntbuf,firsttimebuf,lasttimebuf);erridx++;
//04 WATER
firecntbuf = 0;firsttimebuf = 0; lasttimebuf=0;
item = &(ovenst->srvdata->err_log.items.inner_temp_fail);
firsttimebuf = item->first_fired;lasttimebuf = item->last_fried;firecntbuf=item->fired_cnt;
item = &(ovenst->srvdata->err_log.items.qunching_temp_fail);
if( firsttimebuf > item->first_fired && item->first_fired != 0 ) firsttimebuf = item->first_fired;
if( lasttimebuf < item->last_fried ) lasttimebuf = item->last_fried;
firecntbuf += item->fired_cnt;
saveHistoryLineData(out, erridx,firecntbuf,firsttimebuf,lasttimebuf);erridx++;
//05 구성품
firecntbuf = 0;firsttimebuf = 0; lasttimebuf=0;
saveHistoryLineData(out, erridx,firecntbuf,firsttimebuf,lasttimebuf);erridx++;
//07 B1 센서 에러
firecntbuf = 0;firsttimebuf = 0; lasttimebuf=0;
item = &(ovenst->srvdata->err_log.items.inner_temp_high_alarm);
firsttimebuf = item->first_fired;lasttimebuf = item->last_fried;firecntbuf=item->fired_cnt;
saveHistoryLineData(out, erridx,firecntbuf,firsttimebuf,lasttimebuf);erridx++;
//08 B2 센서 에러
firecntbuf = 0;firsttimebuf = 0; lasttimebuf=0;
item = &(ovenst->srvdata->err_log.items.qunching_temp_high_alarm);
saveHistoryLineData(out, erridx,firecntbuf,firsttimebuf,lasttimebuf);erridx++;
//10 B4 센서 에러
firecntbuf = 0;firsttimebuf = 0; lasttimebuf=0;
item = &(ovenst->srvdata->err_log.items.wall_temp1_high_alarm);
firsttimebuf = item->first_fired;lasttimebuf = item->last_fried;firecntbuf=item->fired_cnt;
saveHistoryLineData(out, erridx,firecntbuf,firsttimebuf,lasttimebuf);erridx++;
//11 B5 센서 에러
firecntbuf = 0;firsttimebuf = 0; lasttimebuf=0;
item = &(ovenst->srvdata->err_log.items.steam_gen_temp_high_alram);
firsttimebuf = item->first_fired;lasttimebuf = item->last_fried;firecntbuf=item->fired_cnt;
saveHistoryLineData(out, erridx,firecntbuf,firsttimebuf,lasttimebuf);erridx++;
firecntbuf = 0;firsttimebuf = 0; lasttimebuf=0;
item = &(ovenst->srvdata->err_log.items.water_level_sensor_fail);
firsttimebuf = item->first_fired;lasttimebuf = item->last_fried;firecntbuf=item->fired_cnt;
saveHistoryLineData(out, erridx,firecntbuf,firsttimebuf,lasttimebuf);erridx++;
file.close();
}
sync();
ui->ctrWjProcess->setValue(100);
ui->ctrLbRemainTime->setText(tr("남은 예상 시간 : 완료"));
QTimer::singleShot(1000,this,SLOT(close()));
}
}
void FileProcessDlg::servicedataDownload(){
QString strUsbPath;
QString strHeader = "no,name,time\n";
QString strFile;
QFile file;
error_item *item;
uint32_t timetemp, totaltime=0;
int i = 1;
OvenStatistics *ovs = OvenStatistics::getInstance();
if(FileProcessor::detectUSB(strUsbPath)){
strFile = strUsbPath + SERVICE_DATA_FILE;
file.setFileName(strFile);
if(file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)){
QTextStream out(&file);
out.setCodec("UTF-8");
out<< strHeader;
timetemp = ovs->srvdata->use_log.items.steam_heat/3600;
out << i++ << tr(",Steam Heating Time,") << timetemp << "h\n";
timetemp = ovs->srvdata->use_log.items.dry_heat/3600;
out << i++ << tr(",Hot Air Heating Time,") << timetemp << "h\n";
i=1;out<< strHeader;
timetemp = ovs->srvdata->use_log.items.cook_dry_mode/3600;
totaltime+= ovs->srvdata->use_log.items.cook_dry_mode;
out << i++ << tr(",Hot Air Mode,") << timetemp << "h\n";
timetemp = ovs->srvdata->use_log.items.cook_steam_mode/3600;
totaltime += ovs->srvdata->use_log.items.cook_steam_mode;
out << i++ << tr(",Steam Mode,") << timetemp << "h\n";
timetemp = ovs->srvdata->use_log.items.cook_combi_mode/3600;
totaltime += ovs->srvdata->use_log.items.cook_combi_mode;
out << i++ << tr(",Combi Mode,") << timetemp << "h\n";
timetemp = ovs->srvdata->use_log.items.wash_mode_nocleanser/3600;
totaltime += ovs->srvdata->use_log.items.wash_mode_nocleanser;
out << i++ << tr(",세제없이 헹굼,").toUtf8() << timetemp << "h\n";
timetemp = ovs->srvdata->use_log.items.wash_mode_simple/3600;
totaltime += ovs->srvdata->use_log.items.wash_mode_simple;
out << i++ << tr(",간이세척,").toUtf8() << timetemp << "h\n";
timetemp = ovs->srvdata->use_log.items.wash_mode_standard/3600;
totaltime += ovs->srvdata->use_log.items.wash_mode_standard;
out << i++ << tr(",표준세척,").toUtf8() << timetemp << "h\n";
timetemp = ovs->srvdata->use_log.items.wash_mode_strong/3600;
totaltime += ovs->srvdata->use_log.items.wash_mode_strong;
out << i++ << tr(",강세척").toUtf8() << timetemp << "h\n";
timetemp = ovs->srvdata->use_log.items.wash_mode_speed/3600;
totaltime +=ovs->srvdata->use_log.items.wash_mode_speed;
out << i++ << tr(",고속세척,").toUtf8() << timetemp << "h\n";
timetemp = ovs->srvdata->use_log.items.cooldown_mode/3600;
totaltime += ovs->srvdata->use_log.items.cooldown_mode;
out << i++ << tr(",쿨다운,").toUtf8() << timetemp << "h\n";
timetemp = totaltime/3600;
out << i++ << tr(",전체작동시간,").toUtf8() << timetemp << "h\n";
i=1;out<< strHeader;
timetemp = ovs->srvdata->use_log.items.door_open/60;
out << i++ << tr(",도어 Open,").toUtf8() << timetemp << "min\n";
timetemp = ovs->srvdata->use_log.items.dv_open/60;
out << i++ << tr(",볼밸브 Open,").toUtf8() << timetemp << "min\n";
timetemp = ovs->srvdata->use_log.items.ssv_open/60;
out << i++ << tr(",S/G 급수 솔레노이드,").toUtf8() << timetemp << "min\n";
timetemp = ovs->srvdata->use_log.items.qnv_open/60;
out << i++ << tr(",퀀칭 솔레노이드,").toUtf8() << timetemp << "min\n";
timetemp = ovs->srvdata->use_log.items.snv_open/60;
out << i++ << tr(",고내살수 노즐 솔레노이드 ,").toUtf8() << timetemp << "min\n";
timetemp = 0;
out << i++ << tr(",호스릴 솔레노이드,").toUtf8() << timetemp << "min\n";
timetemp = ovs->srvdata->use_log.items.ssp_open/60;
out << i++ << tr(",세제공급장치,").toUtf8() << timetemp << "min\n";
timetemp = ovs->srvdata->use_log.items.hdm_open/60;
out << i++ << tr(",배습댐퍼,").toUtf8() << timetemp << "min\n";
timetemp = ovs->srvdata->use_log.items.dp_open/60;
out << i++ << tr(",소형펌프모터,").toUtf8() << timetemp << "min\n";
timetemp = ovs->srvdata->use_log.items.unp_open/60;
out << i++ << tr(",중형펌프모터,").toUtf8() << timetemp << "min\n";
ui->ctrWjProcess->setValue(100);
ui->ctrLbRemainTime->setText(tr("남은 예상 시간 : 완료"));
file.close();
sync();
QTimer::singleShot(1000,this,SLOT(close()));
}
}
}
void FileProcessDlg::programDownload(){
}
void FileProcessDlg::programUpload(){
}
void FileProcessDlg::configDownload(){
QString strUsbPath;
if(FileProcessor::detectUSB(strUsbPath)){
strUsbPath.append("/config.ini");
qDebug() << strUsbPath;
QFile file;
file.setFileName(strUsbPath);
if(file.exists()) file.remove();
if(QFile::copy("/prime/config/config.ini", strUsbPath)){
sync();
ui->ctrWjProcess->setValue(50);
ui->ctrLbRemainTime->setText(tr("남은 예상 시간 : 1초"));
}
else{
ui->ctrLbRemainTime->setText(tr("설정 다운로드에 실패하였습니다."));
QTimer::singleShot(1000,this,SLOT(close()));
return;
}
strUsbPath.replace("/config.ini","/favorite.ini");
file.setFileName(strUsbPath);
if(file.exists()) file.remove();
if(QFile::copy("/prime/config/favorite.ini", strUsbPath)){
sync();
ui->ctrWjProcess->setValue(100);
ui->ctrLbRemainTime->setText("남은 예상 시간 : 0초");
ui->ctrLbRemainTime->setText(tr("남은 예상 시간 : 완료"));
QTimer::singleShot(1000,this,SLOT(close()));
}
else{
ui->ctrLbRemainTime->setText(tr("즐겨찾기 다운로드에 실패하였습니다."));
QTimer::singleShot(1000,this,SLOT(close()));
}
}
else{
ui->ctrLbRemainTime->setText(tr("USB 인식을 실패하였습니다."));
QTimer::singleShot(1000,this,SLOT(close()));
}
}
void FileProcessDlg::configUpload(){
QString strUsbPath;
Config *cfg = Config::getInstance();
if(FileProcessor::detectUSB(strUsbPath)){
strUsbPath.append("/config.ini");
qDebug() << strUsbPath;
QFile file("/prime/config/config.ini");
file.remove();
if(QFile::copy( strUsbPath , "/prime/config/config.ini")){
sync();
cfg->loadConfig();
cfg->applyConfig();
ui->ctrWjProcess->setValue(50);
ui->ctrLbRemainTime->setText(tr("남은 예상 시간 : 1초"));
}
else{
ui->ctrLbRemainTime->setText(tr("설정 업로드에 실패하였습니다."));
QTimer::singleShot(1000,this,SLOT(close()));
return;
}
QFile file2("/prime/config/favorite.ini");
file2.remove();
strUsbPath.replace("/config.ini", "/favorite.ini");
qDebug() << strUsbPath;
if(QFile::copy( strUsbPath , "/prime/config/favorite.ini")){
sync();
cfg->loadFavorite();
ui->ctrWjProcess->setValue(100);
ui->ctrLbRemainTime->setText(tr("남은 예상 시간 : 완료"));
QTimer::singleShot(1000,this,SLOT(close()));
}
else{
ui->ctrLbRemainTime->setText(tr("즐겨찾기 업로드에 실패하였습니다."));
QTimer::singleShot(1000,this,SLOT(close()));
}
}
else{
ui->ctrLbRemainTime->setText(tr("USB 인식을 실패하였습니다."));
QTimer::singleShot(1000,this,SLOT(close()));
}
}