1#ifndef CANDEVICEQT_H_JYBV8GIQ
2#define CANDEVICEQT_H_JYBV8GIQ
5#include <QtSerialBus/QCanBus>
6#include <QtSerialBus/QCanBusDevice>
21 QObject::connect(_device, &QCanBusDevice::framesWritten, cb);
23 cds_error(
"Calling connect on null CAN device");
24 throw std::runtime_error(
"Calling connect on null CAN device");
31 QObject::connect(_device, &QCanBusDevice::framesReceived, cb);
33 cds_error(
"Calling connect on null CAN device");
34 throw std::runtime_error(
"Calling connect on null CAN device");
41 QObject::connect(_device, &QCanBusDevice::errorOccurred, cb);
43 cds_error(
"Calling connect on null CAN device");
44 throw std::runtime_error(
"Calling connect on null CAN device");
48 virtual bool init(
const QString& backend,
const QString& iface)
override
51 _device = QCanBus::instance()->createDevice(backend.toUtf8(), iface);
59 if (_parent && _parent->thread()) {
60 _device->moveToThread(_parent->thread());
61 _device->setParent(_parent);
67 virtual bool writeFrame(
const QCanBusFrame& frame)
override
70 return _device->writeFrame(frame);
72 cds_error(
"candevice is null. Call init first!");
73 throw std::runtime_error(
"candevice is null. Call init first!");
82 return _device->connectDevice();
84 cds_error(
"candevice is null. Call init first!");
85 throw std::runtime_error(
"candevice is null. Call init first!");
91 return _device->framesAvailable();
93 cds_error(
"candevice is null. Call init first!");
94 throw std::runtime_error(
"candevice is null. Call init first!");
101 return _device->readFrame();
103 cds_error(
"candevice is null. Call init first!");
104 throw std::runtime_error(
"candevice is null. Call init first!");
111 return _device->disconnectDevice();
113 cds_error(
"candevice is null. Call init first!");
114 throw std::runtime_error(
"candevice is null. Call init first!");
121 _device->disconnect();
123 cds_error(
"candevice is null. Call init first!");
124 throw std::runtime_error(
"candevice is null. Call init first!");
131 _device->setConfigurationParameter(key, value);
133 cds_error(
"candevice is null. Call init first!");
134 throw std::runtime_error(
"candevice is null. Call init first!");
139 QCanBusDevice* _device{
nullptr };
140 QObject* _parent{
nullptr };
#define cds_error(fmt,...)
Definition log.h:21
Definition candeviceinterface.h:8
std::function< void()> framesReceived_t
Definition candeviceinterface.h:12
std::function< void(int)> errorOccurred_t
Definition candeviceinterface.h:13
std::function< void(qint64)> framesWritten_t
Definition candeviceinterface.h:11
Definition candeviceqt.h:9
virtual QCanBusFrame readFrame() override
Definition candeviceqt.h:98
virtual void setParent(QObject *parent) override
Definition candeviceqt.h:13
virtual bool connectDevice() override
Definition candeviceqt.h:79
virtual void setErrorOccurredCbk(const errorOccurred_t &cb) override
Definition candeviceqt.h:38
virtual void disconnectDevice() override
Definition candeviceqt.h:108
virtual void setFramesWrittenCbk(const framesWritten_t &cb) override
Definition candeviceqt.h:18
virtual void setFramesReceivedCbk(const framesReceived_t &cb) override
Definition candeviceqt.h:28
virtual bool writeFrame(const QCanBusFrame &frame) override
Definition candeviceqt.h:67
virtual void clearCallbacks() override
Definition candeviceqt.h:118
virtual bool init(const QString &backend, const QString &iface) override
Definition candeviceqt.h:48
virtual void setConfigurationParameter(int key, const QVariant &value) override
Definition candeviceqt.h:128
virtual qint64 framesAvailable() override
Definition candeviceqt.h:88