ComponentInformationManager.h 4.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/****************************************************************************
 *
 * (c) 2009-2020 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.
 *
 ****************************************************************************/

#pragma once

#include "QGCLoggingCategory.h"
#include "QGCMAVLink.h"
#include "StateMachine.h"

Q_DECLARE_LOGGING_CATEGORY(ComponentInformationManagerLog)

class Vehicle;
class ComponentInformationManager;

21 22 23 24 25 26 27
typedef struct {
    uint32_t        metadataUID;
    QString         metadataURI;
    uint32_t        translationUID;
    QString         translationURI;
} ComponentInformation_t;

28 29
class RequestMetaDataTypeStateMachine : public StateMachine
{
30 31
    Q_OBJECT

32 33 34
public:
    RequestMetaDataTypeStateMachine(ComponentInformationManager* compMgr);

35 36 37 38
    void                            request                     (COMP_METADATA_TYPE type);
    QString                         typeToString                (void);
    ComponentInformationManager*    compMgr                     (void) { return _compMgr; }
    void                            handleComponentInformation  (const mavlink_message_t& message);
39 40 41 42 43 44

    // Overrides from StateMachine
    int             stateCount      (void) const final;
    const StateFn*  rgStates        (void) const final;
    void            statesCompleted (void) const final;

45
private slots:
46 47 48
    void    _downloadCompleteMetaDataJson   (const QString& file, const QString& errorMsg);
    void    _downloadCompleteTranslationJson(const QString& file, const QString& errorMsg);
    QString _downloadCompleteJsonWorker     (const QString& jsonFileName, const QString& inflatedFileName);
49

50 51 52 53
private:
    static void _stateRequestCompInfo           (StateMachine* stateMachine);
    static void _stateRequestMetaDataJson       (StateMachine* stateMachine);
    static void _stateRequestTranslationJson    (StateMachine* stateMachine);
54
    static void _stateRequestComplete           (StateMachine* stateMachine);
55 56
    static bool _uriIsFTP                       (const QString& uri);

57 58

    ComponentInformationManager*    _compMgr;
59 60 61
    COMP_METADATA_TYPE              _type               = COMP_METADATA_TYPE_VERSION;
    bool                            _compInfoAvailable  = false;
    ComponentInformation_t          _compInfo;
62 63
    QString                         _jsonMetadataFileName;
    QString                         _jsonTranslationFileName;
64 65 66 67 68 69 70

    static StateFn                  _rgStates[];
    static int                      _cStates;
};

class ComponentInformationManager : public StateMachine
{
71 72
    Q_OBJECT

73 74 75 76 77 78 79 80 81 82 83 84 85
public:
    ComponentInformationManager(Vehicle* vehicle);

    typedef void (*RequestAllCompleteFn)(void* requestAllCompleteFnData);

    void        requestAllComponentInformation  (RequestAllCompleteFn requestAllCompletFn, void * requestAllCompleteFnData);
    Vehicle*    vehicle                         (void) { return _vehicle; }

    // Overrides from StateMachine
    int             stateCount  (void) const final;
    const StateFn*  rgStates    (void) const final;

private:
86 87 88
    void _stateRequestCompInfoComplete  (void);
    void _compInfoJsonAvailable         (const QString& metadataJsonFileName, const QString& translationsJsonFileName);
    bool _isCompTypeSupported           (COMP_METADATA_TYPE type);
89

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    static void _stateRequestCompInfoVersion        (StateMachine* stateMachine);
    static void _stateRequestCompInfoParam          (StateMachine* stateMachine);
    static void _stateRequestAllCompInfoComplete    (StateMachine* stateMachine);

    Vehicle*                        _vehicle                    = nullptr;
    RequestMetaDataTypeStateMachine _requestTypeStateMachine;
    bool                            _versionCompInfoAvailable   = false;
    ComponentInformation_t          _versionCompInfo;
    bool                            _paramCompInfoAvailable     = false;
    ComponentInformation_t          _parameterCompInfo;
    QList<COMP_METADATA_TYPE>       _supportedMetaDataTypes;
    RequestAllCompleteFn            _requestAllCompleteFn       = nullptr;
    void*                           _requestAllCompleteFnData   = nullptr;

    static StateFn                  _rgStates[];
    static int                      _cStates;
106

107 108 109
    static const char*              _jsonVersionKey;
    static const char*              _jsonSupportedCompMetadataTypesKey;

110
    friend class RequestMetaDataTypeStateMachine;
111
};