/QMK-Groundstation/tags/V0.8.0/Logger/CSVLogger.cpp |
---|
0,0 → 1,109 |
/*************************************************************************** |
* Copyright (C) 2008 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* and Andreas Bresser bresser@informatik.uni-bremen.de * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#include "CSVLogger.h" |
CSVLogger::CSVLogger(cSettings * settings, sMode * mode) |
{ |
// QFile-Instanz (Log-Datei) |
csvfile = new QFile(""); |
this->settings = settings; |
this->mode = mode; |
} |
CSVLogger::~CSVLogger() |
{ |
close(); |
} |
//datei ist geöffnet bedeutet wir sind soweit und können schreiben |
bool CSVLogger::ready() |
{ |
return csvfile->isOpen(); |
} |
//Datei schließen |
void CSVLogger::close() |
{ |
if (csvfile->isOpen()) |
csvfile->close(); |
} |
//neuen Log erstellen |
void CSVLogger::newLog() |
{ |
if (!csvfile->isOpen()) |
{ |
QString mode_name = mode->Hardware; |
if (mode_name.size() == 0) |
{ |
mode_name = QString("groundstation_log"); |
} |
QString filename = settings->DIR.Logging + mode_name + "_" + |
QDate::currentDate().toString(("yyyy-MM-dd")) + "_" + |
QTime::currentTime().toString("hh-mm") + ".csv"; |
csvfile = new QFile(filename); |
if (!csvfile->exists()) |
{ |
csvfile->open(QIODevice::Append | QIODevice::Text); |
QTextStream Out(csvfile); |
for (int a = 0; a < MaxAnalog; a++) |
{ |
if (settings->Analog1.LogView[a]) |
{ |
Out << settings->Analog1.Label[a]; |
if (a < MaxAnalog - 1) |
Out << ';'; |
} |
} |
Out << "\n"; |
} |
else |
{ |
csvfile->open(QIODevice::Append | QIODevice::Text); |
} |
} |
} |
//daten schreiben |
void CSVLogger::write(int * analogData) |
{ |
if (csvfile->isOpen()) |
{ |
QTextStream out(csvfile); |
for (int a=0; a<MaxAnalog; a++) |
{ |
if (settings->Analog1.LogView[a]) |
{ |
out << analogData[a]; |
if (a < MaxAnalog - 1) |
out << ';'; |
} |
} |
out << "\n"; |
} |
} |
/QMK-Groundstation/tags/V0.8.0/Logger/CSVLogger.h |
---|
0,0 → 1,57 |
/*************************************************************************** |
* Copyright (C) 2008 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* and Andreas Bresser bresser@informatik.uni-bremen.de * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#ifndef CSVLOGGER_H |
#define CSVLOGGER_H |
#include <QString> |
#include <QTextStream> |
#include <QFile> |
#include <QDate> |
#include <QTime> |
#include "../global.h" |
#include "../Classes/cSettings.h" |
#include "DefaultLogger.h" |
class CSVLogger : public DefaultLogger |
{ |
private: |
// Object für das Datenfile; |
QFile * csvfile; |
cSettings * settings; |
sMode * mode; |
public: |
CSVLogger(cSettings * settings, sMode * mode); |
~CSVLogger(); |
//schreibe log |
void write(int * analogData); |
//erzeuge neue Log-Datei/neuen Datensatz |
void newLog(); |
//alles bereit zum schreiben? |
bool ready(); |
//alles schließen |
void close(); |
}; |
#endif |
/QMK-Groundstation/tags/V0.8.0/Logger/DefaultLogger.h |
---|
0,0 → 1,46 |
/*************************************************************************** |
* Copyright (C) 2009 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* and Andreas Bresser bresser@informatik.uni-bremen.de * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#ifndef DEFAULTLOGGER_H |
#define DEFAULTLOGGER_H |
#include <QString> |
#include "../Classes/cSettings.h" |
//Interface für einen Logger |
class DefaultLogger |
{ |
public: |
//schreibe log |
virtual void write(int *) { }; |
//erzeuge neue Log-Datei/neuen Datensatz |
virtual void newLog() { }; |
//alles bereit zum schreiben? |
virtual bool ready() { return false; }; |
//alles schließen |
virtual void close() {}; |
virtual ~DefaultLogger() {}; |
}; |
#endif |
/QMK-Groundstation/tags/V0.8.0/Logger/Logger.cpp |
---|
0,0 → 1,64 |
/*************************************************************************** |
* Copyright (C) 2009 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* and Andreas Bresser bresser@informatik.uni-bremen.de * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#include "Logger.h" |
Logger::Logger(cSettings * settings, sMode * mode) |
{ |
csv = new CSVLogger(settings, mode); |
logger << csv; |
active = false; |
} |
Logger::~Logger() |
{ |
close(); |
} |
//schreibe log |
void Logger::write(int * analogData) |
{ |
if (active == true) |
foreach (DefaultLogger * log, logger) |
if (log->ready()) |
log->write(analogData); |
} |
//starte Logging |
void Logger::start_Log() |
{ |
active = true; |
foreach (DefaultLogger * log, logger) |
log->newLog(); |
} |
//soll geloggt werden? |
bool Logger::is_active() |
{ |
return active; |
} |
//alles schließen |
void Logger::close() |
{ |
active = false; |
foreach (DefaultLogger * log, logger) |
log->close(); |
} |
/QMK-Groundstation/tags/V0.8.0/Logger/Logger.h |
---|
0,0 → 1,58 |
/*************************************************************************** |
* Copyright (C) 2009 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* and Andreas Bresser bresser@informatik.uni-bremen.de * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program is distributed in the hope that it will be useful, * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* GNU General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#ifndef LOGGER_H |
#define LOGGER_H |
#include <QLinkedList> |
#include <QString> |
#include "DefaultLogger.h" |
#include "../global.h" |
#include "../Classes/cSettings.h" |
//Die verschiedenen header der einzelnen Logger |
//TODO: MySQLLogger, SQLiteLogger und/oder PostGreSQLLogger |
#include "CSVLogger.h" |
class Logger |
{ |
private: |
CSVLogger * csv; |
//Liste aller bekannten Logger |
QLinkedList<DefaultLogger *> logger; |
bool active; |
public: |
Logger(cSettings * settings, sMode * mode); |
~Logger(); |
void start_Log(); |
//soll geloggt werden? |
bool is_active(); |
//schreibe log |
void write(int * analogData); |
//alles schließen |
void close(); |
}; |
#endif |