Commit a884de31 authored by Gus Grubba's avatar Gus Grubba

Handle anonymous login

Add control to set flight duration (which ultimately sets the end_time of flight)
parent e67ba35d
......@@ -150,7 +150,7 @@ AirMapFlightPlanManager::setFlightStartTime(QDateTime start)
_flightEndTime = _flightStartTime.addSecs(30 * 60);
emit flightEndTimeChanged();
}
qCDebug(AirMapManagerLog) << "Set time" << _flightStartTime << _flightEndTime;
qCDebug(AirMapManagerLog) << "Set time start time" << _flightStartTime << _flightEndTime;
}
//-----------------------------------------------------------------------------
......@@ -165,6 +165,7 @@ AirMapFlightPlanManager::setFlightEndTime(QDateTime end)
_flightEndTime = end;
emit flightEndTimeChanged();
}
qCDebug(AirMapManagerLog) << "Set time end time" << _flightStartTime << _flightEndTime;
}
//-----------------------------------------------------------------------------
......@@ -380,7 +381,7 @@ AirMapFlightPlanManager::_createFlightPlan()
qCDebug(AirMapManagerLog) << "Flight Start:" << flightStartTime().toString();
qCDebug(AirMapManagerLog) << "Flight End: " << flightEndTime().toString();
if (_pilotID == "") {
if (_pilotID == "" && !_shared.settings().userName.isEmpty() && !_shared.settings().password.isEmpty()) {
//-- Need to get the pilot id before uploading the flight plan
qCDebug(AirMapManagerLog) << "Getting pilot ID";
_state = State::GetPilotID;
......@@ -509,7 +510,7 @@ AirMapFlightPlanManager::_uploadFlightPlan()
FlightPlans::Create::Parameters params;
params.max_altitude = _flight.maxAltitude;
params.min_altitude = 0.0;
params.buffer = 0.f;
params.buffer = 10.f;
params.latitude = static_cast<float>(_flight.takeoffCoord.latitude());
params.longitude = static_cast<float>(_flight.takeoffCoord.longitude());
params.pilot.id = _pilotID.toStdString();
......
......@@ -40,16 +40,16 @@ AirMapSharedState::login()
}
_isLoginInProgress = true;
if (_settings.userName == "") { //use anonymous login
qCDebug(AirMapManagerLog) << "Anonymous authentication";
Authenticator::AuthenticateAnonymously::Params params;
params.id = "";
params.id = "Anonymous";
_client->authenticator().authenticate_anonymously(params,
[this](const Authenticator::AuthenticateAnonymously::Result& result) {
if (!_isLoginInProgress) { // was logout() called in the meanwhile?
return;
}
if (result) {
qCDebug(AirMapManagerLog)<<"Successfully authenticated with AirMap: id="<< result.value().id.c_str();
qCDebug(AirMapManagerLog) << "Successfully authenticated with AirMap: id="<< result.value().id.c_str();
emit authStatus(AirspaceManager::AuthStatus::Anonymous);
_loginToken = QString::fromStdString(result.value().id);
_processPendingRequests();
......@@ -67,13 +67,14 @@ AirMapSharedState::login()
params.oauth.password = _settings.password.toStdString();
params.oauth.client_id = _settings.clientID.toStdString();
params.oauth.device_id = "QGroundControl";
qCDebug(AirMapManagerLog) << "User authentication" << _settings.userName;
_client->authenticator().authenticate_with_password(params,
[this](const Authenticator::AuthenticateWithPassword::Result& result) {
if (!_isLoginInProgress) { // was logout() called in the meanwhile?
return;
}
if (result) {
qCDebug(AirMapManagerLog)<<"Successfully authenticated with AirMap: id="<< result.value().id.c_str()<<", access="
qCDebug(AirMapManagerLog) << "Successfully authenticated with AirMap: id="<< result.value().id.c_str()<<", access="
<<result.value().access.c_str();
emit authStatus(AirspaceManager::AuthStatus::Autheticated);
_loginToken = QString::fromStdString(result.value().id);
......
......@@ -19,6 +19,13 @@ Item {
implicitWidth: detailCol.width
property real baseHeight: ScreenTools.defaultFontPixelHeight * 22
property real baseWidth: ScreenTools.defaultFontPixelWidth * 40
function setEndTime() {
_dirty = true
var endTime = QGroundControl.airspaceManager.flightPlan.flightStartTime
endTime.setTime(endTime.getTime() + (Math.floor(durationSlider.value * 0.25) * 60 * 60 * 1000))
endTime.setTime(endTime.getTime() + ((durationSlider.value * 15) % 60) * 60 * 1000)
QGroundControl.airspaceManager.flightPlan.flightEndTime = endTime
}
Column {
id: detailCol
spacing: ScreenTools.defaultFontPixelHeight * 0.25
......@@ -44,7 +51,7 @@ Item {
flickableDirection: Flickable.VerticalFlick
Column {
id: flContextCol
spacing: ScreenTools.defaultFontPixelHeight * 0.5
spacing: ScreenTools.defaultFontPixelHeight * 0.25
anchors.right: parent.right
anchors.left: parent.left
QGCLabel {
......@@ -78,11 +85,12 @@ Item {
}
QGCButton {
text: {
var today = QGroundControl.airspaceManager.flightPlan.flightStartTime
if(datePicker.selectedDate.setHours(0,0,0,0) === today.setHours(0,0,0,0)) {
var nowTime = new Date()
var setTime = QGroundControl.airspaceManager.flightPlan.flightStartTime
if(setTime.setHours(0,0,0,0) === nowTime.setHours(0,0,0,0)) {
return qsTr("Today")
} else {
return datePicker.selectedDate.toLocaleDateString(Qt.locale())
return setTime.toLocaleDateString(Qt.locale())
}
}
Layout.fillWidth: true
......@@ -93,26 +101,20 @@ Item {
}
}
}
QGCLabel {
text: qsTr("Flight Start Time")
}
Item {
anchors.right: parent.right
anchors.left: parent.left
height: timeSlider.height
QGCLabel {
id: timeLabel
text: ('00' + hour).slice(-2) + ":" + ('00' + minute).slice(-2)
width: ScreenTools.defaultFontPixelWidth * 5
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
property int hour: Math.floor(timeSlider.value * 0.25)
property int minute: (timeSlider.value * 15) % 60
}
QGCSlider {
id: timeSlider
width: parent.width - timeLabel.width - ScreenTools.defaultFontPixelWidth
stepSize: 1
minimumValue: 0
maximumValue: 95 // 96 blocks of 15 minutes in 24 hours
anchors.right: parent.right
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
onValueChanged: {
_dirty = true
......@@ -120,7 +122,9 @@ Item {
today.setHours(Math.floor(timeSlider.value * 0.25))
today.setMinutes((timeSlider.value * 15) % 60)
today.setSeconds(0)
today.setMilliseconds(0)
QGroundControl.airspaceManager.flightPlan.flightStartTime = today
setEndTime()
}
Component.onCompleted: {
updateTime()
......@@ -132,6 +136,55 @@ Item {
timeSlider.value = Math.ceil(val)
}
}
QGCLabel {
id: timeLabel
text: ('00' + hour).slice(-2) + ":" + ('00' + minute).slice(-2)
width: ScreenTools.defaultFontPixelWidth * 5
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
property int hour: Math.floor(timeSlider.value * 0.25)
property int minute: (timeSlider.value * 15) % 60
}
}
QGCLabel {
text: qsTr("Duration")
}
Item {
anchors.right: parent.right
anchors.left: parent.left
height: durationSlider.height
QGCSlider {
id: durationSlider
width: parent.width - durationLabel.width - ScreenTools.defaultFontPixelWidth
stepSize: 1
minimumValue: 1
maximumValue: 24 // 24 blocks of 15 minutes in 6 hours
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
onValueChanged: {
setEndTime()
}
Component.onCompleted: {
updateTime()
}
function updateTime() {
var startTime = QGroundControl.airspaceManager.flightPlan.flightStartTime
var endTime = QGroundControl.airspaceManager.flightPlan.flightEndTime
var val = (endTime.getTime() - startTime.getTime()) / 1000 / 60
val = (val * (96/360)) + 1
if(val > 24) val = 24
durationSlider.value = Math.ceil(val)
}
}
QGCLabel {
id: durationLabel
text: ('00' + hour).slice(-2) + ":" + ('00' + minute).slice(-2)
width: ScreenTools.defaultFontPixelWidth * 5
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
property int hour: Math.floor(durationSlider.value * 0.25)
property int minute: (durationSlider.value * 15) % 60
}
}
}
}
......
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