diff --git a/src/uas/UASParameterCommsMgr.cc b/src/uas/UASParameterCommsMgr.cc index e52b9a83c763c924b567e8077b6bcfd73c4bf5c8..627a01f4f99d436ee43e4597f8c927ea2aae0138 100644 --- a/src/uas/UASParameterCommsMgr.cc +++ b/src/uas/UASParameterCommsMgr.cc @@ -19,8 +19,9 @@ UASParameterCommsMgr::UASParameterCommsMgr(QObject *parent) : silenceTimeout(1000), transmissionListMode(false) { - - + // We signal to ourselves to start/stop timer on our own thread + connect(this, SIGNAL(_startSilenceTimer(void)), this, SLOT(_startSilenceTimerOnThisThread(void))); + connect(this, SIGNAL(_stopSilenceTimer(void)), this, SLOT(_stopSilenceTimerOnThisThread(void))); } UASParameterCommsMgr* UASParameterCommsMgr::initWithUAS(UASInterface* uas) @@ -254,7 +255,7 @@ void UASParameterCommsMgr::silenceTimerExpired() qDebug() << "maxSilenceTimeout exceeded: " << totalElapsed; int missingReads, missingWrites; clearRetransmissionLists(missingReads,missingWrites); - silenceTimer.stop(); + emit _stopSilenceTimer(); // Stop timer on our thread; lastReceiveTime = 0; lastSilenceTimerReset = curTime; setParameterStatusMsg(tr("TIMEOUT: Abandoning %1 reads %2 writes after %3 seconds").arg(missingReads).arg(missingWrites).arg(totalElapsed/1000)); @@ -370,13 +371,14 @@ void UASParameterCommsMgr::updateSilenceTimer() if (0 == lastReceiveTime) { lastReceiveTime = lastSilenceTimerReset; } - silenceTimer.start(silenceTimeout); + // We signal this to ourselves so timer is started on the right thread + emit _startSilenceTimer(); } else { //all parameters have been received, broadcast to UI emit parameterListUpToDate(); resetAfterListReceive(); - silenceTimer.stop(); + emit _stopSilenceTimer(); // Stop timer on our thread; lastReceiveTime = 0; } @@ -547,3 +549,12 @@ UASParameterCommsMgr::~UASParameterCommsMgr() } +void UASParameterCommsMgr::_startSilenceTimerOnThisThread(void) +{ + silenceTimer.start(silenceTimeout); +} + +void UASParameterCommsMgr::_stopSilenceTimerOnThisThread(void) +{ + silenceTimer.stop(); +} diff --git a/src/uas/UASParameterCommsMgr.h b/src/uas/UASParameterCommsMgr.h index ef313761547352399e0fb23dce851994df8a25f4..20a24bb12ba8733cee67cb174192fad66e52e599 100644 --- a/src/uas/UASParameterCommsMgr.h +++ b/src/uas/UASParameterCommsMgr.h @@ -68,6 +68,11 @@ signals: /** @brief We updated the parameter status message */ void parameterStatusMsgUpdated(QString msg, int level); + + + /// @brief We signal this to ourselves in order to get timer started/stopped on our own thread. + void _startSilenceTimer(void); + void _stopSilenceTimer(void); public slots: /** @brief Iterate through all components, through all pending parameters and send them to UAS */ @@ -113,7 +118,10 @@ protected: bool transmissionListMode; ///< Currently requesting list QMap* > writesWaiting; ///< All writes that have not yet been ack'd, by component ID - +private slots: + /// @brief We signal this to ourselves in order to get timer started/stopped on our own thread. + void _startSilenceTimerOnThisThread(void); + void _stopSilenceTimerOnThisThread(void); }; diff --git a/src/uas/UASWaypointManager.cc b/src/uas/UASWaypointManager.cc index 406dedcad8c6f3339b006e5da71631b2f6833c71..5c57745dd890a9b60ad8672d3f7c99c73568c896 100644 --- a/src/uas/UASWaypointManager.cc +++ b/src/uas/UASWaypointManager.cc @@ -61,6 +61,10 @@ UASWaypointManager::UASWaypointManager(UAS* _uas) { uasid = 0; } + + // We signal to ourselves here so that tiemrs are started and stopped on correct thread + connect(this, SIGNAL(_startProtocolTimer(void)), this, SLOT(_startProtocolTimerOnThisThread(void))); + connect(this, SIGNAL(_stopProtocolTimer(void)), this, SLOT(_stopProtocolTimerOnThisThread(void))); } UASWaypointManager::~UASWaypointManager() @@ -133,7 +137,7 @@ void UASWaypointManager::handleGlobalPositionChanged(UASInterface* mav, double l void UASWaypointManager::handleWaypointCount(quint8 systemId, quint8 compId, quint16 count) { if (current_state == WP_GETLIST && systemId == current_partner_systemid) { - protocol_timer.start(PROTOCOL_TIMEOUT_MS); + emit _startProtocolTimer(); // Start timer on correct thread current_retries = PROTOCOL_MAX_RETRIES; //Clear the old edit-list before receiving the new one @@ -152,7 +156,7 @@ void UASWaypointManager::handleWaypointCount(quint8 systemId, quint8 compId, qui current_state = WP_GETLIST_GETWPS; sendWaypointRequest(current_wp_id); } else { - protocol_timer.stop(); + emit _stopProtocolTimer(); // Stop the time on our thread QTime time = QTime::currentTime(); emit updateStatusString(tr("Done. (updated at %1)").arg(time.toString())); current_state = WP_IDLE; @@ -171,7 +175,7 @@ void UASWaypointManager::handleWaypointCount(quint8 systemId, quint8 compId, qui void UASWaypointManager::handleWaypoint(quint8 systemId, quint8 compId, mavlink_mission_item_t *wp) { if (systemId == current_partner_systemid && current_state == WP_GETLIST_GETWPS && wp->seq == current_wp_id) { - protocol_timer.start(PROTOCOL_TIMEOUT_MS); + emit _startProtocolTimer(); // Start timer on our thread current_retries = PROTOCOL_MAX_RETRIES; if(wp->seq == current_wp_id) { @@ -202,7 +206,7 @@ void UASWaypointManager::handleWaypoint(quint8 systemId, quint8 compId, mavlink_ current_partner_systemid = 0; current_partner_compid = 0; - protocol_timer.stop(); + emit _stopProtocolTimer(); // Stop timer on our thread emit readGlobalWPFromUAS(false); QTime time = QTime::currentTime(); emit updateStatusString(tr("Done. (updated at %1)").arg(time.toString())); @@ -230,7 +234,7 @@ void UASWaypointManager::handleWaypointAck(quint8 systemId, quint8 compId, mavli if (compId == current_partner_compid || compId == MAV_COMP_ID_ALL) { if((current_state == WP_SENDLIST || current_state == WP_SENDLIST_SENDWPS) && (current_wp_id == waypoint_buffer.count()-1 && wpa->type == 0)) { //all waypoints sent and ack received - protocol_timer.stop(); + emit _stopProtocolTimer(); // Stop timer on our thread current_state = WP_IDLE; readWaypoints(false); //Update "Onboard Waypoints"-tab immediately after the waypoint list has been sent. QTime time = QTime::currentTime(); @@ -269,10 +273,10 @@ void UASWaypointManager::handleWaypointAck(quint8 systemId, quint8 compId, mavli emit updateStatusString(tr("ERROR: Unspecified error")); break; } - protocol_timer.stop(); + emit _stopProtocolTimer(); // Stop timer on our thread current_state = WP_IDLE; } else if(current_state == WP_CLEARLIST) { - protocol_timer.stop(); + emit _stopProtocolTimer(); // Stop timer on our thread current_state = WP_IDLE; QTime time = QTime::currentTime(); emit updateStatusString(tr("Done. (updated at %1)").arg(time.toString())); @@ -283,7 +287,7 @@ void UASWaypointManager::handleWaypointAck(quint8 systemId, quint8 compId, mavli void UASWaypointManager::handleWaypointRequest(quint8 systemId, quint8 compId, mavlink_mission_request_t *wpr) { if (systemId == current_partner_systemid && ((current_state == WP_SENDLIST && wpr->seq == 0) || (current_state == WP_SENDLIST_SENDWPS && (wpr->seq == current_wp_id || wpr->seq == current_wp_id + 1)))) { - protocol_timer.start(PROTOCOL_TIMEOUT_MS); + emit _startProtocolTimer(); // Start timer on our thread current_retries = PROTOCOL_MAX_RETRIES; if (wpr->seq < waypoint_buffer.count()) { @@ -314,7 +318,7 @@ void UASWaypointManager::handleWaypointCurrent(quint8 systemId, quint8 compId, m if (systemId == uasid) { // FIXME Petri if (current_state == WP_SETCURRENT) { - protocol_timer.stop(); + emit _stopProtocolTimer(); // Stop timer on our thread current_state = WP_IDLE; // update the local main storage @@ -362,7 +366,7 @@ int UASWaypointManager::setCurrentWaypoint(quint16 seq) if(current_state == WP_IDLE) { //send change to UAS - important to note: if the transmission fails, we have inconsistencies - protocol_timer.start(PROTOCOL_TIMEOUT_MS); + emit _startProtocolTimer(); // Start timer on our thread current_retries = PROTOCOL_MAX_RETRIES; current_state = WP_SETCURRENT; @@ -594,7 +598,7 @@ void UASWaypointManager::clearWaypointList() { if (current_state == WP_IDLE) { - protocol_timer.start(PROTOCOL_TIMEOUT_MS); + emit _startProtocolTimer(); // Start timer on our thread current_retries = PROTOCOL_MAX_RETRIES; current_state = WP_CLEARLIST; @@ -847,7 +851,10 @@ void UASWaypointManager::readWaypoints(bool readToEdit) emit waypointEditableListChanged(); } */ - protocol_timer.start(PROTOCOL_TIMEOUT_MS); + + // We are signalling ourselves here so that the timer gets started on the right thread + emit _startProtocolTimer(); + current_retries = PROTOCOL_MAX_RETRIES; current_state = WP_GETLIST; @@ -899,7 +906,7 @@ void UASWaypointManager::writeWaypoints() if (current_state == WP_IDLE) { // Send clear all if count == 0 if (waypointsEditable.count() > 0) { - protocol_timer.start(PROTOCOL_TIMEOUT_MS); + emit _startProtocolTimer(); // Start timer on our thread current_retries = PROTOCOL_MAX_RETRIES; current_count = waypointsEditable.count(); @@ -1128,3 +1135,14 @@ float UASWaypointManager::getHomeAltitudeOffsetDefault() { return defaultAltitudeHomeOffset; } + + +void UASWaypointManager::_startProtocolTimerOnThisThread(void) +{ + protocol_timer.start(PROTOCOL_TIMEOUT_MS); +} + +void UASWaypointManager::_stopProtocolTimerOnThisThread(void) +{ + protocol_timer.stop(); +} diff --git a/src/uas/UASWaypointManager.h b/src/uas/UASWaypointManager.h index 5c4f8e2cd61864ab85dd8cbcc5b89bafda0e6358..15b8b6326bd91b2e62bdd94e8b72b8230e16911d 100644 --- a/src/uas/UASWaypointManager.h +++ b/src/uas/UASWaypointManager.h @@ -160,6 +160,13 @@ signals: void loadWPFile(); ///< emits signal that a file wp has been load void readGlobalWPFromUAS(bool value); ///< emits signal when finish to read Global WP from UAS + + void _startProtocolTimer(void); ///< emits signal to start protocol timer + void _stopProtocolTimer(void); ///< emits signal to stop protocol timer + +private slots: + void _startProtocolTimerOnThisThread(void); ///< Starts the protocol timer + void _stopProtocolTimerOnThisThread(void); ///< Starts the protocol timer private: UAS* uas; ///< Reference to the corresponding UAS