summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf3
-rw-r--r--TODO11
-rw-r--r--config.tests/socketcan/main.cpp44
-rw-r--r--config.tests/socketcan/socketcan.pro4
-rw-r--r--config.tests/socketcan_fd/main.cpp44
-rw-r--r--config.tests/socketcan_fd/socketcan_fd.pro4
-rw-r--r--example/graphical.pro11
-rw-r--r--example/main.cpp47
-rw-r--r--example/mainwindow.cpp395
-rw-r--r--example/mainwindow.h83
-rw-r--r--example/mainwindow.ui270
-rw-r--r--qtserialbus.pro14
-rw-r--r--src/plugins/can/can.pro16
-rw-r--r--src/plugins/can/main.cpp78
-rw-r--r--src/plugins/can/plugin.json1
-rw-r--r--src/plugins/can/socketcanbackend.cpp240
-rw-r--r--src/plugins/can/socketcanbackend.h73
-rw-r--r--src/plugins/generic/dummybackend.cpp100
-rw-r--r--src/plugins/generic/dummybackend.h68
-rw-r--r--src/plugins/generic/generic.pro16
-rw-r--r--src/plugins/generic/main.cpp74
-rw-r--r--src/plugins/generic/plugin.json1
-rw-r--r--src/plugins/plugins.pro5
-rw-r--r--src/serialbus/doc/qtserialbus.qdocconf11
-rw-r--r--src/serialbus/doc/src/qtserialbus.qdoc82
-rw-r--r--src/serialbus/qbusdummydevice.cpp47
-rw-r--r--src/serialbus/qbusdummydevice.h62
-rw-r--r--src/serialbus/qcanbusdevice.cpp177
-rw-r--r--src/serialbus/qcanbusdevice.h71
-rw-r--r--src/serialbus/qcanbusdevice_p.h77
-rw-r--r--src/serialbus/qcanframe.h85
-rw-r--r--src/serialbus/qserialbus.cpp145
-rw-r--r--src/serialbus/qserialbus.h88
-rw-r--r--src/serialbus/qserialbusbackend.h73
-rw-r--r--src/serialbus/qserialbusdevice.cpp69
-rw-r--r--src/serialbus/qserialbusdevice.h66
-rw-r--r--src/serialbus/qserialbusglobal.h56
-rw-r--r--src/serialbus/qserialbusplugininterface.h58
-rw-r--r--src/serialbus/serialbus.pro30
-rw-r--r--src/src.pro11
-rw-r--r--sync.profile7
-rw-r--r--tests/auto/auto.pro5
-rw-r--r--tests/auto/cmake/CMakeLists.txt14
-rw-r--r--tests/auto/cmake/cmake.pro7
-rw-r--r--tests/auto/qcanbusdevice/qcanbusdevice.pro7
-rw-r--r--tests/auto/qcanbusdevice/tst_qcanbusdevice.cpp132
-rw-r--r--tests/auto/qcanframe/qcanframe.pro7
-rw-r--r--tests/auto/qcanframe/tst_qcanframe.cpp107
-rw-r--r--tests/auto/qserialbus/qserialbus.pro9
-rw-r--r--tests/auto/qserialbus/tst_qserialbus.cpp84
-rw-r--r--tests/tests.pro2
51 files changed, 3191 insertions, 0 deletions
diff --git a/.qmake.conf b/.qmake.conf
new file mode 100644
index 0000000..66a0241
--- /dev/null
+++ b/.qmake.conf
@@ -0,0 +1,3 @@
+load(qt_build_config)
+
+MODULE_VERSION = 5.6.0
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..9a53f77
--- /dev/null
+++ b/TODO
@@ -0,0 +1,11 @@
+Connect and Disconnect methods should be implemented to QSerialBusBackend and all the inherited classes, currently connection happens at the constructor of backend. Method for asking connection state and proper signaling should be added too.
+
+Improve error reporting for SocketCanBackend connect.
+
+Documentation should be done properly for everything.
+
+Check d pointer pattern with qserialbus / qserialbusdevice / qcanbusdevice
+
+Example app should be cleaned up. It is bit too convoluted because of iterative implementation method. Also defined flags from socket CAN header should not be used.
+
+QSerialBusBackend interface should be revised for naming and functionality.
diff --git a/config.tests/socketcan/main.cpp b/config.tests/socketcan/main.cpp
new file mode 100644
index 0000000..b620d42
--- /dev/null
+++ b/config.tests/socketcan/main.cpp
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <linux/can.h>
+#include <linux/can/raw.h>
+
+int main()
+{
+ can_frame frame;
+ return 0;
+}
+
diff --git a/config.tests/socketcan/socketcan.pro b/config.tests/socketcan/socketcan.pro
new file mode 100644
index 0000000..104ea1e
--- /dev/null
+++ b/config.tests/socketcan/socketcan.pro
@@ -0,0 +1,4 @@
+TEMPLATE = app
+
+SOURCES += main.cpp
+
diff --git a/config.tests/socketcan_fd/main.cpp b/config.tests/socketcan_fd/main.cpp
new file mode 100644
index 0000000..71d0cae
--- /dev/null
+++ b/config.tests/socketcan_fd/main.cpp
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <linux/can.h>
+#include <linux/can/raw.h>
+
+int main()
+{
+ canfd_frame frame;
+ return 0;
+}
+
diff --git a/config.tests/socketcan_fd/socketcan_fd.pro b/config.tests/socketcan_fd/socketcan_fd.pro
new file mode 100644
index 0000000..104ea1e
--- /dev/null
+++ b/config.tests/socketcan_fd/socketcan_fd.pro
@@ -0,0 +1,4 @@
+TEMPLATE = app
+
+SOURCES += main.cpp
+
diff --git a/example/graphical.pro b/example/graphical.pro
new file mode 100644
index 0000000..0a47077
--- /dev/null
+++ b/example/graphical.pro
@@ -0,0 +1,11 @@
+QT += core gui serialbus widgets
+
+TARGET = graphical
+TEMPLATE = app
+
+SOURCES += main.cpp\
+ mainwindow.cpp \
+
+HEADERS += mainwindow.h \
+
+FORMS += mainwindow.ui
diff --git a/example/main.cpp b/example/main.cpp
new file mode 100644
index 0000000..bcdc43c
--- /dev/null
+++ b/example/main.cpp
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+
+ return a.exec();
+}
diff --git a/example/mainwindow.cpp b/example/mainwindow.cpp
new file mode 100644
index 0000000..8ca9c96
--- /dev/null
+++ b/example/mainwindow.cpp
@@ -0,0 +1,395 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <QtSerialBus>
+#include <QCanFrame>
+
+#include <QtCore/qbytearray.h>
+#include <QtCore/qvariant.h>
+#include <QtCore/qdebug.h>
+
+#include <iostream>
+
+#include <linux/can.h>
+#include <linux/can/error.h>
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow),
+ currentDevice(0)
+{
+ ui->setupUi(this);
+ init();
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::init()
+{
+ b = QSerialBus::instance();
+ if (!b)
+ return;
+
+ QList<QByteArray> plugins = b->plugins();
+ for (int i = 0; i < plugins.size(); i++)
+ {
+ backends.insert(i, b->createBackend(plugins.at(i), "SocketCAN", "vcan1"));
+ ui->comboBox->insertItem(i, plugins.at(i));
+
+ if (plugins.at(i) == "can") {
+ canDevice = new QCanBusDevice(backends.at(i), this);
+ if (!canDevice)
+ return;
+ canDevice->open(QIODevice::ReadWrite);
+ /*QList<QVariant> var;
+ QHash<QString, QVariant> hash;
+ hash.insert("FilterId", 1);
+ hash.insert("CanMask", CAN_EFF_MASK);
+ var.append(hash);
+ canDevice->setConfiguration(QPair<QString, QVariant>("CanFilter", var));*/ //NOTE: Filtering example
+ connect(canDevice.data(), &QCanBusDevice::readyRead, this, &MainWindow::checkMessages);
+ } else if (plugins.at(i) == "dummy") {
+ dummyDevice = new QBusDummyDevice(backends.at(i), this);
+ if (!dummyDevice)
+ return;
+ dummyDevice->open(QIODevice::ReadWrite);
+ connect(dummyDevice.data(), &QBusDummyDevice::readyRead, this, &MainWindow::checkDummyMessages);
+ }
+ }
+ on_connectButton_clicked(); //initialize plugin selection
+}
+
+void MainWindow::checkDummyMessages()
+{
+ if (!dummyDevice) {
+ init();
+ if (!dummyDevice)
+ return;
+ }
+ if (ui->comboBox->itemText(currentDevice) == QStringLiteral("dummy")) {
+ const QByteArray result = dummyDevice->readAll();
+ if (!result.isEmpty())
+ ui->listWidget->addItem(result);
+ }
+}
+
+void MainWindow::checkMessages()
+{
+ if (ui->comboBox->itemText(currentDevice) == QStringLiteral("can")) {
+ QCanFrame frame = canDevice->readFrame();
+
+ if (frame.payload().isEmpty())
+ return;
+
+ bool EFF = false;
+ bool RTR = false;
+ bool ERR = false;
+
+ qint32 id = frame.frameId();
+ qint8 dataLength = frame.payload().size();
+
+ if (!dataLength)
+ return;
+
+ EFF = id & CAN_EFF_FLAG;
+ RTR = id & CAN_RTR_FLAG;
+ ERR = id & CAN_ERR_FLAG;
+
+ //removes possible flags from id
+ id &= ~(CAN_EFF_FLAG|CAN_RTR_FLAG|CAN_ERR_FLAG);
+
+ if (!EFF && id > 2047) //11 bits
+ id = 2047;
+
+ QString view;
+ if (ERR) {
+ frame.setFrameId(id);
+ interpretError(view, frame);
+ } else {
+ view += "Id: ";
+ view += QString::number(id, 16);
+ view += " bytes: ";
+ view += QString::number(dataLength, 10);
+ view += " data: ";
+ view += frame.payload().data();
+ }
+
+ if (RTR) {
+ ui->requestList->addItem(view);
+ } else if (ERR) {
+ ui->errorList->addItem(view);
+ } else {
+ ui->listWidget->addItem(view);
+ }
+ }
+}
+
+void MainWindow::on_sendButton_clicked()
+{
+ if (!canDevice || !dummyDevice) {
+ init();
+ if (!canDevice || !dummyDevice)
+ return;
+ }
+
+ QByteArray writings = ui->lineEdit->displayText().toUtf8();
+ ui->lineEdit->clear();
+ if (ui->comboBox->itemText(currentDevice) == QStringLiteral("can")) {
+ QCanFrame frame;
+ const int maxPayload = ui->fdBox->checkState() ? 64 : 8;
+ int size = writings.size();
+ if (size > maxPayload)
+ size = maxPayload;
+ writings = writings.left(size);
+ frame.setPayload(writings);
+
+ qint32 id = ui->idEdit->displayText().toInt();
+ ui->idEdit->clear();
+ if (!ui->EFF->checkState() && id > 2047) //11 bits
+ id = 2047;
+
+ if (ui->EFF->checkState())
+ id |= CAN_EFF_FLAG;
+ if (ui->RTR->checkState())
+ id |= CAN_RTR_FLAG;
+ if (ui->ERR->checkState())
+ id |= CAN_ERR_FLAG;
+ frame.setFrameId(id);
+
+ canDevice->writeFrame(frame);
+ } else if (ui->comboBox->itemText(currentDevice) == QStringLiteral("dummy")) {
+ dummyDevice->write(writings);
+ }
+}
+
+void MainWindow::on_connectButton_clicked()
+{
+ currentDevice = ui->comboBox->currentIndex();
+ ui->connectedToLabel->setText("Connected to : " + ui->comboBox->currentText());
+ checkMessages();
+}
+
+void MainWindow::interpretError(QString &view, const QCanFrame &frame)
+{
+ switch (frame.frameId()) {
+ case CAN_ERR_TX_TIMEOUT:
+ view += QStringLiteral("TX timeout\n");
+ break;
+ case CAN_ERR_LOSTARB:
+ view += QStringLiteral("lost arbitration\n");
+ break;
+ case CAN_ERR_CRTL:
+ view += QStringLiteral("controller problems\n");
+ break;
+ case CAN_ERR_PROT:
+ view += QStringLiteral("protocol violations\n");
+ break;
+ case CAN_ERR_TRX:
+ view += QStringLiteral("transceiver status\n");
+ break;
+ case CAN_ERR_ACK:
+ view += QStringLiteral("received no ACK on transmission\n");
+ break;
+ case CAN_ERR_BUSOFF:
+ view += QStringLiteral("bus off\n");
+ break;
+ case CAN_ERR_BUSERROR:
+ view += QStringLiteral("bus error\n");
+ break;
+ case CAN_ERR_RESTARTED:
+ view += QStringLiteral("controller restarted\n");
+ break;
+ default:
+ break;
+ }
+
+ const QByteArray payload = frame.payload();
+ view += QStringLiteral("arbitration lost in bit: ");
+ view += QString::number(payload.at(0), 16);
+ view += QStringLiteral("\n");
+
+ switch (payload.at(1)) {
+ case CAN_ERR_CRTL_RX_OVERFLOW:
+ view += QStringLiteral("RX buffer overflow\n");
+ break;
+ case CAN_ERR_CRTL_TX_OVERFLOW:
+ view += QStringLiteral("TX buffer overflow\n");
+ break;
+ case CAN_ERR_CRTL_RX_WARNING:
+ view += QStringLiteral("reached warning level for RX errors\n");
+ break;
+ case CAN_ERR_CRTL_TX_WARNING:
+ view += QStringLiteral("reached warning level for TX errors\n");
+ break;
+ case CAN_ERR_CRTL_RX_PASSIVE:
+ view += QStringLiteral("reached error passive status RX\n");
+ break;
+ case CAN_ERR_CRTL_TX_PASSIVE:
+ view += QStringLiteral("reached error passive status TX\n");
+ break;
+ default:
+ break;
+ }
+
+ switch (payload.at(2)) { //type
+ case CAN_ERR_PROT_BIT:
+ view += QStringLiteral("single bit error\n");
+ break;
+ case CAN_ERR_PROT_FORM:
+ view += QStringLiteral("frame format error\n");
+ break;
+ case CAN_ERR_PROT_STUFF:
+ view += QStringLiteral("bit stuffing error\n");
+ break;
+ case CAN_ERR_PROT_BIT0:
+ view += QStringLiteral("unable to send dominant bit\n");
+ break;
+ case CAN_ERR_PROT_BIT1:
+ view += QStringLiteral("unable to send recessive bit\n");
+ break;
+ case CAN_ERR_PROT_OVERLOAD:
+ view += QStringLiteral("bus overload\n");
+ break;
+ case CAN_ERR_PROT_ACTIVE:
+ view += QStringLiteral("active error announcement\n");
+ break;
+ case CAN_ERR_PROT_TX:
+ view += QStringLiteral("error occurred on transmission\n");
+ break;
+ default:
+ break;
+ }
+
+ switch (payload.at(3)) { //location
+ case CAN_ERR_PROT_LOC_SOF:
+ view += QStringLiteral("start of frame\n");
+ break;
+ case CAN_ERR_PROT_LOC_ID28_21:
+ view += QStringLiteral("ID bits 28 - 21 (SFF: 10 - 3)\n");
+ break;
+ case CAN_ERR_PROT_LOC_ID20_18:
+ view += QStringLiteral("ID bits 20 - 18 (SFF: 2 - 0 )\n");
+ break;
+ case CAN_ERR_PROT_LOC_SRTR:
+ view += QStringLiteral("substitute RTR (SFF: RTR)\n");
+ break;
+ case CAN_ERR_PROT_LOC_IDE:
+ view += QStringLiteral("identifier extension\n");
+ break;
+ case CAN_ERR_PROT_LOC_ID17_13:
+ view += QStringLiteral("ID bits 17-13\n");
+ break;
+ case CAN_ERR_PROT_LOC_ID12_05:
+ view += QStringLiteral("ID bits 12-5\n");
+ break;
+ case CAN_ERR_PROT_LOC_ID04_00:
+ view += QStringLiteral("ID bits 4-0\n");
+ break;
+ case CAN_ERR_PROT_LOC_RTR:
+ view += QStringLiteral("RTR\n");
+ break;
+ case CAN_ERR_PROT_LOC_RES1:
+ view += QStringLiteral("reserved bit 1\n");
+ break;
+ case CAN_ERR_PROT_LOC_RES0:
+ view += QStringLiteral("reserved bit 0\n");
+ break;
+ case CAN_ERR_PROT_LOC_DLC:
+ view += QStringLiteral("data length code\n");
+ break;
+ case CAN_ERR_PROT_LOC_DATA:
+ view += QStringLiteral("data section\n");
+ break;
+ case CAN_ERR_PROT_LOC_CRC_SEQ:
+ view += QStringLiteral("CRC sequence\n");
+ break;
+ case CAN_ERR_PROT_LOC_CRC_DEL:
+ view += QStringLiteral("CRC delimiter\n");
+ break;
+ case CAN_ERR_PROT_LOC_ACK:
+ view += QStringLiteral("ACK slot\n");
+ break;
+ case CAN_ERR_PROT_LOC_ACK_DEL:
+ view += QStringLiteral("ACK delimiter\n");
+ break;
+ case CAN_ERR_PROT_LOC_EOF:
+ view += QStringLiteral("end of frame\n");
+ break;
+ case CAN_ERR_PROT_LOC_INTERM:
+ view += QStringLiteral("Intermission\n");
+ break;
+ default:
+ break;
+ }
+
+ switch (payload.at(4)) {
+ case CAN_ERR_TRX_CANH_NO_WIRE:
+ view += QStringLiteral("CAN-transceiver CANH no wire\n");
+ break;
+ case CAN_ERR_TRX_CANH_SHORT_TO_BAT:
+ view += QStringLiteral("CAN-transceiver CANH short to bat\n");
+ break;
+ case CAN_ERR_TRX_CANH_SHORT_TO_VCC:
+ view += QStringLiteral("CAN-transceiver CANH short to vcc\n");
+ break;
+ case CAN_ERR_TRX_CANH_SHORT_TO_GND:
+ view += QStringLiteral("CAN-transceiver CANH short to ground\n");
+ break;
+ case CAN_ERR_TRX_CANL_NO_WIRE:
+ view += QStringLiteral("CAN-transceiver CANL no wire\n");
+ break;
+ case CAN_ERR_TRX_CANL_SHORT_TO_BAT:
+ view += QStringLiteral("CAN-transceiver CANL short to bat\n");
+ break;
+ case CAN_ERR_TRX_CANL_SHORT_TO_VCC:
+ view += QStringLiteral("CAN-transceiver CANL short to vcc\n");
+ break;
+ case CAN_ERR_TRX_CANL_SHORT_TO_GND:
+ view += QStringLiteral("CAN-transceiver CANL short to ground\n");
+ break;
+ case CAN_ERR_TRX_CANL_SHORT_TO_CANH:
+ view += QStringLiteral("CAN-transceiver CANL short to CANH\n");
+ break;
+ default:
+ break;
+ }
+}
diff --git a/example/mainwindow.h b/example/mainwindow.h
new file mode 100644
index 0000000..ba7f9fa
--- /dev/null
+++ b/example/mainwindow.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <linux/can.h>
+#include <QPointer>
+
+class QSerialBusBackend;
+class QSerialBus;
+class QBusDummyDevice;
+class QCanBusDevice;
+class QSerialBusDevice;
+class QCanFrame;
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+private Q_SLOTS:
+
+ void checkDummyMessages();
+ void checkMessages();
+ void on_sendButton_clicked();
+ void on_connectButton_clicked();
+
+private:
+ void init();
+ void interpretError(QString&, const QCanFrame&);
+
+ QPointer<QSerialBus> b;
+ QPointer<QBusDummyDevice> dummyDevice;
+ QPointer<QCanBusDevice> canDevice;
+ Ui::MainWindow *ui;
+ QList< QPointer<QSerialBusBackend> > backends;
+ QList<QSerialBusDevice *> devices;
+ qint64 currentDevice;
+};
+
+#endif // MAINWINDOW_H
diff --git a/example/mainwindow.ui b/example/mainwindow.ui
new file mode 100644
index 0000000..a2a9a0c
--- /dev/null
+++ b/example/mainwindow.ui
@@ -0,0 +1,270 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>1254</width>
+ <height>852</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <widget class="QLineEdit" name="lineEdit">
+ <property name="geometry">
+ <rect>
+ <x>180</x>
+ <y>40</y>
+ <width>191</width>
+ <height>27</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="sendButton">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>130</y>
+ <width>191</width>
+ <height>61</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>send</string>
+ </property>
+ </widget>
+ <widget class="QComboBox" name="comboBox">
+ <property name="geometry">
+ <rect>
+ <x>850</x>
+ <y>70</y>
+ <width>85</width>
+ <height>27</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QListWidget" name="listWidget">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>250</y>
+ <width>391</width>
+ <height>541</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="idEdit">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>40</y>
+ <width>113</width>
+ <height>27</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>20</y>
+ <width>67</width>
+ <height>17</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Id</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_2">
+ <property name="geometry">
+ <rect>
+ <x>190</x>
+ <y>20</y>
+ <width>67</width>
+ <height>17</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Data</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="EFF">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>100</y>
+ <width>97</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>EFF</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="RTR">
+ <property name="geometry">
+ <rect>
+ <x>170</x>
+ <y>100</y>
+ <width>97</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>RTR</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="connectButton">
+ <property name="geometry">
+ <rect>
+ <x>600</x>
+ <y>40</y>
+ <width>171</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Connect</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="connectedToLabel">
+ <property name="geometry">
+ <rect>
+ <x>850</x>
+ <y>120</y>
+ <width>341</width>
+ <height>17</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Connected to :</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_3">
+ <property name="geometry">
+ <rect>
+ <x>850</x>
+ <y>40</y>
+ <width>67</width>
+ <height>17</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Plugins:</string>
+ </property>
+ </widget>
+ <widget class="QListWidget" name="requestList">
+ <property name="geometry">
+ <rect>
+ <x>420</x>
+ <y>250</y>
+ <width>411</width>
+ <height>541</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QListWidget" name="errorList">
+ <property name="geometry">
+ <rect>
+ <x>840</x>
+ <y>250</y>
+ <width>401</width>
+ <height>541</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_4">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>230</y>
+ <width>67</width>
+ <height>17</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Messages</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_5">
+ <property name="geometry">
+ <rect>
+ <x>430</x>
+ <y>227</y>
+ <width>67</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Requests</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_6">
+ <property name="geometry">
+ <rect>
+ <x>860</x>
+ <y>230</y>
+ <width>67</width>
+ <height>17</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Errors</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="fdBox">
+ <property name="geometry">
+ <rect>
+ <x>280</x>
+ <y>100</y>
+ <width>161</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Flexible Data-Rate</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="ERR">
+ <property name="geometry">
+ <rect>
+ <x>440</x>
+ <y>100</y>
+ <width>97</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>ERR</string>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>1254</width>
+ <height>25</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/qtserialbus.pro b/qtserialbus.pro
new file mode 100644
index 0000000..4a09bc9
--- /dev/null
+++ b/qtserialbus.pro
@@ -0,0 +1,14 @@
+lessThan(QT_MAJOR_VERSION, 5) {
+ message("Cannot build current QtSerialBus sources with Qt version $${QT_VERSION}.")
+}
+
+load(configure)
+!qtCompileTest(socketcan) {
+ warning("You need linux/can.h and linux/can/raw.h linux headers for socketCAN support, disabling it")
+}
+!qtCompileTest(socketcan_fd) {
+ warning("Newer kernel needed for flexible data-rate frame support 'canfd_frame'")
+}
+
+
+load(qt_parts)
diff --git a/src/plugins/can/can.pro b/src/plugins/can/can.pro
new file mode 100644
index 0000000..bfa1c03
--- /dev/null
+++ b/src/plugins/can/can.pro
@@ -0,0 +1,16 @@
+QT += core-private serialbus
+
+TARGET = qtcanbus
+
+PLUGIN_TYPE = serialbuses
+PLUGIN_EXTENDS = serialbus
+PLUGIN_CLASS_NAME = SocketCanBusPlugin
+load(qt_plugin)
+
+HEADERS += \
+ socketcanbackend.h \
+
+SOURCES += main.cpp \
+ socketcanbackend.cpp \
+
+OTHER_FILES = plugin.json
diff --git a/src/plugins/can/main.cpp b/src/plugins/can/main.cpp
new file mode 100644
index 0000000..86785b5
--- /dev/null
+++ b/src/plugins/can/main.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "socketcanbackend.h"
+
+#include <QtCore/qfile.h>
+#include <QtCore/qdebug.h>
+
+#include <qserialbusplugininterface.h>
+#include <qserialbus.h>
+
+QT_BEGIN_NAMESPACE
+
+class SocketCanBusPlugin : public QObject, public QSerialBusPluginInterface, public QSerialBusBackendFactory
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSerialBusPluginInterface" FILE "plugin.json")
+ Q_INTERFACES(QSerialBusPluginInterface)
+
+
+public:
+ void registerBus()
+ {
+ const QByteArray id("can");
+ QSerialBus::registerBackend(id, this);
+ }
+
+ QPointer<QSerialBusBackend> createBackend(const QString &bus, const QString &name)
+ {
+ if (bus == QStringLiteral("SocketCAN")) {
+ QPointer<QSerialBusBackend> backend = new SocketCanBackend(name);
+ return backend;
+ } else {
+ qWarning() << "No backend with name" << bus
+ << "found in CAN plugin. Defaulting to SocketCAN";
+ QPointer<QSerialBusBackend> backend = new SocketCanBackend(name);
+ return backend;
+ }
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "main.moc"
+
diff --git a/src/plugins/can/plugin.json b/src/plugins/can/plugin.json
new file mode 100644
index 0000000..c146a78
--- /dev/null
+++ b/src/plugins/can/plugin.json
@@ -0,0 +1 @@
+{ "Keys": [ "can" ] }
diff --git a/src/plugins/can/socketcanbackend.cpp b/src/plugins/can/socketcanbackend.cpp
new file mode 100644
index 0000000..b0d4771
--- /dev/null
+++ b/src/plugins/can/socketcanbackend.cpp
@@ -0,0 +1,240 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "socketcanbackend.h"
+#include <QtCore/qdebug.h>
+#include <QtCore/qdatastream.h>
+#include <QtCore/qsocketnotifier.h>
+#include <QtCore/qpair.h>
+
+#include <linux/can/raw.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+
+
+SocketCanBackend::SocketCanBackend(const QString &name) :
+ canSocketName(name),
+ version(0)
+{
+ QDataStream stream;
+ version = stream.version();
+ //TODO: remove implicit call to connect() in ctor (related to missing open/close() call in QSerialBusDevice
+ connectSocket();
+}
+
+QByteArray SocketCanBackend::readAll()
+{
+ return read(CANFD_MTU);
+}
+
+QByteArray SocketCanBackend::read(qint64 maxSize)
+{
+ Q_UNUSED(maxSize);
+ const canfd_frame frame = readFrame();
+
+ if (!frame.len)
+ return QByteArray();
+
+ struct timeval timeStamp;
+ if (ioctl(canSocket, SIOCGSTAMP, &timeStamp) < 0) {
+ qWarning() << "ERROR SocketCanBackend: couldn't get timestamp";
+ timeStamp.tv_sec = 0;
+ timeStamp.tv_usec = 0;
+ }
+ return serialize(frame, timeStamp);
+}
+
+QByteArray SocketCanBackend::serialize(const canfd_frame &frame, const timeval &timeStamp)
+{
+ QByteArray array;
+ QDataStream stream(&array, QIODevice::WriteOnly);
+ stream.setVersion(version);
+
+ stream << frame.can_id;
+ QByteArray payload;
+ for (int i = 0; i < frame.len; i++)
+ payload.insert(i, frame.data[i]);
+
+ stream << payload
+ << qint64(timeStamp.tv_sec)
+ << qint64(timeStamp.tv_usec);
+ return array;
+}
+
+canfd_frame SocketCanBackend::deserialize(const QByteArray &array)
+{
+ canfd_frame frame;
+ QDataStream stream(array);
+ stream.setVersion(version);
+
+ QByteArray payload;
+
+ stream >> frame.can_id
+ >> payload;
+
+ frame.len = payload.size();
+ for (int i = 0; i < frame.len ; i++)
+ frame.data[i] = payload.at(i);
+
+ return frame;
+}
+
+void SocketCanBackend::writeToBus(const QByteArray &data)
+{
+ const canfd_frame frame = deserialize(data);
+
+ if (::write(canSocket, &frame, CANFD_MTU) < 0)
+ qWarning() << "ERROR SocketCanBackend: cannot write to socket";
+}
+
+void SocketCanBackend::setConfiguration(const QPair<QString, QVariant> &conf)
+{
+ if (conf.first == QStringLiteral("Loopback")) {
+ const int loopback = conf.second.toBool() ? 1 : 0;
+ if (setsockopt(canSocket, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &loopback, sizeof(loopback)) < 0)
+ qWarning() << "ERROR SocketCanBackend: setsockopt CAN_RAW_LOOPBACK failed";
+ } else if (conf.first == QStringLiteral("ReceiveOwnMessages")) {
+ const int receiveOwnMessages = conf.second.toBool() ? 1 : 0;
+ if (setsockopt(canSocket, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS,
+ &receiveOwnMessages, sizeof(receiveOwnMessages)) < 0)
+ qWarning() << "ERROR SocketCanBackend: setsockopt CAN_RAW_RECV_OWN_MSGS failed";
+ } else if (conf.first == QStringLiteral("ErrorMask")) {
+ const int errorMask = conf.second.toInt();
+ if (setsockopt(canSocket, SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
+ &errorMask, sizeof(errorMask)) < 0)
+ qWarning() << "ERROR SocketCanBackend: setsockopt CAN_RAW_ERR_FILTER failed";
+ } else if (conf.first == QStringLiteral("CanFilter")) {
+ const QList<QVariant> filterList = conf.second.toList();
+ const int size = filterList.size();
+ if (size == 0)
+ qWarning() << "ERROR SocketCanBackend: \"CanFilter\" QList<QVariant> empty or not valid";
+ can_filter filters[size];
+ for (int i = 0; i < size; i++) {
+ can_filter filter;
+ const QHash<QString, QVariant> filterHash = filterList.at(i).toHash();
+ bool ok = true;
+ filter.can_id = filterHash.value("FilterId").toInt(&ok);
+ if (!ok) {
+ qWarning() << "ERROR SocketCanBackend: \"CanFilter\" FilterId key not found or value is not valid in index:" << i;
+ return;
+ }
+ filter.can_mask = filterHash.value("CanMask").toInt(&ok);
+ if (!ok) {
+ qWarning() << "ERROR SocketCanBackend: \"CanFilter\" CanMask key not found or value is not valid in index:" << i;
+ return;
+ }
+ filters[i] = filter;
+ }
+ if (setsockopt(canSocket, SOL_CAN_RAW, CAN_RAW_FILTER, filters, sizeof(filters)) < 0)
+ qWarning() << "ERROR SocketCanBackend: setsockopt CAN_RAW_FILTER failed";
+ } else {
+ qWarning() << "SocketCanBackend: No such configuration as" << conf.first << "in SocketCanBackend";
+ }
+}
+
+
+qint64 SocketCanBackend::connectSocket()
+{
+ struct sockaddr_can address;
+ struct ifreq interface;
+
+ if ((canSocket = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
+ qWarning() << "ERROR SocketCanBackend: cannot open socket";
+ return -1;
+ }
+
+ strcpy(interface.ifr_name, canSocketName.toLatin1().data());
+ if (ioctl(canSocket, SIOCGIFINDEX, &interface) < 0) {
+ qWarning() << "ERROR SocketCanBackend: failed to retrieve the interface index";
+ return -1;
+ }
+
+ address.can_family = AF_CAN;
+ address.can_ifindex = interface.ifr_ifindex;
+
+ if (bind(canSocket, (struct sockaddr *)&address, sizeof(address)) < 0) {
+ qWarning() << "ERROR SocketCanBackend: cannot bind socket";
+ return -2;
+ }
+
+ const int fd_frames = 1;
+ if (setsockopt(canSocket, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &fd_frames, sizeof(fd_frames)) < 0) {
+ qWarning() << "ERROR SocketCanBackend: setsockopt CAN_RAW_FD_FRAMES failed";
+ }
+
+ notifier = new QSocketNotifier(canSocket, QSocketNotifier::Read);
+ connect(notifier.data(), &QSocketNotifier::activated, this, &SocketCanBackend::readyRead);
+
+ //TODO: improve the error reporting
+ return 0;
+}
+
+void SocketCanBackend::setDataStreamVersion(int version)
+{
+ version = version;
+}
+
+int SocketCanBackend::dataStreamVersion() const
+{
+ return version;
+}
+
+qint64 SocketCanBackend::size() const
+{
+ return CANFD_MTU;
+}
+
+canfd_frame SocketCanBackend::readFrame()
+{
+ struct canfd_frame frame;
+ int bytesReceived = 0;
+
+ struct timeval timeout = {0, 0};
+ fd_set readSet;
+ FD_ZERO(&readSet);
+ FD_SET(canSocket, &readSet);
+ if (select((canSocket + 1), &readSet, NULL, NULL, &timeout) >= 0) {
+ if (FD_ISSET(canSocket, &readSet)) {
+ bytesReceived = ::read(canSocket, &frame, CANFD_MTU);
+ if (bytesReceived)
+ return frame;
+ }
+ }
+ frame.len = 0;
+ return frame;
+}
diff --git a/src/plugins/can/socketcanbackend.h b/src/plugins/can/socketcanbackend.h
new file mode 100644
index 0000000..ca30f8b
--- /dev/null
+++ b/src/plugins/can/socketcanbackend.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SOCKETCANBACKEND_H
+#define SOCKETCANBACKEND_H
+
+#include <qserialbusbackend.h>
+#include <QtCore/qpointer.h>
+
+class QSocketNotifier;
+
+struct canfd_frame;
+
+class SocketCanBackend : public QSerialBusBackend
+{
+ Q_OBJECT
+public:
+ explicit SocketCanBackend(const QString &name);
+ QByteArray readAll();
+ QByteArray read(qint64);
+ void writeToBus(const QByteArray &data);
+ void setDataStreamVersion(int version);
+ void setConfiguration(const QPair<QString, QVariant> &conf);
+ int dataStreamVersion() const;
+ qint64 size() const;
+
+private:
+ qint64 connectSocket();
+ QByteArray serialize(const canfd_frame &frame, const timeval &time);
+ canfd_frame deserialize(const QByteArray &frame);
+ canfd_frame readFrame();
+
+ qint64 canSocket;
+ QPointer<QSocketNotifier> notifier;
+ QByteArray frameArray;
+ QString canSocketName;
+ int version;
+};
+
+#endif // SOCKETCANBACKEND_H
diff --git a/src/plugins/generic/dummybackend.cpp b/src/plugins/generic/dummybackend.cpp
new file mode 100644
index 0000000..0eef932
--- /dev/null
+++ b/src/plugins/generic/dummybackend.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "dummybackend.h"
+#include <QtCore/qdebug.h>
+#include <QtCore/qtimer.h>
+
+DummyBackend::DummyBackend() :
+ sendTimer(new QTimer(this)),
+ byteArray("abc")
+{
+ sendTimer->setInterval(1000);
+ sendTimer->setSingleShot(false);
+ connect(sendTimer, SIGNAL(timeout()), this, SLOT(sendMessage()));
+ sendTimer->start();
+}
+
+void DummyBackend::sendMessage()
+{
+ byteArray.append("def");
+ emit readyRead();
+}
+
+QByteArray DummyBackend::read(qint64 maxSize)
+{
+ const qint64 len = byteArray.size();
+ if (len > maxSize) {
+ QByteArray data = byteArray.left(maxSize);
+ byteArray = byteArray.mid(maxSize);
+ return data;
+ } else {
+ const QByteArray data = byteArray;
+ byteArray.clear();
+ return data;
+ }
+}
+
+void DummyBackend::writeToBus(const QByteArray &data) {
+ qDebug() << "DummyBackend wrote: " << data.data();
+}
+
+void DummyBackend::setDataStreamVersion(int version)
+{
+ Q_UNUSED(version);
+}
+
+int DummyBackend::dataStreamVersion() const
+{
+ return 0;
+}
+
+qint64 DummyBackend::size() const
+{
+ return byteArray.size();
+}
+
+QByteArray DummyBackend::readAll()
+{
+ QByteArray temp = byteArray;
+ byteArray.clear();
+ return temp;
+}
+
+void DummyBackend::setConfiguration(const QPair<QString, QVariant> &conf)
+{
+ Q_UNUSED(conf);
+}
diff --git a/src/plugins/generic/dummybackend.h b/src/plugins/generic/dummybackend.h
new file mode 100644
index 0000000..7058baa
--- /dev/null
+++ b/src/plugins/generic/dummybackend.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DUMMYBACKEND_H
+#define DUMMYBACKEND_H
+
+#include <qserialbusbackend.h>
+#include <QtCore/qbytearray.h>
+
+#include <QtCore/qpointer.h>
+
+class QTimer;
+
+class DummyBackend : public QSerialBusBackend
+{
+ Q_OBJECT
+public:
+ explicit DummyBackend();
+ QByteArray readAll();
+ QByteArray read(qint64 maxSize);
+ void writeToBus(const QByteArray &data);
+ void setDataStreamVersion(int version);
+ void setConfiguration(const QPair<QString, QVariant> &);
+ int dataStreamVersion() const;
+ qint64 size() const;
+
+public Q_SLOTS:
+ void sendMessage();
+
+private:
+ QPointer<QTimer> sendTimer;
+ QByteArray byteArray;
+};
+
+#endif // DUMMYBACKEND_H
diff --git a/src/plugins/generic/generic.pro b/src/plugins/generic/generic.pro
new file mode 100644
index 0000000..614d288
--- /dev/null
+++ b/src/plugins/generic/generic.pro
@@ -0,0 +1,16 @@
+QT += core-private serialbus widgets
+
+TARGET = qtbusgeneric
+
+PLUGIN_TYPE = serialbuses
+PLUGIN_EXTENDS = serialbus
+PLUGIN_CLASS_NAME = DummyBusPlugin
+load(qt_plugin)
+
+HEADERS += \
+ dummybackend.h
+
+SOURCES += main.cpp \
+ dummybackend.cpp
+
+OTHER_FILES = plugin.json
diff --git a/src/plugins/generic/main.cpp b/src/plugins/generic/main.cpp
new file mode 100644
index 0000000..bb9142d
--- /dev/null
+++ b/src/plugins/generic/main.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "dummybackend.h"
+
+#include <qserialbusplugininterface.h>
+#include <qserialbus.h>
+
+#include <QtCore/qfile.h>
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+class GenericBusPlugin : public QObject, public QSerialBusPluginInterface, public QSerialBusBackendFactory
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSerialBusPluginInterface" FILE "plugin.json")
+ Q_INTERFACES(QSerialBusPluginInterface)
+
+
+public:
+ void registerBus()
+ {
+ const QByteArray id("dummy");
+ QSerialBus::registerBackend(id, this);
+ }
+
+ QPointer<QSerialBusBackend> createBackend(const QString &bus, const QString &name)
+ {
+ Q_UNUSED(bus)
+ Q_UNUSED(name)
+ QPointer<QSerialBusBackend> backend = new DummyBackend();
+ return backend;
+ }
+
+public slots:
+};
+
+QT_END_NAMESPACE
+
+#include "main.moc"
diff --git a/src/plugins/generic/plugin.json b/src/plugins/generic/plugin.json
new file mode 100644
index 0000000..d3e579e
--- /dev/null
+++ b/src/plugins/generic/plugin.json
@@ -0,0 +1 @@
+{ "Keys": [ "generic" ] }
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro
new file mode 100644
index 0000000..de4bc3a
--- /dev/null
+++ b/src/plugins/plugins.pro
@@ -0,0 +1,5 @@
+TEMPLATE = subdirs
+SUBDIRS += generic
+config_socketcan {
+ SUBDIRS += can
+}
diff --git a/src/serialbus/doc/qtserialbus.qdocconf b/src/serialbus/doc/qtserialbus.qdocconf
new file mode 100644
index 0000000..51fa0b0
--- /dev/null
+++ b/src/serialbus/doc/qtserialbus.qdocconf
@@ -0,0 +1,11 @@
+outputdir = html
+
+headerdirs += .. \
+ ../../plugins
+
+sourcedirs += .. \
+ ../../plugins
+
+exampledirs = ../../../examples/
+
+imagedirs = ./images
diff --git a/src/serialbus/doc/src/qtserialbus.qdoc b/src/serialbus/doc/src/qtserialbus.qdoc
new file mode 100644
index 0000000..eec608f
--- /dev/null
+++ b/src/serialbus/doc/src/qtserialbus.qdoc
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \page qtserialbus-index.html
+ \title Qt Serial Bus
+ \brief Provides framework and implementartion for SocketCAN an potentially other serial buses.
+
+ The Qt Serial Bus API provides access to socketCAN via C++ interface.
+ Module is designed and named thus it can be extended with any serial bus backend.
+
+ Currently the API is supported on \l{http://doc.qt.io/qt-5/linux.html}{Linux}
+
+ \section1 Information about classes
+
+ QSerialBus
+ The QSerialBus class handles registration and creation of bus backends.
+
+ QSerialBusDevice
+ Interface between the module user and the actual bus. Inherited from QIODevice.
+
+ QCanBusDevice
+ Inherited from QSerialBusDevice. Designed to work with SocketCanBackend.
+ QCanBusDevice takes ownership of QSerialBusBackend given in object creation.
+
+ QSerialBusDeviceFilter
+ Acts as an interpreter for data read by the QSerialBusDevice.
+
+ QBusDeviceBackend
+ The backend is the access point to the actual device.
+ It is responsible for the bit/byte level communication with the hardware and also providing
+ the data and notifications to the QSerialBusDevice
+
+ \section2 Minimal application example
+
+ \code
+ QSerialBus *serialBus = QSerialBus::Instance();
+ QBusDeviceBackend *socketCanBackend = serialBus->createBackend("can", "socketcan");
+ QCanBusDevice *socketCanDevice = new QCanBusDevice(socketCanBackend, this);
+
+ socketCanDevice->open(QIODevice::ReadWrite);
+
+ //Write frame (id, data, size in bytes)
+ socketCanDevice->writeFrame(12, 32, 1);
+ \endcode
+
+
+
+*/
diff --git a/src/serialbus/qbusdummydevice.cpp b/src/serialbus/qbusdummydevice.cpp
new file mode 100644
index 0000000..3efe0c9
--- /dev/null
+++ b/src/serialbus/qbusdummydevice.cpp
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbusdummydevice.h"
+#include "qserialbusdevice.h"
+
+#include <QtCore/qdebug.h>
+
+QBusDummyDevice::QBusDummyDevice(QSerialBusBackend *backend, QObject *parent) :
+ QSerialBusDevice(backend, parent),
+ busBackend(backend)
+{
+ connect(backend, &QSerialBusBackend::readyRead, this, &QBusDummyDevice::readyRead);
+}
diff --git a/src/serialbus/qbusdummydevice.h b/src/serialbus/qbusdummydevice.h
new file mode 100644
index 0000000..c522310
--- /dev/null
+++ b/src/serialbus/qbusdummydevice.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QBUSDUMMYDEVICE_H
+#define QBUSDUMMYDEVICE_H
+
+#include <QtSerialBus/qserialbusglobal.h>
+
+#include "qserialbusdevice.h"
+#include "qserialbusbackend.h"
+
+QT_BEGIN_NAMESPACE
+
+//TODO: should be renamed QDummyBusDevice?
+class Q_SERIALBUS_EXPORT QBusDummyDevice : public QSerialBusDevice
+{
+ Q_OBJECT
+public:
+ explicit QBusDummyDevice(QSerialBusBackend *backend, QObject *parent = 0);
+
+Q_SIGNALS:
+ void newData(const QByteArray &data);
+
+private:
+ QSerialBusBackend *busBackend;
+};
+
+QT_END_NAMESPACE
+#endif // QBUSDUMMYDEVICE_H
diff --git a/src/serialbus/qcanbusdevice.cpp b/src/serialbus/qcanbusdevice.cpp
new file mode 100644
index 0000000..a65e2d9
--- /dev/null
+++ b/src/serialbus/qcanbusdevice.cpp
@@ -0,0 +1,177 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcanbusdevice.h"
+#include "qcanbusdevice_p.h"
+
+#include "qcanframe.h"
+#include <QtCore/qdebug.h>
+#include <QtCore/qdatastream.h>
+
+#define SOCKET_CAN_MTU 72
+
+/*!
+ * \class QCanBusDevice
+ * \inmodule QtSerialBus
+ * \inherits QIODevice
+ *
+ * \brief The QCanBusDevice is the interface class for CAN Bus.
+ * Working CAN backend must be given in object creation.
+ * QCanBusDevice takes ownership of QSerialBusBackend given in object creation.
+ * Frames written and read must be serialized/deserialized with QDataStream.
+ * writeFrame() serializes QCanFrame properly before writing.
+ */
+QCanBusDevice::QCanBusDevice(QPointer<QSerialBusBackend> backend, QObject *parent) :
+ QSerialBusDevice(backend, parent)
+{
+ busBackend = backend;
+ connect(busBackend.data(), &QSerialBusBackend::readyRead, this, &QCanBusDevice::readyRead);
+}
+
+/*
+ * For socketCAN following configurations can be done
+ * QPair<key,value>
+ * key: Loopback value: True/False
+ * key: ReceiveOwnMessages value: True/False
+ * key: ErrorMask value: int
+ * key: CanFilter value: QList<QVariant filter>,
+ * QVariant filter is QHash<QString, QVariant>,
+ * QHash has 2 keys: "FilterId" and "CanMask" both values are int
+ */
+void QCanBusDevice::setConfiguration(QPair<QString, QVariant> conf)
+{
+ busBackend->setConfiguration(conf);
+}
+
+/*!
+ * \brief Writes and serializes CAN frame to CAN bus. Both standard 8 byte frame
+ * and 64 byte Flexible Data-Rate(FD) frame are supported
+ * \param id Frame identifier. Standard 11 bits or 29 bits with extended frame format
+ * \param data Data payload. Standard max 8 bytes. FD max 64 bytes
+ * \param dataLength Bytes used in payload
+ * \param EFF Extended frame format. Increases identifier size to 29 bits
+ * \param RTR Remote transmission request. Mark frame as remote request frame.
+ */
+void QCanBusDevice::writeFrame(const QCanFrame &frame)
+{
+ Q_D(QCanBusDevice);
+ write(d->writeFrame(frame));
+}
+
+/*!
+ * \brief Reads one CAN frame worth of information from backend
+ */
+QCanFrame QCanBusDevice::readFrame()
+{
+ //TODO: when additional can backends are implemented,
+ //some kind of frame size chooser must be added
+ return deserialize(read(SOCKET_CAN_MTU));
+}
+
+/*!
+ * \brief Deserializes received data to QCanFrame format.
+ * \param data Serialized data.
+ * \param frame Frame to put all the data in.
+ */
+QCanFrame QCanBusDevice::deserialize(const QByteArray &data)
+{
+ Q_D(QCanBusDevice);
+ return d->deserialize(data);
+}
+
+/*!
+ * \brief Sets same version of QDataStream for QCanBusDevice and backend
+ * \param v enum QDataStream::Version
+ */
+void QCanBusDevice::setDataStreamVersion(int version)
+{
+ busBackend->setDataStreamVersion(version);
+}
+
+/*!
+ * \brief Returns version of QDataStream in use by QCanBusDevice and backend
+ * \return enum QDataStream::Version
+ */
+int QCanBusDevice::dataStreamVersion()
+{
+ return busBackend->dataStreamVersion();
+}
+
+QByteArray QCanBusDevicePrivate::writeFrame(const QCanFrame &frame)
+{
+ return serialize(frame);
+}
+
+QCanFrame QCanBusDevicePrivate::deserialize(const QByteArray &data)
+{
+ Q_Q(QCanBusDevice);
+ QCanFrame frame;
+ if (data.isEmpty())
+ return frame;
+
+ QDataStream stream(data);
+ stream.setVersion(q->dataStreamVersion());
+ QByteArray payload;
+ qint32 id;
+ qint64 sec;
+ qint64 usec;
+
+ stream >> id
+ >> payload
+ >> sec
+ >> usec;
+
+ QCanFrame::TimeStamp stamp;
+ stamp.setSeconds(sec);
+ stamp.setMicroSeconds(usec);
+
+ frame.setFrameId(id);
+ frame.setPayload(payload);
+ frame.setTimeStamp(stamp);
+ return frame;
+}
+
+QByteArray QCanBusDevicePrivate::serialize(const QCanFrame &frame)
+{
+ Q_Q(QCanBusDevice);
+
+ QByteArray data;
+ QDataStream stream(&data, QIODevice::ReadWrite);
+ stream.setVersion(q->dataStreamVersion());
+ stream << frame.frameId()
+ << frame.payload();
+ return data;
+}
diff --git a/src/serialbus/qcanbusdevice.h b/src/serialbus/qcanbusdevice.h
new file mode 100644
index 0000000..6fdb89f
--- /dev/null
+++ b/src/serialbus/qcanbusdevice.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCANBUSDEVICE_H
+#define QCANBUSDEVICE_H
+
+#include <QtSerialBus/qserialbusglobal.h>
+#include <QtCore/qpointer.h>
+#include "qserialbusdevice.h"
+#include "qserialbusbackend.h"
+
+QT_BEGIN_NAMESPACE
+
+class QCanBusDevicePrivate;
+class QCanFrame;
+
+//TODO for this class: review const member functions for this class
+class Q_SERIALBUS_EXPORT QCanBusDevice : public QSerialBusDevice
+{
+ Q_OBJECT
+public:
+ explicit QCanBusDevice(QPointer<QSerialBusBackend> backend, QObject *parent = 0);
+ void setConfiguration(QPair<QString, QVariant> conf);
+
+ void writeFrame(const QCanFrame &frame);
+ QCanFrame readFrame();
+ QCanFrame deserialize(const QByteArray &data);
+ void setDataStreamVersion(int version);
+ int dataStreamVersion();
+
+ Q_DECLARE_PRIVATE(QCanBusDevice)
+
+private:
+ QPointer<QSerialBusBackend> busBackend;
+};
+
+QT_END_NAMESPACE
+#endif // QCANBUSDEVICE_H
diff --git a/src/serialbus/qcanbusdevice_p.h b/src/serialbus/qcanbusdevice_p.h
new file mode 100644
index 0000000..8a55ca5
--- /dev/null
+++ b/src/serialbus/qcanbusdevice_p.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCANBUSDEVICE_P_H
+#define QCANBUSDEVICE_P_H
+
+#include "qcanbusdevice.h"
+#include "private/qobject_p.h"
+
+#include <QtCore/qpointer.h>
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QCanFrame;
+
+class QCanBusDevicePrivate : public QObjectPrivate
+{
+
+ Q_DECLARE_PUBLIC(QCanBusDevice)
+public:
+ QCanBusDevicePrivate()
+ {
+ }
+
+ QByteArray writeFrame(const QCanFrame &frame);
+ QCanFrame deserialize(const QByteArray &data);
+ QByteArray serialize(const QCanFrame &frame);
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QCANBUSDEVICE_P_H
diff --git a/src/serialbus/qcanframe.h b/src/serialbus/qcanframe.h
new file mode 100644
index 0000000..43135c9
--- /dev/null
+++ b/src/serialbus/qcanframe.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCANFRAME_H
+#define QCANFRAME_H
+
+#include <QtSerialBus/qserialbusglobal.h>
+#include <QtCore/qobject.h>
+
+QT_BEGIN_NAMESPACE
+
+
+//TODO: stream operator for this class
+//TODO: review ctors for this class
+class QCanFrame
+{
+public:
+ class TimeStamp {
+ public:
+ Q_DECL_CONSTEXPR TimeStamp(qint64 seconds = 0, qint64 microSeconds = 0) Q_DECL_NOTHROW
+ : secs(seconds), usecs(microSeconds) {}
+ Q_DECL_CONSTEXPR qint64 seconds() const Q_DECL_NOTHROW { return secs; }
+ Q_DECL_CONSTEXPR qint64 microSeconds() const Q_DECL_NOTHROW { return usecs; }
+
+ inline void setSeconds(qint64 seconds) { secs = seconds; }
+ inline void setMicroSeconds(qint64 microSeconds) { usecs = microSeconds; }
+ private:
+ qint64 secs;
+ qint64 usecs;
+ };
+
+ QCanFrame(qint32 identifier = 0, QByteArray payload = "") :
+ id(identifier), load(payload) {}
+ inline void setFrameId(qint32 frameId) { id = frameId; }
+ inline void setPayload(const QByteArray &payload) { load = payload; }
+ inline void setTimeStamp(const TimeStamp &timeStamp) { stamp = timeStamp; }
+ inline qint32 frameId() const { return id; }
+ QByteArray payload() const { return load; }
+ TimeStamp timeStamp() const { return stamp; }
+
+private:
+ qint32 id;
+ QByteArray load;
+ TimeStamp stamp;
+};
+
+Q_DECLARE_TYPEINFO(QCanFrame, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QCanFrame::TimeStamp, Q_PRIMITIVE_TYPE);
+
+QT_END_NAMESPACE
+
+#endif // QCANFRAME_H
diff --git a/src/serialbus/qserialbus.cpp b/src/serialbus/qserialbus.cpp
new file mode 100644
index 0000000..a0f1bb4
--- /dev/null
+++ b/src/serialbus/qserialbus.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qserialbusplugininterface.h"
+#include "qserialbus.h"
+#include "qserialbusdevice.h"
+
+#include <QtCore/qobject.h>
+#include <QtCore/qpluginloader.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qglobalstatic.h>
+
+#include <private/qfactoryloader_p.h>
+#include <private/qlibrary_p.h>
+
+QPointer<QSerialBus> QSerialBus::serialBus = Q_NULLPTR;
+
+class QSerialBusPrivate
+{
+ friend class QSerialBus;
+public:
+ QSerialBusPrivate()
+ : loader(new QFactoryLoader("org.qt-project.Qt.QSerialBusPluginInterface", QLatin1String("/serialbuses"))) {}
+
+ QHash<QByteArray, QSerialBusBackendFactory*> factoryByIdentifier;
+
+private:
+ QPointer<QFactoryLoader> loader;
+};
+
+/*!
+ \class QSerialBus
+ \inmodule QtSerialBus
+
+ \brief The QSerialBus class handles registration and creation of bus backends.
+
+ Bus plugins register backends using the registerBackend() function.
+*/
+
+/*!
+ * \brief Returns pointer to the QSerialBus Class. The object is loaded if necessary.
+ */
+QPointer<QSerialBus> QSerialBus::instance()
+{
+ if (!serialBus)
+ serialBus = new QSerialBus();
+
+ return serialBus;
+}
+
+QSerialBus::QSerialBus(QObject *parent) :
+ QObject(parent)
+{
+ loadPlugins();
+}
+
+Q_GLOBAL_STATIC(QSerialBusPrivate, serialBusPrivate)
+
+void QSerialBus::loadPlugins()
+{
+ QSerialBusPrivate *d = serialBusPrivate();
+ const QList<QJsonObject> meta = d->loader->metaData();
+ for (int i = 0; i < meta.count(); i++) {
+ QSerialBusPluginInterface *plugin = qobject_cast<QSerialBusPluginInterface*>(d->loader->instance(i));
+ if (plugin)
+ plugin->registerBus();
+ }
+}
+
+/*!
+ * Create a bus backend for \a identifier with \a type with \a name
+ * Returns \c null if no suitable \a identifier can be found.
+ */
+QPointer<QSerialBusBackend> QSerialBus::createBackend(const QByteArray &identifier, const QString &type, const QString &name)
+{
+ QSerialBusPrivate *d = serialBusPrivate();
+ loadPlugins();
+ if (!(d->factoryByIdentifier[identifier])) {
+ QPointer<QSerialBusBackend> faulty;
+ return faulty;
+ }
+ return d->factoryByIdentifier[identifier]->createBackend(type, name);
+}
+
+/*!
+ * Register backend for the \a identifier. The \a identifier must be unique.
+ * The \a factory will be asked to create instances of the backend.
+ */
+void QSerialBus::registerBackend(const QByteArray &identifier, QSerialBusBackendFactory *factory)
+{
+ QSerialBusPrivate *d = serialBusPrivate();
+ if (!d->factoryByIdentifier.contains(identifier))
+ d->factoryByIdentifier[identifier] = factory;
+}
+
+/*!
+ * Returns QList of identifiers for all loaded plugins.
+ */
+QList<QByteArray> QSerialBus::plugins()
+{
+ QSerialBusPrivate *d = serialBusPrivate();
+ loadPlugins();
+ return d->factoryByIdentifier.keys();
+}
+
+
+QSerialBusBackendFactory::~QSerialBusBackendFactory()
+{
+}
+
+#include "qserialbus.moc"
diff --git a/src/serialbus/qserialbus.h b/src/serialbus/qserialbus.h
new file mode 100644
index 0000000..7ff0a1b
--- /dev/null
+++ b/src/serialbus/qserialbus.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSERIALBUS_H
+#define QSERIALBUS_H
+
+#include <QtSerialBus/qserialbusglobal.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qpointer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSerialBusPrivate;
+class QSerialBusBackend;
+class QSerialBusBackendFactory;
+class QFactoryLoader;
+
+class Q_SERIALBUS_EXPORT QSerialBus : public QObject
+{
+ Q_OBJECT
+
+public:
+ //TODO: return raw pointer
+ static QPointer<QSerialBus> instance();
+
+ QList<QByteArray> plugins();
+ static void registerBackend(const QByteArray &identifier, QSerialBusBackendFactory *factory);
+ //TODO: return raw pointer
+ QPointer<QSerialBusBackend> createBackend(const QByteArray &identifier, const QString &type, const QString &name);
+
+private:
+ QSerialBus(QObject *parent = 0);
+ void loadPlugins();
+ QSerialBusPrivate *d_ptr;
+
+ static QPointer<QSerialBus> serialBus;
+
+ Q_DECLARE_PRIVATE(QSerialBus)
+ Q_DISABLE_COPY(QSerialBus)
+};
+
+
+class Q_SERIALBUS_EXPORT QSerialBusBackendFactory
+{
+public:
+ //TODO: return raw pointer
+ virtual QPointer<QSerialBusBackend> createBackend(const QString &busBackend, const QString &name) = 0;
+protected:
+ virtual ~QSerialBusBackendFactory();
+};
+
+
+QT_END_NAMESPACE
+
+#endif // QSERIALBUS_H
diff --git a/src/serialbus/qserialbusbackend.h b/src/serialbus/qserialbusbackend.h
new file mode 100644
index 0000000..b592d19
--- /dev/null
+++ b/src/serialbus/qserialbusbackend.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSERIALBUSBACKEND_H
+#define QSERIALBUSBACKEND_H
+
+#include <QtSerialBus/qserialbusglobal.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qbytearray.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_SERIALBUS_EXPORT QSerialBusBackend : public QObject
+{
+ Q_OBJECT
+public:
+ //TODO: remove
+ virtual QByteArray readAll() = 0;
+ virtual QByteArray read(qint64) = 0;
+ //TODO: SetConfigurationParameter?
+ //TODO: (const QString &key, const QVariant &value)?
+ //TODO: getConfiguration?
+ virtual void setConfiguration(const QPair<QString, QVariant> &) = 0;
+ //TODO: inconsistent naming.
+ //TODO: Should it be (const char*, int len) instead of QByteArray;
+ virtual void writeToBus(const QByteArray &) = 0;
+ //TODO: better way than QDataStream to pass the information
+ virtual void setDataStreamVersion(int) = 0;
+ virtual int dataStreamVersion() const = 0;
+ //TODO: size? bytesAvailable
+ virtual qint64 size() const = 0;
+
+Q_SIGNALS:
+ void readyRead();
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QSERIALBUSBACKEND_H
diff --git a/src/serialbus/qserialbusdevice.cpp b/src/serialbus/qserialbusdevice.cpp
new file mode 100644
index 0000000..1f3a41c
--- /dev/null
+++ b/src/serialbus/qserialbusdevice.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qserialbusdevice.h"
+#include "qserialbusbackend.h"
+
+QSerialBusDevice::QSerialBusDevice(QPointer<QSerialBusBackend> backend, QObject *parent) :
+ QIODevice(parent),
+ busBackend(backend)
+{
+}
+
+qint64 QSerialBusDevice::readData(char *data, qint64 maxSize)
+{
+ if (!busBackend)
+ return -1;
+
+ qint64 length = busBackend->size();
+ if (maxSize < length)
+ length = maxSize;
+
+ const QByteArray temp = busBackend->read(length);
+ length = temp.size();
+ memcpy(data, temp.constData(), length);
+ return length;
+}
+
+qint64 QSerialBusDevice::writeData(const char *data, qint64 maxSize)
+{
+ if (!busBackend)
+ return -1;
+
+ QByteArray temp(data, maxSize);
+ busBackend->writeToBus(temp);
+ return 0;
+}
diff --git a/src/serialbus/qserialbusdevice.h b/src/serialbus/qserialbusdevice.h
new file mode 100644
index 0000000..d205a5e
--- /dev/null
+++ b/src/serialbus/qserialbusdevice.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSERIALBUSDEVICE_H
+#define QSERIALBUSDEVICE_H
+
+#include <QtSerialBus/qserialbusglobal.h>
+#include <QtCore/qiodevice.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSerialBusBackend;
+
+//TODO: close()/open()/connect() functions missing
+//TODO: error reporting missing
+//TODO: state reporting missing
+class Q_SERIALBUS_EXPORT QSerialBusDevice : public QIODevice
+{
+ Q_OBJECT
+
+public:
+ explicit QSerialBusDevice(QPointer<QSerialBusBackend> backend, QObject *parent = 0);
+protected:
+ virtual qint64 readData(char *data, qint64 maxSize) Q_DECL_OVERRIDE;
+ virtual qint64 writeData(const char *data, qint64 maxSize) Q_DECL_OVERRIDE;
+
+private:
+ QPointer<QSerialBusBackend> busBackend;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSERIALBUSDEVICE_H
diff --git a/src/serialbus/qserialbusglobal.h b/src/serialbus/qserialbusglobal.h
new file mode 100644
index 0000000..6cc31b6
--- /dev/null
+++ b/src/serialbus/qserialbusglobal.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSERIALBUSGLOBAL_H
+#define QSERIALBUSGLOBAL_H
+
+#include <QtCore/qglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_STATIC
+# if defined(QT_BUILD_SERIALBUS_LIB)
+# define Q_SERIALBUS_EXPORT Q_DECL_EXPORT
+# else
+# define Q_SERIALBUS_EXPORT Q_DECL_IMPORT
+# endif
+#else
+# define Q_SERIALBUS_EXPORT
+#endif
+
+QT_END_NAMESPACE
+
+#endif // QSERIALBUSGLOBAL_H
diff --git a/src/serialbus/qserialbusplugininterface.h b/src/serialbus/qserialbusplugininterface.h
new file mode 100644
index 0000000..dfc0ff3
--- /dev/null
+++ b/src/serialbus/qserialbusplugininterface.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSERIALBUSPLUGININTERFACE_H
+#define QSERIALBUSPLUGININTERFACE_H
+
+#include <QtSerialBus/qserialbusglobal.h>
+#include <QtCore/qplugin.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_SERIALBUS_EXPORT QSerialBusPluginInterface
+{
+public:
+ virtual void registerBus() = 0;
+protected:
+ virtual ~QSerialBusPluginInterface(){}
+};
+
+Q_DECLARE_INTERFACE(QSerialBusPluginInterface, "org.qt-project.Qt.QSerialBusPluginInterface")
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/serialbus/serialbus.pro b/src/serialbus/serialbus.pro
new file mode 100644
index 0000000..6f876e4
--- /dev/null
+++ b/src/serialbus/serialbus.pro
@@ -0,0 +1,30 @@
+TARGET = QtSerialBus
+QT = core-private
+
+QMAKE_DOCS = $$PWD/doc/qtserialbus.qdocconf
+
+MODULE_PLUGIN_TYPES = \
+ serialbuses
+
+load(qt_module)
+
+PUBLIC_HEADERS += \
+ qcanbusdevice.h \
+ qcanframe.h \
+ qserialbus.h \
+ qserialbusbackend.h \
+ qserialbusdevice.h \
+ qserialbusglobal.h \
+ qserialbusplugininterface.h \
+
+PRIVATE_HEADERS += \
+ qbusdummydevice.h \
+ qcanbusdevice_p.h
+
+SOURCES += \
+ qbusdummydevice.cpp \
+ qcanbusdevice.cpp \
+ qserialbus.cpp \
+ qserialbusdevice.cpp \
+
+HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
diff --git a/src/src.pro b/src/src.pro
new file mode 100644
index 0000000..9175d9c
--- /dev/null
+++ b/src/src.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+
+SUBDIRS += serialbus
+serialbus.subdir = serialbus
+serialbus.target = sub-serialbus
+
+SUBDIRS += plugins
+plugins.subdir = plugins
+plugins.target = sub-plugins
+plugins.depends = serialbus
+
diff --git a/sync.profile b/sync.profile
new file mode 100644
index 0000000..5dd22e7
--- /dev/null
+++ b/sync.profile
@@ -0,0 +1,7 @@
+%modules = (
+ "QtSerialBus" => "$basedir/src/serialbus",
+);
+
+%dependencies = (
+ "qtbase" => "",
+);
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
new file mode 100644
index 0000000..bfb6ba2
--- /dev/null
+++ b/tests/auto/auto.pro
@@ -0,0 +1,5 @@
+TEMPLATE = subdirs
+SUBDIRS += cmake \
+ qcanframe \
+ qserialbus \
+ qcanbusdevice \
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt
new file mode 100644
index 0000000..58ecb44
--- /dev/null
+++ b/tests/auto/cmake/CMakeLists.txt
@@ -0,0 +1,14 @@
+
+cmake_minimum_required(VERSION 2.8)
+
+project(qmake_cmake_files)
+
+enable_testing()
+
+find_package(Qt5Core REQUIRED)
+
+include("${_Qt5CTestMacros}")
+
+test_module_includes(
+ SerialBus QCanFrame
+)
diff --git a/tests/auto/cmake/cmake.pro b/tests/auto/cmake/cmake.pro
new file mode 100644
index 0000000..d39b951
--- /dev/null
+++ b/tests/auto/cmake/cmake.pro
@@ -0,0 +1,7 @@
+
+# Cause make to do nothing.
+TEMPLATE = subdirs
+
+CMAKE_QT_MODULES_UNDER_TEST = serialbus
+
+CONFIG += ctest_testcase
diff --git a/tests/auto/qcanbusdevice/qcanbusdevice.pro b/tests/auto/qcanbusdevice/qcanbusdevice.pro
new file mode 100644
index 0000000..254d803
--- /dev/null
+++ b/tests/auto/qcanbusdevice/qcanbusdevice.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+QT = core testlib
+TARGET = tst_qcanbusdevice
+
+QT += serialbus
+
+SOURCES += tst_qcanbusdevice.cpp
diff --git a/tests/auto/qcanbusdevice/tst_qcanbusdevice.cpp b/tests/auto/qcanbusdevice/tst_qcanbusdevice.cpp
new file mode 100644
index 0000000..7962551
--- /dev/null
+++ b/tests/auto/qcanbusdevice/tst_qcanbusdevice.cpp
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtSerialBus/QCanBusDevice>
+#include <QtSerialBus/QCanFrame>
+#include <QtSerialBus/QSerialBusBackend>
+
+#include <QtTest/QtTest>
+#include <QSignalSpy>
+
+class tst_Backend : public QSerialBusBackend
+{
+ Q_OBJECT
+public:
+ QByteArray readAll(){ return QByteArray(); };
+ QByteArray read(qint64){ return QByteArray("data"); };
+ void setConfiguration(const QPair<QString, QVariant>&) {};
+ void writeToBus(const QByteArray &) { emit written(); };
+ void setDataStreamVersion(int v){ version = v; };
+ int dataStreamVersion() const { return version; };
+ qint64 size() const { return 0; };
+
+signals:
+ void written();
+
+private:
+ int version;
+};
+
+class tst_QCanBusDevice : public QObject
+{
+ Q_OBJECT
+public:
+ explicit tst_QCanBusDevice();
+
+private slots:
+ void initTestCase();
+ void conf();
+ void write();
+ void read();
+ void version();
+
+private:
+ QCanBusDevice *device;
+ QSerialBusBackend *backend;
+};
+
+tst_QCanBusDevice::tst_QCanBusDevice() :
+ device(0),
+ backend(0)
+{
+}
+
+void tst_QCanBusDevice::initTestCase()
+{
+ backend = new tst_Backend();
+ device = new QCanBusDevice(backend);
+ QVERIFY(device);
+ QVERIFY(backend);
+}
+
+void tst_QCanBusDevice::conf()
+{
+ QPair<QString, QVariant> configuration;
+ device->setConfiguration(configuration);
+}
+
+void tst_QCanBusDevice::write()
+{
+ QSignalSpy spy(backend, SIGNAL(written()));
+ QCanFrame frame;
+ frame.setPayload(QByteArray("testData"));
+ device->writeFrame(frame);
+ QCOMPARE(spy.count(), 0);
+
+ device->open(QIODevice::WriteOnly);
+ device->writeFrame(frame);
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_QCanBusDevice::read()
+{
+ QCanFrame frame1 = device->readFrame();
+ device->open(QIODevice::ReadOnly);
+ QCanFrame frame2 = device->readFrame();
+ QVERIFY(!frame1.frameId());
+ QVERIFY(frame2.frameId());
+}
+
+void tst_QCanBusDevice::version()
+{
+ int version = 7;
+ device->setDataStreamVersion(version);
+ QCOMPARE(version, device->dataStreamVersion());
+}
+
+QTEST_MAIN(tst_QCanBusDevice)
+
+#include "tst_qcanbusdevice.moc"
diff --git a/tests/auto/qcanframe/qcanframe.pro b/tests/auto/qcanframe/qcanframe.pro
new file mode 100644
index 0000000..f3eff5b
--- /dev/null
+++ b/tests/auto/qcanframe/qcanframe.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+QT = core testlib
+TARGET = tst_qcanframe
+
+QT += serialbus
+
+SOURCES += tst_qcanframe.cpp
diff --git a/tests/auto/qcanframe/tst_qcanframe.cpp b/tests/auto/qcanframe/tst_qcanframe.cpp
new file mode 100644
index 0000000..e935a54
--- /dev/null
+++ b/tests/auto/qcanframe/tst_qcanframe.cpp
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtSerialBus/QCanFrame>
+
+class tst_QCanFrame : public QObject
+{
+ Q_OBJECT
+public:
+ explicit tst_QCanFrame();
+
+private slots:
+ void constructors();
+ void id();
+ void payload();
+ void timeStamp();
+};
+
+tst_QCanFrame::tst_QCanFrame()
+{
+}
+
+void tst_QCanFrame::constructors()
+{
+ QCanFrame frame1;
+ QCanFrame frame2(123, "tst");
+ QCanFrame::TimeStamp timeStamp1;
+ QCanFrame::TimeStamp timeStamp2(5, 5);
+
+ QVERIFY(frame1.payload().isEmpty());
+ QVERIFY(!frame1.frameId());
+
+ QVERIFY(!frame2.payload().isEmpty());
+ QVERIFY(frame2.frameId());
+
+ QVERIFY(!timeStamp1.seconds());
+ QVERIFY(!timeStamp1.microSeconds());
+
+ QVERIFY(timeStamp2.seconds());
+ QVERIFY(timeStamp2.microSeconds());
+}
+
+void tst_QCanFrame::id()
+{
+ QCanFrame frame;
+ QVERIFY(!frame.frameId());
+ frame.setFrameId(512);
+ QCOMPARE(frame.frameId(), 512);
+}
+
+void tst_QCanFrame::payload()
+{
+ QCanFrame frame;
+ QVERIFY(frame.payload().isEmpty());
+ frame.setPayload("test");
+ QCOMPARE(frame.payload().data(), "test");
+}
+
+void tst_QCanFrame::timeStamp()
+{
+ QCanFrame frame;
+ QCanFrame::TimeStamp timeStamp = frame.timeStamp();
+ QVERIFY(!timeStamp.seconds());
+ QVERIFY(!timeStamp.microSeconds());
+ timeStamp.setMicroSeconds(5);
+ timeStamp.setSeconds(4);
+ QCOMPARE(timeStamp.seconds(), 4);
+ QCOMPARE(timeStamp.microSeconds(), 5);
+}
+
+QTEST_MAIN(tst_QCanFrame)
+
+#include "tst_qcanframe.moc"
diff --git a/tests/auto/qserialbus/qserialbus.pro b/tests/auto/qserialbus/qserialbus.pro
new file mode 100644
index 0000000..96d5b6d
--- /dev/null
+++ b/tests/auto/qserialbus/qserialbus.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+QT = core testlib
+TARGET = tst_qserialbus
+
+QT += serialbus
+
+HEADERS +=
+
+SOURCES += tst_qserialbus.cpp \
diff --git a/tests/auto/qserialbus/tst_qserialbus.cpp b/tests/auto/qserialbus/tst_qserialbus.cpp
new file mode 100644
index 0000000..da61305
--- /dev/null
+++ b/tests/auto/qserialbus/tst_qserialbus.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtSerialBus module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtSerialBus/QSerialBus>
+
+#include <QtTest/QtTest>
+
+class tst_QSerialBus : public QObject
+{
+ Q_OBJECT
+public:
+ explicit tst_QSerialBus();
+
+private slots:
+ void initTestCase();
+ void plugins();
+ void createBackend();
+
+private:
+ QSerialBus *bus;
+};
+
+tst_QSerialBus::tst_QSerialBus() :
+ bus(0)
+{
+}
+
+void tst_QSerialBus::initTestCase()
+{
+ bus = QSerialBus::instance();
+ QVERIFY(bus != 0);
+ QSerialBus *sameInstance;
+ sameInstance = QSerialBus::instance();
+ QCOMPARE(bus, sameInstance);
+}
+
+void tst_QSerialBus::plugins()
+{
+ QVERIFY(!bus->plugins().isEmpty());
+}
+
+void tst_QSerialBus::createBackend()
+{
+ QPointer<QSerialBusBackend> faulty = bus->createBackend("foo","socketFoo","vfoo");
+ QVERIFY(faulty.isNull());
+ QPointer<QSerialBusBackend> dummy = bus->createBackend("dummy", "unused", "unused");
+}
+
+QTEST_MAIN(tst_QSerialBus)
+
+#include "tst_qserialbus.moc"
diff --git a/tests/tests.pro b/tests/tests.pro
new file mode 100644
index 0000000..157ef34
--- /dev/null
+++ b/tests/tests.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += auto