RadioConfigTest.h 4.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL 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.
 
 QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

24 25
#ifndef RadioConfigTest_H
#define RadioConfigTest_H
26

Don Gagne's avatar
Don Gagne committed
27
#include "UnitTest.h"
28
#include "MockLink.h"
Don Gagne's avatar
Don Gagne committed
29
#include "MultiSignalSpy.h"
30
#include "RadioComponentController.h"
31
#include "QGCLoggingCategory.h"
32
#include "AutoPilotPlugin.h"
33
#include "QGCQmlWidgetHolder.h"
34 35

/// @file
36
///     @brief Radio Config unit test
37 38 39
///
///     @author Don Gagne <don@thegagnes.com>

40
Q_DECLARE_LOGGING_CATEGORY(RadioConfigTestLog)
41

42
class RadioConfigTest : public UnitTest
43 44 45 46
{
    Q_OBJECT
    
public:
47
    RadioConfigTest(void);
48 49 50 51
    
private slots:
    void cleanup(void);
    
Don Gagne's avatar
Don Gagne committed
52 53 54
    void _fullCalibration_px4_test(void);
    void _fullCalibration_apm_test(void);

55
private:
Don Gagne's avatar
Don Gagne committed
56 57 58 59 60 61 62
    /// @brief Modes to run worker functions
    enum TestMode {
        testModeStandalone,     ///< Perform standalone test of calibration state
        testModePrerequisite,   ///< Setup prequisites for subsequent calibration state
        testModeFullSequence,   ///< Run as full calibration sequence
    };
    
Don Gagne's avatar
Don Gagne committed
63 64 65 66 67 68
    enum MoveToDirection {
        moveToMax,
        moveToMin,
        moveToCenter,
    };
    
69 70 71 72 73 74 75
    enum {
        validateMinMaxMask =    1 << 0,
        validateTrimsMask =     1 << 1,
        validateReversedMask =  1 << 2,
        validateMappingMask =   1 << 3,
        validateAllMask = 0xFFFF
    };
Don Gagne's avatar
Don Gagne committed
76 77

    struct ChannelSettings {
Don Gagne's avatar
Don Gagne committed
78
        int function;
Don Gagne's avatar
Don Gagne committed
79 80 81 82 83
        int rcMin;
        int rcMax;
        int rcTrim;
        int reversed;
    };
Don Gagne's avatar
Don Gagne committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

    void _init(MAV_AUTOPILOT firmwareType);
    void _channelHomePosition(void);
    void _minRCChannels(void);
    void _beginCalibration(void);
    void _stickMoveWaitForSettle(int channel, int value);
    void _stickMoveAutoStep(const char* functionStr, enum RadioComponentController::rcCalFunctions function, enum MoveToDirection direction, bool identifyStep);
    void _switchMinMaxStep(void);
    void _flapsDetectStep(void);
    void _switchSelectAutoStep(const char* functionStr, RadioComponentController::rcCalFunctions function);
    bool _px4Vehicle(void) const;
    const struct RadioComponentController::FunctionInfo* _functionInfo(void) const;
    const struct ChannelSettings* _channelSettings(void) const;
    const struct ChannelSettings* _channelSettingsValidate(void) const;
    void _fullCalibrationWorker(MAV_AUTOPILOT firmwareType);
    int _chanMax(void) const;
Don Gagne's avatar
Don Gagne committed
100
    
Don Gagne's avatar
Don Gagne committed
101
    void _validateParameters(void);
102
    
103
    AutoPilotPlugin*    _autopilot;
104
    
105
    QGCQmlWidgetHolder* _calWidget;
106 107 108 109
    
    enum {
        nextButtonMask =        1 << 0,
        cancelButtonMask =      1 << 1,
Don Gagne's avatar
Don Gagne committed
110
        skipButtonMask =        1 << 2
111 112
    };
    
Don Gagne's avatar
Don Gagne committed
113 114
    const char*         _rgSignals[1];
    MultiSignalSpy*     _multiSpyNextButtonMessageBox;
Don Gagne's avatar
Don Gagne committed
115 116 117 118 119
    
    // When settings values into min/max/trim we set them slightly different than the defaults so that
    // we can distinguish between the two values.
    static const int _testMinValue;
    static const int _testMaxValue;
Don Gagne's avatar
Don Gagne committed
120
    static const int _testCenterValue;
Don Gagne's avatar
Don Gagne committed
121
    
Don Gagne's avatar
Don Gagne committed
122
    static const int _stickSettleWait;
123
	
Don Gagne's avatar
Don Gagne committed
124 125 126 127 128
    static const struct ChannelSettings _rgChannelSettingsPX4[RadioComponentController::_chanMaxPX4];
    static const struct ChannelSettings _rgChannelSettingsAPM[RadioComponentController::_chanMaxAPM];
    static const struct ChannelSettings _rgChannelSettingsValidatePX4[RadioComponentController::_chanMaxPX4];
    static const struct ChannelSettings _rgChannelSettingsValidateAPM[RadioComponentController::_chanMaxAPM];

129 130 131
	int _rgFunctionChannelMap[RadioComponentController::rcCalFunctionMax];
    
    RadioComponentController*   _controller;
132 133 134
};

#endif