/QMK-Groundstation/trunk/Logger/CSVLogger.cpp |
---|
0,0 → 1,73 |
/*************************************************************************** |
* 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) { |
// QFile-Instanz (Log-Datei) |
csvfile = new QFile(""); |
this->settings = settings; |
} |
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(QString filename) { |
if (!csvfile->isOpen()) |
{ |
csvfile = new QFile(filename); |
if (!csvfile->exists()) |
{ |
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/trunk/Logger/CSVLogger.h |
---|
0,0 → 1,53 |
/*************************************************************************** |
* 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 "../Classes/cSettings.h" |
#include "DefaultLogger.h" |
class CSVLogger : public DefaultLogger |
{ |
private: |
// Object für das Datenfile; |
QFile * csvfile; |
cSettings * settings; |
public: |
CSVLogger(cSettings * settings); |
~CSVLogger(); |
//schreibe log |
void write(int * analogData); |
//erzeuge neue Log-Datei/neuen Datensatz |
void newLog(QString name); |
//alles bereit zum schreiben? |
bool ready(); |
//alles schließen |
void close(); |
}; |
#endif |
/QMK-Groundstation/trunk/Logger/DefaultLogger.h |
---|
0,0 → 1,44 |
/*************************************************************************** |
* 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(QString) { }; |
//alles bereit zum schreiben? |
virtual bool ready() { return false; }; |
//alles schließen |
virtual void close() {}; |
}; |
#endif |
/QMK-Groundstation/trunk/Logger/Logger.cpp |
---|
0,0 → 1,69 |
/*************************************************************************** |
* 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) |
{ |
csv = new CSVLogger(settings); |
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); |
} |
//erzeuge neue Log-Datei/neuen Datensatz |
void Logger::newLog(QString name) |
{ |
foreach (DefaultLogger * log, logger) |
log->newLog(name); |
} |
//starte Logging |
void Logger::start_Log() |
{ |
active = true; |
} |
//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/trunk/Logger/Logger.h |
---|
0,0 → 1,60 |
/*************************************************************************** |
* 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 "../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); |
~Logger(); |
void start_Log(); |
//soll geloggt werden? |
bool is_active(); |
//schreibe log |
void write(int * analogData); |
//erzeuge neue Log-Datei/neuen Datensatz |
void newLog(QString name); |
//alles schließen |
void close(); |
}; |
#endif |