From d872da768c72e0d96a6fe68131e82f6f3fca3956 Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Sat, 4 May 2019 14:58:43 -0700 Subject: [PATCH] Safer handling of missing params --- .../APM/APMFlightModesComponentController.cc | 12 +++++++----- .../APM/APMFlightModesComponentController.h | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/AutoPilotPlugins/APM/APMFlightModesComponentController.cc b/src/AutoPilotPlugins/APM/APMFlightModesComponentController.cc index af00bf41d..8eb4feaed 100644 --- a/src/AutoPilotPlugins/APM/APMFlightModesComponentController.cc +++ b/src/AutoPilotPlugins/APM/APMFlightModesComponentController.cc @@ -16,13 +16,15 @@ bool APMFlightModesComponentController::_typeRegistered = false; +const char* APMFlightModesComponentController::_simpleParamName = "SIMPLE"; +const char* APMFlightModesComponentController::_superSimpleParamName = "SUPER_SIMPLE"; + APMFlightModesComponentController::APMFlightModesComponentController(void) - : _rover (_vehicle->rover()) - , _activeFlightMode (0) + : _activeFlightMode (0) , _channelCount (Vehicle::cMaxRcChannels) , _simpleMode (SimpleModeStandard) - , _simpleModeFact (_rover ? nullptr : getParameterFact(-1, "SIMPLE")) - , _superSimpleModeFact (_rover ? nullptr : getParameterFact(-1, "SUPER_SIMPLE")) + , _simpleModeFact (parameterExists(-1, _simpleParamName) ? getParameterFact(-1, _simpleParamName) : nullptr) + , _superSimpleModeFact (parameterExists(-1, _superSimpleParamName) ? getParameterFact(-1, _superSimpleParamName) : nullptr) , _simpleModesSupported (_simpleModeFact && _superSimpleModeFact) { if (!_typeRegistered) { @@ -38,7 +40,7 @@ APMFlightModesComponentController::APMFlightModesComponentController(void) _superSimpleModeEnabled.append(QVariant(false)); } - if (!_rover) { + if (_simpleModesSupported) { _setupSimpleModeEnabled(); uint8_t simpleModeValue = static_cast(_simpleModeFact->rawValue().toUInt()); diff --git a/src/AutoPilotPlugins/APM/APMFlightModesComponentController.h b/src/AutoPilotPlugins/APM/APMFlightModesComponentController.h index e7a9e4412..459111822 100644 --- a/src/AutoPilotPlugins/APM/APMFlightModesComponentController.h +++ b/src/AutoPilotPlugins/APM/APMFlightModesComponentController.h @@ -67,7 +67,6 @@ private slots: void _setupSimpleModeEnabled (void); private: - bool _rover; QString _modeParamPrefix; QString _modeChannelParam; int _activeFlightMode; @@ -86,6 +85,9 @@ private: static const int _cSimpleModeBits = 8; static const int _cFltModes = 6; + static const char* _simpleParamName; + static const char* _superSimpleParamName; + static bool _typeRegistered; }; -- 2.22.0