Skip to content

Commit 225e248

Browse files
committed
Fix sniffer window to work properly with CAN-FD traffic (up to 64 data bytes)
1 parent 40a3eb2 commit 225e248

7 files changed

+96
-28
lines changed

re/sniffer/SnifferDelegate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void SnifferDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
4949
return;
5050
}
5151

52-
if (index.column() > 10) return;
52+
if (index.column() > 66) return;
5353

5454
int x;
5555
SnifferItem *item = static_cast<SnifferItem*>(index.internalPointer());

re/sniffer/snifferitem.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ SnifferItem::SnifferItem(const CANFrame& pFrame, quint32 seq):
99
const unsigned char *data = reinterpret_cast<const unsigned char *>(pFrame.payload().constData());
1010
int dataLen = pFrame.payload().length();
1111

12+
if (dataLen > MAX_BYTES) dataLen = MAX_BYTES;
13+
1214
for (int i = 0; i < dataLen; i++) {
1315
mNotch[i] = 0;
1416
mMarker.data[i] = 0;
@@ -41,7 +43,7 @@ float SnifferItem::getDelta() const
4143
return ((float)(mCurrentTime-mLastTime))/1000000;
4244
}
4345

44-
//Get a data byte by index 0-7 (but not more than the length of the actual frame)
46+
//Get a data byte by index 0-63 (but not more than the length of the actual frame)
4547
int SnifferItem::getData(uchar i) const
4648
{
4749
return (i >= mCurrent.len) ? -1 : mCurrent.data[i];
@@ -67,7 +69,7 @@ quint32 SnifferItem::getSeqInterval(uchar i) const
6769
return mCurrSeqVal - getDataTimestamp(i);
6870
}
6971

70-
//Return whether a given data byte (by index 0-7) has incremented, deincremented, or stayed the same
72+
//Return whether a given data byte (by index 0-63) has incremented, deincremented, or stayed the same
7173
//since the last message
7274
//The If checks first that we aren't past the actual data length
7375
// then checks whether lastMarker shows that some bits have changed in the previous 200ms cycle
@@ -120,6 +122,8 @@ void SnifferItem::update(const CANFrame& pFrame, quint32 timeSeq, bool mute)
120122
const unsigned char *data = reinterpret_cast<const unsigned char *>(pFrame.payload().constData());
121123
int dataLen = pFrame.payload().length();
122124

125+
if (dataLen > MAX_BYTES) dataLen = MAX_BYTES;
126+
123127
/* copy new value */
124128
for (int i = 0; i < dataLen; i++)
125129
{
@@ -139,7 +143,7 @@ void SnifferItem::update(const CANFrame& pFrame, quint32 timeSeq, bool mute)
139143
/* update marker */
140144
//We "OR" our stored marker with the changed bits.
141145
//this accumulates changed bits into the marker
142-
for (int i = 0 ; i < 8; i++) mMarker.data[i] |= mLast.data[i] ^ mCurrent.data[i]; //XOR causes only changed bits to be 1's
146+
for (int i = 0 ; i < MAX_BYTES; i++) mMarker.data[i] |= mLast.data[i] ^ mCurrent.data[i]; //XOR causes only changed bits to be 1's
143147
mMarker.len |= mLast.len ^ mCurrent.len;
144148

145149
/* restart timeout */
@@ -151,17 +155,17 @@ void SnifferItem::update(const CANFrame& pFrame, quint32 timeSeq, bool mute)
151155
void SnifferItem::updateMarker()
152156
{
153157
mLastMarker = mMarker;
154-
for (int i = 0; i < 8; i++) mMarker.data[i] = 0;
158+
for (int i = 0; i < MAX_BYTES; i++) mMarker.data[i] = 0;
155159
}
156160

157161
//Notch or un-notch this snifferitem / frame
158162
void SnifferItem::notch(bool pNotch)
159163
{
160164
if(pNotch)
161165
{
162-
for (int i = 0; i < 8; i++) mNotch[i] |= mLastMarker.data[i]; //add changed bits to notch value
166+
for (int i = 0; i < MAX_BYTES; i++) mNotch[i] |= mLastMarker.data[i]; //add changed bits to notch value
163167
}
164168

165169
else
166-
for (int i = 0; i < 8; i++) mNotch[i] = 0;
170+
for (int i = 0; i < MAX_BYTES; i++) mNotch[i] = 0;
167171
}

re/sniffer/snifferitem.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
#include <QElapsedTimer>
66
#include "can_structs.h"
77

8+
#define MAX_BYTES 64
9+
810
struct fstCan
911
{
10-
quint8 data[8];
11-
quint32 dataTimestamp[8];
12+
quint8 data[MAX_BYTES];
13+
quint32 dataTimestamp[MAX_BYTES];
1214
int len;
1315
};
1416

@@ -45,7 +47,7 @@ class SnifferItem
4547
struct fstCan mCurrent;
4648
struct fstCan mLastMarker;
4749
struct fstCan mMarker;
48-
quint8 mNotch[8];
50+
quint8 mNotch[MAX_BYTES];
4951
quint64 mLastTime;
5052
quint64 mCurrentTime;
5153
quint64 mCurrSeqVal;

re/sniffer/sniffermodel.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ QVariant SnifferModel::data(const QModelIndex &index, int role) const
7373
default:
7474
break;
7575
}
76-
if(tc::DATA_0<=col && col <=tc::DATA_7)
76+
if(tc::DATA_0<=col && col < tc::LAST)
7777
{
7878
int data = item->getData(col-tc::DATA_0);
7979
if(data >= 0)
@@ -111,7 +111,7 @@ QVariant SnifferModel::data(const QModelIndex &index, int role) const
111111
return QBrush(QColor(128,0,0));
112112
}
113113
}
114-
else if(tc::DATA_0<=col && col<=tc::DATA_7)
114+
else if(tc::DATA_0 <= col && col < tc::LAST)
115115
{
116116
dc change = item->dataChange(col-tc::DATA_0);
117117
switch(change)
@@ -152,13 +152,13 @@ QVariant SnifferModel::headerData(int section, Qt::Orientation orientation, int
152152
case tc::DELTA:
153153
return QString("Delta");
154154
case tc::FREQUENCY:
155-
return QString("Frequency");
155+
return QString("Freq");
156156
case tc::ID:
157157
return QString("ID");
158158
default:
159159
break;
160160
}
161-
if(tc::DATA_0<=section && section <=tc::DATA_7)
161+
if(tc::DATA_0<=section && section < tc::LAST)
162162
return QString::number(section-tc::DATA_0);
163163
}
164164

re/sniffer/snifferwindow.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ SnifferWindow::SnifferWindow(QWidget *parent) :
2525
/* set column width */
2626
ui->treeView->setColumnWidth(tc::ID, 80);
2727
ui->treeView->setColumnWidth(tc::LAST, 1);
28-
for(int i=tc::DATA_0 ; i<=tc::DATA_7 ; i++)
29-
ui->treeView->setColumnWidth(i, 92);
28+
for(int i=tc::DATA_0 ; i<=tc::LAST ; i++)
29+
ui->treeView->setColumnWidth(i, 50);
3030
ui->treeView->setUniformRowHeights(true);
3131
ui->treeView->header()->setDefaultAlignment(Qt::AlignCenter);
3232
//ui->treeView->setItemDelegate(new SnifferDelegate());

re/sniffer/snifferwindow.h

+56
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,62 @@ enum tc
2323
DATA_5,
2424
DATA_6,
2525
DATA_7,
26+
DATA_8,
27+
DATA_9,
28+
DATA_10,
29+
DATA_11,
30+
DATA_12,
31+
DATA_13,
32+
DATA_14,
33+
DATA_15,
34+
DATA_16,
35+
DATA_17,
36+
DATA_18,
37+
DATA_19,
38+
DATA_20,
39+
DATA_21,
40+
DATA_22,
41+
DATA_23,
42+
DATA_24,
43+
DATA_25,
44+
DATA_26,
45+
DATA_27,
46+
DATA_28,
47+
DATA_29,
48+
DATA_30,
49+
DATA_31,
50+
DATA_32,
51+
DATA_33,
52+
DATA_34,
53+
DATA_35,
54+
DATA_36,
55+
DATA_37,
56+
DATA_38,
57+
DATA_39,
58+
DATA_40,
59+
DATA_41,
60+
DATA_42,
61+
DATA_43,
62+
DATA_44,
63+
DATA_45,
64+
DATA_46,
65+
DATA_47,
66+
DATA_48,
67+
DATA_49,
68+
DATA_50,
69+
DATA_51,
70+
DATA_52,
71+
DATA_53,
72+
DATA_54,
73+
DATA_55,
74+
DATA_56,
75+
DATA_57,
76+
DATA_58,
77+
DATA_59,
78+
DATA_60,
79+
DATA_61,
80+
DATA_62,
81+
DATA_63,
2682
LAST
2783
};
2884

ui/snifferwindow.ui

+18-12
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@
1515
</property>
1616
<layout class="QHBoxLayout" name="horizontalLayout">
1717
<property name="sizeConstraint">
18-
<enum>QLayout::SetDefaultConstraint</enum>
18+
<enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
1919
</property>
2020
<item>
2121
<widget class="QTreeView" name="treeView">
2222
<property name="selectionMode">
23-
<enum>QAbstractItemView::NoSelection</enum>
23+
<enum>QAbstractItemView::SelectionMode::NoSelection</enum>
2424
</property>
25+
<attribute name="headerMinimumSectionSize">
26+
<number>24</number>
27+
</attribute>
28+
<attribute name="headerStretchLastSection">
29+
<bool>false</bool>
30+
</attribute>
2531
</widget>
2632
</item>
2733
<item>
@@ -79,7 +85,7 @@
7985
<string>Notch Interval</string>
8086
</property>
8187
<property name="alignment">
82-
<set>Qt::AlignCenter</set>
88+
<set>Qt::AlignmentFlag::AlignCenter</set>
8389
</property>
8490
</widget>
8591
</item>
@@ -121,13 +127,13 @@
121127
</size>
122128
</property>
123129
<property name="frameShadow">
124-
<enum>QFrame::Plain</enum>
130+
<enum>QFrame::Shadow::Plain</enum>
125131
</property>
126132
<property name="lineWidth">
127133
<number>2</number>
128134
</property>
129135
<property name="orientation">
130-
<enum>Qt::Horizontal</enum>
136+
<enum>Qt::Orientation::Horizontal</enum>
131137
</property>
132138
</widget>
133139
</item>
@@ -137,7 +143,7 @@
137143
<string>Expire Interval</string>
138144
</property>
139145
<property name="alignment">
140-
<set>Qt::AlignCenter</set>
146+
<set>Qt::AlignmentFlag::AlignCenter</set>
141147
</property>
142148
</widget>
143149
</item>
@@ -176,13 +182,13 @@
176182
</size>
177183
</property>
178184
<property name="frameShadow">
179-
<enum>QFrame::Plain</enum>
185+
<enum>QFrame::Shadow::Plain</enum>
180186
</property>
181187
<property name="lineWidth">
182188
<number>2</number>
183189
</property>
184190
<property name="orientation">
185-
<enum>Qt::Horizontal</enum>
191+
<enum>Qt::Orientation::Horizontal</enum>
186192
</property>
187193
</widget>
188194
</item>
@@ -203,10 +209,10 @@
203209
<item>
204210
<spacer name="verticalSpacer">
205211
<property name="orientation">
206-
<enum>Qt::Vertical</enum>
212+
<enum>Qt::Orientation::Vertical</enum>
207213
</property>
208214
<property name="sizeType">
209-
<enum>QSizePolicy::Maximum</enum>
215+
<enum>QSizePolicy::Policy::Maximum</enum>
210216
</property>
211217
<property name="sizeHint" stdset="0">
212218
<size>
@@ -235,7 +241,7 @@
235241
</property>
236242
<layout class="QVBoxLayout" name="verticalLayout_5">
237243
<property name="sizeConstraint">
238-
<enum>QLayout::SetDefaultConstraint</enum>
244+
<enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
239245
</property>
240246
<item>
241247
<widget class="QListWidget" name="listWidget">
@@ -262,7 +268,7 @@
262268
<item>
263269
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0">
264270
<property name="sizeConstraint">
265-
<enum>QLayout::SetDefaultConstraint</enum>
271+
<enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
266272
</property>
267273
<item>
268274
<widget class="QPushButton" name="btAll">

0 commit comments

Comments
 (0)