Added support for CAN FD frames to the SERIALBUS

This commit is contained in:
Bohdan Buinich
2022-10-11 22:18:58 +03:00
parent 677d9ba9f8
commit 2c82535ca7
5 changed files with 42 additions and 8 deletions
+14 -2
View File
@@ -8,6 +8,7 @@ CANBus::CANBus()
listenOnly = false; listenOnly = false;
singleWire = false; singleWire = false;
active = false; active = false;
canFD = false;
} }
@@ -15,14 +16,16 @@ CANBus::CANBus(const CANBus& pBus) :
speed(pBus.speed), speed(pBus.speed),
listenOnly(pBus.listenOnly), listenOnly(pBus.listenOnly),
singleWire(pBus.singleWire), singleWire(pBus.singleWire),
active(pBus.active) {} active(pBus.active),
canFD(pBus.canFD) {}
bool CANBus::operator==(const CANBus& bus) const{ bool CANBus::operator==(const CANBus& bus) const{
return speed == bus.speed && return speed == bus.speed &&
listenOnly == bus.listenOnly && listenOnly == bus.listenOnly &&
singleWire == bus.singleWire && singleWire == bus.singleWire &&
active == bus.active; active == bus.active &&
canFD == bus.canFD;
} }
void CANBus::setSpeed(int newSpeed){ void CANBus::setSpeed(int newSpeed){
@@ -45,6 +48,11 @@ void CANBus::setActive(bool mode){
active = mode; active = mode;
} }
void CANBus::setCanFD(bool mode){
//qDebug() << "CANBUS setCanFD = " << mode;
canFD = mode;
}
int CANBus::getSpeed(){ int CANBus::getSpeed(){
return speed; return speed;
} }
@@ -61,6 +69,10 @@ bool CANBus::isActive(){
return active; return active;
} }
bool CANBus::isCanFD(){
return canFD;
}
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus ) QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus )
{ {
+3 -1
View File
@@ -16,16 +16,18 @@ public:
bool listenOnly; bool listenOnly;
bool singleWire; bool singleWire;
bool active; //is this bus turned on? bool active; //is this bus turned on?
bool canFD;
void setSpeed(int); // new speed void setSpeed(int); // new speed
void setListenOnly(bool); //bool for whether to only listen void setListenOnly(bool); //bool for whether to only listen
void setSingleWire(bool); //bool for whether to use single wire mode void setSingleWire(bool); //bool for whether to use single wire mode
void setActive(bool); //whether this bus should be enabled or not. void setActive(bool); //whether this bus should be enabled or not.
void setCanFD(bool); // enable or disable CANFD support
int getSpeed(); int getSpeed();
bool isListenOnly(); bool isListenOnly();
bool isSingleWire(); bool isSingleWire();
bool isActive(); bool isActive();
bool isCanFD();
}; };
QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus ); QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus );
+9 -1
View File
@@ -365,6 +365,7 @@ void ConnectionWindow::saveBusSettings()
bus.setSpeed(ui->cbBusSpeed->currentText().toInt()); bus.setSpeed(ui->cbBusSpeed->currentText().toInt());
bus.setActive(ui->ckEnable->isChecked()); bus.setActive(ui->ckEnable->isChecked());
bus.setListenOnly(ui->ckListenOnly->isChecked()); bus.setListenOnly(ui->ckListenOnly->isChecked());
bus.setCanFD(ui->canFDEnable->isChecked());
conn_p->setBusSettings(offset, bus); conn_p->setBusSettings(offset, bus);
} }
} }
@@ -381,7 +382,8 @@ void ConnectionWindow::populateBusDetails(int offset)
{ {
//bool ret; //bool ret;
//int numBuses; //int numBuses;
ui->canFDEnable->setVisible(false);
ui->canFDEnable_label->setVisible(false);
CANConnection* conn_p = connModel->getAtIdx(selIdx); CANConnection* conn_p = connModel->getAtIdx(selIdx);
CANBus bus; CANBus bus;
if(!conn_p) return; if(!conn_p) return;
@@ -396,6 +398,12 @@ void ConnectionWindow::populateBusDetails(int offset)
//ui->lblBusNum->setText(QString::number(busBase + offset)); //ui->lblBusNum->setText(QString::number(busBase + offset));
ui->ckListenOnly->setChecked(bus.isListenOnly()); ui->ckListenOnly->setChecked(bus.isListenOnly());
ui->ckEnable->setChecked(bus.isActive()); ui->ckEnable->setChecked(bus.isActive());
if (conn_p->getType() == CANCon::type::SERIALBUS)
{
ui->canFDEnable->setVisible(true);
ui->canFDEnable_label->setVisible(true);
ui->canFDEnable->setChecked(bus.isCanFD());
}
bool found = false; bool found = false;
for (int i = 0; i < ui->cbBusSpeed->count(); i++) for (int i = 0; i < ui->cbBusSpeed->count(); i++)
+2
View File
@@ -47,6 +47,7 @@ void SerialBusConnection::piStarted()
mTimer.setSingleShot(false); //keep ticking mTimer.setSingleShot(false); //keep ticking
mTimer.start(); mTimer.start();
mBusData[0].mBus.setActive(true); mBusData[0].mBus.setActive(true);
mBusData[0].mBus.setCanFD(false);
mBusData[0].mConfigured = true; mBusData[0].mConfigured = true;
} }
@@ -103,6 +104,7 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus)
//You cannot set the speed of a socketcan interface, it has to be set with console commands. //You cannot set the speed of a socketcan interface, it has to be set with console commands.
//But, you can probabaly set the speed of many of the other serialbus devices so go ahead and try //But, you can probabaly set the speed of many of the other serialbus devices so go ahead and try
mDev_p->setConfigurationParameter(QCanBusDevice::BitRateKey, bus.speed); mDev_p->setConfigurationParameter(QCanBusDevice::BitRateKey, bus.speed);
mDev_p->setConfigurationParameter(QCanBusDevice::CanFdKey, bus.canFD);
/* connect device */ /* connect device */
if (!mDev_p->connectDevice()) { if (!mDev_p->connectDevice()) {
+14 -4
View File
@@ -64,9 +64,6 @@
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
<layout class="QVBoxLayout" name="qhBox20"> <layout class="QVBoxLayout" name="qhBox20">
<item>
<widget class="QTabBar" name="tabBuses" native="true"/>
</item>
<item> <item>
<layout class="QFormLayout" name="formLayout_2"> <layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0"> <item row="0" column="0">
@@ -107,15 +104,28 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="4" column="1">
<widget class="QPushButton" name="btnSaveBus"> <widget class="QPushButton" name="btnSaveBus">
<property name="text"> <property name="text">
<string>Save Bus Settings</string> <string>Save Bus Settings</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1">
<widget class="QCheckBox" name="canFDEnable"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="canFDEnable_label">
<property name="text">
<string>Enable CAN FD:</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item>
<widget class="QTabBar" name="tabBuses" native="true"/>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>