/
qhmidata.cpp
467 lines (410 loc) · 12.5 KB
/
qhmidata.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
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
#include "qhmidata.h"
#include "pattern.h"
#include "qmdmessagebox.h"
#include "data.h"
#include <QTimerEvent>
#include <QProcess>
#include "qparam.h"
#include"config.h"
#include<QSettings>
#include"communicat.h"
QHMIData::QHMIData(QParam *param,QComm *qcomm,QObject *parent):
QObject(parent),pparam(param),pcomm(qcomm),speedlimit(0),
alarmlimit(0),shazuiup(1),isruning(FALSE),isinitfinish(FALSE){
connect(pcomm,SIGNAL(DataChangedFromCtrl(unsigned short,QVariant)),
SLOT(On_DataChanged_FromCtrl(unsigned short,QVariant)));
connect(&timer700ms,SIGNAL(timeout()),SLOT(on_700mstimeout()));
connect(pcomm,SIGNAL(commTimerOut(unsigned char)),SLOT(on_CommTimerOut(unsigned char)));
timer700ms.setInterval(1000);
timer700ms.setSingleShot(FALSE);
sys_wrkFilePath = "defalt.wrk";
}
/*void QHMIData::setPatternFile(const QString &cntfilename,const QString &patfilename,const QString &sazfilename){
patterndata.SetFile(cntfilename,patfilename);
patterndata.LoadFile(TRUE,FALSE);
}
*/
void QHMIData::onParamChanged(){
#if DUAL_SYSTEM
bool dankoulock = pparam->fechData(QParam::SpaItemHd_Xtcs,20);
if(this->dankoulock!=dankoulock)
emit sigDankouLock(dankoulock);
#endif
}
void QHMIData::on_CommTimerOut(unsigned char code){
if((alarmque.isEmpty())||alarmque.last()!=59){
alarmque.enqueue(59);
if(alarmque.size()>20)
alarmque.dequeue();
if(commerrorcode.size()<20)
commerrorcode.enqueue(code);
emit alarm(59);
}
}
int QHMIData::pollSysVersion(){
return pcomm->pollSysVersion(mainboardversion,bagversion);
}
QString QHMIData::mainboardVersion(){
return mainboardversion;
}
QString QHMIData::bagVersion(){
return bagversion;
}
QString QHMIData::fetchAlarm(){
int code=0;
if(!alarmque.empty()){
code = alarmque.dequeue();
}
if(code!=59){
return CWBJ_ErrorCode[code];
}
else{
QString str = CWBJ_ErrorCode[59];
return str.append(QString::number(commerrorcode.dequeue(),16));
}
}
void QHMIData::clearAlarm(){
pcomm->ClearError();
}
void QHMIData::On_DataChanged_FromCtrl(unsigned short index,const QVariant &Val){
switch(index){
case QHMIData::YXHXCL:{ //运行时换向
QByteArray bytearray = Val.toByteArray();
QDataStream stream(bytearray);
stream.setByteOrder(QDataStream::BigEndian);
unsigned short tatalloop,leftloop,loopstart,loopend,finishcount,cntnumber;
unsigned char derection,stat;
stream >> tatalloop;
if(tatalloop!=dataBuf[RUN_LOOP_TOTAL]){
dataBuf[RUN_LOOP_TOTAL] = tatalloop;
emit hmi_loopTatal(tatalloop);
}
stream >> cntnumber; //cntnumber 以1开始
if(cntnumber==0){
cntnumber=0x01;
}
dataBuf[RUN_CNT_NUMBER] = cntnumber;
emit hmi_cntNumber(cntnumber);
stream >> leftloop;
if(leftloop!=dataBuf[RUN_LOOP_LEFT]){
dataBuf[RUN_LOOP_LEFT] = leftloop;
emit hmi_loopleft(leftloop);
}
stream >> derection;
if(derection!=dataBuf[RUN_DERECTION]){
dataBuf[RUN_DERECTION] = derection;
emit hmi_direction(derection?Md::LEFT:Md::RIGHT);
}
stream >> loopstart;
if(loopstart!=dataBuf[RUN_LOOP_STARTNO]){
dataBuf[RUN_LOOP_STARTNO] = loopstart;
emit hmi_loopStart(loopstart);
}
stream >> loopend;
if(loopend!=dataBuf[RUN_LOOP_ENDNO]){
dataBuf[RUN_LOOP_ENDNO] = loopend;
emit hmi_loopend(loopend);
}
stream >> stat;
if(stat!=dataBuf[RUN_JUMPORNOT]){
dataBuf[RUN_JUMPORNOT] = stat; //0:正常运行,1:跳行
}
stream >> finishcount;
if(finishcount!=dataBuf[RUN_COUNT_FINISH]){
dataBuf[RUN_COUNT_FINISH] = finishcount;
runTimeHistory = runTime;
stopTimeHistory = stopTime;
runTime = 0;
stopTime = 0;
emit clothFinishCountChanged(finishcount);
}
break;
}
case QHMIData::DQZDJZT: //当前主电机状态
//收到数据01表示停止,停车检查定时器(700ms)重新启动
//运行定时器关,停车定时器开
timer700ms.start();//reset timer;
if(isruning != FALSE){
isruning = FALSE;
emit runing(FALSE);
}
break;
case QHMIData::CWBJXX:{//报警信息
int i = Val.toInt();
if(i==0)
break;
if(i>79 )
i = 79;
if((alarmque.isEmpty())||(alarmque.last()!=i)){
alarmque.enqueue(i);
emit alarm(i);
}
if(alarmque.size()>20)
alarmque.dequeue();
break;
}
case QHMIData::JTXDZS:{//机头相对针数,显示在主界面上
dataBuf[JTXDZS]=(short)(Val.toInt());
emit hmi_jitouxiangduizhengshu(dataBuf[JTXDZS]);
break;
}
case QHMIData::GLWC:{
int val = Val.toInt();
if(0xaa==val){
emit xtRunOrGuiling(TRUE);
xtrunorguiling = TRUE;
}
else if(0xbb==val)
emit xtGuilingError();
break;
}
case QHMIData::XTDD:{
int val = Val.toInt();
if(0x55==val)
emit powerDown();
break;
}
default:
emit DataChanged_ToHMI(index,Val);
break;
}
}
void QHMIData::on_700mstimeout(){
isruning = TRUE;
emit runing(TRUE);
}
bool QHMIData::isRuning(){
return isruning;
}
int QHMIData::TogSysStat(SysStat stat){
unsigned char val=0;
switch(stat){
case SysIdle:
val =0x00;
break;
case SysRun:
val = 72;//0x01; 72 73 下面的机器 0b 0a;
break;
case SysTest:
val = 0x02;
break;
case SysReset:
val =73; // 0x03;
break;
case SysInParam:
val = 0x04;
break;
default:
break;
}
return pcomm->TogSysStat(val);
}
bool QHMIData::mainboardRomAvailable()
{
int commResult = pcomm->IsInBoot();
if(commResult & Md::InBootState)
return FALSE;
else
return TRUE;
}
void QHMIData::loadParam(const QString &inifilepath){
QSettings sysset(inifilepath,QSettings::IniFormat,this);
sysconfigfilename = inifilepath;
sysset.beginGroup("run");
int clothsetcount = sysset.value("clothSetCount").toInt();
int clothfinishcount = sysset.value("clothFinishCount").toInt();
setclothSetCount(clothsetcount,FALSE);
setclothFinishCount(clothfinishcount,FALSE);
int stopperone = sysset.value("stopperone").toBool();
setStopPerOne(stopperone,FALSE);
int linelock = sysset.value("linelock").toBool();
setLineLock(linelock,FALSE);
xtrunorguiling = sysset.value("resetrun").toBool();
stopTime = sysset.value("stoptime").toLongLong();
runTime = sysset.value("runtime").toLongLong();
sysset.endGroup();
sysset.beginGroup("history");
stopTimeHistory = sysset.value("stoptime").toLongLong();
runTimeHistory = sysset.value("runtime").toLongLong();
sysset.endGroup();
sysset.beginGroup("system");
udiskDirPath = sysset.value("udiskFilePath").toString();
sysLogFilePath = sysset.value("syslogfile").toString();
customerId = sysset.value("cd").toString().toInt(0);
sysset.endGroup();
patternPath = sysset.value("pattern/path").toString();
spaFilePath = sysset.value("param/spafile").toString();
}
int QHMIData::errorCode(){
return errorcode;
}
void QHMIData::finish(){
saveSysCfgFile();
}
void QHMIData::startTimer1s(){
timeid1s = startTimer(1000);
}
void QHMIData::timerEvent(QTimerEvent * event){
int id = event->timerId();
if(id==timeid1s){
QDateTime datatime = QDateTime::currentDateTime();
curruntTime = datatime.toTime_t();
if(isruning)
runTime++;
else
stopTime++;
emit time1sOuted();
if(!alarmque.isEmpty())
emit alarm(alarmque.last());
}
}
void QHMIData::saveSysCfgFile(){
QSettings sysset(sysconfigfilename,QSettings::IniFormat,this);
sysset.beginGroup("run");
sysset.setValue("clothFinishCount",QString::number(clothfinishcount));
sysset.setValue("clothSetCount",QString::number(clothsetcount));
sysset.setValue("linelock",QString::number(linelock));
sysset.setValue("resetrun",QString::number(xtrunorguiling));
sysset.setValue("stopperone",QString::number(stopperone));
sysset.setValue("runtime",QString::number(runTime));
sysset.setValue("stoptime",QString::number(stopTime));
sysset.endGroup();
sysset.setValue("pattern/path",patternPath);
sysset.beginGroup("history");
sysset.setValue("runtime",QString::number(runTimeHistory));
sysset.setValue("stoptime",QString::number(stopTimeHistory));
sysset.endGroup();
sysset.sync();
system("cat sysconfig.conf >> /dev/null && sync"); //NOTICE: qsetting will lost filedata ,so call shell command
}
int QHMIData::sendParamaInRun(){//dankoulock在机器系统参数中
return pcomm->sendParamaInRun(clothsetcount,clothfinishcount,
speedlimit,stopperone,
alarmlimit,dankoulock);
}
int QHMIData::setSpeedLimit(bool limit,bool send){
int r=0;
if(send)
r = pcomm->sendParamaInRun(clothsetcount,clothfinishcount,limit,
stopperone,alarmlimit,dankoulock);
if(r==Md::Ok)
speedlimit = limit;
emit speedLimit(speedlimit);
return r;
}
int QHMIData::setAlarmLimit(bool limit,bool send){
int r=0;
if(send)
r = pcomm->sendParamaInRun(clothsetcount,clothfinishcount,
speedlimit,stopperone,limit,dankoulock);
if(Md::Ok==r)
alarmlimit = limit;
emit alarmLimit(alarmlimit);
return r;
}
int QHMIData::setShazuiUp(bool up,bool send){
int r=0;
if(send)
r = pcomm->sazuiDownUp(up);
if(Md::Ok==r)
shazuiup = up;
emit shazuiUp(shazuiup);
return r;
}
int QHMIData::setStopPerOne(bool stop,bool send){
int r=0;
if(send)
r = pcomm->sendParamaInRun(clothsetcount,clothfinishcount,
speedlimit,stop,alarmlimit,dankoulock);
if(Md::Ok==r)
stopperone = stop;
emit stopPerOne(stopperone);
return r;
}
int QHMIData::setLineLock(bool lock,bool send){
int r=0;
if(send)
r = pcomm->lineLock(lock);
if(Md::Ok==r)
linelock = lock;
emit lineLock(linelock);
return r;
}
#if DUAL_SYSTEM
int QHMIData::setDankouLock(bool lock,bool send){
int r=0;
if(send)
r = pcomm->sendParamaInRun(clothsetcount,clothfinishcount,
speedlimit,stopperone,alarmlimit,lock);
if(Md::Ok==r)
dankoulock = lock;
pparam->setDankouLock(dankoulock);
emit sigDankouLock(dankoulock);
return r;
}
int QHMIData::toggleDankouLock(){
return setDankouLock(!dankoulock,TRUE);
}
bool QHMIData::dankouLock(){
return this->dankoulock;
}
#endif
bool QHMIData::xtGuiling(){
if(TogSysStat(SysReset)==Md::Ok){
emit xtRunOrGuiling(FALSE);
xtrunorguiling = FALSE;
return TRUE;
}
return FALSE;
}
bool QHMIData::xtRun()
{
if(TogSysStat(SysRun)==Md::Ok){
emit xtRunOrGuiling(TRUE);
xtrunorguiling = TRUE;
return TRUE;
}
return FALSE;
}
void QHMIData::start(){
timer700ms.start();
isinitfinish = TRUE;
if(xtrunorguiling)
xtRun();
else
xtGuiling();
}
int QHMIData::setclothSetCount(unsigned short val,bool send){
int r=0;
if(send)
r = pcomm->sendParamaInRun(val,clothfinishcount,
speedlimit,stopperone,alarmlimit,dankoulock);
if(Md::Ok==r)
clothsetcount = val;
emit clothSetCountChanged(clothsetcount);
return r;
}
int QHMIData::setclothFinishCount(unsigned short val,bool send){
int r=0;
if(send)
r = pcomm->sendParamaInRun(clothsetcount,val,
speedlimit,stopperone,alarmlimit,dankoulock);
if(Md::Ok==r)
clothfinishcount = val;
emit clothFinishCountChanged(clothfinishcount);
return r;
}
int QHMIData::clothFinishCount(){
return clothfinishcount;
}
int QHMIData::clothSetCount(){
return clothsetcount;
}
void QHMIData::on_patternChange(const QString &dirpath,const QString &name){
partternName = name;
QString path = dirpath+"/"+name;
if(patternPath!=path){
patternPath = path;
setclothFinishCount(0,TRUE);
}
}