dlgdatafile.cpp 26.2 KB
Newer Older
Alexander Steffens's avatar
Alexander Steffens committed
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
#include <QTimer>
#include <QMessageBox>
#include <QSpacerItem>
#include <QCloseEvent>
#include <QFileInfo>
#include <QSettings>

#include "dlgdatafile.h"
#include "ui_dlgdatafile.h"
#include "concentrator_def.h"
#include "maroc_def.h"
#include "funktionen.h"

/*
 * format.setUnderlineStyle( QTextCharFormat::SingleUnderline );
format.setForeground( QBrush( QColor( "red" ) ) );
cursor.setCharFormat( format );
cursor.insertText( "Hello world!" );
format.setFontWeight( QFont::Bold );
format.setForeground( QBrush( QColor( "green" ) ) );
cursor.setCharFormat( format );
cursor.insertText( "Hello world!" );
format.setFontWeight( QFont::Normal );
format.setBackground( QBrush( QColor( "black" ) ) );
format.setForeground( QBrush( QColor( "yellow" ) ) );
cursor.setCharFormat( format );
cursor.insertText( "Hello world!" );
format.setBackground( QBrush( QColor( "white" ) ) );
format.setForeground( QBrush( QColor( "black" ) ) );
cursor.setCharFormat( format );
cursor.insertText( "Hello world!" );
*/

dlgdatafile::dlgdatafile(QWidget *parent, QString filename) :
    QDialog(parent),
    ui(new Ui::dlgdatafile)
{
    ui->setupUi(this);
    _FileName       = filename;
    _FileNameInfo   = QFileInfo(filename).path()+"/"+QFileInfo(filename).completeBaseName() + ".txt";
    _Serial         = QFileInfo(filename).completeBaseName().mid(3,10); // SN_0x3AF0E383_Con_08_29__11_37_46

    _Error      = false;
    _Line       = 0;
    _Values     = 0;
    ui->FileName->setText(_FileName);

    ui->Text->clear();

    _ErrorTypeTxt.append("No Error");
    _ErrorTypeTxt.append("X X / Y Y");
    _ErrorTypeTxt.append("Timediff");
    _ErrorTypeTxt.append("Coinc. Overflow");
    _ErrorTypeTxt.append("Output Fifo PCI Overflow");
    _ErrorTypeTxt.append("Temp Fifo Overflow");


    _FunctionNames.append(CC_FUNCTION_0);
    _FunctionNames.append(CC_FUNCTION_1);
    _FunctionNames.append(CC_FUNCTION_2);
    _FunctionNames.append(CC_FUNCTION_3);
    _FunctionNames.append(CC_FUNCTION_4);
    _FunctionNames.append(CC_FUNCTION_5);

    int f;
    for (f=0; f<CC_MAX_COMMANDS; f++) {
        QLabel *label = new QLabel();
        label->setText(_FunctionNames.at(f));
        ui->ValuesGrid->addWidget(label,1+f,0);

        _Stamps[f] = new QLabel();
        _Stamps[f]->setText("");
        _Stamps[f]->setMinimumWidth(70);
        _Stamps[f]->setFrameStyle(QFrame::Sunken|QFrame::Box);
        ui->ValuesGrid->addWidget(_Stamps[f],1+f,1);
    }
/*
 *     QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::Ignored);
    ui->ValuesGrid->addItem(spacer,1+f,0);
*/


#define IDX_CON_NOERROR             0
#define IDX_CON_ERRORXXYY           1
#define IDX_CON_ERRORTIME           2

#define IDX_CON_OVR_COINCOFL        3
#define IDX_CON_OVR_PCIFIFOFULL     4
#define IDX_CON_OVR_TMPFIFOFULL     5

#define IDX_CON_ERRORUNKNOWN        6

    _Cursor = new QTextCursor( ui->Text->textCursor() );
    _Format = new QTextCharFormat();

    _Format->setFont( QFont( "Courier", 9 ) );

    ui->Progress->setRange(0,1);
    ui->Progress->setValue(0);

    _Updater = new UUpdater(this,ui,&_Mutex);
    _Updater->start();

    QTimer::singleShot(200,this,SLOT(OpenDataFile()));
}


void dlgdatafile::closeEvent(QCloseEvent *event)
{
    if (_Updater->isRunning()) _Updater->terminate();
    event->accept();
}



dlgdatafile::~dlgdatafile()
{
    CloseDataFile();
    delete ui;
}

void dlgdatafile::CloseDataFile()
{
    if (_DataFile.isOpen()) _DataFile.close();
}

void dlgdatafile::OpenDataFile()
{
    QSettings settings(_FileNameInfo, QSettings::IniFormat);
    QString ModType = CON_SETTINGSPREV+_Serial+"/";

    if (!FileExists(_FileNameInfo)) {
        QMessageBox::information(this, "Data settings file", "Data settings file doesn't exist !\nPlease set the Coincidence parameters.\n(Default values used.)", QMessageBox::Ok);
    }

    _Coinc_g0                   = settings.value(QString("%1Koinzidenz/coinc_g0").arg(ModType),50).toUInt();
    _Coinc_g1                   = settings.value(QString("%1Koinzidenz/coinc_g1").arg(ModType),250).toUInt();
    _Coinc_clen                 = settings.value(QString("%1Koinzidenz/coinc_clen").arg(ModType),1500).toUInt();
    _Coinc_Ch_devi              = settings.value(QString("%1Koinzidenz/coinc_ch_devi").arg(ModType),4).toUInt();
    _Coinc_Ch_repe              = settings.value(QString("%1Koinzidenz/coinc_ch_repe").arg(ModType),3).toUInt();

    _Coinc_Ena                  = settings.value(QString("%1Koinzidenz/coinc_ena").arg(ModType),1).toBool();
    _Coinc_Single               = settings.value(QString("%1Koinzidenz/Coinc_Single").arg(ModType),0).toBool();
    _Coinc_OnlyXY               = settings.value(QString("%1Koinzidenz/Coinc_OnlyXY").arg(ModType),0).toBool();
    _Coinc_Mark                 = settings.value(QString("%1Koinzidenz/Coinc_Mark").arg(ModType),0).toBool();

    ui->coinc_g0->setValue(_Coinc_g0);
    ui->coinc_g1->setValue(_Coinc_g1);
    ui->coinc_clen->setValue(_Coinc_clen);
    ui->coinc_ch_devi->setValue(_Coinc_Ch_devi);
    ui->coinc_ch_repe->setValue(_Coinc_Ch_repe);

    ui->coincEna->setChecked(_Coinc_Ena);
    ui->coincSingle->setChecked(_Coinc_Single);
    ui->coincOnlyXY->setChecked(_Coinc_OnlyXY);
    ui->coincMark->setChecked(_Coinc_Mark);

    _DataFile.setFileName(_FileName);
    if(!_DataFile.open(QIODevice::ReadOnly)) {
        QMessageBox::information(this, "Check Data File", "error opening file", QMessageBox::Ok);
        _Error = true;
        return;
    }
    _LastErrorLine  = 0;
    _Line           = 0;
    _Values         = 0;
    _DaqFifoFulls   = 0;
    _Unit1          = 0;
    _Unit2          = 0;
    _Channel1       = 0;
    _Channel2       = 0;
    _Time1          = 0;
    _Time2          = 0;
    _LastPos        = 0;
    _DataValues     = _DataFile.size()/sizeof(quint32);
    ui->ValuesInFile->setText(QString("%1").arg(_DataValues));


    ui->Progress->setRange(0,100);
    ui->Progress->setValue(0);
    _Intervall      = _DataValues/100;
}




void dlgdatafile::on_More_clicked()
{
    _Line = ShowData(_Line,_Line+DDF_DUMPBLOCKSIZE,0);
}


void dlgdatafile::on_ReadUntilError_clicked()
{
    ReadDataFileErrors();
}


bool dlgdatafile::ReadDataFileErrors()
{
    quint32 Unit            = 0;
    quint32 Channel         = 0;
    quint8  hbits           = 0;
    quint32 EventTime       = 0;

    quint32 ErrorLine       = 0;
    quint8  ErrorType       = 0;


    if (_Error) return false;

    _Cursor->movePosition(QTextCursor::End);

    if (!_DataFile.atEnd()) {

        ErrorLine       = 0;
        int i           = 0;
        int Progress    = 1;
        _DataFile.read((char *)data,DDF_BLOCKSIZE*sizeof(quint32));
//        qDebug(qPrintable(QString("Data 0: 0x%1  1: %2").arg(data[0],8,16,QChar('0')).arg(data[DDF_BLOCKSIZE-1],8,16,QChar('0'))));

        do {

            if ((_Line%_Intervall)==0) {
                _Mutex.lock();
                ui->Progress->setValue(Progress++);
                _Mutex.unlock();
            }


            hbits = (data[i] & 0xE0000000)>>29;
            if ((hbits&0x04)==0) {
                // normaler Datensatz
                Unit    = (data[i] & 0x70000000) >> 28;
                Channel = (data[i] & 0x0FC00000) >> 22;
                // Die Unitnummer unterscheidet zwischen x 0,1,2 und y 4,5,6
                // im Diagramm werden aber alle hintereinander ausgegeben, deshalb bei
                // Unitnummer >2 1 abziehen.
                // Unit 7 für Timestamps
                if (Unit==7) {
                    // Central Clock Eintrag
                    if (Channel<CC_MAX_COMMANDS) {
                        _Mutex.lock();
                        _Updater->_TimeStamps[Channel]++;
                        _Mutex.unlock();

//                        _Stamps[Channel]->setText(QString("%1").arg(_TimeStamps[Channel]));
                    }
                } else {
                    // Unit x oder Y
                    if (Unit>CON_MAX_CONFIG_X-1) Unit--;
                    EventTime = data[i] & 0x003FFFFF;

                    // XY Modus
                    if (_Coinc_OnlyXY) {
                        // Modi in denen nur die X/Y bzw. Y/X Paare gesendet werden.
                        if (_Values==0) { // erster Wert
                            _Unit1       = Unit;
                            _Channel1    = Channel;
                            _Time1       = EventTime;
                            _Values++;
                        } else { // zweiter Wert
                            _Unit2       = Unit;
                            _Channel2    = Channel;
                            _Time2       = EventTime;
                            if (((_Time2-_Time1)&0x003FFFFF)<=_Coinc_g0) {
                                // Zeitdifferenz ok
                                if (((_Unit1>2)&&(_Unit2>2))||((_Unit1<3)&&(_Unit2<3))) {
                                    // Error, darf nicht sein, 2 mal X oder 2 mal Y
                                    _Mutex.lock();
                                    _Updater->_ErrorXXYY++;
                                    _Mutex.unlock();
                                    ErrorLine = _Line;
                                    ErrorType = IDX_CON_ERRORXXYY;
                                } else {
                                    // Position ok, kein Fehler
                                }
                                _Values  = 0;
                            } else {
                                // Fehler Zeit zu groß
                                _Mutex.lock();
                                _Updater->_ErrorTimediff++;
                                _Mutex.unlock();
                                ErrorLine   = _Line;
                                ErrorType   = IDX_CON_ERRORTIME;
                                _Values     = 1;
                            }
                        }
                    }
                }
            } else {
                switch (hbits) {
                    case 0x04:  // Grobzeit
//                                _Values     = 0;
                                break;

                    case 0x07:  // Grobzeit vor Timestamp
                                break;

                    case 0x06:  // Overflow Statusregister
                                if (data[i]&CON_OVR_COINCOFL) {
                                    _Mutex.lock();
                                    _Updater->_CoincOfl++;
                                    _Mutex.unlock();
                                    ErrorLine = _Line;
                                    ErrorType = IDX_CON_OVR_COINCOFL;
                                }
                                if (data[i]&CON_OVR_PCIFIFOFULL) {
                                    _Mutex.lock();
                                    _Updater->_PciFifoFull++;
                                    _Mutex.unlock();
                                    ErrorLine = _Line;
                                    ErrorType = IDX_CON_OVR_PCIFIFOFULL;
                                }
                                if (data[i]&CON_OVR_TMPFIFOFULL) {
                                    _Mutex.lock();
                                    _Updater->_TmpFifoFull++;
                                    _Mutex.unlock();
                                    ErrorLine = _Line;
                                    ErrorType = IDX_CON_OVR_TMPFIFOFULL;
                                }
                                break;

                    default:    // unknown
                                ErrorLine = _Line;
                                ErrorType = IDX_CON_ERRORUNKNOWN;
                                break;
                }
            }

            if (ErrorLine>0) {
                _Mutex.lock();
                _Updater->_ErrorsFound++;
                _Mutex.unlock();

                quint32 line = 0;
                _LastPos = _DataFile.pos();
                if (ErrorLine<DDF_SEEKBACK+1) {
                    line       = 0;
                } else line = ErrorLine-DDF_SEEKBACK-1;

                if (_Line<_LastErrorLine) {
                    line = _LastErrorLine;
                    _LastErrorLine += DDF_SEEKBACK;
                } else _LastErrorLine = line+DDF_SEEKBACK+DDF_SEEKAFTER;
                // Anzeigen
                _Cursor->movePosition(QTextCursor::End);
//                qDebug(qPrintable(QString("ErrorLine: %1 Data: 0x%2 Error: %3").arg(ErrorLine).arg(data[i],8,16,QChar('0')).arg(_ErrorTypeTxt.at(ErrorType))));
                _Mutex.lock();
                TxtWhBk(QString("---- Error [#%1] (%2) at line %3 -----------------------------------------------------------\n").arg(_Updater->_ErrorsFound).arg(_ErrorTypeTxt.at(ErrorType)).arg(ErrorLine));
                _Mutex.unlock();
                ShowData(line,_LastErrorLine,ErrorLine);
                _DataFile.seek(_LastPos);
                ErrorLine = 0;
//                return true;
            }
            _Line++;
            i++;
            if (i>=DDF_BLOCKSIZE) {
                i = 0;
                if (_DataFile.atEnd()) return true;
                _DataFile.read((char *)data,DDF_BLOCKSIZE*sizeof(quint32));
//                qDebug(qPrintable(QString("Data 0: 0x%1  1: %2").arg(data[0],8,16,QChar('0')).arg(data[DDF_BLOCKSIZE-1],8,16,QChar('0'))));
            }

//    if (_ErrorsFound>3) return true;
            if (_Line>=_DataValues) {
                ui->Progress->setValue(100);
                return true;
            }
        } while (1);


    } else QMessageBox::information(this, "Check Data File", "No more data in file !", QMessageBox::Ok);

    return false;
}

quint32 dlgdatafile::ShowData(quint32 start, quint32 end, quint32 ErrorLine)
{
    quint32 Unit            = 0;
    quint32 Channel         = 0;
    quint8  hbits           = 0;
    quint32 EventTime       = 0;

    quint32 line            = 0;
    quint32 data[DDF_BLOCKSIZE];
    quint8  Values          = 0;
    bool    GrobzeitVh      = false;

    if (_Error) return false;

    _Cursor->movePosition(QTextCursor::End);

    if (!_DataFile.atEnd()) {

        int i = 0;

        line = start;
        _DataFile.seek(start*sizeof(quint32));

        _DataFile.read((char *)data,DDF_BLOCKSIZE*sizeof(quint32));

        do {

            hbits = (data[i] & 0xE0000000)>>29;
            if ((hbits&0x04)==0) {
                // normaler Datensatz
                Unit    = (data[i] & 0x70000000) >> 28;
                Channel = (data[i] & 0x0FC00000) >> 22;
                // Die Unitnummer unterscheidet zwischen x 0,1,2 und y 4,5,6
                // im Diagramm werden aber alle hintereinander ausgegeben, deshalb bei
                // Unitnummer >2 1 abziehen.
                // Unit 7 für Timestamps
                if (Unit==7) {
                    LineNo(line,GrobzeitVh,data[i]);
                    // Timestamp Funktion
                    TxtWhRe(QString("CC Funktion %1\n").arg(Channel,Channel));
                    _Cursor->movePosition(QTextCursor::End);
                    ui->Text->ensureCursorVisible();
                } else {
                    // Unit x oder Y
                    if (Unit>CON_MAX_CONFIG_X-1) Unit--;
                    EventTime = data[i] & 0x003FFFFF;

                    // XY Modus
                    if (_Coinc_OnlyXY) {
                        // Modi in denen nur die X/Y bzw. Y/X Paare gesendet werden.
                        if (Values==0) { // erster Wert
                            _Unit1       = Unit;
                            _Channel1    = Channel;
                            _Time1       = EventTime;
                            Values++;

                            LineNo(line,GrobzeitVh,data[i]);
                            if (Unit>2)
                                    TxtWhBk(QString("Y: %1 \n").arg((Unit-3)*MAROC_MAXMAROCCHANNELS+Channel,3));
                            else    TxtWhBk(QString("X: %1 \n").arg(Unit*MAROC_MAXMAROCCHANNELS+Channel,3));
                            _Cursor->movePosition(QTextCursor::End);
                            ui->Text->ensureCursorVisible();
                        } else { // zweiter Wert
                            _Unit2       = Unit;
                            _Channel2    = Channel;
                            _Time2       = EventTime;
                            if (((_Time2-_Time1)&0x003FFFFF)<=_Coinc_g0) {
                                // Zeitdifferenz ok
                                if (((_Unit1>2)&&(_Unit2>2))||((_Unit1<3)&&(_Unit2<3))) {
                                    // Error, darf nicht sein, 2 mal X oder 2 mal Y
                                    if (line>=ErrorLine) {
                                        if (_Unit1>2) { // Der erste war ein Y
                                            TxtReWh(QString("%1:   0x%2 - Y: %3 -> Error: Y Y [%4] [%5]\n").arg(line,12).arg(data[i],8,16,QChar('0')).arg((_Unit2-3)*MAROC_MAXMAROCCHANNELS+_Channel2,3).arg(_Unit1).arg(_Unit2));
                                        } else {
                                            TxtReWh(QString("%1:   0x%2 - X: %3 -> Error: X X [%4] [%5]\n").arg(line,12).arg(data[i],8,16,QChar('0')).arg(_Unit2*MAROC_MAXMAROCCHANNELS+_Channel2,3).arg(_Unit1).arg(_Unit2));
                                        }
                                        _Cursor->movePosition(QTextCursor::End);
                                        ui->Text->ensureCursorVisible();
                                    }
                                } else {
                                    // Position ok
                                    LineNo(line,GrobzeitVh,data[i]);
                                    if (_Unit1>2) { // Der erste war ein Y
                                        TxtWhBk(QString("X: %1 -> X: %2, Y: %3\n").arg(_Unit2*MAROC_MAXMAROCCHANNELS+_Channel2,3).arg(_Unit2*MAROC_MAXMAROCCHANNELS+_Channel2,3).arg((_Unit1-3)*MAROC_MAXMAROCCHANNELS+_Channel1,3));
                                    } else { // Der erste war ein X
                                        TxtWhBk(QString("Y: %1 -> X: %2, Y: %3\n").arg((_Unit2-3)*MAROC_MAXMAROCCHANNELS+_Channel2,3).arg(_Unit1*MAROC_MAXMAROCCHANNELS+_Channel1,3).arg((_Unit2-3)*MAROC_MAXMAROCCHANNELS+_Channel2,3));
                                    }
                                    _Cursor->movePosition(QTextCursor::End);
                                    ui->Text->ensureCursorVisible();
                                }
                                Values  = 0;
                            } else {
                                // Fehler Zeit zu groß
                                if (line>=ErrorLine) {
                                    TxtReWh( QString("%1:   0x%2 - Error: Timediff [%3] (Max: %4)\n").arg(line,12).arg(data[i],8,16,QChar('0')).arg((quint32)((_Time2-_Time1)&0x003FFFFF),10).arg(_Coinc_g0));
                                    _Cursor->movePosition(QTextCursor::End);
                                    ui->Text->ensureCursorVisible();
                                }
                                Values  = 1;
                            }
                        }
                    }
                }
            } else {
                switch (hbits) {
                    case 0x04:  // Grobzeit
                                GrobzeitVh  = true;
                                LineNo(line,GrobzeitVh,data[i]);
                                TxtWhBk_B( QString("GT [0x%1]\n").arg(data[i]&0x0003FFFF,8,16,QChar('0')));
//                                Values = 0;
                                _Cursor->movePosition(QTextCursor::End);
                                ui->Text->ensureCursorVisible();
                                break;

                    case 0x07:  // Grobzeit vor Timestamp
                                LineNo(line,GrobzeitVh,data[i]);
                                TxtBlYe( QString("CC-TS [0x%1]\n").arg(data[i]&0x0003FFFF,8,16,QChar('0')));
                                _Cursor->movePosition(QTextCursor::End);
                                ui->Text->ensureCursorVisible();
                                break;

                    case 0x06:  // Overflow Statusregister
                                LineNo(line,GrobzeitVh,data[i]);
                                TxtYeBk( QString("OVR [0x%1]").arg(data[i],8,16,QChar('0')));
                                if (data[i]&CON_OVR_COINCOFL) {
                                    TxtYeBk( QString(" - %1").arg(_ErrorTypeTxt.at(IDX_CON_OVR_COINCOFL)));
                                }
                                if (data[i]&CON_OVR_PCIFIFOFULL) {
                                    TxtReWh( QString(" - %1").arg(_ErrorTypeTxt.at(IDX_CON_OVR_PCIFIFOFULL)));
                                    TxtReWh( QString(" <<<< !!!!!!!!"));
                                }
                                if (data[i]&CON_OVR_TMPFIFOFULL) {
                                    TxtYeBk( QString(" - %1").arg(_ErrorTypeTxt.at(IDX_CON_OVR_TMPFIFOFULL)));
                                }
                                _Cursor->insertText("\n");
                                _Cursor->movePosition(QTextCursor::End);
                                ui->Text->ensureCursorVisible();
                                break;

                    default:    // unknown
                                LineNo(line,GrobzeitVh,data[i]);
                                TxtWhRe("Unknown Error\n");
                                _Cursor->movePosition(QTextCursor::End);
                                ui->Text->ensureCursorVisible();
                                break;
                }
            }

            i++;
            line++;

            if (line>end) return line;
            if (line>=_DataValues) return line;
        } while (1);


    } else QMessageBox::information(this, "Check Data File", "No more data in file !", QMessageBox::Ok);

    return line;
}

void dlgdatafile::LineNo(quint32 line, bool grobvh, quint32 data)
{
    TxtWhBk(QString("%1: %2 0x%3 - ").arg(line,12).arg(grobvh?" ":"*").arg(data,8,16,QChar('0')));
}


void dlgdatafile::TxtWhBk(QString txt) {
    _Cursor->movePosition(QTextCursor::End);
    _Format->setFontWeight( QFont::Normal );
    _Format->setBackground( QBrush( QColor( "white" ) ) );
    _Format->setForeground( QBrush( QColor( "black" ) ) );
    _Cursor->setCharFormat( *_Format );
    _Cursor->insertText(txt);
}

void dlgdatafile::TxtWhBk_B(QString txt) {
    _Cursor->movePosition(QTextCursor::End);
    _Format->setFontWeight( QFont::Bold );
    _Format->setBackground( QBrush( QColor( "white" ) ) );
    _Format->setForeground( QBrush( QColor( "black" ) ) );
    _Cursor->setCharFormat( *_Format );
    _Cursor->insertText(txt);
}

void dlgdatafile::TxtReWh(QString txt) {
    _Cursor->movePosition(QTextCursor::End);
    _Format->setFontWeight( QFont::Normal );
    _Format->setBackground( QBrush( QColor( "red" ) ) );
    _Format->setForeground( QBrush( QColor( "white" ) ) );
    _Cursor->setCharFormat( *_Format );
    _Cursor->insertText(txt);
}

void dlgdatafile::TxtWhRe(QString txt) {
    _Cursor->movePosition(QTextCursor::End);
    _Format->setFontWeight( QFont::Normal );
    _Format->setBackground( QBrush( QColor( "white" ) ) );
    _Format->setForeground( QBrush( QColor( "red" ) ) );
    _Cursor->setCharFormat( *_Format );
    _Cursor->insertText(txt);
}

void dlgdatafile::TxtBlYe(QString txt) {
    _Cursor->movePosition(QTextCursor::End);
    _Format->setFontWeight( QFont::Normal );
    _Format->setBackground( QBrush( QColor( "blue" ) ) );
    _Format->setForeground( QBrush( QColor( "Yellow" ) ) );
    _Cursor->setCharFormat( *_Format );
    _Cursor->insertText(txt);
}

void dlgdatafile::TxtYeBk(QString txt) {
    _Cursor->movePosition(QTextCursor::End);
    _Format->setFontWeight( QFont::Normal );
    _Format->setBackground( QBrush( QColor( "Yellow" ) ) );
    _Format->setForeground( QBrush( QColor( "black" ) ) );
    _Cursor->setCharFormat( *_Format );
    _Cursor->insertText(txt);
}






void dlgdatafile::on_coinc_g0_editingFinished()
{
    _Coinc_g0 = ui->coinc_g0->value();
}

void dlgdatafile::on_coinc_g1_editingFinished()
{
    _Coinc_g1 = ui->coinc_g1->value();
}

void dlgdatafile::on_coinc_clen_editingFinished()
{
    _Coinc_clen = ui->coinc_clen->value();
}

void dlgdatafile::on_coinc_ch_devi_editingFinished()
{
    _Coinc_Ch_devi = ui->coinc_ch_devi->value();
}

void dlgdatafile::on_coinc_ch_repe_editingFinished()
{
    _Coinc_Ch_repe = ui->coinc_ch_repe->value();
}

void dlgdatafile::on_coincMark_stateChanged(int arg1)
{
    _Coinc_Mark = arg1==Qt::Checked;
}

void dlgdatafile::on_coincOnlyXY_stateChanged(int arg1)
{
    _Coinc_OnlyXY = arg1==Qt::Checked;
}

void dlgdatafile::on_coincSingle_stateChanged(int arg1)
{
    _Coinc_Single = arg1==Qt::Checked;
}

void dlgdatafile::on_coincEna_stateChanged(int arg1)
{
    _Coinc_Ena = arg1==Qt::Checked;
}




UUpdater::UUpdater(QObject *parent, Ui::dlgdatafile *ui, QMutex *mutex) :
    QThread(parent)
{
    _Mutex      = mutex;
    _ParentUi   = (Ui::dlgdatafile*)ui;
    _Parent     = (dlgdatafile*)parent;
    for (int f=0; f<CC_MAX_COMMANDS; f++) {
        _TimeStamps[f] = 0;
    }
    _ErrorsFound    = 0;
    _TmpFifoFull    = 0;
    _PciFifoFull    = 0;
    _CoincOfl       = 0;
    _ErrorXXYY      = 0;
    _ErrorTimediff  = 0;
}


void UUpdater::run()
{
    forever {
        msleep(200);
        _Mutex->lock();
        _ParentUi->ErrorsFound->setText(QString("%1").arg(_ErrorsFound));
        _ParentUi->TempFifoFull->setText(QString("%1").arg(_TmpFifoFull));
        _ParentUi->PciFifoFull->setText(QString("%1").arg(_PciFifoFull));
        _ParentUi->CoincOfl->setText(QString("%1").arg(_CoincOfl));

        _ParentUi->ErrorXXYY->setText(QString("%1").arg(_ErrorXXYY));
        _ParentUi->ErrorTimediff->setText(QString("%1").arg(_ErrorTimediff));

        for (int i=0; i<CC_MAX_COMMANDS; i++)
            _Parent->_Stamps[i]->setText(QString("%1").arg(_TimeStamps[i]));
        emit Update();
        _Mutex->unlock();
    }
}