summaryrefslogtreecommitdiffstats
path: root/src/plugins/canbus/peakcan
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/canbus/peakcan')
-rw-r--r--src/plugins/canbus/peakcan/peakcan.pro10
-rw-r--r--src/plugins/canbus/peakcan/peakcanbackend.cpp85
-rw-r--r--src/plugins/canbus/peakcan/peakcanbackend_p.h14
3 files changed, 54 insertions, 55 deletions
diff --git a/src/plugins/canbus/peakcan/peakcan.pro b/src/plugins/canbus/peakcan/peakcan.pro
index e868f39..bcea9ac 100644
--- a/src/plugins/canbus/peakcan/peakcan.pro
+++ b/src/plugins/canbus/peakcan/peakcan.pro
@@ -2,10 +2,8 @@ TARGET = qtpeakcanbus
QT = core-private serialbus
-PUBLIC_HEADERS += \
- peakcanbackend.h
-
-PRIVATE_HEADERS += \
+HEADERS += \
+ peakcanbackend.h \
peakcanbackend_p.h \
peakcan_symbols_p.h
@@ -13,9 +11,7 @@ SOURCES += \
main.cpp \
peakcanbackend.cpp
-OTHER_FILES = plugin.json
-
-HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
+DISTFILES = plugin.json
PLUGIN_TYPE = canbus
PLUGIN_EXTENDS = serialbus
diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp
index 9598003..3f5d2c0 100644
--- a/src/plugins/canbus/peakcan/peakcanbackend.cpp
+++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp
@@ -73,21 +73,22 @@ bool PeakCanBackend::canCreate(QString *errorReason)
}
#if defined(Q_OS_WIN32)
-class IncomingEventNotifier : public QWinEventNotifier
+class ReadNotifier : public QWinEventNotifier
{
+ // no Q_OBJECT macro!
public:
- explicit IncomingEventNotifier(PeakCanBackendPrivate *d, QObject *parent)
+ explicit ReadNotifier(PeakCanBackendPrivate *d, QObject *parent)
: QWinEventNotifier(parent)
, dptr(d)
{
- setHandle(dptr->incomingEventHandle);
+ setHandle(dptr->readHandle);
}
protected:
bool event(QEvent *e) override
{
if (e->type() == QEvent::WinEventAct) {
- dptr->canReadNotification();
+ dptr->startRead();
return true;
}
return QWinEventNotifier::event(e);
@@ -97,11 +98,12 @@ private:
PeakCanBackendPrivate *dptr;
};
#else
-class IncomingEventNotifier : public QSocketNotifier
+class ReadNotifier : public QSocketNotifier
{
+ // no Q_OBJECT macro!
public:
- explicit IncomingEventNotifier(PeakCanBackendPrivate *d, QObject *parent)
- : QSocketNotifier(d->incomingEventHandle, QSocketNotifier::Read, parent)
+ explicit ReadNotifier(PeakCanBackendPrivate *d, QObject *parent)
+ : QSocketNotifier(d->readHandle, QSocketNotifier::Read, parent)
, dptr(d)
{
}
@@ -110,7 +112,7 @@ protected:
bool event(QEvent *e) override
{
if (e->type() == QEvent::SockAct) {
- dptr->canReadNotification();
+ dptr->startRead();
return true;
}
return QSocketNotifier::event(e);
@@ -121,10 +123,11 @@ private:
};
#endif
-class OutgoingEventNotifier : public QTimer
+class WriteNotifier : public QTimer
{
+ // no Q_OBJECT macro!
public:
- OutgoingEventNotifier(PeakCanBackendPrivate *d, QObject *parent)
+ WriteNotifier(PeakCanBackendPrivate *d, QObject *parent)
: QTimer(parent)
, dptr(d)
{
@@ -134,7 +137,7 @@ protected:
void timerEvent(QTimerEvent *e) override
{
if (e->timerId() == timerId()) {
- dptr->canWriteNotification();
+ dptr->startWrite();
return;
}
QTimer::timerEvent(e);
@@ -148,12 +151,12 @@ PeakCanBackendPrivate::PeakCanBackendPrivate(PeakCanBackend *q)
: q_ptr(q)
, isOpen(false)
, channelIndex(PCAN_NONEBUS)
- , outgoingEventNotifier(nullptr)
- , incomingEventNotifier(nullptr)
+ , writeNotifier(nullptr)
+ , readNotifier(nullptr)
#if defined(Q_OS_WIN32)
- , incomingEventHandle(INVALID_HANDLE_VALUE)
+ , readHandle(INVALID_HANDLE_VALUE)
#else
- , incomingEventHandle(-1)
+ , readHandle(-1)
#endif
{
}
@@ -229,9 +232,9 @@ void PeakCanBackendPrivate::close()
enableWriteNotification(false);
releaseReadNotification();
- if (outgoingEventNotifier) {
- delete outgoingEventNotifier;
- outgoingEventNotifier = nullptr;
+ if (writeNotifier) {
+ delete writeNotifier;
+ writeNotifier = nullptr;
}
const TPCANStatus st = ::CAN_Uninitialize(channelIndex);
@@ -318,21 +321,21 @@ void PeakCanBackendPrivate::enableWriteNotification(bool enable)
{
Q_Q(PeakCanBackend);
- if (outgoingEventNotifier) {
+ if (writeNotifier) {
if (enable) {
- if (!outgoingEventNotifier->isActive())
- outgoingEventNotifier->start();
+ if (!writeNotifier->isActive())
+ writeNotifier->start();
} else {
- outgoingEventNotifier->stop();
+ writeNotifier->stop();
}
} else if (enable) {
- outgoingEventNotifier = new OutgoingEventNotifier(this, q);
- outgoingEventNotifier->setInterval(0);
- outgoingEventNotifier->start();
+ writeNotifier = new WriteNotifier(this, q);
+ writeNotifier->setInterval(0);
+ writeNotifier->start();
}
}
-void PeakCanBackendPrivate::canWriteNotification()
+void PeakCanBackendPrivate::startWrite()
{
Q_Q(PeakCanBackend);
@@ -371,9 +374,9 @@ bool PeakCanBackendPrivate::acquireReadNotification()
Q_Q(PeakCanBackend);
#if defined(Q_OS_WIN32)
- if (incomingEventHandle == INVALID_HANDLE_VALUE) {
- incomingEventHandle = ::CreateEvent(nullptr, FALSE, FALSE, nullptr);
- if (!incomingEventHandle) {
+ if (readHandle == INVALID_HANDLE_VALUE) {
+ readHandle = ::CreateEvent(nullptr, FALSE, FALSE, nullptr);
+ if (!readHandle) {
q->setError(qt_error_string(::GetLastError()), QCanBusDevice::ReadError);
return false;
}
@@ -381,15 +384,15 @@ bool PeakCanBackendPrivate::acquireReadNotification()
#endif
const TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT,
- &incomingEventHandle, sizeof(incomingEventHandle));
+ &readHandle, sizeof(readHandle));
if (st != PCAN_ERROR_OK) {
q->setError(systemErrorString(st), QCanBusDevice::ReadError);
return false;
}
- if (!incomingEventNotifier) {
- incomingEventNotifier = new IncomingEventNotifier(this, q);
- incomingEventNotifier->setEnabled(true);
+ if (!readNotifier) {
+ readNotifier = new ReadNotifier(this, q);
+ readNotifier->setEnabled(true);
}
return true;
@@ -404,23 +407,23 @@ void PeakCanBackendPrivate::releaseReadNotification()
if (st != PCAN_ERROR_OK)
q->setError(systemErrorString(st), QCanBusDevice::ConnectionError);
- if (incomingEventNotifier) {
- delete incomingEventNotifier;
- incomingEventNotifier = nullptr;
+ if (readNotifier) {
+ delete readNotifier;
+ readNotifier = nullptr;
}
#if defined(Q_OS_WIN32)
- if (incomingEventHandle && (incomingEventHandle != INVALID_HANDLE_VALUE)) {
- if (!::CloseHandle(incomingEventHandle))
+ if (readHandle && (readHandle != INVALID_HANDLE_VALUE)) {
+ if (!::CloseHandle(readHandle))
q->setError(qt_error_string(::GetLastError()), QCanBusDevice::ConnectionError);
- incomingEventHandle = INVALID_HANDLE_VALUE;
+ readHandle = INVALID_HANDLE_VALUE;
}
#else
- incomingEventHandle = -1;
+ readHandle = -1;
#endif
}
-void PeakCanBackendPrivate::canReadNotification()
+void PeakCanBackendPrivate::startRead()
{
Q_Q(PeakCanBackend);
diff --git a/src/plugins/canbus/peakcan/peakcanbackend_p.h b/src/plugins/canbus/peakcan/peakcanbackend_p.h
index f8b848c..88f39f5 100644
--- a/src/plugins/canbus/peakcan/peakcanbackend_p.h
+++ b/src/plugins/canbus/peakcan/peakcanbackend_p.h
@@ -76,24 +76,24 @@ public:
void setupDefaultConfigurations();
QString systemErrorString(int errorCode);
void enableWriteNotification(bool enable);
- void canWriteNotification();
+ void startWrite();
bool acquireReadNotification();
void releaseReadNotification();
- void canReadNotification();
+ void startRead();
bool verifyBitRate(int bitrate);
PeakCanBackend * const q_ptr;
bool isOpen;
int channelIndex;
- QTimer *outgoingEventNotifier;
+ QTimer *writeNotifier;
#if defined(Q_OS_WIN32)
- QWinEventNotifier *incomingEventNotifier;
- HANDLE incomingEventHandle;
+ QWinEventNotifier *readNotifier;
+ HANDLE readHandle;
#else
- QSocketNotifier *incomingEventNotifier;
- int incomingEventHandle;
+ QSocketNotifier *readNotifier;
+ int readHandle;
#endif
};