diff options
Diffstat (limited to 'src/plugins/canbus/peakcan')
-rw-r--r-- | src/plugins/canbus/peakcan/main.cpp | 6 | ||||
-rw-r--r-- | src/plugins/canbus/peakcan/peakcan_symbols_p.h | 20 | ||||
-rw-r--r-- | src/plugins/canbus/peakcan/peakcanbackend.cpp | 37 | ||||
-rw-r--r-- | src/plugins/canbus/peakcan/peakcanbackend_p.h | 4 |
4 files changed, 32 insertions, 35 deletions
diff --git a/src/plugins/canbus/peakcan/main.cpp b/src/plugins/canbus/peakcan/main.cpp index 7444f6d..8ab1b99 100644 --- a/src/plugins/canbus/peakcan/main.cpp +++ b/src/plugins/canbus/peakcan/main.cpp @@ -41,8 +41,12 @@ #include <QtSerialBus/qcanbusdevice.h> #include <QtSerialBus/qcanbusfactory.h> +#include <QtCore/qloggingcategory.h> + QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(QT_CANBUS_PLUGINS_PEAKCAN, "qt.canbus.plugins.peakcan") + class PeakCanBusPlugin : public QObject, public QCanBusFactoryV2 { Q_OBJECT @@ -62,7 +66,7 @@ public: { QString errorReason; if (!PeakCanBackend::canCreate(&errorReason)) { - qWarning("%ls", qUtf16Printable(errorReason)); + qCWarning(QT_CANBUS_PLUGINS_PEAKCAN, "%ls", qUtf16Printable(errorReason)); if (errorMessage) *errorMessage = errorReason; return nullptr; diff --git a/src/plugins/canbus/peakcan/peakcan_symbols_p.h b/src/plugins/canbus/peakcan/peakcan_symbols_p.h index 7c91750..d94a7ec 100644 --- a/src/plugins/canbus/peakcan/peakcan_symbols_p.h +++ b/src/plugins/canbus/peakcan/peakcan_symbols_p.h @@ -49,24 +49,15 @@ // We mean it. // -#ifdef LINK_LIBPCANBASIC - -extern "C" -{ -#include <pcanbasic.h> -} - -#else - #include <QtCore/qlibrary.h> #include <QtCore/qstring.h> #include <QtCore/qdebug.h> #ifdef Q_OS_WIN32 -#include <windows.h> -#define DRV_CALLBACK_TYPE WINAPI +# include <windows.h> +# define DRV_CALLBACK_TYPE WINAPI #else -#define DRV_CALLBACK_TYPE +# define DRV_CALLBACK_TYPE #endif // Currently defined and supported PCAN channels @@ -234,6 +225,7 @@ extern "C" #define PCAN_BAUD_20K 0x532F // 20 kBit/s #define PCAN_BAUD_10K 0x672F // 10 kBit/s #define PCAN_BAUD_5K 0x7F7F // 5 kBit/s +#define PCAN_BAUD_INVALID 0xFFFF // unknown or invalid baudrate #define PCAN_TYPE_ISA 0x01 // PCAN-ISA 82C200 #define PCAN_TYPE_ISA_SJA 0x09 // PCAN-ISA SJA1000 @@ -277,7 +269,7 @@ typedef struct tagTPCANTimestamp static fp_##symbolName symbolName; #define RESOLVE_SYMBOL(symbolName) \ - symbolName = (fp_##symbolName)pcanLibrary->resolve(#symbolName); \ + symbolName = reinterpret_cast<fp_##symbolName>(pcanLibrary->resolve(#symbolName)); \ if (!symbolName) \ return false; @@ -314,6 +306,4 @@ inline bool resolveSymbols(QLibrary *pcanLibrary) return true; } -#endif - #endif // PEAKCAN_SYMBOLS_P_H diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index 8f97f5d..5460951 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -43,17 +43,20 @@ #include <QtCore/qtimer.h> #include <QtCore/qcoreevent.h> +#include <QtCore/qloggingcategory.h> #include <algorithm> #ifdef Q_OS_WIN32 -#include <QtCore/qwineventnotifier.h> +# include <QtCore/qwineventnotifier.h> #else -#include <QtCore/qsocketnotifier.h> +# include <QtCore/qsocketnotifier.h> #endif QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(QT_CANBUS_PLUGINS_PEAKCAN) + #ifndef LINK_LIBPCANBASIC Q_GLOBAL_STATIC(QLibrary, pcanLibrary) #endif @@ -76,7 +79,7 @@ struct PcanChannel{ char name[6]; TPCANHandle index; }; -PcanChannel pcanChannels[] = { +static const PcanChannel pcanChannels[] = { { "usb0", PCAN_USBBUS1 }, { "usb1", PCAN_USBBUS2 }, { "usb2", PCAN_USBBUS3 }, @@ -154,7 +157,7 @@ protected: } private: - PeakCanBackendPrivate *dptr; + PeakCanBackendPrivate * const dptr; }; #else class ReadNotifier : public QSocketNotifier @@ -178,7 +181,7 @@ protected: } private: - PeakCanBackendPrivate *dptr; + PeakCanBackendPrivate * const dptr; }; #endif @@ -203,7 +206,7 @@ protected: } private: - PeakCanBackendPrivate *dptr; + PeakCanBackendPrivate * const dptr; }; PeakCanBackendPrivate::PeakCanBackendPrivate(PeakCanBackend *q) @@ -214,7 +217,7 @@ PeakCanBackendPrivate::PeakCanBackendPrivate(PeakCanBackend *q) struct BitrateItem { int bitrate; - int code; + TPCANBaudrate code; }; struct BitrateLessFunctor @@ -225,7 +228,7 @@ struct BitrateLessFunctor } }; -static int bitrateCodeFromBitrate(int bitrate) +static TPCANBaudrate bitrateCodeFromBitrate(int bitrate) { static const BitrateItem bitratetable[] = { { 5000, PCAN_BAUD_5K }, @@ -248,7 +251,7 @@ static int bitrateCodeFromBitrate(int bitrate) const BitrateItem item = { bitrate , 0 }; const BitrateItem *where = std::lower_bound(bitratetable, endtable, item, BitrateLessFunctor()); - return where != endtable ? where->code : -1; + return where != endtable ? where->code : PCAN_BAUD_INVALID; } bool PeakCanBackendPrivate::open() @@ -256,7 +259,7 @@ bool PeakCanBackendPrivate::open() Q_Q(PeakCanBackend); const int bitrate = q->configurationParameter(QCanBusDevice::BitRateKey).toInt(); - const int bitrateCode = bitrateCodeFromBitrate(bitrate); + const TPCANBaudrate bitrateCode = bitrateCodeFromBitrate(bitrate); const TPCANStatus st = ::CAN_Initialize(channelIndex, bitrateCode, 0, 0, 0); if (Q_UNLIKELY(st != PCAN_ERROR_OK)) { @@ -359,7 +362,7 @@ void PeakCanBackendPrivate::setupDefaultConfigurations() q->setConfigurationParameter(QCanBusDevice::BitRateKey, 500000); } -QString PeakCanBackendPrivate::systemErrorString(int errorCode) +QString PeakCanBackendPrivate::systemErrorString(TPCANStatus errorCode) { QByteArray buffer(256, 0); if (Q_UNLIKELY(::CAN_GetErrorText(errorCode, 0, buffer.data()) != PCAN_ERROR_OK)) @@ -383,7 +386,7 @@ void PeakCanBackendPrivate::startWrite() ::memset(&message, 0, sizeof(message)); message.ID = frame.frameId(); - message.LEN = payload.size(); + message.LEN = static_cast<quint8>(payload.size()); message.MSGTYPE = frame.hasExtendedFrameFormat() ? PCAN_MESSAGE_EXTENDED : PCAN_MESSAGE_STANDARD; if (frame.frameType() == QCanBusFrame::RemoteRequestFrame) @@ -428,7 +431,7 @@ void PeakCanBackendPrivate::startRead() QCanBusFrame frame(message.ID, QByteArray(reinterpret_cast<const char *>(message.DATA), int(message.LEN))); const quint64 millis = timestamp.millis + Q_UINT64_C(0xFFFFFFFF) * timestamp.millis_overflow; const quint64 micros = Q_UINT64_C(1000) * millis + timestamp.micros; - frame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(micros)); + frame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(static_cast<qint64>(micros))); frame.setExtendedFrameFormat(message.MSGTYPE & PCAN_MESSAGE_EXTENDED); frame.setFrameType((message.MSGTYPE & PCAN_MESSAGE_RTR) ? QCanBusFrame::RemoteRequestFrame : QCanBusFrame::DataFrame); @@ -448,7 +451,7 @@ bool PeakCanBackendPrivate::verifyBitRate(int bitrate) return false; } - if (Q_UNLIKELY(bitrateCodeFromBitrate(bitrate) == -1)) { + if (Q_UNLIKELY(bitrateCodeFromBitrate(bitrate) == PCAN_BAUD_INVALID)) { q->setError(PeakCanBackend::tr("Unsupported bitrate value"), QCanBusDevice::ConfigurationError); return false; @@ -494,8 +497,8 @@ bool PeakCanBackend::open() const QVariant param = configurationParameter(key); const bool success = d->setConfigurationParameter(key, param); if (Q_UNLIKELY(!success)) { - qWarning("Cannot apply parameter: %d with value: %ls.", - key, qUtf16Printable(param.toString())); + qCWarning(QT_CANBUS_PLUGINS_PEAKCAN, "Cannot apply parameter: %d with value: %ls.", + key, qUtf16Printable(param.toString())); } } } @@ -541,7 +544,7 @@ bool PeakCanBackend::writeFrame(const QCanBusFrame &newData) } // CAN FD frame format not implemented at this stage - if (Q_UNLIKELY(newData.payload().size() > 8)) { + if (Q_UNLIKELY(newData.hasFlexibleDataRateFormat())) { setError(tr("CAN FD frame format not supported."), QCanBusDevice::WriteError); return false; } diff --git a/src/plugins/canbus/peakcan/peakcanbackend_p.h b/src/plugins/canbus/peakcan/peakcanbackend_p.h index a6c6458..2dc8197 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend_p.h +++ b/src/plugins/canbus/peakcan/peakcanbackend_p.h @@ -75,7 +75,7 @@ public: bool setConfigurationParameter(int key, const QVariant &value); void setupChannel(const QByteArray &interfaceName); void setupDefaultConfigurations(); - QString systemErrorString(int errorCode); + QString systemErrorString(TPCANStatus errorCode); void startWrite(); void startRead(); bool verifyBitRate(int bitrate); @@ -83,7 +83,7 @@ public: PeakCanBackend * const q_ptr; bool isOpen = false; - int channelIndex = PCAN_NONEBUS; + TPCANHandle channelIndex = PCAN_NONEBUS; QTimer *writeNotifier = nullptr; #if defined(Q_OS_WIN32) |