-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcanbusnode.cpp
More file actions
54 lines (45 loc) · 1.26 KB
/
Copy pathcanbusnode.cpp
File metadata and controls
54 lines (45 loc) · 1.26 KB
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
54
#include "canbusnode.h"
#include <QCanBusDevice>
#include <QTimer>
CanBusNode::CanBusNode(QCanBusDevice* canBusDevice, quint32 frameIdSending, quint32 frameIdReceiving, QObject* parent)
: QObject(parent),
m_canBusDevice(canBusDevice),
m_frameIdSending(frameIdSending),
m_frameIdReceiving(frameIdReceiving),
m_timeOutTimer(new QTimer(this))
{
setTimeoutInterval(5000);
connect(m_timeOutTimer, &QTimer::timeout, this, &CanBusNode::timeout);
}
void CanBusNode::sendFrame(quint32 frameId, const QByteArray& data)
{
QCanBusFrame frame(frameId, data);
m_canBusDevice->writeFrame(frame);
}
void CanBusNode::sendFrame(const QByteArray& data)
{
sendFrame(m_frameIdSending, data);
}
void CanBusNode::receiveFrame(const QByteArray& data)
{
Q_UNUSED(data);
}
void CanBusNode::receiveFrame(quint32 frameId, const QByteArray& data)
{
Q_UNUSED(frameId);
Q_UNUSED(data);
}
void CanBusNode::receiveFrame(const QCanBusFrame& frame)
{
m_timeOutTimer->start();
receiveFrame(frame.payload());
receiveFrame(frame.frameId(), frame.payload());
}
QVector<quint32> CanBusNode::receivingFrameIds() const
{
return { m_frameIdReceiving };
}
void CanBusNode::setTimeoutInterval(int interval)
{
m_timeOutTimer->setInterval(interval);
}