From 0519e2d2c9af173e0856acd3e7c9f61770b22900 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 22 Oct 2017 20:42:02 -0400 Subject: [PATCH] More work on supporting swcan - it's there now! Untested as of yet. --- connections/canconnectionmodel.cpp | 6 +-- connections/gvretserial.cpp | 82 +++++++++++++++++++++++------- connections/socketcan.cpp | 6 ++- 3 files changed, 72 insertions(+), 22 deletions(-) diff --git a/connections/canconnectionmodel.cpp b/connections/canconnectionmodel.cpp index 4a94f0a..f68b9d0 100644 --- a/connections/canconnectionmodel.cpp +++ b/connections/canconnectionmodel.cpp @@ -71,7 +71,7 @@ int CANConnectionModel::rowCount(const QModelIndex &parent) const foreach(const CANConnection* conn_p, conns) rows += conn_p->getNumBuses(); - qDebug() << "Num Rows: " << rows; + //qDebug() << "Num Rows: " << rows; return rows; } @@ -145,7 +145,7 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); - qDebug() << "Row: " << index.row(); + //qDebug() << "Row: " << index.row(); int busId; CANConnection *conn_p = getAtIdx(index.row(), busId); @@ -154,7 +154,7 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const ret = conn_p->getBusSettings(busId, bus); bool isSocketCAN = (conn_p->getType() == CANCon::SOCKETCAN) ? true: false; - qDebug() << "ConnP: " << conn_p << " ret " << ret; + //qDebug() << "ConnP: " << conn_p << " ret " << ret; if (role == Qt::DisplayRole) { if(!conn_p) diff --git a/connections/gvretserial.cpp b/connections/gvretserial.cpp index b336e87..62b6f78 100644 --- a/connections/gvretserial.cpp +++ b/connections/gvretserial.cpp @@ -125,25 +125,71 @@ void GVRetSerial::piSetBusSettings(int pBusIdx, CANBus bus) } else deviceSingleWireMode = 0; } + else if (pBusIdx == 2) + { + swcanBaud = bus.getSpeed(); + swcanBaud |= 0x80000000; + if (bus.isActive()) + { + swcanBaud |= 0x40000000; + swcanEnabled = true; + } + else swcanEnabled = false; - /* update baud rates */ - QByteArray buffer; - qDebug() << "Got signal to update bauds. 1: " << can0Baud <<" 2: " << can1Baud; - debugOutput("Got signal to update bauds. 1: " + QString::number(can0Baud) + " 2: " + QString::number(can1Baud)); - buffer[0] = (char)0xF1; //start of a command over serial - buffer[1] = 5; //setup canbus - buffer[2] = (unsigned char)(can0Baud & 0xFF); //four bytes of ID LSB first - buffer[3] = (unsigned char)(can0Baud >> 8); - buffer[4] = (unsigned char)(can0Baud >> 16); - buffer[5] = (unsigned char)(can0Baud >> 24); - buffer[6] = (unsigned char)(can1Baud & 0xFF); //four bytes of ID LSB first - buffer[7] = (unsigned char)(can1Baud >> 8); - buffer[8] = (unsigned char)(can1Baud >> 16); - buffer[9] = (unsigned char)(can1Baud >> 24); - buffer[10] = 0; - if (serial == NULL) return; - if (!serial->isOpen()) return; - serial->write(buffer); + if (bus.isListenOnly()) + { + swcanBaud |= 0x20000000; + swcanListenOnly = true; + } + else swcanListenOnly = false; + + } + + if (pBusIdx < 2) { + /* update baud rates */ + QByteArray buffer; + qDebug() << "Got signal to update bauds. 1: " << can0Baud <<" 2: " << can1Baud; + debugOutput("Got signal to update bauds. 1: " + QString::number(can0Baud) + " 2: " + QString::number(can1Baud)); + buffer[0] = (char)0xF1; //start of a command over serial + buffer[1] = 5; //setup canbus + buffer[2] = (unsigned char)(can0Baud & 0xFF); //four bytes of ID LSB first + buffer[3] = (unsigned char)(can0Baud >> 8); + buffer[4] = (unsigned char)(can0Baud >> 16); + buffer[5] = (unsigned char)(can0Baud >> 24); + buffer[6] = (unsigned char)(can1Baud & 0xFF); //four bytes of ID LSB first + buffer[7] = (unsigned char)(can1Baud >> 8); + buffer[8] = (unsigned char)(can1Baud >> 16); + buffer[9] = (unsigned char)(can1Baud >> 24); + buffer[10] = 0; + if (serial == NULL) return; + if (!serial->isOpen()) return; + serial->write(buffer); + } + else + { + /* update baud rates */ + QByteArray buffer; + qDebug() << "Got signal to update extended bus speeds SWCAN: " << swcanBaud <<" LIN1: " << lin1Baud << " LIN2: " << lin2Baud; + debugOutput("Got signal to update extended bus speeds SWCAN: " + QString::number(swcanBaud) + " LIN1: " + QString::number(lin1Baud) + " LIN2: " + QString::number(lin2Baud)); + buffer[0] = (char)0xF1; //start of a command over serial + buffer[1] = 14; //setup extended buses + buffer[2] = (unsigned char)(swcanBaud & 0xFF); //four bytes of ID LSB first + buffer[3] = (unsigned char)(swcanBaud >> 8); + buffer[4] = (unsigned char)(swcanBaud >> 16); + buffer[5] = (unsigned char)(swcanBaud >> 24); + buffer[6] = (unsigned char)(lin1Baud & 0xFF); //four bytes of ID LSB first + buffer[7] = (unsigned char)(lin1Baud >> 8); + buffer[8] = (unsigned char)(lin1Baud >> 16); + buffer[9] = (unsigned char)(lin1Baud >> 24); + buffer[10] = (unsigned char)(lin2Baud & 0xFF); //four bytes of ID LSB first + buffer[11] = (unsigned char)(lin2Baud >> 8); + buffer[12] = (unsigned char)(lin2Baud >> 16); + buffer[13] = (unsigned char)(lin2Baud >> 24); + buffer[14] = 0; + if (serial == NULL) return; + if (!serial->isOpen()) return; + serial->write(buffer); + } } diff --git a/connections/socketcan.cpp b/connections/socketcan.cpp index 6455d21..3fd9eeb 100644 --- a/connections/socketcan.cpp +++ b/connections/socketcan.cpp @@ -31,6 +31,7 @@ void SocketCan::piStarted() mTimer.setInterval(1000); mTimer.setSingleShot(false); //keep ticking mTimer.start(); + mBusData[0].mBus.setEnabled(true); } @@ -59,6 +60,7 @@ bool SocketCan::piGetBusSettings(int pBusIdx, CANBus& pBus) void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus) { + CANConStatus stats; /* sanity checks */ if(0 != pBusIdx) return; @@ -109,7 +111,6 @@ bool SocketCan::piSendFrame(const CANFrame& pFrame) /* sanity checks */ if(0 != pFrame.bus || pFrame.len>8) return false; - if (!mDev_p) return false; /* fill frame */ @@ -232,7 +233,10 @@ void SocketCan::testConnection() { /* try to reconnect */ CANBus bus; if(getBusConfig(0, bus)) + { + bus.setEnabled(true); setBusSettings(0, bus); + } } /* disconnect test instance */ dev_p->disconnectDevice();