ovenstatics.cpp 29.2 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 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 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
#include "ovenstatics.h"
#include <QtDebug>
#include <QApplication>
#include <QTimer>
#include "mainwindow.h"
#include "ovencontroller.h"
#include "engineermenuwindow.h"
#include "errorpopupdlg.h"
#include "historylistwindow.h"
#include "servicepassinputdlg.h"

OvenStatistics* OvenStatistics::p_singletonInstance=NULL;

OvenStatistics* OvenStatistics::getInstance(QObject *parent){
    if(!p_singletonInstance){
        p_singletonInstance = new OvenStatistics(parent);
        p_singletonInstance->udp = UdpHandler::getInstance();
        p_singletonInstance->oven = Oven::getInstance();
        p_singletonInstance->cfg = Config::getInstance();
        //for singletone event debug
//        MainWindow* mw = (MainWindow*)parent;
//        connect(mw->pcombiButton, SIGNAL(clicked()),p_singtonInstance, SLOT(onDataChanged()));
        connect(p_singletonInstance->udp , SIGNAL(changed()), p_singletonInstance, SLOT(onDataChanged()));
        QTimer *timer = new QTimer(p_singletonInstance);
        connect(timer, SIGNAL(timeout()),p_singletonInstance,SLOT(oneSecTimerFired()));
        timer->start(1000); //1000ms fired
    }
    return p_singletonInstance;
}

void OvenStatistics::destroy(){
    if(!p_singletonInstance)
        delete p_singletonInstance;
}


OvenStatistics::OvenStatistics(QObject* parent) :QObject(parent)
{
    int i = 0;
    curdoorstate = false;
    curSysErrorState = 0;
    curCommErrorState = 0;
    curSensorErrorState = 0;
    curControlErrorState = 0;
    bDataRefreshed = false;
    realdata.d32 = 0;
    m_bPopupShow = false;
    m_nLastPopupidx = MAX_ERROR_TYPE_CNT;

    for(i=0;i<MAX_LOG_SENSOR;i++){
        curSensorValue[i].utemp = 0;
    }

    curSensorValue[12].itemp = 100;

    srvdata = new ServiceData();

}

OvenStatistics::~OvenStatistics(){
    delete srvdata;
}


void OvenStatistics::onDataChanged()
{
    error_item *item;
    time_t ltime=0;
    uint16_t errstatetemp;
    uint8_t cookingstate=0;
    udp->fillControl(control);
    udp->fillData(state);
    bDataRefreshed = true;
    time(&ltime);

    if((control.cooking || oven->cooking() || oven->preheating() || oven->cooldown())) cookingstate = 1;

    if(oven->cooking() && control.system){
        if(state.door_state ==1 && curdoorstate==0){
            //door error
            item = &(srvdata->err_log.items.door);
            item->fired_cnt+=1;
            if(item->first_fired==0)item->first_fired = ltime;
            item->last_fried = ltime;
        }
        curdoorstate = state.door_state;
    }

    qDebug() << "cooking state " << cookingstate << "model " << cfg->getConfigValue(Define::config_model).d32;
    qDebug() << state.system_error << "and sys mask " << sys_err_mask[cookingstate][cfg->getConfigValue(Define::config_model).d32];
    if(state.system_error!=0 &&  state.system_error != curSysErrorState){
        processSystemError( (state.system_error & sys_err_mask[cookingstate][cfg->getConfigValue(Define::config_model).d32]) ,ltime);
    }
    curSysErrorState = state.system_error;

//    errstatetemp = state.communication_error;
//    if(errstatetemp!=0 && errstatetemp != curCommErrorState ){
//        processCommError( (errstatetemp & comm_err_mask[cookingstate][cfg->getConfigValue(Define::config_model).d32]),ltime );
//    }
//    curCommErrorState = errstatetemp;

    errstatetemp = state.sensor_error;
    if(errstatetemp!=0 && errstatetemp != curSensorErrorState ){
        processSensorError( (errstatetemp& sensor_err_mask[cookingstate][cfg->getConfigValue(Define::config_model).d32]),ltime );
    }
    curSensorErrorState = errstatetemp;

//    errstatetemp = state.controller_error;
//    if(errstatetemp != 0 && errstatetemp != curControlErrorState){
//        processStateError((errstatetemp&state_err_mask[cookingstate][cfg->getConfigValue(Define::config_model).d32]),ltime);
//    }
//    curControlErrorState = errstatetemp;

}

void OvenStatistics::processSensorError(uint16_t errflag, time_t ltime){
    error_item *item;
    QString strMsg = "",strTitle="";
    uint8_t state;
    bool bCookingState = (control.cooking || oven->cooking() || oven->preheating() || oven->cooldown());
    if( control.system==0 && !bCookingState  ) state = SYS_OFF_COOK_OFF;
    else if(control.system != 0 && !bCookingState) state = SYS_ON_COOK_OFF;
    else if(control.system !=0 && bCookingState) state = SYS_ON_COOK_ON;
    else state = SYS_ON_COOK_OFF;

    if(errflag & MAKE_MASK(SENSOR_ERR_SENSOR_1)){
        item = &(srvdata->err_log.items.inner_temp_fail);
        strTitle = tr("내부 온도 이상 발생");
        strMsg  = tr("내부 온도 센서에 이상이 발생하였습니다.");
        processErrorItems(item,sensor_err_type_def[state][SENSOR_ERR_SENSOR_1],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(SENSOR_ERR_SENSOR_2)){
        item = &(srvdata->err_log.items.qunching_temp_fail);
        strTitle  = tr("퀀칭 온도 이상 발생");
        strMsg  = tr("퀀칭 온도에 이상이 발생하였습니다.");
        processErrorItems(item,sensor_err_type_def[state][SENSOR_ERR_SENSOR_2],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(SENSOR_ERR_SENSOR_3)){
        //Reserved allerrornoe 설정
        item = &(srvdata->err_log.items.qunching_temp_fail);
        strTitle  = tr("퀀칭 온도 이상 발생");
        strMsg  = tr("퀀칭 온도  센서에 이상이 발생하였습니다.");
        processErrorItems(item,sensor_err_type_def[state][SENSOR_ERR_SENSOR_3],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(SENSOR_ERR_SENSOR_4)){
        item = &(srvdata->err_log.items.wall_temp1_fail);
        strTitle  = tr("벽면 온도 이상 발생");
        strMsg  = tr("벽면 온도 센서에 이상이 발생하였습니다.");
        processErrorItems(item,sensor_err_type_def[state][SENSOR_ERR_SENSOR_4],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(SENSOR_ERR_SENSOR_5)){
        item = &(srvdata->err_log.items.steam_gen_temp_fail);
        strTitle  = tr("스팀제네레이터 온도 이상 발생");
        strMsg  = tr("스팀제네레이터 온도 센서에 이상이 발생하였습니다.");
        processErrorItems(item,sensor_err_type_def[state][SENSOR_ERR_SENSOR_5],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(SENSOR_ERR_SENSOR_6)){
        item = &(srvdata->err_log.items.meatprove_temp1_fail);
        strTitle  = tr("미트프로브 온도 이상 발생");
        strMsg  = tr("미트프로브 온도 센서에 이상이 발생하였습니다.");
        processErrorItems(item,sensor_err_type_def[state][SENSOR_ERR_SENSOR_6],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(SENSOR_ERR_SENSOR_7)){
       //Reseved
        item = &(srvdata->err_log.items.meatprove_temp2_fail);
        strTitle  = tr("미트프로브2 온도 이상 발생");
        strMsg  = tr("미트프로브2 온도 센서에 이상이 발생하였습니다.");
        processErrorItems(item,sensor_err_type_def[state][SENSOR_ERR_SENSOR_7],strMsg , strTitle, ltime);
    }
    if(errflag & MAKE_MASK(SENSOR_ERR_SENSOR_8)){
        //Reserved
        item = &(srvdata->err_log.items.meatprove_temp3_fail);
        strMsg  = tr("미트프로브3 온도 센서에 이상이 발생하였습니다.");
        strTitle  = tr("미트프로브3 온도 이상 발생");
        processErrorItems(item,sensor_err_type_def[state][SENSOR_ERR_SENSOR_8],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(SENSOR_ERR_SENSOR_9)){
        //Reserved
        item = &(srvdata->err_log.items.meatprove_temp4_fail);
        strMsg  = tr("미트프로브4 온도 센서에 이상이 발생하였습니다.");
        strTitle  = tr("미트프로브4 온도 이상 발생");
        processErrorItems(item,sensor_err_type_def[state][SENSOR_ERR_SENSOR_9],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(SENSOR_ERR_SENSOR_10)){
        item = &(srvdata->err_log.items.pcb_temp_fail);
        strMsg  = tr("PCB 온도 센서에 이상이 발생하였습니다.");
        strTitle  = tr("PCB 온도 이상 발생");
        processErrorItems(item,sensor_err_type_def[state][SENSOR_ERR_SENSOR_10],strMsg,strTitle, ltime);
    }
}

void OvenStatistics::processCommError(uint16_t errflag, time_t ltime){
    error_item *item;
    QString strMsg = "",strTitle="";
    uint8_t state;
    bool bCookingState = (control.cooking || oven->cooking() || oven->preheating() || oven->cooldown());
    if( control.system==0 && !bCookingState  ) state = SYS_OFF_COOK_OFF;
    else if(control.system != 0 && !bCookingState) state = SYS_ON_COOK_OFF;
    else if(control.system !=0 && bCookingState) state = SYS_ON_COOK_ON;
    else state = SYS_ON_COOK_OFF;

    if(errflag & MAKE_MASK(COMM_ERR_BUNNER1)){
        item = &(srvdata->err_log.items.upper_pan_fail);
        strMsg  = tr("상부 송풍기 통신 이상 발생");
        strTitle  = tr("상부 송풍기 이상 발생");
        processErrorItems(item,comm_err_type_def[state][COMM_ERR_BUNNER1],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(COMM_ERR_BUNNER2)){
        item = &(srvdata->err_log.items.lower_pan_fail);
        strMsg  = tr("하부 송풍기 통신 이상 발생");
        strTitle  = tr("하부 송풍기 이상 발생");
        processErrorItems(item,comm_err_type_def[state][COMM_ERR_BUNNER2],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(COMM_ERR_BUNNER3)){
        item = &(srvdata->err_log.items.steam_pan_fail);
        strMsg  = tr("스팀 송풍기 통신 이상 발생");
        strTitle  = tr("스팀 송풍기 이상 발생");
        processErrorItems(item,comm_err_type_def[state][COMM_ERR_BUNNER3],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(COMM_ERR_LOWERFAN)){
        item = &(srvdata->err_log.items.lower_motor_fail);
        strMsg  = tr("하부 FAN 컨트롤러 통신 이상 발생");
        strTitle  = tr("하부 FAN 컨트롤러 이상 발생");
        processErrorItems(item,comm_err_type_def[state][COMM_ERR_BUNNER2],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(COMM_ERR_UPPERFAN)){
        item = &(srvdata->err_log.items.upper_motor_fail);
        strMsg  = tr("상부 FAN 컨트롤러 통신 이상 발생");
        strTitle  = tr("상부 FAN 컨트롤러 이상 발생");
        processErrorItems(item,comm_err_type_def[state][COMM_ERR_BUNNER2],strMsg,strTitle, ltime);
    }
}

void OvenStatistics::processStateError(uint16_t errflag, time_t ltime){
    error_item *item;
    QString strMsg = "",strTitle="";
    uint8_t state;
    bool bCookingState = (control.cooking || oven->cooking() || oven->preheating() || oven->cooldown());
    if( control.system==0 && !bCookingState  ) state = SYS_OFF_COOK_OFF;
    else if(control.system != 0 && !bCookingState) state = SYS_ON_COOK_OFF;
    else if(control.system !=0 && bCookingState) state = SYS_ON_COOK_ON;
    else state = SYS_ON_COOK_OFF;

    if(errflag & MAKE_MASK(STATE_ERR_BUNNER1)){
        item = &(srvdata->err_log.items.upper_pan_fail);
        strMsg  = tr("버너컨트롤러 1 이상 발생하였습니다.");
        strTitle  = tr("버너컨트롤러 1 이상 발생");
        processErrorItems(item,state_err_type_def[state][STATE_ERR_BUNNER1],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(STATE_ERR_BUNNER2)){
        item = &(srvdata->err_log.items.lower_pan_fail);
        strMsg  = tr("버너컨트롤러 2 이상  발생하였습니다.");
        strTitle  = tr("버너컨트롤러 2 이상 발생");
        processErrorItems(item,state_err_type_def[state][STATE_ERR_BUNNER2],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(STATE_ERR_BUNNER3)){
        item = &(srvdata->err_log.items.steam_pan_fail);
        strMsg  = tr("버너컨트롤러 3 이상 발생하였습니다.");
        strTitle  = tr("버너컨트롤러 3 이상 발생");
        processErrorItems(item,state_err_type_def[state][STATE_ERR_BUNNER3],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(STATE_ERR_LOWERFAN)){
        item = &(srvdata->err_log.items.lower_motor_fail);
        strMsg  = tr("하부 FAN 컨트롤러 이상 발생하였습니다.");
        strTitle  = tr("하부 FAN 컨트롤러 이상 발생");
        processErrorItems(item,state_err_type_def[state][STATE_ERR_BUNNER2],strMsg,strTitle, ltime);
    }
    if(errflag & MAKE_MASK(STATE_ERR_UPPERFAN)){
        item = &(srvdata->err_log.items.upper_motor_fail);
        strMsg  = tr("상부 FAN 컨트롤러 이상 발생하였습니다.");
        strTitle  = tr("상부 FAN 컨트롤러 이상 발생");
        processErrorItems(item,state_err_type_def[state][STATE_ERR_BUNNER2],strMsg,strTitle, ltime);
    }
}

void OvenStatistics::processSystemError(uint16_t errflag,time_t ltime){
   error_item *item;
   QString strMsg = "",strTitle = "";
   uint8_t state;
   bool bCookingState = (control.cooking || oven->cooking() || oven->preheating() || oven->cooldown());
   if( control.system==0 && !bCookingState  ) state = SYS_OFF_COOK_OFF;
   else if(control.system != 0 && !bCookingState) state = SYS_ON_COOK_OFF;
   else if(control.system !=0 && bCookingState) state = SYS_ON_COOK_ON;
   else state = SYS_ON_COOK_OFF;

    if( errflag & MAKE_MASK(SYS_ERR_FIRE_TRIGGER1)){
        //버너 컨트롤러 1 착화 이상
        item = &(srvdata->err_log.items.upper_fire_fail);
        strMsg  = tr("상부 버너 착화가 되지 않습니다.");
        strTitle = tr("상부 버너 착화 이상 발생");
        processErrorItems(item, sys_err_type_def[state][SYS_ERR_FIRE_TRIGGER1],strMsg,strTitle,ltime);
    }
    if(errflag & MAKE_MASK(SYS_ERR_FIRE_TRIGGER2)){
        //버너 컨트롤러 2 착화 이상
        item = &(srvdata->err_log.items.lower_fire_fail);
        strMsg  = tr("하부 버너 착화가 되지 않습니다.");
        strTitle  = tr("하부 버너 착화 이상 발생");
        processErrorItems(item, sys_err_type_def[state][SYS_ERR_FIRE_TRIGGER2],strMsg,strTitle,ltime);
    }
    if(errflag & MAKE_MASK(SYS_ERR_FIRE_TRIGGER3)){
        item = &(srvdata->err_log.items.steam_fire_fail);
        strMsg  = tr("스팀 버너 착화가 되지 않습니다.");
        strTitle  = tr("스팀 버너 착화 이상 발생");
         processErrorItems(item, sys_err_type_def[state][SYS_ERR_FIRE_TRIGGER3],strMsg,strTitle,ltime);
    }
    if(errflag & MAKE_MASK(SYS_ERR_OVNE_TEMP_ALARM)){
        item = &(srvdata->err_log.items.inner_temp_high_alarm);
        strMsg  = tr("내부 온도가 과열되었습니다.");
        strTitle  = tr("내부 온도 과열 발생");
         processErrorItems(item, sys_err_type_def[state][SYS_ERR_OVNE_TEMP_ALARM],strMsg,strTitle,ltime);
    }
    if(errflag & MAKE_MASK(SYS_ERR_QUN_TEMP_ALARM)){
        //퀀칭 온도 센서 과열
        item = &(srvdata->err_log.items.qunching_temp_high_alarm);
        strTitle  = tr("퀀칭 온도 센서 이상 발생");
        strMsg  = tr("퀀칭 온도 센서가 과열되었습니다");
         processErrorItems(item, sys_err_type_def[state][SYS_ERR_QUN_TEMP_ALARM],strMsg,strTitle,ltime);
    }
    if(errflag & MAKE_MASK(SYS_ERR_CENTER_TEMP_ALARM)){
        //중심 온도 과열
        item = &(srvdata->err_log.items.meatprove_temp1_high_alarm);
        strTitle  = tr("미트프로브 온도 센서 이상 발생.");
        strMsg  = tr("미트프로브 온도 센서 과열되었습니다.");
         processErrorItems(item, sys_err_type_def[state][SYS_ERR_CENTER_TEMP_ALARM],strMsg,strTitle,ltime);
    }
    if(errflag & MAKE_MASK(SYS_ERR_WALL_TEMP_ALARM)){
        item = &(srvdata->err_log.items.wall_temp1_high_alarm);
        strTitle  = tr("벽면 온도 센서 이상 발생.");
        strMsg  = tr("벽면 온도 센서가 과열 되었습니다.");
         processErrorItems(item, sys_err_type_def[state][SYS_ERR_WALL_TEMP_ALARM],strMsg,strTitle,ltime);
    }
   if(errflag & MAKE_MASK(SYS_ERR_STAM_TEMP_ALARM)){
       item = &(srvdata->err_log.items.steam_gen_temp_high_alram);
       strTitle  = tr("스팀제네레이터 온도 이상 발생.");
       strMsg  = tr("스팀제네레이터 온도 센서가 과열 되었습니다.");
        processErrorItems(item, sys_err_type_def[state][SYS_ERR_STAM_TEMP_ALARM],strMsg,strTitle,ltime);
   }
    if(errflag & MAKE_MASK(SYS_ERR_WATER_SPLY_FAIL)){
        //급수 이상 -> 유량 센서 이상
        item = &(srvdata->err_log.items.water_level_sensor_fail);
        strTitle  = tr("급수 이상 발생");
        strMsg  = tr("급수가 되지 않습니다.");
         processErrorItems(item, sys_err_type_def[state][SYS_ERR_WATER_SPLY_FAIL],strMsg,strTitle,ltime);
    }
    if(errflag & MAKE_MASK(SYS_ERR_WATER_LEVEL_FAIL)){
        //급수 이상 -> 수위 센서 이상
        item = &(srvdata->err_log.items.water_level_sensor_fail);
        strTitle = tr("급수 이상 발생");
        strMsg  = tr("급수가 되지 않습니다.");
         processErrorItems(item, sys_err_type_def[state][SYS_ERR_WATER_LEVEL_FAIL],strMsg,strTitle,ltime);
    }
}




bool OvenStatistics::getNeedErrorClear(){
    return bNeedErrorClear;
}

void OvenStatistics::clearNeedErrorClear(){
    //에러클리어 송신 후 flag clear
    bNeedErrorClear = false;
}

void OvenStatistics::oneSecTimerFired(void){
    static int nOneSecCnt=1;
    time_t ltime;

    static int nStateErrValStableCnt = 0;
    static int nCommErrValStableCnt = 0;
    static uint16_t nCommErrVal = 0;
    static uint16_t nStateErrVal = 0;
    uint16_t errstatetemp=0;
    int cookingstate=0;
    if((control.cooking || oven->cooking() || oven->preheating() || oven->cooldown())) cookingstate  =1;

    ltime = time(NULL);

    nOneSecCnt++;
    if( (nOneSecCnt % 10) ==0 ) {
        srvdata->saveServiceData();
    }


    if(bDataRefreshed) bDataRefreshed= false;
    else{
        udp->fillControl(control);
        udp->fillData(state);
    }

    if(nCommErrVal !=  state.communication_error){
        nCommErrVal = state.communication_error;
        if(nCommErrVal ==0) {
            curCommErrorState = nCommErrVal;
            nCommErrValStableCnt = 60;
        }
        else {
            nCommErrValStableCnt=0;
        }
    }
    else{
        if(nCommErrValStableCnt >=60){
            errstatetemp = state.communication_error;
            if(errstatetemp!=0 && errstatetemp != curCommErrorState ){
                processCommError( (errstatetemp & comm_err_mask[cookingstate][cfg->getConfigValue(Define::config_model).d32]),ltime );
            }
            curCommErrorState = errstatetemp;
        }
        else nCommErrValStableCnt++;
    }

    if(nStateErrVal != state.controller_error){
        nStateErrVal = state.controller_error;
        if(nStateErrVal == 0 ) {
            curControlErrorState = nStateErrVal;
            nStateErrValStableCnt=60;
        }
        else{
            nStateErrValStableCnt=0;
        }
    }
    else{
        if(nStateErrValStableCnt>=60){
            errstatetemp = state.controller_error;
            if(errstatetemp != 0 && errstatetemp != curControlErrorState){
                processStateError((errstatetemp&state_err_mask[cookingstate][cfg->getConfigValue(Define::config_model).d32]),ltime);
            }
            curControlErrorState = errstatetemp;
        }
        else nStateErrValStableCnt++;
    }

    //가열부 시간 측정
    if( (state.onoff_state1 & LOAD_STATE1_STEAM_BUNNER) !=0){
        srvdata->use_log.items.steam_heat +=1;
    }
    if( (state.onoff_state1 & (LOAD_STATE1_UPPER_BUNNER | LOAD_STATE1_LOWER_FAN))!=0){
        srvdata->use_log.items.dry_heat+=1;
        if(state.onoff_state1 & (LOAD_STATE1_UPPER_BUNNER)){
            srvdata->use_log.items.upper_heat +=1;
        }
        if((state.onoff_state2 & LOAD_STATE1_LOWER_BUNNER)!=0){
            srvdata->use_log.items.lower_heat +=1;
        }
    }
    //모드 시간 계산
    if(state.cooking_mode !=0){
        if(state.cooking_humidity==0){
            //건열 모드
            srvdata->use_log.items.cook_dry_mode+=1;
        }
        else if(state.cooking_humidity ==100){
            //스팀모드
            srvdata->use_log.items.cook_steam_mode+=1;
        }
        else srvdata->use_log.items.cook_combi_mode+=1;
    }
    if(state.cleaning_mode !=0 && state.cleaning_sate !=0){
        switch (state.cleaning_mode) {
        case (uint16_t)wash_mode_nocleanser:
            srvdata->use_log.items.wash_mode_nocleanser+=1;
            break;
        case (uint16_t)wash_mode_simple:
            srvdata->use_log.items.wash_mode_simple+=1;
            break;
        case (uint16_t)wash_mode_standard:
            srvdata->use_log.items.wash_mode_standard+=1;
            break;
        case (uint16_t)wash_mode_strong:
            srvdata->use_log.items.wash_mode_strong+=1;
            break;
        case (uint16_t)wash_mode_highspeed:
            srvdata->use_log.items.wash_mode_speed+=1;
            break;
        default:
            break;
        }
    }
    if(control.cooldown ==1){
        srvdata->use_log.items.cooldown_mode+=1;
    }
    //부품
    if(state.door_state !=0){
        srvdata->use_log.items.door_open+=1;

    }


    if(state.onoff_state2 !=0){
           if( (state.onoff_state2 & LOAD_STATE2_DV)!=0){
               srvdata->use_log.items.dv_open+=1;
           }
           if((state.onoff_state2 & LOAD_STATE2_SSV)!=0){
               srvdata->use_log.items.ssv_open+=1;
           }
           if((state.onoff_state2 & LOAD_STATE2_QNV)!=0){
               srvdata->use_log.items.qnv_open+=1;
           }
           if((state.onoff_state2 & LOAD_STATE2_SNV)!=0){
               srvdata->use_log.items.snv_open+=1;
           }
           if((state.onoff_state2 & LOAD_STATE2_SSP)!=0){
               srvdata->use_log.items.ssp_open+=1;
           }
           if((state.onoff_state2 & LOAD_STATE2_HDM)!=0){
               srvdata->use_log.items.hdm_open+=1;
           }
           if((state.onoff_state2 & LOAD_STATE2_DP)!=0){
               srvdata->use_log.items.dp_open+=1;
           }
           if((state.onoff_state2 & LOAD_STATE2_UNP) !=0){
               srvdata->use_log.items.unp_open+=1;
           }
    }

    //Real time Data Refresh

    realdata.b.door_open = state.door_state==0?0:1;
    realdata.b.dv_open = (state.onoff_state2&LOAD_STATE2_DV)==0?0:1;
    realdata.b.qnv_open = (state.onoff_state2&LOAD_STATE2_QNV)==0?0:1;
    realdata.b.sgnv_open = (state.onoff_state2&LOAD_STATE2_SGNV)==0?0:1;
    realdata.b.snv_open = (state.onoff_state2&LOAD_STATE2_SNV)==0?0:1;
    realdata.b.wsv_open = (state.onoff_state2&LOAD_STATE2_WSV)==0?0:1;
    realdata.b.ssv_open = (state.onoff_state2&LOAD_STATE2_SSV)==0?0:1;

    if( (state.reserved11&0x0018)  ==  0x0018)  realdata.b.water_level = water_level_high;
    else if( (state.reserved11&0x0018)  == 0x0000) realdata.b.water_level = water_level_low;
    else realdata.b.water_level = water_level_normal;

    if(srvdata->sensor_log.items.B1.high_temp.itemp < state.sensor1 ){
        srvdata->sensor_log.items.B1.high_temp.itemp = state.sensor1;
        srvdata->sensor_log.items.B1.last_high_time = ltime;
    }
    curSensorValue[0].itemp = state.sensor1;

    if(srvdata->sensor_log.items.B2.high_temp.itemp < state.sensor2 ){
        srvdata->sensor_log.items.B2.high_temp.itemp = state.sensor2;
        srvdata->sensor_log.items.B2.last_high_time = ltime;
    }
    curSensorValue[1].itemp = state.sensor2;

    if(srvdata->sensor_log.items.B3_1.high_temp.itemp < state.sensor6 ){
        srvdata->sensor_log.items.B3_1.high_temp.itemp = state.sensor6;
        srvdata->sensor_log.items.B3_1.last_high_time = ltime;
    }
    curSensorValue[5].itemp = state.sensor6;

    if(srvdata->sensor_log.items.B4.high_temp.itemp < state.sensor4 ){
        srvdata->sensor_log.items.B4.high_temp.itemp = state.sensor4;
        srvdata->sensor_log.items.B4.last_high_time = ltime;
    }
     curSensorValue[3].itemp = state.sensor4;

    if(srvdata->sensor_log.items.B5.high_temp.itemp < state.sensor5 ){
        srvdata->sensor_log.items.B5.high_temp.itemp = state.sensor5;
        srvdata->sensor_log.items.B5.last_high_time = ltime;
    }
    curSensorValue[4].itemp = state.sensor5;

    if(srvdata->sensor_log.items.B3_2.high_temp.itemp < state.sensor7 ){
        srvdata->sensor_log.items.B3_2.high_temp.itemp = state.sensor7;
        srvdata->sensor_log.items.B3_2.last_high_time = ltime;
    }
    curSensorValue[6].itemp = state.sensor7;

    if(srvdata->sensor_log.items.B3_3.high_temp.itemp < state.sensor8 ){
        srvdata->sensor_log.items.B3_3.high_temp.itemp = state.sensor8;
        srvdata->sensor_log.items.B3_3.last_high_time = ltime;
    }
    curSensorValue[7].itemp = state.sensor8;

    if(srvdata->sensor_log.items.B3_4.high_temp.itemp < state.sensor9 ){
        srvdata->sensor_log.items.B3_4.high_temp.itemp = state.sensor9;
        srvdata->sensor_log.items.B3_4.last_high_time = ltime;
    }
    curSensorValue[8].itemp = state.sensor9;

    if(srvdata->sensor_log.items.mbar1.high_temp.utemp < state.sensor11 ){
        srvdata->sensor_log.items.mbar1.high_temp.utemp = state.sensor11;
        srvdata->sensor_log.items.mbar1.last_high_time = ltime;
    }
    curSensorValue[10].utemp = state.sensor11;
    if(srvdata->sensor_log.items.mbar2.high_temp.utemp < state.sensor12 ){
        srvdata->sensor_log.items.mbar2.high_temp.utemp = state.sensor12;
        srvdata->sensor_log.items.mbar2.last_high_time = ltime;
    }
    curSensorValue[11].utemp = state.sensor12;

    if(srvdata->sensor_log.items.pcb.high_temp.itemp < state.sensor13 ){
        srvdata->sensor_log.items.pcb.high_temp.itemp = state.sensor13;
        srvdata->sensor_log.items.pcb.last_high_time = ltime;
    }
    curSensorValue[12].itemp = state.sensor13;

    if(srvdata->sensor_log.items.adc.high_temp.itemp < state.sensor14 ){
        srvdata->sensor_log.items.adc.high_temp.itemp = state.sensor14;
        srvdata->sensor_log.items.adc.last_high_time = ltime;
    }
    curSensorValue[13].itemp = state.sensor14;




}

void OvenStatistics::processErrorItems(error_item *item, error_exe_type errtype, const QString &MsgDesc, const QString &MsgTitle, time_t ltime){
    QWidget* pParent;
    uint32_t erridx = (uint32_t) (item - &(srvdata->err_log.values[0]));

    qDebug() << (uint32_t) (item - &(srvdata->err_log.values[0]))  <<   "ERROR Fired!";
   if(m_pLastErrItem == item ){
        srvdata->err_log.items.repeat_error.fired_cnt =item->fired_cnt;
        srvdata->err_log.items.repeat_error.first_fired = item->first_fired;
        srvdata->err_log.items.repeat_error.last_fried = item->last_fried;
   }
   m_pLastErrItem = item;
    qDebug() << "error type" << errtype;
    if(errtype >= error_type_onlychk){
        item->fired_cnt+=1;
        if(item->first_fired == 0) item->first_fired = ltime;
        item->last_fried = ltime;
    }

    emit onErrorFired(erridx);

    if(errtype>=error_type_chkclrstopcmd){
        qDebug() << "exec killchild";
        if(MainWindow::killChildCook()){
            pParent = MainWindow::getInstance();
        }
        else{
            pParent = QApplication::activeWindow();
        }
    }
    else{
        pParent = QApplication::activeWindow();
    }



    switch(errtype){
        case error_type_onlypop:
        case error_type_popclr:
        case error_type_popnonclr:
        case error_type_popclrstopcmd:
            {
                if(m_mapPopupList.find(erridx) == m_mapPopupList.end()){
                    ErrorPopupDlg *dlg = new ErrorPopupDlg(pParent,MsgDesc,MsgTitle , (errtype > error_type_clrsplit), erridx);
                    connect(dlg,SIGNAL(closedErrorPopup(int)), this, SLOT(onErrorPopupClosed(int)));
                    m_mapPopupList.insert(erridx,dlg);
                    qApp->setActiveWindow(dlg);
                    dlg->showFullScreen();
                }
                break;
            }
        case error_type_engclr:
        case error_type_engnonclr:
        case error_type_onlyeng:
        case error_type_engclrstopcmd:
            {
                //EngineerMenuWindow *w = new EngineerMenuWindow(0);
                //w->showFullScreen();
                if(m_mapPopupList.find(erridx)==m_mapPopupList.end()){
                    ErrorPopupDlg *dlg = new ErrorPopupDlg(pParent,MsgDesc,MsgTitle, false,erridx);
                    connect(dlg,SIGNAL(closedErrorPopup(int)),this,SLOT(onErrorPopupClosed(int)));
                    m_mapPopupList.insert(erridx,dlg);
                    dlg->showFullScreen();

                    ServicePassInputDlg *w = new ServicePassInputDlg(pParent, NORMAL_SERVICE_PASS_MODE, (errtype > error_type_clrsplit));
                    //w->exec();
                    connect(dlg, SIGNAL(destroyed(QObject*)), w, SLOT(showFullScreen()));
                 }
                break;
            }
        default:
            break;
    }

//    if(errtype > error_type_clrsplit){
//        //에러 클리어 명령 송신
////       if(errtype == error_type_engclr){
////            //확인 후 송신
////            bNeedErrorClear = true;
////        }
////        else{
////            //에러클리어 메시지 즉시 송신
//           qDebug() << "send error clr";
//            udp->set(TG_ERROR_CLEAR,0xCECE);
////        }
    //}


}

realtime_data OvenStatistics::getPartsRealtimeData(void){
    return realdata;
}

uint8_t OvenStatistics::getSensorTypeByIdx(uint16_t idx){
    if(idx > MAX_LOG_SENSOR)  return 0;
    return sensorTypeInfo[idx];
}

type_temp OvenStatistics::getCurSensorValueByIdx(uint16_t idx){
    return curSensorValue[idx];
}

void OvenStatistics::resetSensorHistory()
{
    srvdata->resetSensorlogData();
}

void OvenStatistics::onErrorPopupClosed(int erridx){
    qDebug() << "error idx" << erridx;
    if(m_mapPopupList.find(erridx)!= m_mapPopupList.end()){
        m_mapPopupList.remove(erridx);
    }
}