This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devicehandler.h
163 lines (137 loc) · 6.46 KB
/
devicehandler.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
162
163
#pragma once
// Qt includes
#include <QDateTime>
#include <QTimer>
#include <QVector>
#include <QLowEnergyController>
#include <QLowEnergyService>
// local includes
#include "bluetoothbaseclass.h"
class DeviceInfo;
class DeviceHandler : public BluetoothBaseClass
{
Q_OBJECT
Q_PROPERTY(AddressType addressType READ addressType WRITE setAddressType)
Q_PROPERTY(bool alive READ alive NOTIFY aliveChanged)
Q_PROPERTY(float frontVoltage READ frontVoltage NOTIFY frontVoltageChanged);
Q_PROPERTY(float backVoltage READ backVoltage NOTIFY backVoltageChanged);
Q_PROPERTY(float frontTemperature READ frontTemperature NOTIFY frontTemperatureChanged);
Q_PROPERTY(float backTemperature READ backTemperature NOTIFY backTemperatureChanged);
Q_PROPERTY(int frontLeftError READ frontLeftError NOTIFY frontLeftErrorChanged);
Q_PROPERTY(int frontRightError READ frontRightError NOTIFY frontRightErrorChanged);
Q_PROPERTY(int backLeftError READ backLeftError NOTIFY backLeftErrorChanged);
Q_PROPERTY(int backRightError READ backRightError NOTIFY backRightErrorChanged);
Q_PROPERTY(float frontLeftSpeed READ frontLeftSpeed NOTIFY frontLeftSpeedChanged);
Q_PROPERTY(float frontRightSpeed READ frontRightSpeed NOTIFY frontRightSpeedChanged);
Q_PROPERTY(float backLeftSpeed READ backLeftSpeed NOTIFY backLeftSpeedChanged);
Q_PROPERTY(float backRightSpeed READ backRightSpeed NOTIFY backRightSpeedChanged);
Q_PROPERTY(float frontLeftDcLink READ frontLeftDcLink NOTIFY frontLeftDcLinkChanged);
Q_PROPERTY(float frontRightDcLink READ frontRightDcLink NOTIFY frontRightDcLinkChanged);
Q_PROPERTY(float backLeftDcLink READ backLeftDcLink NOTIFY backLeftDcLinkChanged);
Q_PROPERTY(float backRightDcLink READ backRightDcLink NOTIFY backRightDcLinkChanged);
Q_PROPERTY(bool remoteControlActive READ remoteControlActive WRITE setRemoteControlActive NOTIFY remoteControlActiveChanged);
Q_PROPERTY(int remoteControlFrontLeft WRITE setRemoteControlFrontLeft);
Q_PROPERTY(int remoteControlFrontRight WRITE setRemoteControlFrontRight);
Q_PROPERTY(int remoteControlBackLeft WRITE setRemoteControlBackLeft);
Q_PROPERTY(int remoteControlBackRight WRITE setRemoteControlBackRight);
public:
enum class AddressType {
PublicAddress,
RandomAddress
};
Q_ENUM(AddressType)
DeviceHandler(QObject *parent = nullptr);
void setDevice(const QBluetoothDeviceInfo &device);
void setAddressType(AddressType type);
AddressType addressType() const;
bool alive() const;
float frontVoltage() const { return m_frontVoltage; }
float backVoltage() const { return m_backVoltage; }
float frontTemperature() const { return m_frontTemperature; }
float backTemperature() const { return m_backTemperature; }
int frontLeftError() const { return m_frontLeftError; }
int frontRightError() const { return m_frontRightError; }
int backLeftError() const { return m_backLeftError; }
int backRightError() const { return m_backRightError; }
float frontLeftSpeed() const { return m_frontLeftSpeed; }
float frontRightSpeed() const { return m_frontRightSpeed; }
float backLeftSpeed() const { return m_backLeftSpeed; }
float backRightSpeed() const { return m_backRightSpeed; }
float frontLeftDcLink() const { return m_frontLeftDcLink; }
float frontRightDcLink() const { return m_frontRightDcLink; }
float backLeftDcLink() const { return m_backLeftDcLink; }
float backRightDcLink() const { return m_backRightDcLink; }
bool remoteControlActive() const { return m_timerId != -1; }
void setRemoteControlActive(bool remoteControlActive);
void setRemoteControlFrontLeft(int remoteControlFrontLeft) { m_remoteControlFrontLeft = remoteControlFrontLeft; }
void setRemoteControlFrontRight(int remoteControlFrontRight) { m_remoteControlFrontRight = remoteControlFrontRight; }
void setRemoteControlBackLeft(int remoteControlBackLeft) { m_remoteControlBackLeft = remoteControlBackLeft; }
void setRemoteControlBackRight(int remoteControlBackRight) { m_remoteControlBackRight = remoteControlBackRight; }
signals:
void aliveChanged();
void frontVoltageChanged();
void backVoltageChanged();
void frontTemperatureChanged();
void backTemperatureChanged();
void frontLeftErrorChanged();
void frontRightErrorChanged();
void backLeftErrorChanged();
void backRightErrorChanged();
void frontLeftSpeedChanged();
void frontRightSpeedChanged();
void backLeftSpeedChanged();
void backRightSpeedChanged();
void frontLeftDcLinkChanged();
void frontRightDcLinkChanged();
void backLeftDcLinkChanged();
void backRightDcLinkChanged();
void remoteControlActiveChanged();
protected:
void timerEvent(QTimerEvent *event) override;
public slots:
void disconnectService();
private:
void disconnectInternal();
//QLowEnergyController
void serviceDiscovered(const QBluetoothUuid &);
void serviceScanDone();
//QLowEnergyService
void serviceStateChanged(QLowEnergyService::ServiceState s);
void updateBobbycarValue(const QLowEnergyCharacteristic &c,
const QByteArray &value);
void confirmedDescriptorWrite(const QLowEnergyDescriptor &d,
const QByteArray &value);
void confirmedCharacteristicWrite(const QLowEnergyCharacteristic &info,
const QByteArray &value);
void sendRemoteControl();
private:
QLowEnergyController::RemoteAddressType m_addressType = QLowEnergyController::PublicAddress;
QLowEnergyController *m_control = nullptr;
QLowEnergyService *m_service = nullptr;
QLowEnergyDescriptor m_notificationDescLivestats;
QLowEnergyCharacteristic m_remotecontrolCharacteristic;
QBluetoothDeviceInfo m_currentDevice;
bool m_foundBobbycarService{};
float m_frontVoltage{};
float m_backVoltage{};
float m_frontTemperature{};
float m_backTemperature{};
uint8_t m_frontLeftError{};
uint8_t m_frontRightError{};
uint8_t m_backLeftError{};
uint8_t m_backRightError{};
float m_frontLeftSpeed{};
float m_frontRightSpeed{};
float m_backLeftSpeed{};
float m_backRightSpeed{};
float m_frontLeftDcLink{};
float m_frontRightDcLink{};
float m_backLeftDcLink{};
float m_backRightDcLink{};
int m_timerId{-1};
int m_remoteControlFrontLeft{};
int m_remoteControlFrontRight{};
int m_remoteControlBackLeft{};
int m_remoteControlBackRight{};
bool m_waitingForWrite{};
};