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

10

11 12
#ifndef QGCSerialPortInfo_H
#define QGCSerialPortInfo_H
13

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

#include "QGCLoggingCategory.h"

Q_DECLARE_LOGGING_CATEGORY(QGCSerialPortInfoLog)
23

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

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

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

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

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

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

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

Don Gagne's avatar
Don Gagne committed
55
private:
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 91
    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;
92 93
};

Don Gagne's avatar
Don Gagne committed
94
#endif