-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslcanopennode.h
134 lines (97 loc) · 3.45 KB
/
slcanopennode.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef SLCANOPENNODE_H
#define SLCANOPENNODE_H
#include <QObject>
#include <QSerialPort>
#include <QQueue>
#include <chrono>
#include "slcan/slcan_master.h"
#include "CANopen.h"
#include "coobjectdict.h"
#include "sdocomm.h"
class QTimer;
class SLCanOpenNode : public QObject
{
Q_OBJECT
public:
using NodeId = quint8;
using Index = quint16;;
using SubIndex = quint8;
explicit SLCanOpenNode(QObject *parent = nullptr);
~SLCanOpenNode();
bool openPort(const QString& name, QSerialPort::BaudRate baud,
QSerialPort::Parity parity, QSerialPort::StopBits stopBits);
void closePort();
bool createCO(uint newBitrate = 125);
void destroyCO();
bool isConnected() const;
quint16 firstHBTime() const;
void setFirstHBTime(quint16 newFirstHBTime);
quint16 SDOserverTimeout() const;
void setSDOserverTimeout(quint16 newSDOserverTimeout);
quint16 SDOclientTimeout() const;
void setSDOclientTimeout(quint16 newSDOclientTimeout);
bool SDOclientBlockTransfer() const;
void setSDOclientBlockTransfer(bool newSDOclientBlockTransfer);
quint8 nodeId() const;
void setNodeId(NodeId newNodeId);
uint32_t cobidClientToServer() const;
void setCobidClientToServer(uint32_t newCobidClientToServer);
uint32_t cobidServerToClient() const;
void setCobidServerToClient(uint32_t newCobidServerToClient);
uint16_t heartbeatTime() const;
void setHeartbeatTime(uint16_t newHeartbeatTime);
// SLCan poll & CO process timer interval in ms.
int coTimerInterval() const;
void setCoTimerInterval(int newCoTimerInterval);
int defaultTimeout() const;
void setDefaultTimeout(int newDefaultTimeout);
bool adapterNoAnswers() const;
void setAdapterNoAnswers(bool newNoAnswers);
bool updateOd();
/*
* read & write:
* timeout == -1 -> max timeout (65535).
* timeout == 0 -> default timeout.
* sdocomm == nullptr -> alloc new sdo comm.
*/
SDOComm* read(NodeId devId, Index dataIndex, SubIndex dataSubIndex,
void* data, size_t dataSize, SDOComm* sdocomm = nullptr, int timeout = -1);
SDOComm* write(NodeId devId, Index dataIndex, SubIndex dataSubIndex,
const void* data, size_t dataSize, SDOComm* sdocomm = nullptr, int timeout = -1);
bool read(SDOComm* sdocom);
bool write(SDOComm* sdocom);
// return true if sdoc removed(not in) from queue and can be deleted or reused.
// when return true - not finish sdo comm.
bool cancel(SDOComm* sdoc);
signals:
void connected();
void disconnected();
private slots:
void slcanSerialReadyRead();
void slcanSerialBytesWritten(qint64 bytes);
void pollSlcanProcessCO();
private:
slcan_t m_sc;
slcan_master_t m_scm;
COObjectDict m_od;
CO_t* m_co;
QTimer* m_coProcessTimer;
using meas_clock = std::chrono::steady_clock;
meas_clock::time_point m_coProcessTp;
quint16 m_firstHBTime;
quint16 m_SDOserverTimeout;
quint16 m_SDOclientTimeout;
bool m_SDOclientBlockTransfer;
NodeId m_nodeId;
uint32_t m_cobidClientToServer;
uint32_t m_cobidServerToClient;
uint16_t m_heartbeatTime;
int m_defaultTimeout;
QQueue<SDOComm*> m_sdoComms;
void processSDOClient(uint32_t dt);
bool processFrontComm(uint32_t dt);
SDOComm::Error sdoCommError(CO_SDO_abortCode_t code) const;
void cancelAllSDOComms();
void createOd();
};
#endif // SLCANOPENNODE_H