QGCSerialPortInfo.h 2.67 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

13 14 15 16 17 18 19 20 21
#ifdef __android__
    #include "qserialportinfo.h"
#else
    #include <QSerialPortInfo>
#endif

#include "QGCLoggingCategory.h"

Q_DECLARE_LOGGING_CATEGORY(QGCSerialPortInfoLog)
22

23 24 25 26
/// QGC's version of Qt QSerialPortInfo. It provides additional information about board types
/// that QGC cares about.
class QGCSerialPortInfo : public QSerialPortInfo
{
27
public:
28
    typedef enum {
29 30
        BoardTypePixhawk,
        BoardTypeSiKRadio,
31
        BoardTypePX4Flow,
32
        BoardTypeOpenPilot,
33
        BoardTypeRTKGPS,
34 35 36
        BoardTypeUnknown
    } BoardType_t;

Don Gagne's avatar
Don Gagne committed
37
    QGCSerialPortInfo(void);
38 39 40 41 42
    QGCSerialPortInfo(const QSerialPort & port);

    /// Override of QSerialPortInfo::availablePorts
    static QList<QGCSerialPortInfo> availablePorts(void);

43
    bool getBoardInfo(BoardType_t& boardType, QString& name) const;
44

45 46 47
    /// @return true: we can flash this board type
    bool canFlash(void);

48 49 50
    /// @return true: Board is currently in bootloader
    bool isBootloader(void) const;

51
    /// @return true: Port is a system port and not an autopilot
52
    static bool isSystemPort(QSerialPortInfo* port);
53

Don Gagne's avatar
Don Gagne committed
54
private:
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    typedef struct {
        const char* classString;
        BoardType_t boardType;
    } BoardClassString2BoardType_t;

    typedef struct {
        int         vendorId;
        int         productId;
        BoardType_t boardType;
        QString     name;
    } BoardInfo_t;

    typedef struct {
        QString     regExp;
        BoardType_t boardType;
        bool        androidOnly;
    } BoardFallback_t;

    static void _loadJsonData(void);
    static BoardType_t _boardClassStringToType(const QString& boardClass);
    static QString _boardTypeToString(BoardType_t boardType);

    static bool         _jsonLoaded;
    static const char*  _jsonFileTypeValue;
    static const char*  _jsonBoardInfoKey;
    static const char*  _jsonBoardFallbackKey;
    static const char*  _jsonVendorIDKey;
    static const char*  _jsonProductIDKey;
    static const char*  _jsonBoardClassKey;
    static const char*  _jsonNameKey;
    static const char*  _jsonRegExpKey;
    static const char*  _jsonAndroidOnlyKey;

    static const BoardClassString2BoardType_t   _rgBoardClass2BoardType[BoardTypeUnknown];
    static QList<BoardInfo_t>                   _boardInfoList;
    static QList<BoardFallback_t>               _boardFallbackList;
91 92
};