Commit 600008e2 authored by Gus Grubba's avatar Gus Grubba

Dealing with brief features and telemetry.

parent 4283729f
...@@ -254,7 +254,7 @@ AirMapFlightPlanManager::updateFlightPlan() ...@@ -254,7 +254,7 @@ AirMapFlightPlanManager::updateFlightPlan()
} }
_flightPermitStatus = AirspaceFlightPlanProvider::PermitPending; _flightPermitStatus = AirspaceFlightPlanProvider::PermitPending;
emit flightPermitStatusChanged(); emit flightPermitStatusChanged();
_updateFlightPlan(); _updateFlightPlan(true);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -373,9 +373,6 @@ AirMapFlightPlanManager::_createFlightPlan() ...@@ -373,9 +373,6 @@ AirMapFlightPlanManager::_createFlightPlan()
qCDebug(AirMapManagerLog) << "Flight Start:" << flightStartTime().toString(); qCDebug(AirMapManagerLog) << "Flight Start:" << flightStartTime().toString();
qCDebug(AirMapManagerLog) << "Flight End: " << flightEndTime().toString(); qCDebug(AirMapManagerLog) << "Flight End: " << flightEndTime().toString();
//-- Not Yet
//return;
if (_pilotID == "") { if (_pilotID == "") {
//-- Need to get the pilot id before uploading the flight plan //-- Need to get the pilot id before uploading the flight plan
qCDebug(AirMapManagerLog) << "Getting pilot ID"; qCDebug(AirMapManagerLog) << "Getting pilot ID";
...@@ -413,7 +410,7 @@ AirMapFlightPlanManager::_createFlightPlan() ...@@ -413,7 +410,7 @@ AirMapFlightPlanManager::_createFlightPlan()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
AirMapFlightPlanManager::_updateRulesAndFeatures(std::vector<RuleSet::Id>& rulesets, std::unordered_map<std::string, RuleSet::Feature::Value>& features) AirMapFlightPlanManager::_updateRulesAndFeatures(std::vector<RuleSet::Id>& rulesets, std::unordered_map<std::string, RuleSet::Feature::Value>& features, bool updateFeatures)
{ {
AirMapRulesetsManager* pRulesMgr = dynamic_cast<AirMapRulesetsManager*>(qgcApp()->toolbox()->airspaceManager()->ruleSets()); AirMapRulesetsManager* pRulesMgr = dynamic_cast<AirMapRulesetsManager*>(qgcApp()->toolbox()->airspaceManager()->ruleSets());
if(pRulesMgr) { if(pRulesMgr) {
...@@ -422,34 +419,42 @@ AirMapFlightPlanManager::_updateRulesAndFeatures(std::vector<RuleSet::Id>& rules ...@@ -422,34 +419,42 @@ AirMapFlightPlanManager::_updateRulesAndFeatures(std::vector<RuleSet::Id>& rules
//-- If this ruleset is selected //-- If this ruleset is selected
if(ruleSet && ruleSet->selected()) { if(ruleSet && ruleSet->selected()) {
rulesets.push_back(ruleSet->id().toStdString()); rulesets.push_back(ruleSet->id().toStdString());
//-- Features within each rule //-- Features within each rule (only when updating)
for(int r = 0; r < ruleSet->rules()->count(); r++) { if(updateFeatures) {
AirMapRule* rule = qobject_cast<AirMapRule*>(ruleSet->rules()->get(r)); for(int r = 0; r < ruleSet->rules()->count(); r++) {
if(rule) { AirMapRule* rule = qobject_cast<AirMapRule*>(ruleSet->rules()->get(r));
for(int f = 0; f < rule->features()->count(); f++) { if(rule) {
AirMapRuleFeature* feature = qobject_cast<AirMapRuleFeature*>(rule->features()->get(f)); for(int f = 0; f < rule->features()->count(); f++) {
if(feature && feature->value().isValid()) { AirMapRuleFeature* feature = qobject_cast<AirMapRuleFeature*>(rule->features()->get(f));
switch(feature->type()) { if(features.find(feature->name().toStdString()) != features.end()) {
case AirspaceRuleFeature::Boolean: qCDebug(AirMapManagerLog) << "Removing duplicate:" << feature->name();
//-- Skip not set responses (feature->value is initialized to "2") continue;
if(feature->value().toInt() == 0 || feature->value().toInt() == 1) { }
features[feature->name().toStdString()] = RuleSet::Feature::Value(feature->value().toBool()); if(feature && feature->value().isValid()) {
} switch(feature->type()) {
break; case AirspaceRuleFeature::Boolean:
case AirspaceRuleFeature::Float: if(feature->value().toInt() == 0 || feature->value().toInt() == 1) {
//-- Sanity check for floats features[feature->name().toStdString()] = RuleSet::Feature::Value(feature->value().toBool());
if(std::isfinite(feature->value().toFloat())) { } else {
features[feature->name().toStdString()] = RuleSet::Feature::Value(feature->value().toFloat()); //-- If not set, default to false
} features[feature->name().toStdString()] = RuleSet::Feature::Value(false);
break; }
case AirspaceRuleFeature::String: break;
//-- Skip empty responses case AirspaceRuleFeature::Float:
if(!feature->value().toString().isEmpty()) { //-- Sanity check for floats
features[feature->name().toStdString()] = RuleSet::Feature::Value(feature->value().toString().toStdString()); if(std::isfinite(feature->value().toFloat())) {
features[feature->name().toStdString()] = RuleSet::Feature::Value(feature->value().toFloat());
}
break;
case AirspaceRuleFeature::String:
//-- Skip empty responses
if(!feature->value().toString().isEmpty()) {
features[feature->name().toStdString()] = RuleSet::Feature::Value(feature->value().toString().toStdString());
}
break;
default:
qCWarning(AirMapManagerLog) << "Unknown type for feature" << feature->name();
} }
break;
default:
qCWarning(AirMapManagerLog) << "Unknown type for feature" << feature->name();
} }
} }
} }
...@@ -516,15 +521,19 @@ AirMapFlightPlanManager::_uploadFlightPlan() ...@@ -516,15 +521,19 @@ AirMapFlightPlanManager::_uploadFlightPlan()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
AirMapFlightPlanManager::_updateFlightPlan() AirMapFlightPlanManager::_updateFlightPlanOnTimer()
{ {
//-- TODO: This is broken as the parameters for updating the plan have _updateFlightPlan(false);
// little to do with those used when creating it. }
//-----------------------------------------------------------------------------
void
AirMapFlightPlanManager::_updateFlightPlan(bool interactive)
{
qCDebug(AirMapManagerLog) << "Updating flight plan. State:" << (int)_state; qCDebug(AirMapManagerLog) << "Updating flight plan. State:" << (int)_state;
if(_state != State::Idle) { if(_state != State::Idle) {
QTimer::singleShot(100, this, &AirMapFlightPlanManager::_updateFlightPlan); QTimer::singleShot(100, this, &AirMapFlightPlanManager::_updateFlightPlanOnTimer);
return; return;
} }
//-- Get flight data //-- Get flight data
...@@ -546,7 +555,8 @@ AirMapFlightPlanManager::_updateFlightPlan() ...@@ -546,7 +555,8 @@ AirMapFlightPlanManager::_updateFlightPlan()
//-- Rules & Features //-- Rules & Features
_flightPlan.rulesets.clear(); _flightPlan.rulesets.clear();
_flightPlan.features.clear(); _flightPlan.features.clear();
_updateRulesAndFeatures(_flightPlan.rulesets, _flightPlan.features); //-- If interactive, we collect features otherwise we don't
_updateRulesAndFeatures(_flightPlan.rulesets, _flightPlan.features, interactive);
//-- Geometry: polygon //-- Geometry: polygon
Geometry::Polygon polygon; Geometry::Polygon polygon;
for (const auto& qcoord : _flight.coords) { for (const auto& qcoord : _flight.coords) {
...@@ -600,6 +610,19 @@ rules_sort(QObject* a, QObject* b) ...@@ -600,6 +610,19 @@ rules_sort(QObject* a, QObject* b)
return (int)aa->status() > (int)bb->status(); return (int)aa->status() > (int)bb->status();
} }
//-----------------------------------------------------------------------------
bool
AirMapFlightPlanManager::_findBriefFeature(const QString& name)
{
for(int i = 0; i < _briefFeatures.count(); i++ ) {
AirMapRuleFeature* feature = qobject_cast<AirMapRuleFeature*>(_briefFeatures.get(i));
if (feature && feature->name() == name) {
return true;
}
}
return false;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
AirMapFlightPlanManager::_pollBriefing() AirMapFlightPlanManager::_pollBriefing()
...@@ -657,8 +680,12 @@ AirMapFlightPlanManager::_pollBriefing() ...@@ -657,8 +680,12 @@ AirMapFlightPlanManager::_pollBriefing()
AirMapRuleFeature* pFeature = new AirMapRuleFeature(feature, this); AirMapRuleFeature* pFeature = new AirMapRuleFeature(feature, this);
pRule->_features.append(pFeature); pRule->_features.append(pFeature);
if(rule.status == RuleSet::Rule::Status::missing_info) { if(rule.status == RuleSet::Rule::Status::missing_info) {
_briefFeatures.append(pFeature); if(!_findBriefFeature(pFeature->name())) {
qCDebug(AirMapManagerLog) << "Adding briefing feature" << pFeature->name() << pFeature->description() << pFeature->type(); _briefFeatures.append(pFeature);
qCDebug(AirMapManagerLog) << "Adding briefing feature" << pFeature->name() << pFeature->description() << pFeature->type();
} else {
qCDebug(AirMapManagerLog) << "Skipping briefing feature duplicate" << pFeature->name() << pFeature->description() << pFeature->type();
}
} }
} }
pRuleSet->_rules.append(pRule); pRuleSet->_rules.append(pRule);
......
...@@ -90,6 +90,7 @@ public: ...@@ -90,6 +90,7 @@ public:
AirspaceFlightModel*flightList () override { return &_flightList; } AirspaceFlightModel*flightList () override { return &_flightList; }
bool loadingFlightList () override { return _loadingFlightList; } bool loadingFlightList () override { return _loadingFlightList; }
QString flightPlanID () {return QString::fromStdString(_flightPlan.id); } QString flightPlanID () {return QString::fromStdString(_flightPlan.id); }
QString flightID () {return _flightId; }
void updateFlightPlan () override; void updateFlightPlan () override;
void submitFlightPlan () override; void submitFlightPlan () override;
...@@ -107,13 +108,15 @@ private slots: ...@@ -107,13 +108,15 @@ private slots:
void _missionChanged (); void _missionChanged ();
void _endFlight (); void _endFlight ();
void _uploadFlightPlan (); void _uploadFlightPlan ();
void _updateFlightPlan (); void _updateFlightPlanOnTimer ();
void _loadFlightList (); void _loadFlightList ();
private: private:
void _createFlightPlan (); void _createFlightPlan ();
bool _collectFlightDtata (); bool _collectFlightDtata ();
void _updateRulesAndFeatures (std::vector<airmap::RuleSet::Id>& rulesets, std::unordered_map<std::string, airmap::RuleSet::Feature::Value>& features); void _updateFlightPlan (bool interactive = false);
bool _findBriefFeature (const QString& name);
void _updateRulesAndFeatures (std::vector<airmap::RuleSet::Id>& rulesets, std::unordered_map<std::string, airmap::RuleSet::Feature::Value>& features, bool updateFeatures = false);
private: private:
enum class State { enum class State {
......
...@@ -42,8 +42,8 @@ AirMapManager::AirMapManager(QGCApplication* app, QGCToolbox* toolbox) ...@@ -42,8 +42,8 @@ AirMapManager::AirMapManager(QGCApplication* app, QGCToolbox* toolbox)
{ {
_logger = std::make_shared<qt::Logger>(); _logger = std::make_shared<qt::Logger>();
qt::register_types(); // TODO: still needed? qt::register_types(); // TODO: still needed?
_logger->logging_category().setEnabled(QtDebugMsg, true); _logger->logging_category().setEnabled(QtDebugMsg, false);
_logger->logging_category().setEnabled(QtInfoMsg, true); _logger->logging_category().setEnabled(QtInfoMsg, false);
_logger->logging_category().setEnabled(QtWarningMsg, false); _logger->logging_category().setEnabled(QtWarningMsg, false);
_dispatchingLogger = std::make_shared<qt::DispatchingLogger>(_logger); _dispatchingLogger = std::make_shared<qt::DispatchingLogger>(_logger);
connect(&_shared, &AirMapSharedState::error, this, &AirMapManager::_error); connect(&_shared, &AirMapSharedState::error, this, &AirMapManager::_error);
......
...@@ -31,6 +31,7 @@ AirMapRuleFeature::AirMapRuleFeature(airmap::RuleSet::Feature feature, QObject* ...@@ -31,6 +31,7 @@ AirMapRuleFeature::AirMapRuleFeature(airmap::RuleSet::Feature feature, QObject*
settings.beginGroup(kAirMapFeatureGroup); settings.beginGroup(kAirMapFeatureGroup);
switch(_feature.type) { switch(_feature.type) {
case RuleSet::Feature::Type::boolean: case RuleSet::Feature::Type::boolean:
//-- For boolean, we have 3 states: 0 - false, 1 - true and 2 - not set
_value = settings.value(name(), 2); _value = settings.value(name(), 2);
break;; break;;
case RuleSet::Feature::Type::floating_point: case RuleSet::Feature::Type::floating_point:
...@@ -45,6 +46,14 @@ AirMapRuleFeature::AirMapRuleFeature(airmap::RuleSet::Feature feature, QObject* ...@@ -45,6 +46,14 @@ AirMapRuleFeature::AirMapRuleFeature(airmap::RuleSet::Feature feature, QObject*
settings.endGroup(); settings.endGroup();
} }
//-----------------------------------------------------------------------------
QVariant
AirMapRuleFeature::value()
{
//qCDebug(AirMapManagerLog) << "Value of" << name() << "==>" << _value << type();
return _value;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
AirspaceRuleFeature::Type AirspaceRuleFeature::Type
AirMapRuleFeature::type() AirMapRuleFeature::type()
...@@ -100,6 +109,25 @@ AirMapRuleFeature::measurement() ...@@ -100,6 +109,25 @@ AirMapRuleFeature::measurement()
void void
AirMapRuleFeature::setValue(const QVariant val) AirMapRuleFeature::setValue(const QVariant val)
{ {
switch(_feature.type) {
case RuleSet::Feature::Type::boolean:
if(val.toInt() != 0 && val.toInt() != 1) {
return;
}
break;
case RuleSet::Feature::Type::floating_point:
if(!std::isfinite(val.toDouble())) {
return;
}
break;;
case RuleSet::Feature::Type::string:
if(val.toString().isEmpty()) {
return;
}
break;;
default:
return;
}
_value = val; _value = val;
//-- Make value persistent //-- Make value persistent
QSettings settings; QSettings settings;
......
...@@ -39,7 +39,7 @@ public: ...@@ -39,7 +39,7 @@ public:
Measurement measurement () override; Measurement measurement () override;
QString name () override { return QString::fromStdString(_feature.name); } QString name () override { return QString::fromStdString(_feature.name); }
QString description () override { return QString::fromStdString(_feature.description); } QString description () override { return QString::fromStdString(_feature.description); }
QVariant value () override { return _value; } QVariant value () override;
void setValue (const QVariant val) override; void setValue (const QVariant val) override;
private: private:
airmap::RuleSet::Feature _feature; airmap::RuleSet::Feature _feature;
......
...@@ -84,6 +84,7 @@ AirMapTelemetry::_handleGlobalPositionInt(const mavlink_message_t& message) ...@@ -84,6 +84,7 @@ AirMapTelemetry::_handleGlobalPositionInt(const mavlink_message_t& message)
globalPosition.vz / 100.f globalPosition.vz / 100.f
}; };
//qCDebug(AirMapManagerLog) << "Telemetry:" << globalPosition.lat / 1e7 << globalPosition.lon / 1e7;
Flight flight; Flight flight;
flight.id = _flightID.toStdString(); flight.id = _flightID.toStdString();
_shared.client()->telemetry().submit_updates(flight, _key, _shared.client()->telemetry().submit_updates(flight, _key,
......
...@@ -7,9 +7,12 @@ ...@@ -7,9 +7,12 @@
* *
****************************************************************************/ ****************************************************************************/
#include "AirspaceFlightPlanProvider.h"
#include "AirMapFlightPlanManager.h"
#include "AirMapVehicleManager.h" #include "AirMapVehicleManager.h"
#include "AirMapManager.h" #include "AirMapManager.h"
#include "QGCApplication.h"
#include "Vehicle.h" #include "Vehicle.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -30,9 +33,13 @@ AirMapVehicleManager::AirMapVehicleManager(AirMapSharedState& shared, const Vehi ...@@ -30,9 +33,13 @@ AirMapVehicleManager::AirMapVehicleManager(AirMapSharedState& shared, const Vehi
void void
AirMapVehicleManager::startTelemetryStream() AirMapVehicleManager::startTelemetryStream()
{ {
if (!_flightManager.flightID().isEmpty()) { AirMapFlightPlanManager* planMgr = (AirMapFlightPlanManager*)qgcApp()->toolbox()->airspaceManager()->flightPlan();
//-- TODO: This will start telemetry using the current flight ID in memory if (!planMgr->flightID().isEmpty()) {
_telemetry.startTelemetryStream(_flightManager.flightID()); //-- TODO: This will start telemetry using the current flight ID in memory (current flight in AirMapFlightPlanManager)
qCDebug(AirMapManagerLog) << "AirMap telemetry stream enabled";
_telemetry.startTelemetryStream(planMgr->flightID());
} else {
qCDebug(AirMapManagerLog) << "AirMap telemetry stream not possible (No Flight ID)";
} }
} }
...@@ -54,8 +61,9 @@ AirMapVehicleManager::isTelemetryStreaming() ...@@ -54,8 +61,9 @@ AirMapVehicleManager::isTelemetryStreaming()
void void
AirMapVehicleManager::endFlight() AirMapVehicleManager::endFlight()
{ {
if (!_flightManager.flightID().isEmpty()) { AirMapFlightPlanManager* planMgr = (AirMapFlightPlanManager*)qgcApp()->toolbox()->airspaceManager()->flightPlan();
_flightManager.endFlight(_flightManager.flightID()); if (!planMgr->flightID().isEmpty()) {
_flightManager.endFlight(planMgr->flightID());
} }
_trafficMonitor.stop(); _trafficMonitor.stop();
} }
......
...@@ -312,11 +312,11 @@ QGCView { ...@@ -312,11 +312,11 @@ QGCView {
anchors.fill: parent anchors.fill: parent
TableView { TableView {
id: tableView id: tableView
anchors.top: parent.top
anchors.bottom: parent.bottom
model: _flightList model: _flightList
selectionMode: SelectionMode.SingleSelection selectionMode: SelectionMode.SingleSelection
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true
onCurrentRowChanged: { onCurrentRowChanged: {
var o = _flightList.get(tableView.currentRow) var o = _flightList.get(tableView.currentRow)
if(o) { if(o) {
......
...@@ -56,10 +56,12 @@ Rectangle { ...@@ -56,10 +56,12 @@ Rectangle {
QGCCheckBox { QGCCheckBox {
id: checkBox id: checkBox
text: "" text: ""
checked: feature.value && feature.value < 2 ? feature.value : false
onClicked: feature.value = checked onClicked: feature.value = checked
anchors.left: parent.left anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
Component.onCompleted: {
checked = feature.value && feature.value < 2 ? feature.value : false
}
} }
QGCLabel { QGCLabel {
id: label id: label
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
AirspaceVehicleManager::AirspaceVehicleManager(const Vehicle& vehicle) AirspaceVehicleManager::AirspaceVehicleManager(const Vehicle& vehicle)
: _vehicle(vehicle) : _vehicle(vehicle)
{ {
qCDebug(AirspaceManagementLog) << "Instatiating AirspaceVehicleManager";
connect(&_vehicle, &Vehicle::armedChanged, this, &AirspaceVehicleManager::_vehicleArmedChanged); connect(&_vehicle, &Vehicle::armedChanged, this, &AirspaceVehicleManager::_vehicleArmedChanged);
connect(&_vehicle, &Vehicle::mavlinkMessageReceived, this, &AirspaceVehicleManager::vehicleMavlinkMessageReceived); connect(&_vehicle, &Vehicle::mavlinkMessageReceived, this, &AirspaceVehicleManager::vehicleMavlinkMessageReceived);
} }
...@@ -23,9 +24,11 @@ AirspaceVehicleManager::AirspaceVehicleManager(const Vehicle& vehicle) ...@@ -23,9 +24,11 @@ AirspaceVehicleManager::AirspaceVehicleManager(const Vehicle& vehicle)
void AirspaceVehicleManager::_vehicleArmedChanged(bool armed) void AirspaceVehicleManager::_vehicleArmedChanged(bool armed)
{ {
if (armed) { if (armed) {
qCDebug(AirspaceManagementLog) << "Starting telemetry";
startTelemetryStream(); startTelemetryStream();
_vehicleWasInMissionMode = _vehicle.flightMode() == _vehicle.missionFlightMode(); _vehicleWasInMissionMode = _vehicle.flightMode() == _vehicle.missionFlightMode();
} else { } else {
qCDebug(AirspaceManagementLog) << "Stopping telemetry";
stopTelemetryStream(); stopTelemetryStream();
// end the flight if we were in mission mode during arming or disarming // end the flight if we were in mission mode during arming or disarming
// TODO: needs to be improved. for instance if we do RTL and then want to continue the mission... // TODO: needs to be improved. for instance if we do RTL and then want to continue the mission...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment