Fixes to make the new generic serialbus support actually work properly.
This commit is contained in:
@@ -26,6 +26,22 @@ SerialBusConnection::~SerialBusConnection()
|
|||||||
|
|
||||||
void SerialBusConnection::piStarted()
|
void SerialBusConnection::piStarted()
|
||||||
{
|
{
|
||||||
|
qDebug() << "piStarted()";
|
||||||
|
/* create device */
|
||||||
|
QString errorString;
|
||||||
|
qDebug() << "Creating device instance";
|
||||||
|
mDev_p = QCanBus::instance()->createDevice(getDriver(), getPort(), &errorString);
|
||||||
|
if (!mDev_p) {
|
||||||
|
disconnectDevice();
|
||||||
|
qDebug() << "Error: createDevice(" << getType() << getDriver() << getPort() << "):" << errorString;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* connect slots */
|
||||||
|
connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SerialBusConnection::errorReceived);
|
||||||
|
connect(mDev_p, &QCanBusDevice::framesWritten, this, &SerialBusConnection::framesWritten);
|
||||||
|
connect(mDev_p, &QCanBusDevice::framesReceived, this, &SerialBusConnection::framesReceived);
|
||||||
|
|
||||||
connect(&mTimer, SIGNAL(timeout()), this, SLOT(testConnection()));
|
connect(&mTimer, SIGNAL(timeout()), this, SLOT(testConnection()));
|
||||||
mTimer.setInterval(1000);
|
mTimer.setInterval(1000);
|
||||||
mTimer.setSingleShot(false); //keep ticking
|
mTimer.setSingleShot(false); //keep ticking
|
||||||
@@ -47,6 +63,7 @@ void SerialBusConnection::piSuspend(bool pSuspend)
|
|||||||
|
|
||||||
|
|
||||||
void SerialBusConnection::piStop() {
|
void SerialBusConnection::piStop() {
|
||||||
|
qDebug() << "piStop()";
|
||||||
mTimer.stop();
|
mTimer.stop();
|
||||||
disconnectDevice();
|
disconnectDevice();
|
||||||
}
|
}
|
||||||
@@ -65,6 +82,8 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
|||||||
if(0 != pBusIdx)
|
if(0 != pBusIdx)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!mDev_p) return;
|
||||||
|
|
||||||
/* disconnect device if we have one connected */
|
/* disconnect device if we have one connected */
|
||||||
disconnectDevice();
|
disconnectDevice();
|
||||||
|
|
||||||
@@ -75,20 +94,6 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
|||||||
if(!bus.active)
|
if(!bus.active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* create device */
|
|
||||||
QString errorString;
|
|
||||||
mDev_p = QCanBus::instance()->createDevice(getDriver(), getPort(), &errorString);
|
|
||||||
if (!mDev_p) {
|
|
||||||
disconnectDevice();
|
|
||||||
qDebug() << "Error: createDevice(" << getType() << getDriver() << getPort() << "):" << errorString;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* connect slots */
|
|
||||||
connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SerialBusConnection::errorReceived);
|
|
||||||
connect(mDev_p, &QCanBusDevice::framesWritten, this, &SerialBusConnection::framesWritten);
|
|
||||||
connect(mDev_p, &QCanBusDevice::framesReceived, this, &SerialBusConnection::framesReceived);
|
|
||||||
|
|
||||||
/* set configuration */
|
/* set configuration */
|
||||||
/*if (p.useConfigurationEnabled) {
|
/*if (p.useConfigurationEnabled) {
|
||||||
foreach (const SettingsDialog::ConfigurationItem &item, p.configurations)
|
foreach (const SettingsDialog::ConfigurationItem &item, p.configurations)
|
||||||
@@ -116,8 +121,8 @@ bool SerialBusConnection::piSendFrame(const CANFrame& pFrame)
|
|||||||
|
|
||||||
/* fill frame */
|
/* fill frame */
|
||||||
QCanBusFrame frame;
|
QCanBusFrame frame;
|
||||||
frame.setFrameId(pFrame.ID);
|
|
||||||
frame.setExtendedFrameFormat(pFrame.extended);
|
frame.setExtendedFrameFormat(pFrame.extended);
|
||||||
|
frame.setFrameId(pFrame.ID);
|
||||||
if (pFrame.remote) {
|
if (pFrame.remote) {
|
||||||
frame.setFrameType(QCanBusFrame::FrameType::RemoteRequestFrame);
|
frame.setFrameType(QCanBusFrame::FrameType::RemoteRequestFrame);
|
||||||
} else {
|
} else {
|
||||||
@@ -138,8 +143,6 @@ bool SerialBusConnection::piSendFrame(const CANFrame& pFrame)
|
|||||||
void SerialBusConnection::disconnectDevice() {
|
void SerialBusConnection::disconnectDevice() {
|
||||||
if(mDev_p) {
|
if(mDev_p) {
|
||||||
mDev_p->disconnectDevice();
|
mDev_p->disconnectDevice();
|
||||||
delete mDev_p;
|
|
||||||
mDev_p = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,13 +259,12 @@ void SerialBusConnection::framesReceived()
|
|||||||
|
|
||||||
|
|
||||||
void SerialBusConnection::testConnection() {
|
void SerialBusConnection::testConnection() {
|
||||||
QCanBusDevice* dev_p = QCanBus::instance()->createDevice("socketcan", getPort());
|
|
||||||
CANConStatus stats;
|
CANConStatus stats;
|
||||||
|
|
||||||
switch(getStatus())
|
switch(getStatus())
|
||||||
{
|
{
|
||||||
case CANCon::CONNECTED:
|
case CANCon::CONNECTED:
|
||||||
if (!dev_p || !dev_p->connectDevice()) {
|
if (!mDev_p || mDev_p->state() == QCanBusDevice::UnconnectedState) {
|
||||||
/* we have lost connectivity */
|
/* we have lost connectivity */
|
||||||
disconnectDevice();
|
disconnectDevice();
|
||||||
|
|
||||||
@@ -273,18 +275,14 @@ void SerialBusConnection::testConnection() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CANCon::NOT_CONNECTED:
|
case CANCon::NOT_CONNECTED:
|
||||||
if (dev_p && dev_p->connectDevice()) {
|
if (mDev_p && mDev_p->state() == QCanBusDevice::UnconnectedState) {
|
||||||
if(!mDev_p) {
|
/* try to reconnect */
|
||||||
/* try to reconnect */
|
CANBus bus;
|
||||||
CANBus bus;
|
if(getBusConfig(0, bus))
|
||||||
if(getBusConfig(0, bus))
|
{
|
||||||
{
|
bus.setEnabled(true);
|
||||||
bus.setEnabled(true);
|
setBusSettings(0, bus);
|
||||||
setBusSettings(0, bus);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* disconnect test instance */
|
|
||||||
dev_p->disconnectDevice();
|
|
||||||
|
|
||||||
setStatus(CANCon::CONNECTED);
|
setStatus(CANCon::CONNECTED);
|
||||||
stats.conStatus = getStatus();
|
stats.conStatus = getStatus();
|
||||||
@@ -294,7 +292,4 @@ void SerialBusConnection::testConnection() {
|
|||||||
break;
|
break;
|
||||||
default: {}
|
default: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dev_p)
|
|
||||||
delete dev_p;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user