Lots more comments in sniffer code, a few fixes in sniffer code too.

This commit is contained in:
Collin Kidder
2018-10-21 19:55:22 -04:00
parent 2df7a2a9fc
commit c427115d7c
2 changed files with 33 additions and 8 deletions
+32 -7
View File
@@ -30,18 +30,37 @@ float SnifferItem::getDelta() const
return ((float)(mCurrentTime-mLastTime))/1000000;
}
//Get a data byte by index 0-7 (but not more than the length of the actual frame)
int SnifferItem::getData(uchar i) const
{
return (i>=mCurrent.len) ? -1 : ((uchar*) &mCurrent.data)[i];
return (i >= mCurrent.len) ? -1 : ((uchar*) &mCurrent.data)[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
// then checks whether lastMarker shows that some bits have changed in the previous 200ms cycle
// then we check if the byte in mNotch has bits set and if it does we say nothing changed (notched out)
dc SnifferItem::dataChange(uchar i) const
{
if( i<mCurrent.len &&
((uchar*) &mLastMarker.data)[i] &&
!((uchar*) &mNotch)[i] )
if (i >= mCurrent.len) return dc::NO;
uchar notch = ((uchar*) &mNotch)[i];
uchar byt = ((uchar*) &mCurrent.data)[i];
uchar last = ((uchar*) &mLast.data)[i];
uchar lastMark = ((uchar*) &mLastMarker.data)[i];
if( lastMark )
{
return ((uchar*) &mCurrent.data)[i] >= ((uchar*) &mLast.data)[i] ? dc::INC : dc::DEINC;
if (!notch) //if no notching is set
return (byt >= last ? dc::INC : dc::DEINC);
else //mNotch contained a bit pattern so use masks and do things more complicated
{
byt &= ~notch; //mask off bits that were notched
if (byt == 0) return dc::NO; //and if result is null then nothing changed (other than maybe notched bits and they don't count)
last &= ~notch; //need to mask last too
if (last == byt) return dc::NO;
return (byt >= last ? dc::INC : dc::DEINC); //then compare the masked copies to see which way the bit(s) went
}
}
return dc::NO;
@@ -52,6 +71,7 @@ int SnifferItem::elapsed() const
return mTime.elapsed();
}
//called when a new frame comes in that matches our same ID
void SnifferItem::update(const CANFrame& pFrame)
{
/* copy current to last */
@@ -64,23 +84,28 @@ void SnifferItem::update(const CANFrame& pFrame)
mCurrentTime = pFrame.timestamp;
/* update marker */
mMarker.data |= mLast.data ^ mCurrent.data;
//We "OR" our stored marker with the changed bits.
//this accumulates changed bits into the marker
mMarker.data |= mLast.data ^ mCurrent.data; //XOR causes only changed bits to be 1's
mMarker.len |= mLast.len ^ mCurrent.len;
/* restart timeout */
mTime.restart();
}
//Called in refresh from the model. Interval about 200ms currently.
//So, this means the marker only accumulates for 200ms then resets
void SnifferItem::updateMarker()
{
mLastMarker = mMarker;
mMarker = {0, 0};
}
//Notch or un-notch this snifferitem / frame
void SnifferItem::notch(bool pNotch)
{
if(pNotch)
mNotch |= mLastMarker.data;
mNotch |= mLastMarker.data; //add changed bits to notch value
else
mNotch = 0;
}
+1 -1
View File
@@ -154,7 +154,7 @@ void SnifferModel::clear()
endResetModel();
}
//Called from window with a timer (currently 200ms)
void SnifferModel::refresh()
{
QMap<quint32, SnifferItem*>::iterator i;