forked from vedderb/vesc_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.h
104 lines (86 loc) · 5.04 KB
/
utility.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
/*
Copyright 2017 Benjamin Vedder benjamin@vedder.se
This file is part of VESC Tool.
VESC 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.
VESC 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 UTILITY_H
#define UTILITY_H
#include <QObject>
#include <QMetaEnum>
#include <cstdint>
#include "vescinterface.h"
#define FE_WGS84 (1.0/298.257223563) // earth flattening (WGS84)
#define RE_WGS84 6378137.0 // earth semimajor axis (WGS84) (m)
class Utility : public QObject
{
Q_OBJECT
public:
explicit Utility(QObject *parent = nullptr);
static double map(double x, double in_min, double in_max, double out_min, double out_max);
static float throttle_curve(float val, float curve_acc, float curve_brake, int mode);
static bool autoconnectBlockingWithProgress(VescInterface *vesc, QWidget *parent = nullptr);
Q_INVOKABLE static void checkVersion(VescInterface *vesc = nullptr);
Q_INVOKABLE static QString fwChangeLog();
Q_INVOKABLE static QString vescToolChangeLog();
Q_INVOKABLE static QString aboutText();
Q_INVOKABLE static QString uuid2Str(QByteArray uuid, bool space);
Q_INVOKABLE static bool requestFilePermission();
Q_INVOKABLE static void keepScreenOn(bool on);
Q_INVOKABLE static bool waitSignal(QObject *sender, QString signal, int timeoutMs);
Q_INVOKABLE static void sleepWithEventLoop(int timeMs);
Q_INVOKABLE static QString detectAllFoc(VescInterface *vesc,
bool detect_can, double max_power_loss, double min_current_in,
double max_current_in, double openloop_rpm, double sl_erpm);
Q_INVOKABLE static bool resetInputCan(VescInterface *vesc, QVector<int> canIds);
Q_INVOKABLE static bool setBatteryCutCan(VescInterface *vesc, QVector<int> canIds,
double cutStart, double cutEnd);
Q_INVOKABLE static bool setBatteryCutCanFromCurrentConfig(VescInterface *vesc, QVector<int> canIds);
Q_INVOKABLE static bool setInvertDirection(VescInterface *vesc, int canId, bool inverted);
Q_INVOKABLE static bool getInvertDirection(VescInterface *vesc, int canId);
Q_INVOKABLE static QString testDirection(VescInterface *vesc, int canId, double duty, int ms);
Q_INVOKABLE static bool restoreConfAll(VescInterface *vesc, bool can, bool mc, bool app);
Q_INVOKABLE static bool almostEqual(double A, double B, double eps);
static bool createParamParserC(VescInterface *vesc, QString filename);
static bool createParamParserC(ConfigParams *params, QString configName, QString filename);
static bool createCompressedConfigC(ConfigParams *params, QString configName, QString filename);
static uint32_t crc32c(uint8_t *data, uint32_t len);
static bool getFwVersionBlocking(VescInterface *vesc, FW_RX_PARAMS *params);
static bool getFwVersionBlockingCan(VescInterface *vesc, FW_RX_PARAMS *params, int canId);
Q_INVOKABLE static FW_RX_PARAMS getFwVersionBlockingCan(VescInterface *vesc, int canId);
static bool checkFwCompatibility(VescInterface *vesc);
Q_INVOKABLE static QVariantList getNetworkAddresses();
Q_INVOKABLE static void startGnssForegroundService();
Q_INVOKABLE static void stopGnssForegroundService();
static void llhToXyz(double lat, double lon, double height, double *x, double *y, double *z);
static void xyzToLlh(double x, double y, double z, double *lat, double *lon, double *height);
static void createEnuMatrix(double lat, double lon, double *enuMat);
static void llhToEnu(const double *iLlh, const double *llh, double *xyz);
static void enuToLlh(const double *iLlh, const double *xyz, double *llh);
static bool configCheckCompatibility(int fwMajor, int fwMinor);
static bool configLoad(VescInterface *vesc, int fwMajor, int fwMinor);
static QPair<int, int> configLatestSupported();
static bool configLoadLatest(VescInterface *vesc);
static QVector<QPair<int, int>> configSupportedFws();
static bool configLoadCompatible(VescInterface *vesc, QString &uuidRx);
Q_INVOKABLE static QVector<int> scanCanVescOnly(VescInterface *vesc);
template<typename QEnum>
static QString QEnumToQString (const QEnum value) {
return QString(QMetaEnum::fromType<QEnum>().valueToKey(value));
}
signals:
public slots:
private:
static void serialFunc(ConfigParams *params, QTextStream &s);
static void deserialFunc(ConfigParams *params, QTextStream &s);
static void defaultFunc(ConfigParams *params, QTextStream &s);
};
#endif // UTILITY_H