blob: be7fb4091b913585b7c1e08d121a6c1673117435 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "testcanbackend.h"
#include <QtCore/qdatetime.h>
#include <QtCore/qdebug.h>
#include <QtCore/qtimer.h>
QT_BEGIN_NAMESPACE
TestCanBackend::TestCanBackend() :
simulateReceivingTimer(new QTimer(this))
{
connect(simulateReceivingTimer, &QTimer::timeout, [this]() {
const quint64 timeStamp = QDateTime::currentDateTime().toMSecsSinceEpoch();
QCanBusFrame dummyFrame(12, "def");
dummyFrame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(timeStamp * 1000));
enqueueReceivedFrames({dummyFrame});
});
}
bool TestCanBackend::open()
{
simulateReceivingTimer->start(1000);
setState(QCanBusDevice::ConnectedState);
return true;
}
void TestCanBackend::close()
{
simulateReceivingTimer->stop();
setState(QCanBusDevice::UnconnectedState);
}
bool TestCanBackend::writeFrame(const QCanBusFrame &data)
{
qDebug("DummyBackend::writeFrame: %ls", qUtf16Printable(data.toString()));
return true;
}
QString TestCanBackend::interpretErrorFrame(const QCanBusFrame &/*errorFrame*/)
{
return QString();
}
QList<QCanBusDeviceInfo> TestCanBackend::interfaces()
{
return {createDeviceInfo(QStringLiteral("testcan"), QStringLiteral("can0"), true, true)};
}
QT_END_NAMESPACE
|