From a138968e8537b0326c8b5aba9d813cfb0de72bcc Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 30 Dec 2018 20:10:12 -0500 Subject: [PATCH] Additional work on new sniffer bitfield view. --- re/sniffer/SnifferDelegate.cpp | 53 +++++++++++++++++++++++++++------- re/sniffer/SnifferDelegate.h | 2 +- re/sniffer/snifferitem.cpp | 16 ++++++++++ re/sniffer/snifferitem.h | 4 +++ re/sniffer/sniffermodel.cpp | 2 +- 5 files changed, 64 insertions(+), 13 deletions(-) diff --git a/re/sniffer/SnifferDelegate.cpp b/re/sniffer/SnifferDelegate.cpp index 77dcd6b..18da5c7 100644 --- a/re/sniffer/SnifferDelegate.cpp +++ b/re/sniffer/SnifferDelegate.cpp @@ -8,9 +8,9 @@ SnifferDelegate::SnifferDelegate(QWidget *parent) : QItemDelegate(parent) { blackBrush = QBrush(Qt::black); whiteBrush = QBrush(Qt::white); - //redBrush = QBrush(Qt::red); - //greenBrush = QBrush(Qt::green); - //grayBrush = QBrush(QColor(230,230,230)); + redBrush = QBrush(Qt::red); + greenBrush = QBrush(Qt::green); + grayBrush = QBrush(QColor(230,230,230)); mainFont.setPointSize(10); mainFontInfo = new QFontInfo(mainFont); } @@ -29,7 +29,11 @@ void SnifferDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio int x, y; SnifferItem *item = static_cast(index.internalPointer()); - int val = item->getData(index.column() - 2); + int idx = index.column() - 2; + int val = item->getData(idx); + int prevVal = item->getLastData(idx); + int notchPattern = item->getNotchPattern(idx); + int maskPattern; if (val < 0) return; QRect viewport = option.rect; @@ -40,23 +44,50 @@ void SnifferDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio //qDebug() << "XSpan" << xSpan << " YSpan " << ySpan; int xSector = xSpan / 8; - - painter->setPen(QPen(Qt::black)); - painter->setFont(mainFont); + int v = item->getSeqInterval(index.column() - 2) * 10; + if (v > 225) v = 225; + if (v < 0) v = 0; for (x = 0; x < 8; x++) { - if (val & (1 << x)) + maskPattern = 1 << (7-x); + //We look to see if each bit has changed since the last update or not. If not we + //straight draw it black if set or white if unset. If it changed then draw it green if it is newly set + //and red if newly unset + //But also, if a bit is notched we just plain draw it gray no matter what it's doing + if (notchPattern & maskPattern) { - painter->setBrush(blackBrush); + painter->setBrush(grayBrush); } - else + else if ( (val & maskPattern) == (prevVal & maskPattern) ) //wasn't notched so has it changed? No? Then... { - painter->setBrush(whiteBrush); + if (val & maskPattern) + { + painter->setBrush(blackBrush); + } + else + { + painter->setBrush(whiteBrush); + } } + else //wasn't notched and did change since last time. + { + if (val & maskPattern) + { + painter->setBrush(greenBrush); + } + else + { + painter->setBrush(redBrush); + } + } + painter->setOpacity((255 - v) / 255.0); painter->drawRect(viewport.left() + x * xSector, viewport.top(), xSector, xSector); } + //painter->setPen(QPen(QColor(v,v,v,255))); + painter->setPen(Qt::black); + painter->setFont(mainFont); painter->drawText(QRect(viewport.left(), viewport.top() + xSector, xSpan, mainFontInfo->pixelSize()), Qt::AlignCenter, Utility::formatNumber(val)); } diff --git a/re/sniffer/SnifferDelegate.h b/re/sniffer/SnifferDelegate.h index e808ac3..fcae02c 100644 --- a/re/sniffer/SnifferDelegate.h +++ b/re/sniffer/SnifferDelegate.h @@ -16,7 +16,7 @@ signals: public slots: private: - QBrush blackBrush, whiteBrush;//, redBrush, greenBrush, grayBrush; + QBrush blackBrush, whiteBrush, redBrush, greenBrush, grayBrush; QFont mainFont; QFontInfo* mainFontInfo; }; diff --git a/re/sniffer/snifferitem.cpp b/re/sniffer/snifferitem.cpp index 2f5f1a9..b86462b 100644 --- a/re/sniffer/snifferitem.cpp +++ b/re/sniffer/snifferitem.cpp @@ -42,11 +42,26 @@ int SnifferItem::getData(uchar i) const return (i >= mCurrent.len) ? -1 : mCurrent.data[i]; } +quint8 SnifferItem::getNotchPattern(uchar i) const +{ + return (i >= mCurrent.len) ? -1 : mNotch[i]; +} + +quint8 SnifferItem::getLastData(uchar i) const +{ + return (i >= mLast.len) ? -1 : mLast.data[i]; +} + quint32 SnifferItem::getDataTimestamp(uchar i) const { return (i >= mCurrent.len) ? 0 : mCurrent.dataTimestamp[i]; } +quint32 SnifferItem::getSeqInterval(uchar i) const +{ + return mCurrSeqVal - getDataTimestamp(i); +} + //Return whether a given data byte (by index 0-7) has incremented, deincremented, or stayed the same //since the last message //The If checks first that we aren't past the actual data length @@ -95,6 +110,7 @@ void SnifferItem::update(const CANFrame& pFrame, quint32 timeSeq, bool mute) /* copy current to last */ mLast = mCurrent; mLastTime = mCurrentTime; + mCurrSeqVal = timeSeq; /* copy new value */ for (int i = 0; i < 8; i++) diff --git a/re/sniffer/snifferitem.h b/re/sniffer/snifferitem.h index b5961c9..0995a10 100644 --- a/re/sniffer/snifferitem.h +++ b/re/sniffer/snifferitem.h @@ -29,7 +29,10 @@ public: quint64 getId() const; float getDelta() const; int getData(uchar i) const; + quint8 getNotchPattern(uchar i) const; + quint8 getLastData(uchar i) const; quint32 getDataTimestamp(uchar i) const; + quint32 getSeqInterval(uchar i) const; dc dataChange(uchar) const; int elapsed() const; void update(const CANFrame& pFrame, quint32 timeSeq, bool mute); @@ -45,6 +48,7 @@ private: quint8 mNotch[8]; quint64 mLastTime; quint64 mCurrentTime; + quint64 mCurrSeqVal; QTime mTime; }; diff --git a/re/sniffer/sniffermodel.cpp b/re/sniffer/sniffermodel.cpp index cffd8bf..c55163c 100644 --- a/re/sniffer/sniffermodel.cpp +++ b/re/sniffer/sniffermodel.cpp @@ -70,7 +70,7 @@ QVariant SnifferModel::data(const QModelIndex &index, int role) const case Qt::ForegroundRole: { if (!mFadeInactive || col < 2) return QBrush(Qt::black); - int v = (mTimeSequence - item->getDataTimestamp(col - 2)) * 10; + int v = item->getSeqInterval(col - 2) * 10; //qDebug() << "mTS: " << mTimeSequence << " gDT(" << (col - 2) << ") " << item->getDataTimestamp(col - 2); if (v > 225) v = 225; if (v < 0) v = 0;