Rev 442 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 442 | Rev 449 | ||
---|---|---|---|
1 | /*************************************************************************** |
1 | /*************************************************************************** |
2 | * Copyright (C) 2008 by Manuel Schrape * |
2 | * Copyright (C) 2008 by Manuel Schrape * |
3 | * manuel.schrape@gmx.de * |
3 | * manuel.schrape@gmx.de * |
4 | * and Andreas Bresser bresser@informatik.uni-bremen.de * |
4 | * and Andreas Bresser bresser@informatik.uni-bremen.de * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ***************************************************************************/ |
19 | ***************************************************************************/ |
20 | 20 | ||
21 | #include "CSVLogger.h" |
21 | #include "CSVLogger.h" |
22 | 22 | ||
23 | CSVLogger::CSVLogger(cSettings * settings, KopterData * data) |
23 | CSVLogger::CSVLogger(cSettings * settings, KopterData * data) |
24 | { |
24 | { |
25 | // QFile-Instanz (Log-Datei) |
25 | // QFile-Instanz (Log-Datei) |
26 | csvfile = new QFile(""); |
26 | csvfile = new QFile(""); |
27 | this->settings = settings; |
27 | this->settings = settings; |
28 | this->data = data; |
28 | this->data = data; |
29 | } |
29 | } |
30 | 30 | ||
31 | CSVLogger::~CSVLogger() |
31 | CSVLogger::~CSVLogger() |
32 | { |
32 | { |
33 | close(); |
33 | close(); |
34 | } |
34 | } |
35 | 35 | ||
36 | //datei ist geöffnet bedeutet wir sind soweit und können schreiben |
36 | //datei ist geöffnet bedeutet wir sind soweit und können schreiben |
37 | bool CSVLogger::ready() |
37 | bool CSVLogger::ready() |
38 | { |
38 | { |
39 | return csvfile->isOpen(); |
39 | return csvfile->isOpen(); |
40 | } |
40 | } |
41 | 41 | ||
42 | //Datei schließen |
42 | //Datei schließen |
43 | void CSVLogger::close() |
43 | void CSVLogger::close() |
44 | { |
44 | { |
45 | if (csvfile->isOpen()) |
45 | if (csvfile->isOpen()) |
46 | csvfile->close(); |
46 | csvfile->close(); |
47 | } |
47 | } |
48 | 48 | ||
49 | //neuen Log erstellen |
49 | //neuen Log erstellen |
50 | void CSVLogger::newLog() |
50 | void CSVLogger::newLog() |
51 | { |
51 | { |
52 | if (!csvfile->isOpen()) |
52 | if (!csvfile->isOpen()) |
53 | { |
53 | { |
54 | QString mode_name = QString(data->mode.hardware.c_str()); |
54 | QString mode_name = QString(data->mode.hardware); |
55 | 55 | ||
56 | if (mode_name.size() == 0) |
56 | if (mode_name.size() == 0) |
57 | { |
57 | { |
58 | mode_name = QString("groundstation_log"); |
58 | mode_name = QString("groundstation_log"); |
59 | } |
59 | } |
60 | 60 | ||
61 | QString filename = settings->DIR.Logging + mode_name + "_" + |
61 | QString filename = settings->DIR.Logging + mode_name + "_" + |
62 | QDate::currentDate().toString(("yyyy-MM-dd")) + "_" + |
62 | QDate::currentDate().toString(("yyyy-MM-dd")) + "_" + |
63 | QTime::currentTime().toString("hh-mm") + ".csv"; |
63 | QTime::currentTime().toString("hh-mm") + ".csv"; |
64 | 64 | ||
65 | csvfile = new QFile(filename); |
65 | csvfile = new QFile(filename); |
66 | 66 | ||
67 | if (!csvfile->exists()) |
67 | if (!csvfile->exists()) |
68 | { |
68 | { |
69 | csvfile->open(QIODevice::Append | QIODevice::Text); |
69 | csvfile->open(QIODevice::Append | QIODevice::Text); |
70 | 70 | ||
71 | QTextStream Out(csvfile); |
71 | QTextStream Out(csvfile); |
72 | 72 | ||
73 | for (int a = 0; a < MaxAnalog; a++) |
73 | for (int a = 0; a < MaxAnalog; a++) |
74 | { |
74 | { |
75 | if (settings->Analog1.LogView[a]) |
75 | if (settings->Analog1.LogView[a]) |
76 | { |
76 | { |
77 | Out << settings->Analog1.Label[a]; |
77 | Out << settings->Analog1.Label[a]; |
78 | 78 | ||
79 | if (a < MaxAnalog - 1) |
79 | if (a < MaxAnalog - 1) |
80 | Out << ';'; |
80 | Out << ';'; |
81 | } |
81 | } |
82 | } |
82 | } |
83 | Out << "\n"; |
83 | Out << "\n"; |
84 | } |
84 | } |
85 | else |
85 | else |
86 | { |
86 | { |
87 | csvfile->open(QIODevice::Append | QIODevice::Text); |
87 | csvfile->open(QIODevice::Append | QIODevice::Text); |
88 | } |
88 | } |
89 | } |
89 | } |
90 | } |
90 | } |
91 | 91 | ||
92 | //daten schreiben |
92 | //daten schreiben |
93 | void CSVLogger::write(int * analogData) |
93 | void CSVLogger::write(int * analogData) |
94 | { |
94 | { |
95 | if (csvfile->isOpen()) |
95 | if (csvfile->isOpen()) |
96 | { |
96 | { |
97 | QTextStream out(csvfile); |
97 | QTextStream out(csvfile); |
98 | for (int a=0; a<MaxAnalog; a++) |
98 | for (int a=0; a<MaxAnalog; a++) |
99 | { |
99 | { |
100 | if (settings->Analog1.LogView[a]) |
100 | if (settings->Analog1.LogView[a]) |
101 | { |
101 | { |
102 | out << analogData[a]; |
102 | out << analogData[a]; |
103 | if (a < MaxAnalog - 1) |
103 | if (a < MaxAnalog - 1) |
104 | out << ';'; |
104 | out << ';'; |
105 | } |
105 | } |
106 | } |
106 | } |
107 | out << "\n"; |
107 | out << "\n"; |
108 | } |
108 | } |
109 | } |
109 | } |
110 | 110 |