QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PowerComponentController.cc
Go to the documentation of this file.
2#include "Vehicle.h"
3
8
10{
11 _warningMessages.clear();
12 connect(_vehicle, &Vehicle::textMessageReceived, this, &PowerComponentController::_handleVehicleTextMessage);
14}
15
16void PowerComponentController::_stopCalibration(void)
17{
18 disconnect(_vehicle, &Vehicle::textMessageReceived, this, &PowerComponentController::_handleVehicleTextMessage);
19}
20
21void PowerComponentController::_handleVehicleTextMessage(int vehicleId, int /* compId */, int /* severity */, QString text, const QString &description)
22{
23 Q_UNUSED(description);
24
25 if (vehicleId != _vehicle->id()) {
26 return;
27 }
28
29 // All calibration messages start with [cal]
30 QString calPrefix("[cal] ");
31 if (!text.startsWith(calPrefix)) {
32 return;
33 }
34 text = text.right(text.length() - calPrefix.length());
35
36 // Make sure we can understand this firmware rev
37 QString calStartPrefix("calibration started: ");
38 if (text.startsWith(calStartPrefix)) {
39 text = text.right(text.length() - calStartPrefix.length());
40
41 // Split version number and cal type
42 QStringList parts = text.split(" ");
43 if (parts.count() != 2) {
45 return;
46 }
47
48#if 0
49 // FIXME: Cal version check is not working. Needs to be able to cancel, calibration
50
51 int firmwareRev = parts[0].toInt();
52 if (firmwareRev < _neededFirmwareRev) {
53 emit oldFirmware();
54 return;
55 }
56 if (firmwareRev > _neededFirmwareRev) {
57 emit newerFirmware();
58 return;
59 }
60#endif
61 }
62
63 if (text == "Connect battery now") {
64 emit connectBattery();
65 return;
66 }
67
68 if (text == "Battery connected") {
69 emit batteryConnected();
70 return;
71 }
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}
void calibrationSuccess(const QStringList &warningMessages)
Q_INVOKABLE void calibrateEsc(void)
void calibrationFailed(const QString &errorMessage)
void incorrectFirmwareRevReporting(void)
void textMessageReceived(int sysid, int componentid, int severity, QString text, QString description)
int id() const
Definition Vehicle.h:443
void startCalibration(QGCMAVLink::CalibrationType calType)
Definition Vehicle.cc:2408