-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathbmsinterface.h
161 lines (133 loc) · 4.62 KB
/
bmsinterface.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
Original copyright 2018 Benjamin Vedder [email protected] and the VESC Tool project ( https://github.com/vedderb/vesc_tool )
Now forked to:
Danny Bokma [email protected]
This file is part of BMS Tool.
DieBieMS Tool is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DieBieMS Tool is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BMSInterface_H
#define BMSInterface_H
#include <QObject>
#include <QTimer>
#include <QByteArray>
#include <QList>
#include <QTcpSocket>
#include <QSettings>
#include <QHash>
#ifdef HAS_SERIALPORT
#include <QSerialPort>
#endif
#include "datatypes.h"
#include "configparams.h"
#include "commands.h"
#include "packet.h"
#include "bleuart.h"
class BMSInterface : public QObject
{
Q_OBJECT
public:
explicit BMSInterface(QObject *parent = 0);
~BMSInterface();
Q_INVOKABLE Commands *commands() const;
Q_INVOKABLE ConfigParams *bmsConfig();
Q_INVOKABLE ConfigParams *infoConfig();
Q_INVOKABLE QStringList getSupportedFirmwares();
QList<QPair<int, int> > getSupportedFirmwarePairs();
Q_INVOKABLE QString getFirmwareNow();
Q_INVOKABLE void emitStatusMessage(const QString &msg, bool isGood);
Q_INVOKABLE void emitMessageDialog(const QString &title, const QString &msg, bool isGood, bool richText = false);
Q_INVOKABLE bool fwRx();
Q_INVOKABLE BleUart* bleDevice();
Q_INVOKABLE void storeBleName(QString address, QString name);
Q_INVOKABLE QString getBleName(QString address);
// Connection
Q_INVOKABLE bool isPortConnected();
Q_INVOKABLE void disconnectPort();
Q_INVOKABLE bool reconnectLastPort();
Q_INVOKABLE bool autoconnect();
Q_INVOKABLE QString getConnectedPortName();
bool connectSerial(QString port, int baudrate = 115200);
QList<VSerialInfo_t> listSerialPorts();
Q_INVOKABLE void connectTcp(QString server, int port);
Q_INVOKABLE void connectBle(QString address);
Q_INVOKABLE bool isAutoconnectOngoing() const;
Q_INVOKABLE double getAutoconnectProgress() const;
signals:
void statusMessage(const QString &msg, bool isGood);
void messageDialog(const QString &title, const QString &msg, bool isGood, bool richText);
void fwUploadStatus(const QString &status, double progress, bool isOngoing);
void serialPortNotWritable(const QString &port);
void fwRxChanged(bool rx, bool limited);
void portConnectedChanged();
void autoConnectProgressUpdated(double progress, bool isOngoing);
void autoConnectFinished();
public slots:
private slots:
#ifdef HAS_SERIALPORT
void serialDataAvailable();
void serialPortError(QSerialPort::SerialPortError error);
#endif
void tcpInputConnected();
void tcpInputDisconnected();
void tcpInputDataAvailable();
void tcpInputError(QAbstractSocket::SocketError socketError);
void bleDataRx(QByteArray data);
void timerSlot();
void packetDataToSend(QByteArray &data);
void packetReceived(QByteArray &data);
void cmdDataToSend(QByteArray &data);
void fwVersionReceived(int major, int minor, QString hw, QByteArray uuid);
void bmsconfUpdated();
void bmsconfStored();
void ackReceived(QString ackType);
private:
typedef enum {
CONN_NONE = 0,
CONN_SERIAL,
CONN_TCP,
CONN_BLE
} conn_t;
QSettings mSettings;
QHash<QString, QString> mBleNames;
ConfigParams *mbmsConfig;
ConfigParams *mInfoConfig;
QTimer *mTimer;
Packet *mPacket;
Commands *mCommands;
bool mFwVersionReceived;
int mFwRetries;
int mFwPollCnt;
QString mFwTxt;
QString mHwTxt;
bool mIsUploadingFw;
// Connections
conn_t mLastConnType;
#ifdef HAS_SERIALPORT
QSerialPort *mSerialPort;
QString mLastSerialPort;
int mLastSerialBaud;
#endif
QTcpSocket *mTcpSocket;
bool mTcpConnected;
QString mLastTcpServer;
int mLastTcpPort;
BleUart *mBleUart;
QString mLastBleAddr;
bool mSendCanBefore = false;
int mCanIdBefore = 0;
bool mWasConnected;
bool mAutoconnectOngoing;
double mAutoconnectProgress;
void updateFwRx(bool fwRx);
void setLastConnectionType(conn_t type);
};
#endif // BMSInterface_H