RadioConfigTest.h 3.62 KB
Newer Older
1 2
/****************************************************************************
 *
3
 *   (c) 2009-2018 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10

11
#pragma once
12

Don Gagne's avatar
Don Gagne committed
13
#include "UnitTest.h"
14
#include "MockLink.h"
Don Gagne's avatar
Don Gagne committed
15
#include "MultiSignalSpy.h"
16
#include "RadioComponentController.h"
17
#include "QGCLoggingCategory.h"
18
#include "AutoPilotPlugin.h"
19
#include "QGCQmlWidgetHolder.h"
20 21

/// @file
22
///     @brief Radio Config unit test
23 24 25
///
///     @author Don Gagne <don@thegagnes.com>

26
Q_DECLARE_LOGGING_CATEGORY(RadioConfigTestLog)
27

28
class RadioConfigTest : public UnitTest
29 30 31 32
{
    Q_OBJECT
    
public:
33
    RadioConfigTest(void);
34 35 36 37
    
private slots:
    void cleanup(void);
    
Don Gagne's avatar
Don Gagne committed
38 39 40
    void _fullCalibration_px4_test(void);
    void _fullCalibration_apm_test(void);

41
private:
Don Gagne's avatar
Don Gagne committed
42 43 44 45 46 47 48
    /// @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
49 50 51 52 53 54
    enum MoveToDirection {
        moveToMax,
        moveToMin,
        moveToCenter,
    };
    
55 56 57 58 59 60 61
    enum {
        validateMinMaxMask =    1 << 0,
        validateTrimsMask =     1 << 1,
        validateReversedMask =  1 << 2,
        validateMappingMask =   1 << 3,
        validateAllMask = 0xFFFF
    };
Don Gagne's avatar
Don Gagne committed
62 63

    struct ChannelSettings {
Don Gagne's avatar
Don Gagne committed
64
        int function;
Don Gagne's avatar
Don Gagne committed
65 66 67 68 69
        int rcMin;
        int rcMax;
        int rcTrim;
        int reversed;
    };
Don Gagne's avatar
Don Gagne committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83

    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);
    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
84
    
Don Gagne's avatar
Don Gagne committed
85
    void _validateParameters(void);
86
    
87
    AutoPilotPlugin*    _autopilot;
88
    
89
    QGCQmlWidgetHolder* _calWidget;
90 91 92 93
    
    enum {
        nextButtonMask =        1 << 0,
        cancelButtonMask =      1 << 1,
Don Gagne's avatar
Don Gagne committed
94
        skipButtonMask =        1 << 2
95 96
    };
    
Don Gagne's avatar
Don Gagne committed
97 98
    const char*         _rgSignals[1];
    MultiSignalSpy*     _multiSpyNextButtonMessageBox;
Don Gagne's avatar
Don Gagne committed
99 100 101 102 103
    
    // 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
104
    static const int _testCenterValue;
Don Gagne's avatar
Don Gagne committed
105
    
Don Gagne's avatar
Don Gagne committed
106
    static const int _stickSettleWait;
107
	
Don Gagne's avatar
Don Gagne committed
108 109 110 111 112
    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];

113 114 115
	int _rgFunctionChannelMap[RadioComponentController::rcCalFunctionMax];
    
    RadioComponentController*   _controller;
116 117
};