-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of mockcan plugin. Plugin does nothing but can be loa…
…ded.
- Loading branch information
Showing
10 changed files
with
230 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (C) 2019, Burkhard Stubert (DBA Embedded Use) | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project(canbus) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
|
||
find_package(Qt5Core) | ||
find_package(Qt5SerialBus) | ||
|
||
add_library( | ||
${PROJECT_NAME} MODULE | ||
main.cpp | ||
mockcanbackend.cpp | ||
mockcanbackend.h | ||
) | ||
|
||
#add_library(EmUse::mockcan ALIAS ${PROJECT_NAME}) | ||
|
||
target_include_directories(${PROJECT_NAME} INTERFACE .) | ||
|
||
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::SerialBus) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2019, Burkhard Stubert (DBA Embedded Use) | ||
|
||
#include <QCanBus> | ||
#include <QCanBusDevice> | ||
#include <QCanBusFactoryV2> | ||
#include <QObject> | ||
|
||
#include "mockcanbackend.h" | ||
|
||
class MockCanBusPlugin : public QObject, public QCanBusFactoryV2 | ||
{ | ||
Q_OBJECT | ||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactory" FILE "plugin.json") | ||
Q_INTERFACES(QCanBusFactoryV2) | ||
|
||
public: | ||
QList<QCanBusDeviceInfo> availableDevices(QString *errorMessage) const override | ||
{ | ||
Q_UNUSED(errorMessage); | ||
return MockCanBackend::interfaces(); | ||
} | ||
|
||
QCanBusDevice *createDevice(const QString &interfaceName, QString *errorMessage) const override | ||
{ | ||
Q_UNUSED(errorMessage); | ||
auto device = new MockCanBackend(interfaceName); | ||
return device; | ||
} | ||
}; | ||
|
||
#include "main.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (C) 2019, Burkhard Stubert (DBA Embedded Use) | ||
|
||
#include "mockcanbackend.h" | ||
|
||
QList<QCanBusDeviceInfo> MockCanBackend::interfaces() | ||
{ | ||
return {}; | ||
} | ||
|
||
MockCanBackend::MockCanBackend(const QString &name) | ||
{ | ||
Q_UNUSED(name) | ||
resetConfigurations(); | ||
} | ||
|
||
MockCanBackend::~MockCanBackend() | ||
{ | ||
close(); | ||
} | ||
|
||
void MockCanBackend::resetConfigurations() | ||
{ | ||
QCanBusDevice::setConfigurationParameter( | ||
QCanBusDevice::LoopbackKey, true); | ||
QCanBusDevice::setConfigurationParameter( | ||
QCanBusDevice::ReceiveOwnKey, false); | ||
QCanBusDevice::setConfigurationParameter( | ||
QCanBusDevice::ErrorFilterKey, | ||
QVariant::fromValue(QCanBusFrame::FrameErrors(QCanBusFrame::AnyError))); | ||
QCanBusDevice::setConfigurationParameter( | ||
QCanBusDevice::CanFdKey, false); | ||
} | ||
|
||
bool MockCanBackend::open() | ||
{ | ||
setState(QCanBusDevice::ConnectedState); | ||
return true; | ||
} | ||
|
||
void MockCanBackend::close() | ||
{ | ||
setState(QCanBusDevice::UnconnectedState); | ||
} | ||
|
||
void MockCanBackend::setConfigurationParameter(int key, const QVariant &value) | ||
{ | ||
Q_UNUSED(key) | ||
Q_UNUSED(value) | ||
} | ||
|
||
bool MockCanBackend::writeFrame(const QCanBusFrame &newData) | ||
{ | ||
Q_UNUSED(newData) | ||
return false; | ||
} | ||
|
||
QString MockCanBackend::interpretErrorFrame(const QCanBusFrame &errorFrame) | ||
{ | ||
Q_UNUSED(errorFrame) | ||
return {}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2019, Burkhard Stubert (DBA Embedded Use) | ||
|
||
#pragma once | ||
|
||
#include <QCanBusFrame> | ||
#include <QCanBusDevice> | ||
#include <QCanBusDeviceInfo> | ||
#include <QString> | ||
#include <QVariant> | ||
|
||
|
||
class MockCanBackend : public QCanBusDevice | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit MockCanBackend(const QString &name); | ||
~MockCanBackend(); | ||
|
||
bool open() override; | ||
void close() override; | ||
|
||
void setConfigurationParameter(int key, const QVariant &value) override; | ||
|
||
bool writeFrame(const QCanBusFrame &newData) override; | ||
|
||
QString interpretErrorFrame(const QCanBusFrame &errorFrame) override; | ||
|
||
static QList<QCanBusDeviceInfo> interfaces(); | ||
|
||
private: | ||
void resetConfigurations(); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"Key": "mockcan" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright (C) 2019, Burkhard Stubert (DBA Embedded Use) | ||
|
||
cmake_minimum_required(VERSION 3.5) | ||
|
||
add_subdirectory(testmockcanbus) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (C) 2019, Burkhard Stubert (DBA Embedded Use) | ||
|
||
project(testmockcanbus) | ||
|
||
cmake_minimum_required(VERSION 3.5) | ||
|
||
set(CMAKE_AUTOMOC on) | ||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
|
||
find_package(Qt5Test) | ||
find_package(Qt5SerialBus) | ||
|
||
add_executable( | ||
${PROJECT_NAME} | ||
testmockcanbus.cpp | ||
) | ||
|
||
add_test( | ||
NAME ${PROJECT_NAME} | ||
COMMAND ${PROJECT_NAME} | ||
) | ||
|
||
target_link_libraries( | ||
${PROJECT_NAME} | ||
Qt5::SerialBus Qt5::Test | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (C) 2019, Burkhard Stubert (DBA Embedded Use) | ||
|
||
#include <QCoreApplication> | ||
#include <QObject> | ||
#include <QtDebug> | ||
#include <QtTest> | ||
|
||
#include <QCanBus> | ||
|
||
class TestMockCanBus : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
private slots: | ||
void initTestCase(); | ||
void testCreate(); | ||
}; | ||
|
||
void TestMockCanBus::initTestCase() | ||
{ | ||
QCoreApplication::addLibraryPath("../../"); | ||
} | ||
|
||
void TestMockCanBus::testCreate() | ||
{ | ||
QString errorStr{"None"}; | ||
auto device = QCanBus::instance()->createDevice("mockcan", "can0", &errorStr); | ||
qDebug() << "ERROR: " << errorStr; | ||
QVERIFY(device != nullptr); | ||
} | ||
|
||
|
||
QTEST_GUILESS_MAIN(TestMockCanBus) | ||
|
||
#include "testmockcanbus.moc" |