diff --git a/connections/canconfactory.cpp b/connections/canconfactory.cpp index ae2bc6b..774c92c 100644 --- a/connections/canconfactory.cpp +++ b/connections/canconfactory.cpp @@ -14,7 +14,7 @@ CANConnection* CanConFactory::create(type pType, QString pPortName, QString pDri { switch(pType) { case SERIALBUS: - return new SerialBusConnection(pPortName, pDriverName); + return new SerialBusConnection(pPortName, pDriverName, pBusSpeed, pDataRate, pCanFd); case GVRET_SERIAL: if(pPortName.contains(".") && !pPortName.contains("tty") && !pPortName.contains("serial")) return new GVRetSerial(pPortName, true); diff --git a/connections/canconnection.cpp b/connections/canconnection.cpp index 9eac817..e6f0228 100644 --- a/connections/canconnection.cpp +++ b/connections/canconnection.cpp @@ -41,8 +41,13 @@ CANConnection::CANConnection(QString pPort, if (pBusSpeed > 0) mBusData[0].mBus.setSpeed(pBusSpeed); mBusData[0].mBus.setCanFD(pCanFd); - if (pDataRate > 0) mBusData[0].mBus.setDataRate(pDataRate); - + if (pDataRate > 0) { + mBusData[0].mBus.setDataRate(pDataRate); + if (pCanFd) { + mBusData[0].mBus.setCanFD(pCanFd); + } + } + /* if needed, create a thread and move ourself into it */ if(pUseThread) { mThread_p = new QThread(); @@ -210,6 +215,10 @@ int CANConnection::getNumBuses() const{ return mNumBuses; } +int CANConnection::getSerialSpeed() const{ + return mSerialSpeed; +} + bool CANConnection::isConfigured(int pBusId) { if( pBusId < 0 || pBusId >= getNumBuses()) diff --git a/connections/canconnection.h b/connections/canconnection.h index fde8296..b92b229 100644 --- a/connections/canconnection.h +++ b/connections/canconnection.h @@ -52,6 +52,12 @@ public: */ int getNumBuses() const; + /** + * @brief getserialSpeed + * @return returns the serial speed of the device + */ + int getSerialSpeed() const; + /** * @brief getPort * @return returns the port name of the device diff --git a/connections/connectionwindow.cpp b/connections/connectionwindow.cpp index 5e4df7a..a8595bd 100644 --- a/connections/connectionwindow.cpp +++ b/connections/connectionwindow.cpp @@ -551,13 +551,17 @@ void ConnectionWindow::loadConnections() QVector driverNames = settings.value("connections/driverNames").value>(); QVector devTypes = settings.value("connections/types").value>(); + QVector busSpeeds = settings.value("connections/busSpeeds_0").value>(); + QVector DataRates = settings.value("connections/DataRates_0").value>(); + QVector isCanFds = settings.value("connections/isCanFds_0").value>(); + QVector serialSpeeds = settings.value("connections/serialSpeeds").value>(); //don't load the connections if the three setting arrays above aren't all the same size. - if (portNames.count() != driverNames.count() || devTypes.count() != driverNames.count()) return; + if (portNames.count() != driverNames.count() || devTypes.count() != driverNames.count() || busSpeeds.count() != driverNames.count() || isCanFds.count() != driverNames.count() || + DataRates.count() != driverNames.count() || serialSpeeds.count() != driverNames.count() ) return; for(int i = 0 ; i < portNames.count() ; i++) { - //TODO: add serial speed and bus speed to this properly. - CANConnection* conn_p = create((CANCon::type)devTypes[i], portNames[i], driverNames[i], 0, 0, false, 0); + CANConnection* conn_p = create((CANCon::type)devTypes[i], portNames[i], driverNames[i], serialSpeeds[i], busSpeeds[i], isCanFds[i] ? true : false, DataRates[i]); /* add connection to model */ connModel->add(conn_p); } @@ -577,10 +581,19 @@ void ConnectionWindow::saveConnections() QVector driverNames; QVector serialSpeeds; QVector busSpeeds; - + QVector DataRates; + QVector CanFds; + /* save connections */ foreach(CANConnection* conn_p, conns) - { + { CANBus bus; + + if (conn_p->getBusSettings(0, bus)) { + busSpeeds.append(bus.getSpeed()); + CanFds.append(bus.isCanFD() ? 1 : 0); + DataRates.append(bus.getDataRate()); + } + serialSpeeds.append(conn_p->getSerialSpeed()); portNames.append(conn_p->getPort()); devTypes.append(conn_p->getType()); driverNames.append(conn_p->getDriver()); @@ -589,6 +602,10 @@ void ConnectionWindow::saveConnections() settings.setValue("connections/portNames", QVariant::fromValue(portNames)); settings.setValue("connections/types", QVariant::fromValue(devTypes)); settings.setValue("connections/driverNames", QVariant::fromValue(driverNames)); + settings.setValue("connections/busSpeeds_0", QVariant::fromValue(busSpeeds)); + settings.setValue("connections/isCanFds_0", QVariant::fromValue(CanFds)); + settings.setValue("connections/DataRates_0", QVariant::fromValue(DataRates)); + settings.setValue("connections/serialSpeeds", QVariant::fromValue(serialSpeeds)); } void ConnectionWindow::moveConnUp() diff --git a/connections/serialbusconnection.cpp b/connections/serialbusconnection.cpp index 8ebebbf..8938194 100644 --- a/connections/serialbusconnection.cpp +++ b/connections/serialbusconnection.cpp @@ -11,8 +11,8 @@ /**** class definition ****/ /***********************************/ -SerialBusConnection::SerialBusConnection(QString portName, QString driverName) : - CANConnection(portName, driverName, CANCon::SERIALBUS,0 ,0, false, 0 ,1, 4000, true), +SerialBusConnection::SerialBusConnection(QString portName, QString driverName, int pBusSpeed, int pDataRate, bool pCanFd) : + CANConnection(portName, driverName, CANCon::SERIALBUS,0 ,pBusSpeed, pCanFd, pDataRate ,1, 4000, true), mTimer(this) /*NB: set connection as parent of timer to manage it from working thread */ { } diff --git a/connections/serialbusconnection.h b/connections/serialbusconnection.h index f65be43..10c1331 100644 --- a/connections/serialbusconnection.h +++ b/connections/serialbusconnection.h @@ -27,7 +27,8 @@ class SerialBusConnection : public CANConnection Q_OBJECT public: - SerialBusConnection(QString portName, QString driverName); + SerialBusConnection(QString portName, QString driverName, int pBusSpeed, + int pDataRate, bool pCanFd); virtual ~SerialBusConnection(); protected: