QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4EscController.cc
Go to the documentation of this file.
1#include "PX4EscController.h"
2
3#include "QGCMAVLink.h"
4#include "Vehicle.h"
5
7
9{
10 _warningMessages.clear();
11 connect(_vehicle, &Vehicle::textMessageReceived, this, &PX4EscController::_handleVehicleTextMessage,
12 Qt::UniqueConnection);
13 _vehicle->startCalibration(QGCMAVLink::CalibrationEsc);
14}
15
16void PX4EscController::_stopCalibration()
17{
18 disconnect(_vehicle, &Vehicle::textMessageReceived, this, &PX4EscController::_handleVehicleTextMessage);
19}
20
21void PX4EscController::_handleVehicleTextMessage(quint32 vehicleId, int /* compId */, int /* severity */, QString text,
22 const QString& description)
23{
24 Q_UNUSED(description);
25
26 if (vehicleId != _vehicle->id()) {
27 return;
28 }
29
30 // All calibration messages start with [cal]
31 QString calPrefix("[cal] ");
32 if (!text.startsWith(calPrefix)) {
33 return;
34 }
35 text = text.right(text.length() - calPrefix.length());
36
37 // Make sure we can understand this firmware rev
38 QString calStartPrefix("calibration started: ");
39 if (text.startsWith(calStartPrefix)) {
40 text = text.right(text.length() - calStartPrefix.length());
41
42 // Split version number and cal type
43 QStringList parts = text.split(" ");
44 if (parts.count() != 2) {
46 return;
47 }
48
49#if 0
50 // FIXME: Cal version check is not working. Needs to be able to cancel, calibration
51
52 int firmwareRev = parts[0].toInt();
53 if (firmwareRev < _neededFirmwareRev) {
54 emit oldFirmware();
55 return;
56 }
57 if (firmwareRev > _neededFirmwareRev) {
58 emit newerFirmware();
59 return;
60 }
61#endif
62 }
63
64 if (text == "Connect battery now") {
65 emit connectBattery();
66 return;
67 }
68
69 if (text == "Battery connected") {
70 emit batteryConnected();
71 return;
72 }
73
74 QString failedPrefix("calibration failed: ");
75 if (text.startsWith(failedPrefix)) {
76 QString failureText = text.right(text.length() - failedPrefix.length());
77 _stopCalibration();
78 if (failureText.startsWith("Disconnect battery")) {
79 emit disconnectBattery();
80 return;
81 }
82
83 emit calibrationFailed(text.right(text.length() - failedPrefix.length()));
84 return;
85 }
86
87 QString calCompletePrefix("calibration done:");
88 if (text.startsWith(calCompletePrefix)) {
89 _stopCalibration();
90 emit calibrationSuccess(_warningMessages);
91 return;
92 }
93
94 QString warningPrefix("config warning: ");
95 if (text.startsWith(warningPrefix)) {
96 _warningMessages << text.right(text.length() - warningPrefix.length());
97 }
98}
Q_INVOKABLE void calibrateEsc()
void batteryConnected()
void incorrectFirmwareRevReporting()
void disconnectBattery()
void calibrationFailed(const QString &errorMessage)
void calibrationSuccess(const QStringList &warningMessages)
void textMessageReceived(quint32 sysid, int componentid, int severity, QString text, QString description)