diff --git a/connections/canbus.cpp b/connections/canbus.cpp index 8986b28..3779e86 100644 --- a/connections/canbus.cpp +++ b/connections/canbus.cpp @@ -9,6 +9,7 @@ CANBus::CANBus() singleWire = false; active = false; canFD = false; + dataRate = 2000000; } @@ -17,7 +18,8 @@ CANBus::CANBus(const CANBus& pBus) : listenOnly(pBus.listenOnly), singleWire(pBus.singleWire), active(pBus.active), - canFD(pBus.canFD) {} + canFD(pBus.canFD), + dataRate(pBus.dataRate){} bool CANBus::operator==(const CANBus& bus) const{ @@ -57,6 +59,15 @@ int CANBus::getSpeed(){ return speed; } +int CANBus::getDataRate(){ + return dataRate; +} + +void CANBus::setDataRate(int newSpeed){ + //qDebug() << "CANBUS SetSpeed = " << newSpeed; + dataRate = newSpeed; +} + bool CANBus::isListenOnly(){ return listenOnly; } diff --git a/connections/canbus.h b/connections/canbus.h index bcbe879..ff3d887 100644 --- a/connections/canbus.h +++ b/connections/canbus.h @@ -17,6 +17,7 @@ public: bool singleWire; bool active; //is this bus turned on? bool canFD; + int dataRate; void setSpeed(int); // new speed void setListenOnly(bool); //bool for whether to only listen @@ -24,6 +25,8 @@ public: void setActive(bool); //whether this bus should be enabled or not. void setCanFD(bool); // enable or disable CANFD support int getSpeed(); + int getDataRate(); + void setDataRate(int newSpeed); bool isListenOnly(); bool isSingleWire(); bool isActive(); diff --git a/connections/canconfactory.cpp b/connections/canconfactory.cpp index db93da2..ae2bc6b 100644 --- a/connections/canconfactory.cpp +++ b/connections/canconfactory.cpp @@ -10,7 +10,7 @@ using namespace CANCon; -CANConnection* CanConFactory::create(type pType, QString pPortName, QString pDriverName, int pSerialSpeed, int pBusSpeed) +CANConnection* CanConFactory::create(type pType, QString pPortName, QString pDriverName, int pSerialSpeed, int pBusSpeed, bool pCanFd, int pDataRate) { switch(pType) { case SERIALBUS: @@ -23,7 +23,7 @@ CANConnection* CanConFactory::create(type pType, QString pPortName, QString pDri case REMOTE: return new GVRetSerial(pPortName, true); //it's a special case of GVRET connected over TCP/IP so it uses the same class case LAWICEL: - return new LAWICELSerial(pPortName, pSerialSpeed, pBusSpeed); + return new LAWICELSerial(pPortName, pSerialSpeed, pBusSpeed, pCanFd, pDataRate); case KAYAK: return new SocketCANd(pPortName); case MQTT: diff --git a/connections/canconfactory.h b/connections/canconfactory.h index c23ce8b..ecf453d 100644 --- a/connections/canconfactory.h +++ b/connections/canconfactory.h @@ -7,7 +7,7 @@ class CanConFactory { public: - static CANConnection* create(CANCon::type, QString pPortName, QString pDriverName, int pSerialSpeed, int pBusSpeed); + static CANConnection* create(CANCon::type, QString pPortName, QString pDriverName, int pSerialSpeed, int pBusSpeed, bool pCanFd, int pDataRate); }; #endif // CANCONFACTORY_H diff --git a/connections/canconnection.cpp b/connections/canconnection.cpp index 6206045..74e4fb8 100644 --- a/connections/canconnection.cpp +++ b/connections/canconnection.cpp @@ -7,6 +7,8 @@ CANConnection::CANConnection(QString pPort, CANCon::type pType, int pSerialSpeed, int pBusSpeed, + bool pCanFd, + int pDataRate, int pNumBuses, int pQueueLen, bool pUseThread) : @@ -38,6 +40,8 @@ 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 needed, create a thread and move ourself into it */ if(pUseThread) { diff --git a/connections/canconnection.h b/connections/canconnection.h index ab53fc8..fde8296 100644 --- a/connections/canconnection.h +++ b/connections/canconnection.h @@ -32,6 +32,8 @@ protected: CANCon::type pType, int pSerialSpeed, int pBusSpeed, + bool pCanFd, + int pDataRate, int pNumBuses, int pQueueLen, bool pUseThread); diff --git a/connections/canlogserver.cpp b/connections/canlogserver.cpp index 8ddc5b0..78a2bc5 100644 --- a/connections/canlogserver.cpp +++ b/connections/canlogserver.cpp @@ -9,7 +9,7 @@ #include "canlogserver.h" CanLogServer::CanLogServer(QString serverAddressString) : - CANConnection(serverAddressString, "CanLogserver", CANCon::CANLOGSERVER, 0, 0, 1, 4000, true), + CANConnection(serverAddressString, "CanLogserver", CANCon::CANLOGSERVER, 0, 0, false, 0, 1, 4000, true), m_ptcpSocket(new QTcpSocket(this)) { diff --git a/connections/canserver.cpp b/connections/canserver.cpp index e304f83..a8ad145 100644 --- a/connections/canserver.cpp +++ b/connections/canserver.cpp @@ -16,7 +16,7 @@ #include "canserver.h" CANserver::CANserver(QString serverAddressString) : - CANConnection(serverAddressString, "CANserver", CANCon::CANSERVER, 0, 0, 3, 4000, true), + CANConnection(serverAddressString, "CANserver", CANCon::CANSERVER, 0, 0, false, 0, 3, 4000, true), _udpClient(new QUdpSocket(this)), _heartbeatTimer(new QTimer(this)) { diff --git a/connections/connectionwindow.cpp b/connections/connectionwindow.cpp index e748e31..639d531 100644 --- a/connections/connectionwindow.cpp +++ b/connections/connectionwindow.cpp @@ -253,6 +253,8 @@ void ConnectionWindow::handleNewConn() QString newDriver; int newSerialSpeed; int newBusSpeed; + bool newCanFd; + int newDataRate; CANConnection *conn; if (thisDialog->exec() == QDialog::Accepted) @@ -262,7 +264,9 @@ void ConnectionWindow::handleNewConn() newDriver = thisDialog->getDriverName(); newSerialSpeed = thisDialog->getSerialSpeed(); newBusSpeed = thisDialog->getBusSpeed(); - conn = create(newType, newPort, newDriver, newSerialSpeed, newBusSpeed); + newCanFd=thisDialog->isCanFd(); + newDataRate = thisDialog->getDataRate(); + conn = create(newType, newPort, newDriver, newSerialSpeed, newBusSpeed, newCanFd, newDataRate); if (conn) { connModel->add(conn); @@ -297,7 +301,8 @@ void ConnectionWindow::handleResetConn() { QString port, driver; CANCon::type type; - int serSpeed, busSpeed; + int serSpeed, busSpeed, dataRate; + bool canFd; int selIdx = ui->tableConnections->selectionModel()->currentIndex().row(); if (selIdx <0) return; @@ -312,13 +317,16 @@ void ConnectionWindow::handleResetConn() driver = conn_p->getDriver(); serSpeed = 0; //TODO: implement these busSpeed = 0; + dataRate = 0; + canFd = false; + /* stop and delete connection */ conn_p->stop(); conn_p = nullptr; - conn_p = create(type, port, driver, serSpeed, busSpeed); + conn_p = create(type, port, driver, serSpeed, busSpeed,canFd,dataRate); if (conn_p) connModel->replace(selIdx, conn_p); } @@ -366,6 +374,7 @@ void ConnectionWindow::saveBusSettings() bus.setActive(ui->ckEnable->isChecked()); bus.setListenOnly(ui->ckListenOnly->isChecked()); bus.setCanFD(ui->canFDEnable->isChecked()); + bus.setDataRate(ui->cbDataRate->currentText().toInt()); conn_p->setBusSettings(offset, bus); } } @@ -384,6 +393,8 @@ void ConnectionWindow::populateBusDetails(int offset) //int numBuses; ui->canFDEnable->setVisible(false); ui->canFDEnable_label->setVisible(false); + ui->dataRate_label->setVisible(false); + ui->cbDataRate->setVisible(false); CANConnection* conn_p = connModel->getAtIdx(selIdx); CANBus bus; if(!conn_p) return; @@ -398,11 +409,13 @@ void ConnectionWindow::populateBusDetails(int offset) //ui->lblBusNum->setText(QString::number(busBase + offset)); ui->ckListenOnly->setChecked(bus.isListenOnly()); ui->ckEnable->setChecked(bus.isActive()); - if (conn_p->getType() == CANCon::type::SERIALBUS) + if (conn_p->getType() == CANCon::type::SERIALBUS || conn_p->getType() == CANCon::type::LAWICEL) { ui->canFDEnable->setVisible(true); ui->canFDEnable_label->setVisible(true); ui->canFDEnable->setChecked(bus.isCanFD()); + ui->cbDataRate->setVisible(true); + ui->dataRate_label->setVisible(true); } bool found = false; @@ -415,7 +428,19 @@ void ConnectionWindow::populateBusDetails(int offset) break; } } + if (!found) ui->cbBusSpeed->addItem(QString::number(bus.getSpeed())); + found = false; + for (int i = 0; i < ui->cbDataRate->count(); i++) + { + if (bus.getDataRate() == ui->cbDataRate->itemText(i).toInt()) + { + found = true; + ui->cbDataRate->setCurrentIndex(i); + break; + } + } + if (!found) ui->cbDataRate->addItem(QString::number(bus.getDataRate())); } } @@ -490,12 +515,12 @@ void ConnectionWindow::handleSendText() { emit sendDebugData(bytes); } -CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QString pDriver, int pSerialSpeed, int pBusSpeed) +CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QString pDriver, int pSerialSpeed, int pBusSpeed, bool pCanFd, int pDataRate) { CANConnection* conn_p; /* create connection */ - conn_p = CanConFactory::create(pTye, pPortName, pDriver, pSerialSpeed, pBusSpeed); + conn_p = CanConFactory::create(pTye, pPortName, pDriver, pSerialSpeed, pBusSpeed, pCanFd, pDataRate); if(conn_p) { /* connect signal */ @@ -533,7 +558,7 @@ void ConnectionWindow::loadConnections() 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); + CANConnection* conn_p = create((CANCon::type)devTypes[i], portNames[i], driverNames[i], 0, 0, false, 0); /* add connection to model */ connModel->add(conn_p); } diff --git a/connections/connectionwindow.h b/connections/connectionwindow.h index 9bc3076..61a94c5 100644 --- a/connections/connectionwindow.h +++ b/connections/connectionwindow.h @@ -65,7 +65,7 @@ private: QVector remoteDeviceIPGVRET; QVector remoteDeviceKayak; - CANConnection* create(CANCon::type pTye, QString pPortName, QString pDriver, int pSerialSpeed, int pBusSpeed); + CANConnection* create(CANCon::type pTye, QString pPortName, QString pDriver, int pSerialSpeed, int pBusSpeed, bool pCanFd, int pDataRate); void populateBusDetails(int offset); void loadConnections(); void saveConnections(); diff --git a/connections/gvretserial.cpp b/connections/gvretserial.cpp index e59a668..dc63ae0 100644 --- a/connections/gvretserial.cpp +++ b/connections/gvretserial.cpp @@ -9,7 +9,7 @@ #include "gvretserial.h" GVRetSerial::GVRetSerial(QString portName, bool useTcp) : - CANConnection(portName, "gvret", CANCon::GVRET_SERIAL, 0, 0, 3, 4000, true), + CANConnection(portName, "gvret", CANCon::GVRET_SERIAL, 0, 0, false, 0, 3, 4000, true), mTimer(this), /*NB: set this as parent of timer to manage it from working thread */ useTcp(useTcp) { diff --git a/connections/lawicel_serial.cpp b/connections/lawicel_serial.cpp index 7377151..0b502f8 100644 --- a/connections/lawicel_serial.cpp +++ b/connections/lawicel_serial.cpp @@ -9,8 +9,8 @@ #include "lawicel_serial.h" #include "utility.h" -LAWICELSerial::LAWICELSerial(QString portName, int serialSpeed, int lawicelSpeed) : - CANConnection(portName, "LAWICEL", CANCon::LAWICEL,serialSpeed, lawicelSpeed, 3, 4000, true), +LAWICELSerial::LAWICELSerial(QString portName, int serialSpeed, int lawicelSpeed, bool canFd, int dataRate) : + CANConnection(portName, "LAWICEL", CANCon::LAWICEL,serialSpeed, lawicelSpeed, canFd, dataRate, 3, 4000, true), mTimer(this) /*NB: set this as parent of timer to manage it from working thread */ { sendDebug("LAWICELSerial()"); @@ -154,13 +154,31 @@ bool LAWICELSerial::piSendFrame(const CANFrame& frame) int idx = 0; QString buildStr; - if (frame.hasExtendedFrameFormat()) - { - buildStr = QString::asprintf("T%08X%u", ID, frame.payload().length()); + if(frame.hasFlexibleDataRateFormat()){ + if (frame.hasExtendedFrameFormat()) + { + if (frame.hasBitrateSwitch()) + buildStr = QString::asprintf("B%08X%u", ID, LAWICELSerial::bytes_to_dlc_code(frame.payload().length())); + else + buildStr = QString::asprintf("D%08X%u", ID, LAWICELSerial::bytes_to_dlc_code(frame.payload().length())); + } + else + { + if (frame.hasBitrateSwitch()) + buildStr = QString::asprintf("b%03X%u", ID, LAWICELSerial::bytes_to_dlc_code(frame.payload().length())); + else + buildStr = QString::asprintf("d%03X%u", ID, LAWICELSerial::bytes_to_dlc_code(frame.payload().length())); + } } - else - { - buildStr = QString::asprintf("t%03X%u", ID, frame.payload().length()); + else { + if (frame.hasExtendedFrameFormat()) + { + buildStr = QString::asprintf("T%08X%u", ID, frame.payload().length()); + } + else + { + buildStr = QString::asprintf("t%03X%u", ID, frame.payload().length()); + } } foreach (QChar chr, buildStr) { @@ -245,44 +263,71 @@ void LAWICELSerial::deviceConnected() output.clear(); output.append('S'); //configure speed of bus - switch (this->mBusData[0].mBus.getSpeed()) - { - case 10000: - output.append('0'); - break; - case 20000: - output.append('1'); - break; - case 50000: - output.append('2'); - break; - case 100000: - output.append('3'); - break; - case 125000: - output.append('4'); - break; - case 250000: - output.append('5'); - break; - case 500000: - output.append('6'); - break; - case 800000: - output.append('7'); - break; - case 1000000: - output.append('8'); - break; - default: - output.append('6'); - break; - } + switch (this->mBusData[0].mBus.getSpeed()) + { + case 10000: + output.append('0'); + break; + case 20000: + output.append('1'); + break; + case 50000: + output.append('2'); + break; + case 100000: + output.append('3'); + break; + case 125000: + output.append('4'); + break; + case 250000: + output.append('5'); + break; + case 500000: + output.append('6'); + break; + case 800000: + output.append('7'); + break; + case 1000000: + output.append('8'); + break; + default: + output.append('6'); + break; + } + output.append('\x0D'); sendToSerial(output); output.clear(); + + if (this->canFd){ + switch (this->dataRate) + { + case 1000000: + output.append("Y1"); + break; + case 2000000: + output.append("Y2"); + break; + case 4000000: + output.append("Y4"); + break; + case 5000000: + output.append("Y5"); + break; + default: + output.append("Y2"); + break; + } + + output.append('\x0D'); + sendToSerial(output); + output.clear(); + } + output.append('O'); //open bus now that we set the speed output.append(13); @@ -445,6 +490,8 @@ void LAWICELSerial::readSerialData() if (c == 13) //all lawicel commands end in CR { qDebug() << "Got CR!"; + + buildFrame.setTimeStamp(QDateTime::currentMSecsSinceEpoch() * 1000l); switch (mBuildLine[0].toLatin1()) { case 't': //standard frame @@ -502,6 +549,68 @@ void LAWICELSerial::readSerialData() qDebug() << "can't get a frame, ERROR"; } break; + case 'b': + buildFrame.setBitrateSwitch(true); //BRS enabled + case 'd': //standard fd frame, BRS disabled + //tIIILDD + buildFrame.setFlexibleDataRateFormat(true); + buildFrame.setFrameId(mBuildLine.mid(1, 3).toInt(nullptr, 16)); + buildFrame.isReceived = true; + buildFrame.setFrameType(QCanBusFrame::FrameType::DataFrame); + buildData.resize(LAWICELSerial::dlc_code_to_bytes(mBuildLine.mid(4, 1).toInt(nullptr, 16))); + for (int c = 0; c < buildData.size(); c++) + { + buildData[c] = mBuildLine.mid(5 + (c*2), 2).toInt(nullptr, 16); + } + buildFrame.setPayload(buildData); + if (!isCapSuspended()) + { + /* get frame from queue */ + CANFrame* frame_p = getQueue().get(); + if(frame_p) { + //qDebug() << "Lawicel got frame on bus " << frame_p->bus; + /* copy frame */ + *frame_p = buildFrame; + checkTargettedFrame(buildFrame); + /* enqueue frame */ + getQueue().queue(); + } + else + qDebug() << "can't get a frame, ERROR"; + } + break; + case 'B': + buildFrame.setBitrateSwitch(true); //BRS enabled + case 'D': //extended fd frame + //TIIIIIIIILDD. + buildFrame.setFlexibleDataRateFormat(true); + buildFrame.setBitrateSwitch(true); + buildFrame.setFrameId(mBuildLine.mid(1, 8).toInt(nullptr, 16)); + buildFrame.isReceived = true; + buildFrame.setFrameType(QCanBusFrame::FrameType::DataFrame); + buildFrame.setExtendedFrameFormat(true); + buildData.resize(LAWICELSerial::dlc_code_to_bytes(mBuildLine.mid(4, 1).toInt(nullptr, 16))); + for (int c = 0; c < buildData.size(); c++) + { + buildData[c] = mBuildLine.mid(10 + (c*2), 2).toInt(nullptr, 16); + } + buildFrame.setPayload(buildData); + if (!isCapSuspended()) + { + /* get frame from queue */ + CANFrame* frame_p = getQueue().get(); + if(frame_p) { + //qDebug() << "Lawicel got frame on bus " << frame_p->bus; + /* copy frame */ + *frame_p = buildFrame; + checkTargettedFrame(buildFrame); + /* enqueue frame */ + getQueue().queue(); + } + else + qDebug() << "can't get a frame, ERROR"; + } + break; } mBuildLine.clear(); } @@ -520,3 +629,60 @@ void LAWICELSerial::handleTick() //qDebug() << "Tick!"; } + +// Convert a FDCAN_data_length_code to number of bytes in a message +uint8_t LAWICELSerial::dlc_code_to_bytes(int dlc_code) +{ + if (dlc_code<=8) + return dlc_code; + else{ + switch(dlc_code) + { + case 9: + return 12; + case 10: + return 16; + case 11: + return 20; + case 12: + return 24; + case 13: + return 32; + case 14: + return 48; + case 15: + return 64; + default: + return 0; + } + } +} + +uint8_t LAWICELSerial::bytes_to_dlc_code(uint8_t bytes) +{ + if (bytes<=8) + return bytes; + else{ + switch(bytes) + { + case 12: + return 9; + case 16: + return 10; + case 20: + return 11; + case 24: + return 12; + case 32: + return 13; + case 48: + return 14; + case 64: + return 15; + default: + return 0; + } + } +} + + diff --git a/connections/lawicel_serial.h b/connections/lawicel_serial.h index 555d089..3d32a88 100644 --- a/connections/lawicel_serial.h +++ b/connections/lawicel_serial.h @@ -19,7 +19,7 @@ class LAWICELSerial : public CANConnection Q_OBJECT public: - LAWICELSerial(QString portName, int serialSpeed, int lawicelSpeed); + LAWICELSerial(QString portName, int serialSpeed, int lawicelSpeed, bool canFd, int dataRate); virtual ~LAWICELSerial(); protected: @@ -49,6 +49,8 @@ private: void rebuildLocalTimeBasis(); void sendToSerial(const QByteArray &bytes); void sendDebug(const QString debugText); + uint8_t dlc_code_to_bytes(int dlc_code); + uint8_t bytes_to_dlc_code(uint8_t bytes); protected: QTimer mTimer; @@ -61,6 +63,8 @@ protected: CANFrame buildFrame; bool can0Enabled; bool can0ListenOnly; + bool canFd; + int dataRate; }; #endif // LAWICELSERIAL_H diff --git a/connections/mqtt_bus.cpp b/connections/mqtt_bus.cpp index f8511fa..4220e34 100644 --- a/connections/mqtt_bus.cpp +++ b/connections/mqtt_bus.cpp @@ -9,7 +9,7 @@ #include "mqtt_bus.h" MQTT_BUS::MQTT_BUS(QString topicName) : - CANConnection(topicName, "mqtt_client", CANCon::MQTT, 0, 0, 1, 4000, true), + CANConnection(topicName, "mqtt_client", CANCon::MQTT, 0, 0, false, 0, 1, 4000, true), mTimer(this) /*NB: set this as parent of timer to manage it from working thread */ { diff --git a/connections/newconnectiondialog.cpp b/connections/newconnectiondialog.cpp index 6f08fcf..85163e2 100644 --- a/connections/newconnectiondialog.cpp +++ b/connections/newconnectiondialog.cpp @@ -40,6 +40,10 @@ NewConnectionDialog::NewConnectionDialog(QVector* gvretips, QVectorcbSerialSpeed->setHidden(true); ui->lblCANSpeed->setHidden(true); ui->lblSerialSpeed->setHidden(true); + ui->cbCanFd->setHidden(true); + ui->cbDataRate->setHidden(true); + ui->lblDataRate->setHidden(true); + selectSerial(); qDebug() << "Was passed " << remoteDeviceIPGVRET->count() << " remote GVRET IPs"; @@ -89,6 +93,9 @@ void NewConnectionDialog::selectLawicel() ui->cbSerialSpeed->setHidden(false); ui->lblCANSpeed->setHidden(false); ui->lblSerialSpeed->setHidden(false); + ui->cbCanFd->setHidden(false); + ui->cbDataRate->setHidden(false); + ui->lblDataRate->setHidden(false); ui->cbPort->clear(); ports = QSerialPortInfo::availablePorts(); @@ -108,6 +115,13 @@ void NewConnectionDialog::selectLawicel() ui->cbCANSpeed->addItem("500000"); ui->cbCANSpeed->addItem("1000000"); } + if (ui->cbDataRate->count() == 0) + { + ui->cbDataRate->addItem("1000000"); + ui->cbDataRate->addItem("2000000"); + ui->cbDataRate->addItem("4000000"); + ui->cbDataRate->addItem("5000000"); + } if (ui->cbSerialSpeed->count() == 0) { ui->cbSerialSpeed->addItem("115200"); @@ -131,6 +145,9 @@ void NewConnectionDialog::selectSerial() ui->cbSerialSpeed->setHidden(true); ui->lblCANSpeed->setHidden(true); ui->lblSerialSpeed->setHidden(true); + ui->cbCanFd->setHidden(true); + ui->cbDataRate->setHidden(true); + ui->lblDataRate->setHidden(true); ui->cbPort->clear(); ports = QSerialPortInfo::availablePorts(); @@ -148,6 +165,9 @@ void NewConnectionDialog::selectSocketCan() ui->cbSerialSpeed->setHidden(true); ui->lblCANSpeed->setHidden(true); ui->lblSerialSpeed->setHidden(true); + ui->cbCanFd->setHidden(true); + ui->cbDataRate->setHidden(true); + ui->lblDataRate->setHidden(true); ui->cbDeviceType->clear(); QStringList plugins; @@ -167,6 +187,9 @@ void NewConnectionDialog::selectRemote() ui->cbSerialSpeed->setHidden(true); ui->lblCANSpeed->setHidden(true); ui->lblSerialSpeed->setHidden(true); + ui->cbCanFd->setHidden(true); + ui->cbDataRate->setHidden(true); + ui->lblDataRate->setHidden(true); ui->cbPort->clear(); foreach(QString pName, *remoteDeviceIPGVRET) @@ -185,6 +208,9 @@ void NewConnectionDialog::selectKayak() ui->cbSerialSpeed->setHidden(true); ui->lblCANSpeed->setHidden(true); ui->lblSerialSpeed->setHidden(true); + ui->cbCanFd->setHidden(true); + ui->cbDataRate->setHidden(true); + ui->lblDataRate->setHidden(true); ui->cbPort->clear(); foreach(QString pName, *remoteBusKayak) @@ -203,6 +229,9 @@ void NewConnectionDialog::selectMQTT() ui->cbSerialSpeed->setHidden(true); ui->lblCANSpeed->setHidden(true); ui->lblSerialSpeed->setHidden(true); + ui->cbCanFd->setHidden(true); + ui->cbDataRate->setHidden(true); + ui->lblDataRate->setHidden(true); ui->cbPort->clear(); } @@ -217,6 +246,9 @@ void NewConnectionDialog::selectCANserver() ui->cbSerialSpeed->setHidden(true); ui->lblCANSpeed->setHidden(true); ui->lblSerialSpeed->setHidden(true); + ui->cbCanFd->setHidden(true); + ui->cbDataRate->setHidden(true); + ui->lblDataRate->setHidden(true); ui->cbPort->clear(); } @@ -231,6 +263,9 @@ void NewConnectionDialog::selectCANlogserver() ui->cbSerialSpeed->setHidden(true); ui->lblCANSpeed->setHidden(true); ui->lblSerialSpeed->setHidden(true); + ui->cbCanFd->setHidden(true); + ui->cbDataRate->setHidden(true); + ui->lblDataRate->setHidden(true); ui->cbPort->clear(); } @@ -386,3 +421,21 @@ bool NewConnectionDialog::isSerialBusAvailable() if (QCanBus::instance()->plugins().count() > 0) return true; return false; } + +int NewConnectionDialog::getDataRate() +{ + if (getConnectionType() == CANCon::LAWICEL) + { + return ui->cbDataRate->currentText().toInt(); + } + else return 0; +} + +bool NewConnectionDialog::isCanFd() + { + if (getConnectionType() == CANCon::LAWICEL) + { + return ui->cbCanFd; + } + else return 0; + } diff --git a/connections/newconnectiondialog.h b/connections/newconnectiondialog.h index 95dd2b8..387a4fb 100644 --- a/connections/newconnectiondialog.h +++ b/connections/newconnectiondialog.h @@ -26,6 +26,8 @@ public: QString getDriverName(); int getSerialSpeed(); int getBusSpeed(); + bool isCanFd(); + int getDataRate(); public slots: void handleConnTypeChanged(); diff --git a/connections/serialbusconnection.cpp b/connections/serialbusconnection.cpp index a8809fd..a5ec860 100644 --- a/connections/serialbusconnection.cpp +++ b/connections/serialbusconnection.cpp @@ -12,7 +12,7 @@ /***********************************/ SerialBusConnection::SerialBusConnection(QString portName, QString driverName) : - CANConnection(portName, driverName, CANCon::SERIALBUS,0 ,0 ,1, 4000, true), + CANConnection(portName, driverName, CANCon::SERIALBUS,0 ,0, false, 0 ,1, 4000, true), mTimer(this) /*NB: set connection as parent of timer to manage it from working thread */ { } diff --git a/connections/socketcand.cpp b/connections/socketcand.cpp index 1467d01..83fb144 100644 --- a/connections/socketcand.cpp +++ b/connections/socketcand.cpp @@ -10,7 +10,7 @@ #include "socketcand.h" SocketCANd::SocketCANd(QString portName) : - CANConnection(portName, "kayak", CANCon::KAYAK, 0, 0, 1, 4000, true), + CANConnection(portName, "kayak", CANCon::KAYAK, 0, 0, false, 0, 1, 4000, true), mTimer(this) /*NB: set this as parent of timer to manage it from working thread */ { diff --git a/ui/connectionwindow.ui b/ui/connectionwindow.ui index 6dd573d..4f94395 100644 --- a/ui/connectionwindow.ui +++ b/ui/connectionwindow.ui @@ -104,7 +104,7 @@ - + Save Bus Settings @@ -121,6 +121,16 @@ + + + + + + + CAN FD Data Rate + + + diff --git a/ui/newconnectiondialog.ui b/ui/newconnectiondialog.ui index 46d9123..e459583 100644 --- a/ui/newconnectiondialog.ui +++ b/ui/newconnectiondialog.ui @@ -150,6 +150,23 @@ + + + + CAN-FD + + + + + + + CAN-FD data rate + + + + + +