void AliveCollection_c::report( std::ostream& out ) const { for (int i=0; i<256; i++) { for (Category_e categoryIter = categoryBegin; categoryIter != categoryEnd; categoryIter = nextCategory(categoryIter)) { const int32_t ci32_alivePeriod = alivePeriod(categoryIter); if (alives(categoryIter, static_cast<uint8_t>( i )).size()>0) { if (ci32_alivePeriod > 0) { // we have a periodic event! out << std::endl << "ISOBUS node with SA="<<std::hex<<i<<std::dec<<" had the following alive-times for ["<<name(categoryIter)<<"] with alive-periods of "<<alivePeriod(categoryIter)<<" ms:"<<std::endl; } else if (ci32_alivePeriod < 0) { // we have a handshaking event! out << std::endl << "ISOBUS node with SA="<<std::hex<<i<<std::dec<<" had the following alive-times for ["<<name(categoryIter)<<"] with alive-periods of "<<(-alivePeriod(categoryIter))<<" ms:"<<std::endl; } else { // single events!! "== 0" out << std::endl << "ISOBUS node with SA="<<std::hex<<i<<std::dec<<" sent out ["<<name(categoryIter)<<"] at the following times:"<<std::endl; } std::vector<std::pair<msgType_e,std::string> >::const_iterator type_iter=response(categoryIter, static_cast<uint8_t>( i ) ).begin(); for (std::vector<uint64_t>::const_iterator iter=alives(categoryIter, static_cast<uint8_t>( i )).begin(); iter != alives(categoryIter, static_cast<uint8_t>( i )).end(); iter++) { out << std::setfill (' '); out << "absolute time: "<<std::setw(10)<<(*iter/1000)<<"."<<std::setw(3)<<std::setfill('0')<<(*iter%1000)<<std::setfill(' '); if (iter != alives(categoryIter, static_cast<uint8_t>( i )).begin()) { const uint64_t cui32_delta = ( *(iter) - *(iter-1) ); out<< " relative time: "<<std::setw(10)<<cui32_delta; if (ci32_alivePeriod > 0) { // print out the alivePeriod-deviation! out<<" deviation: "; int deviation = int ((double (int32_t (cui32_delta)-ci32_alivePeriod) / ci32_alivePeriod) * 100); uint8_t deviation_bias = (deviation > 0) ? '+' : '-'; deviation = (deviation < 0) ? -deviation : deviation; if (deviation > 100) { out << "EXTREME DEVIATION(!!) OF " << std::setw(10) << deviation << "0"; } else { while (deviation > 10) { out << deviation_bias; deviation -= 10; } } } else if (ci32_alivePeriod < 0) { // Handshaking if (type_iter == response(categoryIter,static_cast<uint8_t>( i )).end()) exit_with_error("No direction/msgType set but is expected. System failure."); int32_t i32_alivePeriodSpecial; switch ((*type_iter).first) { case msgTypeResponse: out << " Response "; i32_alivePeriodSpecial = -ci32_alivePeriod; break; case msgTypeCommand: out << " Command "; i32_alivePeriodSpecial = 0; break; // no timing-requirement here! case msgTypeRTS: out << " (E)TP-CONN: Request to Send (RTS) "; i32_alivePeriodSpecial = 0; break; // no timing-requirement here! case msgTypeCTS: out << " (E)TP-CONN: Clear to Send (CTS) "; i32_alivePeriodSpecial = 1250; break; case msgTypeDPO: out << " (E)TP-CONN: Data Packet Offset (DPO) "; i32_alivePeriodSpecial = 1250; break; /// @todo SOON-260: set the correct values here! case msgTypeEOMACK: out << " (E)TP-CONN: End of Message ACK (EoMACK) "; i32_alivePeriodSpecial = 1250; break; case msgTypeDATA: out << " (E)TP-DATA "; i32_alivePeriodSpecial = 250; break; case msgTypeCONNABORT: out << " (E)TP-CONN: Connection Abort (CONNABORT) "; i32_alivePeriodSpecial = -1; break; // doesn't come normally! case msgTypeSetpoint: out << " (TC->Client) Setpoint "; i32_alivePeriodSpecial = 0; break; case msgTypeMeasurement:out << " (Client->TC) Measrmnt "; i32_alivePeriodSpecial = 0; break; default: out << " ??? "; i32_alivePeriodSpecial = 0; break; } if ( ((*type_iter).first == msgTypeResponse) && ((*(type_iter-1)).first == msgTypeResponse) ) out << " - RESPONSE FOLLOWING A RESPONSE! (check if there was a TP command though)"; if ( ((*type_iter).first == msgTypeCommand) && ((*(type_iter-1)).first == msgTypeCommand) ) out << " - COMMAND FOLLOWING A COMMAND! (check if there was a TP response though)"; if (i32_alivePeriodSpecial > 0) { // print out the time it took! if (cui32_delta > (unsigned int) (i32_alivePeriodSpecial)) out << " *** !!! TIMEOUT - Check relative time!!!! ***"; else { int32_t time = int32_t ((cui32_delta*100) / i32_alivePeriodSpecial); out <<std::setw(2)<<time<< " percent of timeout ("<<std::setw(4)<<i32_alivePeriodSpecial<<"): (one '%' shows 10%) "; while (time > 10) { out << "%"; time -= 10; } } } else if (i32_alivePeriodSpecial < 0) { // unsolicited messages (like CONNABORT) out << "*** UNEXPECTED/UNSOLICITED MESSAGE ***"; } out << (*type_iter).second; } } out << std::endl; if (type_iter != response(categoryIter, static_cast<uint8_t>( i )).end()) ++type_iter; } } } } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { // open database connection db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("/Users/jdoud/dev/brainstorm.sqlite"); if(!db.open()) { qDebug() << db.lastError(); qFatal("Failed to connect."); } // setup UI ui->setupUi(this); ui->toolBar->addWidget(ui->comboFonts); ui->toolBar->addWidget(ui->comboFontSizes); ui->toolBar->addWidget(ui->comboColors); // set text editor defaults ui->textNote->document()->setIndentWidth(20); ui->textNote->setTabStopWidth(20); ui->textNote->setTabChangesFocus(false); ui->actionIncrease_Indent->setShortcut(Qt::Key_Tab); ui->actionDecrease_Indent->setShortcut(Qt::Key_Backtab); // setup comboColors QPixmap pix(16, 16); pix.fill(Qt::white); ui->comboColors->addItem(pix, ""); pix.fill(Qt::black); ui->comboColors->addItem(pix, ""); pix.fill(Qt::red); ui->comboColors->addItem(pix, ""); pix.fill(Qt::blue); ui->comboColors->addItem(pix, ""); pix.fill(Qt::darkGreen); ui->comboColors->addItem(pix, ""); pix.fill(Qt::gray); ui->comboColors->addItem(pix, ""); // create system tray icon createActions(); createTrayIcon(); // create models categoriesModel = new QSqlTableModel(); categoriesModel->setTable("categories"); categoriesModel->setSort(1, Qt::AscendingOrder); categoriesModel->select(); ui->listCategories->setModel(categoriesModel); ui->listCategories->setModelColumn(1); notesModel = new QSqlTableModel(); notesModel->setTable("notes"); ui->listNotes->setModel(notesModel); ui->listNotes->setModelColumn(2); // set splitter size QList<int> sizes; sizes << 230 << 150; ui->splitterLists->setSizes(sizes); sizes.clear(); sizes << 230 << 600; ui->splitterNote->setSizes(sizes); // connect File menu slots connect(ui->actionNew_Category, SIGNAL(triggered()), this, SLOT(newCategory())); connect(ui->actionRename_Category, SIGNAL(triggered()), this, SLOT(renameCategory())); connect(ui->actionDelete_Category, SIGNAL(triggered()), this, SLOT(deleteCategory())); connect(ui->actionNew_Note, SIGNAL(triggered()), this, SLOT(newNote())); connect(ui->actionRename_Note, SIGNAL(triggered()), this, SLOT(renameNote())); connect(ui->actionSave_Note, SIGNAL(triggered()), this, SLOT(saveNote())); connect(ui->actionDelete_Note, SIGNAL(triggered()), this, SLOT(deleteNote())); connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(quit())); // connect Edit menu slots connect(ui->actionFind_Replace, SIGNAL(triggered()), this, SLOT(findAndReplace())); // connect Format menu slots connect(ui->actionBold, SIGNAL(triggered()), this, SLOT(bold())); connect(ui->actionItalic, SIGNAL(triggered()), this, SLOT(italic())); connect(ui->actionUnderline, SIGNAL(triggered()), this, SLOT(underline())); connect(ui->actionStrikethrough, SIGNAL(triggered()), this, SLOT(strikethrough())); connect(ui->actionBullet_List, SIGNAL(triggered()), this, SLOT(bulletList())); connect(ui->actionNumber_List, SIGNAL(triggered()), this, SLOT(numberList())); connect(ui->actionIncrease_Indent, SIGNAL(triggered()), this, SLOT(increaseIndent())); connect(ui->actionDecrease_Indent, SIGNAL(triggered()), this, SLOT(decreaseIndent())); connect(ui->actionShow_Colors, SIGNAL(triggered()), this, SLOT(showColors())); connect(ui->actionShow_Fonts, SIGNAL(triggered()), this, SLOT(showFonts())); connect(ui->actionIncrease_Font, SIGNAL(triggered()), this, SLOT(increaseFont())); connect(ui->actionDecrease_Font, SIGNAL(triggered()), this, SLOT(decreaseFont())); connect(ui->actionReset_Font, SIGNAL(triggered()), this, SLOT(resetFont())); connect(ui->actionAlign_Left, SIGNAL(triggered()), this, SLOT(alignLeft())); connect(ui->actionAlign_Center, SIGNAL(triggered()), this, SLOT(alignCenter())); connect(ui->actionAlign_Right, SIGNAL(triggered()), this, SLOT(alignRight())); connect(ui->actionAlign_Justify, SIGNAL(triggered()), this, SLOT(alignJustify())); // connect View menu slots connect(ui->actionHide_Window, SIGNAL(triggered()), this, SLOT(hide())); connect(ui->actionPrevious_Category, SIGNAL(triggered()), this, SLOT(previousCategory())); connect(ui->actionNext_Category, SIGNAL(triggered()), this, SLOT(nextCategory())); connect(ui->actionPrevious_Note, SIGNAL(triggered()), this, SLOT(previousNote())); connect(ui->actionNext_Note, SIGNAL(triggered()), this, SLOT(nextNote())); // connect Help menu slots connect(ui->actionAbout_Brainstorm, SIGNAL(triggered()), this, SLOT(aboutBrainstorm())); connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt())); // connect application slots connect(ui->textNote, SIGNAL(cursorPositionChanged()), this, SLOT(updateMenus())); connect(ui->textNote, SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(updateMenus())); connect(ui->comboFonts, SIGNAL(activated(QString)), this, SLOT(setFont(QString))); connect(ui->comboFontSizes, SIGNAL(activated(QString)), this, SLOT(setFontSize(QString))); connect(ui->comboColors, SIGNAL(activated(int)), this, SLOT(setFontColor(int))); // connect category list slots connect(ui->listCategories->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(updateNoteList(QModelIndex))); // connect note list slots connect(ui->listNotes->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(updateNoteText(QModelIndex))); // connect text slots ui->textNote->installEventFilter((this)); // connect system tray icon connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); // initialize default data ui->listCategories->selectionModel()->setCurrentIndex(categoriesModel->index(0, 1), QItemSelectionModel::SelectCurrent); }