diff --git a/crazyflie_groundstation/inc/CTOC.h b/crazyflie_groundstation/inc/CTOC.h index b326be5e8b862707c0f5f4d20a97e135c7a18e03..c07aed490f3900db93f3b5201f7c318bb2843d0e 100644 --- a/crazyflie_groundstation/inc/CTOC.h +++ b/crazyflie_groundstation/inc/CTOC.h @@ -60,6 +60,7 @@ struct TOCElement { std::string strIdentifier; bool bIsLogging; double dValue; + double timeLastUpdated; }; @@ -140,6 +141,7 @@ class CTOC { int elementIDinBlock(int nBlockID, int nElementIndex); bool setFloatValueForElementID(int nElementID, float fValue); + bool setLastUpdateForElementID(int nElementID); bool addElementToBlock(int nBlockID, int nElementID); bool unregisterLoggingBlockID(int nID); diff --git a/crazyflie_groundstation/src/CTOC.cpp b/crazyflie_groundstation/src/CTOC.cpp index 4e484aad8f1b294add50ff8d77f133124e4163f2..039b0d95181d7a42e5ca75bf8cf5fea978fddb7f 100644 --- a/crazyflie_groundstation/src/CTOC.cpp +++ b/crazyflie_groundstation/src/CTOC.cpp @@ -216,7 +216,8 @@ bool CTOC::processItem(CCRTPPacket* crtpItem) { teNew.nID = nID; teNew.nType = nType; teNew.bIsLogging = false; - teNew.dValue = 1; + teNew.dValue = 0; + teNew.timeLastUpdated = 0; if(ALL_THE_DEBUG) printf("Group.Name: %s.%s ID: %i Type: %i ", strGroup.c_str(), strIdentifier.c_str(), nID, nType); @@ -377,6 +378,7 @@ bool CTOC::processNextItem(CCRTPPacket* crtpItem) { teNew.nType = nType; teNew.bIsLogging = false; teNew.dValue = 0; + teNew.timeLastUpdated = 0; m_lstTOCElements.push_back(teNew); @@ -935,6 +937,7 @@ void CTOC::processPackets(CCRTPPacket *crtpPacket) { } this->setFloatValueForElementID(nElementID, fValue); + this->setLastUpdateForElementID(nElementID); nOffset += nByteLength; nIndex++; } else { @@ -990,6 +993,25 @@ bool CTOC::setFloatValueForElementID(int nElementID, float fValue) { return false; } +bool CTOC::setLastUpdateForElementID(int nElementID) { + if( ALL_THE_DEBUG ) printf( "%s\n", __FUNCTION__); + int nIndex = 0; + for (std::list<struct TOCElement>::iterator itElement = + m_lstTOCElements.begin(); itElement != m_lstTOCElements.end(); + itElement++, nIndex++) { + struct TOCElement teCurrent = *itElement; + + if (teCurrent.nID == nElementID) { + teCurrent.timeLastUpdated = m_crazyflie->currentTime(); // We store floats as doubles + (*itElement) = teCurrent; + // std::cout << fValue << std::endl; + return true; + } + } + + return false; +} + /* * Open a log file for the quadcopter * diff --git a/crazyflie_groundstation/src/ccrazyflie/CCrazyflie_loggingFuncs.cpp b/crazyflie_groundstation/src/ccrazyflie/CCrazyflie_loggingFuncs.cpp index 32fcc188ad3b370ee2bee2577ac9ec2d842b2221..d0caf41418409adbc4b34ef1c0bcd7f28e1187af 100644 --- a/crazyflie_groundstation/src/ccrazyflie/CCrazyflie_loggingFuncs.cpp +++ b/crazyflie_groundstation/src/ccrazyflie/CCrazyflie_loggingFuncs.cpp @@ -112,10 +112,19 @@ void CCrazyflie::writeLogData() { file_log << "\t\t" << this->sensorDoubleValue("testStand"); */ + bool bFound; + TOCElement response; file_log << std::endl; - file_log << this->currentTime(); + double currentTime = this->currentTime(); + file_log << currentTime; for(int i = 0; i < m_tocLogs->sizeOfActiveList(); i++) { - file_log << "\t" << this->sensorDoubleValue(m_tocLogs->activeLogName(i)); + response = m_tocLogs->elementForName(m_tocLogs->activeLogName(i), bFound); + if(response.timeLastUpdated > currentTime - 0.01) { + file_log << "\t" << this->sensorDoubleValue(m_tocLogs->activeLogName(i)); + } + else { + file_log << "\t" << std::numeric_limits<double>::quiet_NaN(); + } } file_log << "\t" << this->sensorDoubleValue("testStand"); }