Commit d18e0394 authored by Don Gagne's avatar Don Gagne

Make sure timer start/stop happens on class thread

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