diff --git a/CLX000CanBus.cpp b/CLX000CanBus.cpp index ad7cf27..bfb0e8f 100644 --- a/CLX000CanBus.cpp +++ b/CLX000CanBus.cpp @@ -9,12 +9,12 @@ QList CLX000CanBus::interfaces() { QList result; - static QString const description("CLX000"); + static QString const description(QStringLiteral("CLX000")); // Find all available USB-CDC devices. auto allAvailablePorts = QSerialPortInfo::availablePorts(); - for(auto const& portInfo: allAvailablePorts) { + for(auto const& portInfo: qAsConst(allAvailablePorts)) { // Remove all non-CDC ports. if(!portInfo.hasVendorIdentifier() || !portInfo.hasProductIdentifier()) { continue; @@ -31,12 +31,14 @@ QList CLX000CanBus::interfaces() { // Create new interface description for this. result.push_back( createDeviceInfo( + QStringLiteral("clx000can"), // eg. from plugin.json portInfo.portName(), portInfo.serialNumber(), description, - 0, - false, - false + QString(), // alias (empty) + 0, // channel + false, // isVirtual + false // isFlexibleDataRateCapable ) ); } @@ -94,7 +96,7 @@ void CLX000CanBus::attemptParse() { } -bool CLX000CanBus::attemptParseSequence(QByteArray sequence) { +bool CLX000CanBus::attemptParseSequence(const QByteArray &sequence) { QCanBusFrame frame; QByteArray destuffed; @@ -202,7 +204,7 @@ bool CLX000CanBus::packFrame(QCanBusFrame const& frame, QByteArray &packedFrame) /* Escape any 0x7E sequences */ packedFrame.append(0x07E); - for (char const& byteValue: payloadArray) { + for (char const& byteValue: qAsConst(payloadArray)) { if( byteValue == 0x7E ) { packedFrame.append(static_cast(0x7D)); packedFrame.append(static_cast(byteValue ^ 0b00100000) ); diff --git a/CLX000CanBus.h b/CLX000CanBus.h index b82e9fd..d06dd40 100644 --- a/CLX000CanBus.h +++ b/CLX000CanBus.h @@ -5,13 +5,14 @@ #include class CLX000CanBus : public QCanBusDevice { + Q_OBJECT public: static QList interfaces(); protected: QQueue queue; QVector frames; void attemptParse(); - bool attemptParseSequence(QByteArray sequence); + bool attemptParseSequence(const QByteArray &sequence); bool packFrame(QCanBusFrame const& frame, QByteArray &packedFrame); quint64 frameCount; }; diff --git a/CLX000CanBusUSB.cpp b/CLX000CanBusUSB.cpp index d3248d8..c766b01 100644 --- a/CLX000CanBusUSB.cpp +++ b/CLX000CanBusUSB.cpp @@ -4,14 +4,14 @@ #include #include -CLX000CanBusUSB::CLX000CanBusUSB(QString interface) : port(interface) { +CLX000CanBusUSB::CLX000CanBusUSB(const QString &interface) : port(interface) { port.setReadBufferSize(1024*1024*10); connect( &port, - SIGNAL(readyRead()), + &QIODevice::readyRead, this, - SLOT(dataAvailable()) + &CLX000CanBusUSB::dataAvailable ); queue.reserve(1024*1024); diff --git a/CLX000CanBusUSB.h b/CLX000CanBusUSB.h index c12cb41..60e0c92 100644 --- a/CLX000CanBusUSB.h +++ b/CLX000CanBusUSB.h @@ -8,7 +8,7 @@ class CLX000CanBusUSB : public CLX000CanBus { Q_OBJECT public: - explicit CLX000CanBusUSB(QString interface); + explicit CLX000CanBusUSB(const QString &interface); bool open() override; void close() override; diff --git a/CLX000Plugin.h b/CLX000Plugin.h index b811750..fe5bd0b 100644 --- a/CLX000Plugin.h +++ b/CLX000Plugin.h @@ -4,13 +4,13 @@ #include #include #include -#include +#include -class CLX000CanBusPlugin : public QObject, public QCanBusFactoryV2 +class CLX000CanBusPlugin : public QObject, public QCanBusFactory { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactory" FILE "plugin.json") - Q_INTERFACES(QCanBusFactoryV2) + Q_INTERFACES(QCanBusFactory) public: QList availableDevices(QString *errorMessage) const override; diff --git a/CMakeLists.txt b/CMakeLists.txt index 380f461..fd95470 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,18 @@ -cmake_minimum_required(VERSION 3.15) -project(clx000canbus) +cmake_minimum_required(VERSION 3.16) +project(clx000canbus LANGUAGES CXX) set(CMAKE_VERBOSE_MAKEFILE ON) -enable_language(CXX) - set(RELEASE_NAME clx000canbus) # Find required Qt dependencies. -set(REQUIRED_QT5_COMPONENTS +set(REQUIRED_QT_COMPONENTS Core SerialBus SerialPort - ) +) -find_package(Qt5 COMPONENTS ${REQUIRED_QT5_COMPONENTS} REQUIRED) +find_package(Qt6 COMPONENTS ${REQUIRED_QT_COMPONENTS} REQUIRED) # All core source and header files, sorted alphabetically. set(SOURCE_FILES @@ -22,18 +20,18 @@ set(SOURCE_FILES CLX000CanBusUSB.cpp CLX000Plugin.cpp CRC16.cpp - ) +) set(HEADERS_FILES CLX000CanBus.h CLX000CanBusUSB.h CLX000Plugin.h CRC16.h - ) +) set(OTHER_FILES plugin.json - ) +) add_library(${RELEASE_NAME} MODULE ${SOURCE_FILES} ${HEADERS_FILES} ${OTHER_FILES}) @@ -41,12 +39,12 @@ add_library(${RELEASE_NAME} MODULE ${SOURCE_FILES} ${HEADERS_FILES} ${OTHER_FILE set_property(TARGET ${RELEASE_NAME} PROPERTY AUTOMOC ON) # CXX standard configuration. -set_property(TARGET ${RELEASE_NAME} PROPERTY CXX_STANDARD 11) +set_property(TARGET ${RELEASE_NAME} PROPERTY CXX_STANDARD 17) set_property(TARGET ${RELEASE_NAME} PROPERTY CXX_STANDARD_REQUIRED YES) set_property(TARGET ${RELEASE_NAME} PROPERTY CXX_EXTENSIONS NO) # General Qt configuration. -if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") +if(CMAKE_BUILD_TYPE STREQUAL Debug) add_compile_definitions(${RELEASE_NAME} QT_DEBUG) else() add_compile_definitions(${RELEASE_NAME} QT_NO_DEBUG) @@ -54,10 +52,10 @@ else() endif() # Link against all required Qt modules. -foreach(QT_COMPONENT ${REQUIRED_QT5_COMPONENTS}) - target_link_libraries(${RELEASE_NAME} "Qt5::${QT_COMPONENT}") +foreach(QT_COMPONENT ${REQUIRED_QT_COMPONENTS}) + target_link_libraries(${RELEASE_NAME} Qt6::${QT_COMPONENT}) endforeach() add_custom_command(TARGET ${RELEASE_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/plugins/canbus - ) +) diff --git a/CRC16.cpp b/CRC16.cpp index 74be6a5..2d77052 100644 --- a/CRC16.cpp +++ b/CRC16.cpp @@ -2,7 +2,7 @@ #include "CRC16.h" -uint16_t calculateCRC16(QByteArray data, CRC16Type crc16Type) { +uint16_t calculateCRC16(const QByteArray &data, CRC16Type crc16Type) { uint16_t const initial = 0x0000u; uint16_t const polynomial = 0xA001; uint16_t const final = 0x0000; diff --git a/CRC16.h b/CRC16.h index 7f89436..2100bbb 100644 --- a/CRC16.h +++ b/CRC16.h @@ -8,4 +8,4 @@ enum struct CRC16Type { CRC_16_IBM }; -uint16_t calculateCRC16(QByteArray data, CRC16Type crc16Type = CRC16Type::CRC_16_IBM); +uint16_t calculateCRC16(const QByteArray &data, CRC16Type crc16Type = CRC16Type::CRC_16_IBM);