Skip to content

Commit 8a929c1

Browse files
authored
Merge pull request collin80#532 from BBuinich/can_fd_support
Added support for CAN FD frames to the SERIALBUS
2 parents f06fb69 + 16ff5af commit 8a929c1

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

connections/canbus.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,24 @@ CANBus::CANBus()
88
listenOnly = false;
99
singleWire = false;
1010
active = false;
11+
canFD = false;
1112
}
1213

1314

1415
CANBus::CANBus(const CANBus& pBus) :
1516
speed(pBus.speed),
1617
listenOnly(pBus.listenOnly),
1718
singleWire(pBus.singleWire),
18-
active(pBus.active) {}
19+
active(pBus.active),
20+
canFD(pBus.canFD) {}
1921

2022

2123
bool CANBus::operator==(const CANBus& bus) const{
2224
return speed == bus.speed &&
2325
listenOnly == bus.listenOnly &&
2426
singleWire == bus.singleWire &&
25-
active == bus.active;
27+
active == bus.active &&
28+
canFD == bus.canFD;
2629
}
2730

2831
void CANBus::setSpeed(int newSpeed){
@@ -45,6 +48,11 @@ void CANBus::setActive(bool mode){
4548
active = mode;
4649
}
4750

51+
void CANBus::setCanFD(bool mode){
52+
//qDebug() << "CANBUS setCanFD = " << mode;
53+
canFD = mode;
54+
}
55+
4856
int CANBus::getSpeed(){
4957
return speed;
5058
}
@@ -61,6 +69,10 @@ bool CANBus::isActive(){
6169
return active;
6270
}
6371

72+
bool CANBus::isCanFD(){
73+
return canFD;
74+
}
75+
6476

6577
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus )
6678
{

connections/canbus.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ class CANBus
1616
bool listenOnly;
1717
bool singleWire;
1818
bool active; //is this bus turned on?
19-
19+
bool canFD;
2020

2121
void setSpeed(int); // new speed
2222
void setListenOnly(bool); //bool for whether to only listen
2323
void setSingleWire(bool); //bool for whether to use single wire mode
2424
void setActive(bool); //whether this bus should be enabled or not.
25+
void setCanFD(bool); // enable or disable CANFD support
2526
int getSpeed();
2627
bool isListenOnly();
2728
bool isSingleWire();
2829
bool isActive();
30+
bool isCanFD();
2931
};
3032

3133
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus );

connections/connectionwindow.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ void ConnectionWindow::saveBusSettings()
365365
bus.setSpeed(ui->cbBusSpeed->currentText().toInt());
366366
bus.setActive(ui->ckEnable->isChecked());
367367
bus.setListenOnly(ui->ckListenOnly->isChecked());
368+
bus.setCanFD(ui->canFDEnable->isChecked());
368369
conn_p->setBusSettings(offset, bus);
369370
}
370371
}
@@ -381,7 +382,8 @@ void ConnectionWindow::populateBusDetails(int offset)
381382
{
382383
//bool ret;
383384
//int numBuses;
384-
385+
ui->canFDEnable->setVisible(false);
386+
ui->canFDEnable_label->setVisible(false);
385387
CANConnection* conn_p = connModel->getAtIdx(selIdx);
386388
CANBus bus;
387389
if(!conn_p) return;
@@ -396,6 +398,12 @@ void ConnectionWindow::populateBusDetails(int offset)
396398
//ui->lblBusNum->setText(QString::number(busBase + offset));
397399
ui->ckListenOnly->setChecked(bus.isListenOnly());
398400
ui->ckEnable->setChecked(bus.isActive());
401+
if (conn_p->getType() == CANCon::type::SERIALBUS)
402+
{
403+
ui->canFDEnable->setVisible(true);
404+
ui->canFDEnable_label->setVisible(true);
405+
ui->canFDEnable->setChecked(bus.isCanFD());
406+
}
399407

400408
bool found = false;
401409
for (int i = 0; i < ui->cbBusSpeed->count(); i++)

connections/serialbusconnection.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void SerialBusConnection::piStarted()
4747
mTimer.setSingleShot(false); //keep ticking
4848
mTimer.start();
4949
mBusData[0].mBus.setActive(true);
50+
mBusData[0].mBus.setCanFD(false);
5051
mBusData[0].mConfigured = true;
5152
}
5253

@@ -103,6 +104,7 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus)
103104
//You cannot set the speed of a socketcan interface, it has to be set with console commands.
104105
//But, you can probabaly set the speed of many of the other serialbus devices so go ahead and try
105106
mDev_p->setConfigurationParameter(QCanBusDevice::BitRateKey, bus.speed);
107+
mDev_p->setConfigurationParameter(QCanBusDevice::CanFdKey, bus.canFD);
106108

107109
/* connect device */
108110
if (!mDev_p->connectDevice()) {

ui/connectionwindow.ui

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@
6464
<set>Qt::AlignCenter</set>
6565
</property>
6666
<layout class="QVBoxLayout" name="qhBox20">
67-
<item>
68-
<widget class="QTabBar" name="tabBuses" native="true"/>
69-
</item>
7067
<item>
7168
<layout class="QFormLayout" name="formLayout_2">
7269
<item row="0" column="0">
@@ -107,15 +104,28 @@
107104
</property>
108105
</widget>
109106
</item>
110-
<item row="3" column="1">
107+
<item row="4" column="1">
111108
<widget class="QPushButton" name="btnSaveBus">
112109
<property name="text">
113110
<string>Save Bus Settings</string>
114111
</property>
115112
</widget>
116113
</item>
114+
<item row="3" column="1">
115+
<widget class="QCheckBox" name="canFDEnable"/>
116+
</item>
117+
<item row="3" column="0">
118+
<widget class="QLabel" name="canFDEnable_label">
119+
<property name="text">
120+
<string>Enable CAN FD:</string>
121+
</property>
122+
</widget>
123+
</item>
117124
</layout>
118125
</item>
126+
<item>
127+
<widget class="QTabBar" name="tabBuses" native="true"/>
128+
</item>
119129
</layout>
120130
</widget>
121131
</item>

0 commit comments

Comments
 (0)