AirMapFlightPlanManager.h 4.23 KB
Newer Older
Gus Grubba's avatar
Gus Grubba committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/****************************************************************************
 *
 *   (c) 2017 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 "LifetimeChecker.h"
#include "AirMapSharedState.h"
#include "AirspaceFlightPlanProvider.h"

#include <QObject>
#include <QTimer>
#include <QList>
#include <QGeoCoordinate>

21 22
class PlanMasterController;

Gus Grubba's avatar
Gus Grubba committed
23 24 25 26 27 28
//-----------------------------------------------------------------------------
/// class to upload a flight
class AirMapFlightPlanManager : public AirspaceFlightPlanProvider, public LifetimeChecker
{
    Q_OBJECT
public:
Gus Grubba's avatar
Gus Grubba committed
29 30
    AirMapFlightPlanManager     (AirMapSharedState& shared, QObject *parent = nullptr);
    ~AirMapFlightPlanManager    ();
Gus Grubba's avatar
Gus Grubba committed
31

32 33 34 35 36 37
    PermitStatus        flightPermitStatus  () const override { return _flightPermitStatus; }
    QString             flightID            () { return _flightPlan; }
    QDateTime           flightStartTime     () const override { return _flightStartTime; }
    QDateTime           flightEndTime       () const override { return _flightEndTime; }
    bool                valid               () override { return _valid; }
    QmlObjectListModel* advisories          () override { return &_advisories; }
Gus Grubba's avatar
Gus Grubba committed
38
    QmlObjectListModel* ruleSets            () override { return &_rulesets; }
39
    QGCGeoBoundingCube* missionArea         () override { return &_flight.bc; }
40
    AirspaceAdvisoryProvider::AdvisoryColor airspaceColor   () override { return _airspaceColor; }
41

42 43 44 45
    QmlObjectListModel* rulesViolation      () override { return &_rulesViolation; }
    QmlObjectListModel* rulesInfo           () override { return &_rulesInfo; }
    QmlObjectListModel* rulesReview         () override { return &_rulesReview; }
    QmlObjectListModel* rulesFollowing      () override { return &_rulesFollowing; }
46
    QmlObjectListModel* briefFeatures       () override { return &_briefFeatures; }
47

48
    void            startFlightPlanning (PlanMasterController* planController) override;
49 50
    void            setFlightStartTime  (QDateTime start) override;
    void            setFlightEndTime    (QDateTime end) override;
Gus Grubba's avatar
Gus Grubba committed
51 52 53 54 55 56

signals:
    void            error               (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);

private slots:
    void _pollBriefing                  ();
57
    void _missionChanged                ();
Gus Grubba's avatar
Gus Grubba committed
58 59 60

private:
    void _uploadFlightPlan              ();
61
    void _updateFlightPlan              ();
Gus Grubba's avatar
Gus Grubba committed
62
    void _createFlightPlan              ();
Gus Grubba's avatar
Gus Grubba committed
63
    void _deleteFlightPlan              ();
64
    bool _collectFlightDtata            ();
Gus Grubba's avatar
Gus Grubba committed
65 66 67 68 69 70

private:
    enum class State {
        Idle,
        GetPilotID,
        FlightUpload,
71
        FlightUpdate,
Gus Grubba's avatar
Gus Grubba committed
72
        FlightPolling,
Gus Grubba's avatar
Gus Grubba committed
73
        FlightDelete
Gus Grubba's avatar
Gus Grubba committed
74 75 76
    };

    struct Flight {
77
        QGCGeoBoundingCube bc;
Gus Grubba's avatar
Gus Grubba committed
78 79 80 81
        QList<QGeoCoordinate> coords;
        QGeoCoordinate  takeoffCoord;
        float maxAltitude = 0;
        void reset() {
82
            bc.reset();
Gus Grubba's avatar
Gus Grubba committed
83 84 85 86 87 88 89 90 91 92 93
            coords.clear();
            maxAltitude = 0;
        }
    };

    Flight                  _flight;                ///< flight pending to be uploaded
    State                   _state = State::Idle;
    AirMapSharedState&      _shared;
    QTimer                  _pollTimer;             ///< timer to poll for approval check
    QString                 _flightPlan;            ///< Current flight plan
    QString                 _pilotID;               ///< Pilot ID in the form "auth0|abc123"
94
    PlanMasterController*   _planController = nullptr;
95
    bool                    _valid = false;
96 97
    QDateTime               _flightStartTime;
    QDateTime               _flightEndTime;
98
    QmlObjectListModel      _advisories;
Gus Grubba's avatar
Gus Grubba committed
99
    QmlObjectListModel      _rulesets;
100 101 102 103
    QmlObjectListModel      _rulesViolation;
    QmlObjectListModel      _rulesInfo;
    QmlObjectListModel      _rulesReview;
    QmlObjectListModel      _rulesFollowing;
104
    QmlObjectListModel      _briefFeatures;
Gus Grubba's avatar
Gus Grubba committed
105

106
    AirspaceAdvisoryProvider::AdvisoryColor  _airspaceColor;
107
    AirspaceFlightPlanProvider::PermitStatus _flightPermitStatus = AirspaceFlightPlanProvider::PermitNone;
Gus Grubba's avatar
Gus Grubba committed
108 109 110

};