Commit 279dafd7 authored by Don Gagne's avatar Don Gagne

Wait for params before reboot

parent f8b8503c
...@@ -105,23 +105,39 @@ void AirframeComponentController::changeAutostart(void) ...@@ -105,23 +105,39 @@ void AirframeComponentController::changeAutostart(void)
qgcApp()->setOverrideCursor(Qt::WaitCursor); qgcApp()->setOverrideCursor(Qt::WaitCursor);
getParameterFact(-1, "SYS_AUTOSTART")->setValue(_autostartId); Fact* sysAutoStartFact = getParameterFact(-1, "SYS_AUTOSTART");
getParameterFact(-1, "SYS_AUTOCONFIG")->setValue(1); Fact* sysAutoConfigFact = getParameterFact(-1, "SYS_AUTOCONFIG");
// FactSystem doesn't currently have a mechanism to wait for the parameters to come backf from the board. // We need to wait for the vehicleUpdated signals to come back before we reboot
// So instead we wait for enough time for the parameters to hoepfully make it to the board. _waitParamWriteSignalCount = 0;
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents); connect(sysAutoStartFact, &Fact::vehicleUpdated, this, &AirframeComponentController::_waitParamWriteSignal);
QGC::SLEEP::sleep(3); connect(sysAutoConfigFact, &Fact::vehicleUpdated, this, &AirframeComponentController::_waitParamWriteSignal);
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
// Reboot board // We use forceSetValue to params are sent even if the previous value is that same as the new value
sysAutoStartFact->forceSetValue(_autostartId);
sysAutoConfigFact->forceSetValue(1);
}
void AirframeComponentController::_waitParamWriteSignal(QVariant value)
{
Q_UNUSED(value);
_waitParamWriteSignalCount++;
if (_waitParamWriteSignalCount == 2) {
// Now that both params have made it to the vehicle we can reboot it. All these signals are flying
// around on the main thread, so we need to allow the stack to unwind back to the event loop before
// we reboot.
QTimer::singleShot(100, this, &AirframeComponentController::_rebootAfterStackUnwind);
}
}
void AirframeComponentController::_rebootAfterStackUnwind(void)
{
_uas->executeCommand(MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 1, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0); _uas->executeCommand(MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 1, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents); qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
QGC::SLEEP::sleep(1); QGC::SLEEP::sleep(1);
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents); qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
LinkManager::instance()->disconnectAll(); LinkManager::instance()->disconnectAll();
qgcApp()->restoreOverrideCursor(); qgcApp()->restoreOverrideCursor();
} }
......
...@@ -63,15 +63,20 @@ signals: ...@@ -63,15 +63,20 @@ signals:
void autostartIdChanged(int newAutostartId); void autostartIdChanged(int newAutostartId);
void showCustomConfigPanelChanged(bool show); void showCustomConfigPanelChanged(bool show);
private slots:
void _waitParamWriteSignal(QVariant value);
void _rebootAfterStackUnwind(void);
private: private:
static bool _typesRegistered; static bool _typesRegistered;
QVariantList _airframeTypes; QVariantList _airframeTypes;
QString _currentAirframeType; QString _currentAirframeType;
QString _currentVehicleName; QString _currentVehicleName;
int _currentVehicleIndex; int _currentVehicleIndex;
int _autostartId; int _autostartId;
bool _showCustomConfigPanel; bool _showCustomConfigPanel;
int _waitParamWriteSignalCount;
}; };
class Airframe : public QObject class Airframe : public QObject
......
...@@ -49,6 +49,22 @@ Fact::Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObjec ...@@ -49,6 +49,22 @@ Fact::Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObjec
} }
void Fact::forceSetValue(const QVariant& value)
{
if (_metaData) {
QVariant typedValue;
QString errorString;
if (_metaData->convertAndValidate(value, true /* convertOnly */, typedValue, errorString)) {
_value.setValue(typedValue);
emit valueChanged(_value);
emit _containerValueChanged(_value);
}
} else {
qWarning() << "Meta data pointer missing";
}
}
void Fact::setValue(const QVariant& value) void Fact::setValue(const QVariant& value)
{ {
if (_metaData) { if (_metaData) {
...@@ -71,6 +87,7 @@ void Fact::_containerSetValue(const QVariant& value) ...@@ -71,6 +87,7 @@ void Fact::_containerSetValue(const QVariant& value)
{ {
_value = value; _value = value;
emit valueChanged(_value); emit valueChanged(_value);
emit vehicleUpdated(_value);
} }
QString Fact::name(void) const QString Fact::name(void) const
......
...@@ -84,6 +84,9 @@ public: ...@@ -84,6 +84,9 @@ public:
bool maxIsDefaultForType(void); bool maxIsDefaultForType(void);
QString group(void); QString group(void);
/// Sets and sends new value to vehicle even if value is the same
void forceSetValue(const QVariant& value);
/// Sets the meta data associated with the Fact. /// Sets the meta data associated with the Fact.
void setMetaData(FactMetaData* metaData); void setMetaData(FactMetaData* metaData);
...@@ -95,6 +98,9 @@ signals: ...@@ -95,6 +98,9 @@ signals:
/// This signal is only meant for use by the QT property system. It should not be connected to by client code. /// This signal is only meant for use by the QT property system. It should not be connected to by client code.
void valueChanged(QVariant value); void valueChanged(QVariant value);
/// Signalled when the param write ack comes back from the vehicle
void vehicleUpdated(QVariant value);
/// Signalled when property has been changed by a call to the property write accessor /// Signalled when property has been changed by a call to the property write accessor
/// ///
/// This signal is meant for use by Fact container implementations. /// This signal is meant for use by Fact container implementations.
......
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