CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
candevicemodel.h
Go to the documentation of this file.
1#ifndef CANDEVICEMODEL_H
2#define CANDEVICEMODEL_H
3
4#include "candevice.h"
5#include "componentmodel.h"
6#include "nodepainter.h"
7#include <QtCore/QObject>
8#include <QtSerialBus/QCanBusFrame>
9#include <readerwriterqueue.h>
10
11using QtNodes::NodeData;
12using QtNodes::NodeDataType;
13using QtNodes::PortIndex;
14using QtNodes::PortType;
15
16enum class Direction;
17
21class CanDeviceModel : public ComponentModel<CanDevice, CanDeviceModel> {
22 Q_OBJECT
23
24public:
26
32 unsigned int nPorts(PortType portType) const override;
33
40 NodeDataType dataType(PortType portType, PortIndex portIndex) const override;
41
47 std::shared_ptr<NodeData> outData(PortIndex port) override;
48
54 void setInData(std::shared_ptr<NodeData> nodeData, PortIndex port) override;
55
60 QtNodes::NodePainterDelegate* painterDelegate() const override;
61
62 virtual bool hasSeparateThread() const override
63 {
64 return true;
65 }
66
67public slots:
68
73 void frameReceived(const QCanBusFrame& frame);
74
80 void frameSent(bool status, const QCanBusFrame& frame);
81
82signals:
87 void sendFrame(const QCanBusFrame& frame);
89
90private:
91 std::shared_ptr<NodeData> _nodeData;
92 bool _status;
93 Direction _direction;
94 QCanBusFrame _frame;
95 std::unique_ptr<NodePainter> _painter;
96 // 127 to use 4 blocks, 512 bytes each
97 moodycamel::ReaderWriterQueue<std::shared_ptr<NodeData>> _rxQueue{ 127 };
98};
99
100#endif // CANDEVICEMODEL_H
The class provides node graphical representation of CanDevice.
Definition candevicemodel.h:21
virtual bool hasSeparateThread() const override
Definition candevicemodel.h:62
void frameSent(bool status, const QCanBusFrame &frame)
Callback, called when CanDevice emits signal frameReceived.
Definition candevicemodel.cpp:45
void setInData(std::shared_ptr< NodeData > nodeData, PortIndex port) override
Handles data on input port, sends frame if correct.
Definition candevicemodel.cpp:76
NodeDataType dataType(PortType portType, PortIndex portIndex) const override
Used to get data type of each port.
Definition candevicemodel.cpp:56
QtNodes::NodePainterDelegate * painterDelegate() const override
Used to provide custom painter to nodeeditor.
Definition candevicemodel.cpp:22
unsigned int nPorts(PortType portType) const override
Used to get number of ports of each type used by model.
Definition candevicemodel.cpp:27
std::shared_ptr< NodeData > outData(PortIndex port) override
Sets output data for propagation.
Definition candevicemodel.cpp:63
void requestRedraw()
CanDeviceModel()
Definition candevicemodel.cpp:7
void sendFrame(const QCanBusFrame &frame)
Used to send a frame.
void frameReceived(const QCanBusFrame &frame)
Callback, called when CanDevice emits signal frameReceived.
Definition candevicemodel.cpp:34
Definition componentmodel.h:37
Direction
The enum class describing frame direction.
Definition datadirection.h:7