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; 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 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 dc SnifferItem::dataChange(uchar i) const
{ {
if( i<mCurrent.len && if (i >= mCurrent.len) return dc::NO;
((uchar*) &mLastMarker.data)[i] &&
!((uchar*) &mNotch)[i] ) 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; return dc::NO;
@@ -52,6 +71,7 @@ int SnifferItem::elapsed() const
return mTime.elapsed(); return mTime.elapsed();
} }
//called when a new frame comes in that matches our same ID
void SnifferItem::update(const CANFrame& pFrame) void SnifferItem::update(const CANFrame& pFrame)
{ {
/* copy current to last */ /* copy current to last */
@@ -64,23 +84,28 @@ void SnifferItem::update(const CANFrame& pFrame)
mCurrentTime = pFrame.timestamp; mCurrentTime = pFrame.timestamp;
/* update marker */ /* 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; mMarker.len |= mLast.len ^ mCurrent.len;
/* restart timeout */ /* restart timeout */
mTime.restart(); 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() void SnifferItem::updateMarker()
{ {
mLastMarker = mMarker; mLastMarker = mMarker;
mMarker = {0, 0}; mMarker = {0, 0};
} }
//Notch or un-notch this snifferitem / frame
void SnifferItem::notch(bool pNotch) void SnifferItem::notch(bool pNotch)
{ {
if(pNotch) if(pNotch)
mNotch |= mLastMarker.data; mNotch |= mLastMarker.data; //add changed bits to notch value
else else
mNotch = 0; mNotch = 0;
} }
+1 -1
View File
@@ -154,7 +154,7 @@ void SnifferModel::clear()
endResetModel(); endResetModel();
} }
//Called from window with a timer (currently 200ms)
void SnifferModel::refresh() void SnifferModel::refresh()
{ {
QMap<quint32, SnifferItem*>::iterator i; QMap<quint32, SnifferItem*>::iterator i;