QGCSerialPortInfo.h 2.83 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 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
    /// @return true: we can flash this board type
46
    bool canFlash(void) const;
47

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
    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;
71
    } BoardRegExpFallback_t;
72 73 74 75 76 77 78 79

    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;
80 81
    static const char*  _jsonBoardDescriptionFallbackKey;
    static const char*  _jsonBoardManufacturerFallbackKey;
82 83 84 85 86 87 88 89 90
    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;
91 92
    static QList<BoardRegExpFallback_t>         _boardDescriptionFallbackList;
    static QList<BoardRegExpFallback_t>         _boardManufacturerFallbackList;
93 94
};