diff --git a/groundStation/gui/MicroCART/logworker.cpp b/groundStation/gui/MicroCART/logworker.cpp index f09c4b9b9fdce8799be2cac2f57f0b2b7a79aea0..745c5b4a8fc89f05bbced0554e3539645c79bb27 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 539a168c6df1fb0bea0cff994afcf4961bd6ae59..0341c29b59a1b8b37d68bfea5a46e6eb4921776e 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