From a33faed42c20e46dfa1c4d915d0b253561a6db47 Mon Sep 17 00:00:00 2001 From: zeisele <zeisele@iastate.edu> Date: Sun, 27 Mar 2022 20:44:59 +0200 Subject: [PATCH] constantly read log file --- groundStation/gui/MicroCART/logworker.cpp | 48 ++++++++++++++++++++++- groundStation/gui/MicroCART/logworker.h | 2 + 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/groundStation/gui/MicroCART/logworker.cpp b/groundStation/gui/MicroCART/logworker.cpp index f09c4b9b9..745c5b4a8 100644 --- a/groundStation/gui/MicroCART/logworker.cpp +++ b/groundStation/gui/MicroCART/logworker.cpp @@ -26,7 +26,19 @@ void LogWorker::connectBackend() } else { qInfo() << "Attempted to connect crazyflieworker when already connected!"; } - + startReadingLogFile(); +} + +std::string LogWorker::getLogFile(int type) { + struct frontend_getlogfile_data logfile; + char fname[256]; + logfile.command = type; + logfile.name = fname; + if(frontend_getlogfile(conn, &logfile)) { + return ""; + } + std::string result(logfile.name, strlen(logfile.name)); + return result; } /** @@ -42,4 +54,38 @@ void LogWorker::disconnectBackend() conn = NULL; emit (disconnected()); } +} + +void LogWorker::startReadingLogFile() { + std::string filename = getLogFile(0); + std::ifstream logFile; + logFile.open(filename.c_str()); + //std::streamoff p = 0; + std::string line; + + // while(true) { + // logFile.seekg(p); + // while(std::getline(logFile, line)) { + // QString result(line.c_str()); + // qInfo() << result; + // if(logFile.tellg() == -1) { + // p = p + line.size(); + // } + // else { + // p = logFile.tellg(); + // } + // } + // logFile.clear(); + // } + + while(true) { + while(std::getline(logFile, line)) { + QString result(line.c_str()); + qInfo() << result; + } + if(!logFile.eof()) { + break; + } + logFile.clear(); + } } \ No newline at end of file diff --git a/groundStation/gui/MicroCART/logworker.h b/groundStation/gui/MicroCART/logworker.h index 539a168c6..0341c29b5 100644 --- a/groundStation/gui/MicroCART/logworker.h +++ b/groundStation/gui/MicroCART/logworker.h @@ -38,6 +38,8 @@ public slots: private: struct backend_conn * conn; + void startReadingLogFile(); + std::string getLogFile(int type); }; #endif // LOGWORKER_H -- GitLab