Subversion Repositories NaviCtrl

Rev

Rev 762 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 762 Rev 808
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Software Nutzungsbedingungen (english version: see below)
7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
22
// + des Mitverschuldens offen.
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Software LICENSING TERMS
32
// + Software LICENSING TERMS
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
40
// + agreement shall be the property of the Licensor.
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
43
// + The customer shall be responsible for taking reasonable precautions
43
// + The customer shall be responsible for taking reasonable precautions
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
#include <stdio.h>
56
#include <stdio.h>
57
#include "91x_lib.h"
57
#include "91x_lib.h"
58
#include "main.h"
58
#include "main.h"
59
#include "timer1.h"
59
#include "timer1.h"
60
#include "uart1.h"
60
#include "uart1.h"
61
#include "kml.h"
61
#include "kml.h"
62
#include "gpx.h"
62
#include "gpx.h"
63
#include "ssc.h"
63
#include "ssc.h"
64
#include "settings.h"
64
#include "settings.h"
65
#include "led.h"
65
#include "led.h"
66
#include "logging.h"
66
#include "logging.h"
67
#include "triggerlog.h"
67
#include "triggerlog.h"
68
 
68
 
69
#define MIN_SD_INTERVAL_KML  200
69
#define MIN_SD_INTERVAL_KML  200
70
#define MIN_SD_INTERVAL_GPX  200
70
#define MIN_SD_INTERVAL_GPX  200
71
 
71
 
72
u8 SD_LoggingError = 0;
72
u8 SD_LoggingError = 0;
73
 
73
 
74
 
74
 
75
 
75
 
76
 
76
 
77
// logger handler prototypes
77
// logger handler prototypes
78
logfilestate_t Logging_KML(u32 LogDelay);
78
logfilestate_t Logging_KML(u32 LogDelay);
79
logfilestate_t Logging_GPX(u32 LogDelay);
79
logfilestate_t Logging_GPX(u32 LogDelay);
80
 
80
 
81
LogCfg_t LogCfg = {500 , 1000};
81
LogCfg_t LogCfg = {500 , 1000};
82
u32 Logged_GPX_Counter = 0, Logged_KML_Counter = 0;
82
u32 Logged_GPX_Counter = 0, Logged_KML_Counter = 0;
83
u16 KML_Filenum = 0, GPX_Filenum = 0, GPX_logging_active = 0;
83
u16 KML_Filenum = 0, GPX_Filenum = 0, GPX_logging_active = 0;
84
 
84
 
85
//----------------------------------------------------------------------------------------------------
85
//----------------------------------------------------------------------------------------------------
86
s8* GenerateKMLLogFileName(void)
86
s8* GenerateKMLLogFileName(void)
87
{
87
{
88
        static u16 filenum = 0; // file name counter
88
        static u16 filenum = 0; // file name counter
89
        static s8 filename[40];
89
        static s8 filename[40];
90
        static DateTime_t LastTime = {0,0,0,0,0,0,0,0};
90
        static DateTime_t LastTime = {0,0,0,0,0,0,0,0};
91
 
91
 
92
        if(SystemTime.Valid)
92
        if(SystemTime.Valid)
93
        {
93
        {
94
                // if the day has been changed
94
                // if the day has been changed
95
                if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day))
95
                if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day))
96
                {
96
                {
97
                        LastTime.Year = SystemTime.Year;
97
                        LastTime.Year = SystemTime.Year;
98
                        LastTime.Month = SystemTime.Month;
98
                        LastTime.Month = SystemTime.Month;
99
                        LastTime.Day = SystemTime.Day;
99
                        LastTime.Day = SystemTime.Day;
100
                        LastTime.Valid = 1;
100
                        LastTime.Valid = 1;
101
                        filenum = 0; // reset file counter
101
                        filenum = 0; // reset file counter
102
                }
102
                }
103
        if(!(SimulationFlags & SIMULATION_ACTIVE))
103
        if(!(SimulationFlags & SIMULATION_ACTIVE))
104
        {
104
        {
105
                if(filenum < 100) sprintf(filename, "/LOG/%04i%02i%02i/KML/%02i%02i%02i%02i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 100, SystemTime.Month, SystemTime.Day, filenum);
105
                if(filenum < 100) sprintf(filename, "/LOG/%04i%02i%02i/KML/%02i%02i%02i%02i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 100, SystemTime.Month, SystemTime.Day, filenum);
106
                else sprintf(filename, "/LOG/%04i%02i%02i/KML/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum);
106
                else sprintf(filename, "/LOG/%04i%02i%02i/KML/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum);
107
    }
107
    }
108
        else
108
        else
109
        {
109
        {
110
                if(filenum < 100&& SystemTime.Year > 2000) sprintf(filename, "/SIMULATE/%04i%02i%02i/KML/S%1i%02i%02i%02i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 10, SystemTime.Month, SystemTime.Day, filenum);
110
                if(filenum < 100&& SystemTime.Year > 2000) sprintf(filename, "/SIMULATE/%04i%02i%02i/KML/S%1i%02i%02i%02i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 10, SystemTime.Month, SystemTime.Day, filenum);
111
                else sprintf(filename, "/SIMULATE/%04i%02i%02i/KML/SIM%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum);
111
                else sprintf(filename, "/SIMULATE/%04i%02i%02i/KML/SIM%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum);
112
    }
112
    }
113
 
113
 
114
                filenum++;
114
                filenum++;
115
                KML_Filenum = filenum;
115
                KML_Filenum = filenum;
116
                return filename;
116
                return filename;
117
        }
117
        }
118
        else return NULL;
118
        else return NULL;
119
}
119
}
120
 
120
 
121
//----------------------------------------------------------------------------------------------------
121
//----------------------------------------------------------------------------------------------------
122
s8* GenerateGPXLogFileName(void)
122
s8* GenerateGPXLogFileName(void)
123
{
123
{
124
        static u16 filenum = 0; // file name counter
124
        static u16 filenum = 0; // file name counter
125
        static s8 filename[40];
125
        static s8 filename[40];
126
        static DateTime_t LastTime = {0,0,0,0,0,0,0,0};
126
        static DateTime_t LastTime = {0,0,0,0,0,0,0,0};
127
 
127
 
128
        if(SystemTime.Valid)
128
        if(SystemTime.Valid)
129
        {
129
        {
130
                // if the day has been changed
130
                // if the day has been changed
131
                if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day))
131
                if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day))
132
                {
132
                {
133
                        LastTime.Year = SystemTime.Year;
133
                        LastTime.Year = SystemTime.Year;
134
                        LastTime.Month = SystemTime.Month;
134
                        LastTime.Month = SystemTime.Month;
135
                        LastTime.Day = SystemTime.Day;
135
                        LastTime.Day = SystemTime.Day;
136
                        LastTime.Valid = 1;
136
                        LastTime.Valid = 1;
137
                        filenum = 0; // reset file counter
137
                        filenum = 0; // reset file counter
138
                }
138
                }
139
        if(!(SimulationFlags & SIMULATION_ACTIVE))
139
        if(!(SimulationFlags & SIMULATION_ACTIVE))
140
        {
140
        {
141
                if(filenum < 100) sprintf(filename, "/LOG/%04i%02i%02i/GPX/%02i%02i%02i%02i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 100, SystemTime.Month, SystemTime.Day, filenum);
141
                if(filenum < 100) sprintf(filename, "/LOG/%04i%02i%02i/GPX/%02i%02i%02i%02i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 100, SystemTime.Month, SystemTime.Day, filenum);
142
                else sprintf(filename, "/LOG/%04i%02i%02i/GPX/GPS%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum);
142
                else sprintf(filename, "/LOG/%04i%02i%02i/GPX/GPS%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum);
143
        }
143
        }
144
        else
144
        else
145
        {
145
        {
146
                if(filenum < 100 && SystemTime.Year > 2000) sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/S%i%02i%02i%02i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 10, SystemTime.Month, SystemTime.Day, filenum);
146
                if(filenum < 100 && SystemTime.Year > 2000) sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/S%i%02i%02i%02i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 10, SystemTime.Month, SystemTime.Day, filenum);
147
                else sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/SIM%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum);
147
                else sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/SIM%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum);
148
        }
148
        }
149
                GPX_Filenum = filenum;
149
                GPX_Filenum = filenum;
150
                filenum++;
150
                filenum++;
151
                return filename;
151
                return filename;
152
        }
152
        }
153
        else return NULL;
153
        else return NULL;
154
}
154
}
155
 
155
 
156
 
156
 
157
 
157
 
158
//----------------------------------------------------------------------------------------------------
158
//----------------------------------------------------------------------------------------------------
159
// logs the current gps position to a kml file
159
// logs the current gps position to a kml file
160
logfilestate_t Logging_KML(u32 LogDelay)
160
logfilestate_t Logging_KML(u32 LogDelay)
161
{
161
{
162
        static  logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate
162
        static  logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate
163
        static  s8* logfilename = NULL;                                         // the pointer to the logfilename
163
        static  s8* logfilename = NULL;                                         // the pointer to the logfilename
164
        static  u32 logtimer = 0, flushtimer = 0;               // the log update timer
164
        static  u32 logtimer = 0, flushtimer = 0;               // the log update timer
165
        static  KML_Document_t logfile;                                         // the logfilehandle
165
        static  KML_Document_t logfile;                                         // the logfilehandle
166
        static  u32 appendtimer = 0;            // the log update timer
166
        static  u32 appendtimer = 0;            // the log update timer
167
        static  u8 logging_active = 0;
167
        static  u8 logging_active = 0;
168
 
168
 
169
        // initialize if LogDelay is zero
169
        // initialize if LogDelay is zero
170
        if(!LogDelay)
170
        if(!LogDelay)
171
        {
171
        {
172
                switch(logfilestate)
172
                switch(logfilestate)
173
                {
173
                {
174
                        case LOGFILE_OPENED:
174
                        case LOGFILE_OPENED:
175
                                KML_DocumentClose(&logfile); // try to close it
175
                                KML_DocumentClose(&logfile); // try to close it
176
                                break;
176
                                break;
177
                        default:
177
                        default:
178
                                break;
178
                                break;
179
                }
179
                }
180
                logfilestate = LOGFILE_IDLE;
180
                logfilestate = LOGFILE_IDLE;
181
                logfilename = NULL;
181
                logfilename = NULL;
182
                KML_DocumentInit(&logfile);
182
                KML_DocumentInit(&logfile);
183
                logtimer = SetDelay(0); // set logtimer to now
183
                logtimer = SetDelay(0); // set logtimer to now
184
                return logfilestate;
184
                return logfilestate;
185
        }
185
        }
186
        // no init
186
        // no init
187
        if(CheckDelay(logtimer))
187
        if(CheckDelay(logtimer))
188
        {
188
        {
189
                logtimer = SetDelay(LogDelay);  // standard interval
189
                logtimer = SetDelay(LogDelay);  // standard interval
190
 
190
 
191
                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN)
191
                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN)
192
                {
192
                {
193
                        logging_active = 1;
193
                        logging_active = 1;
194
                        appendtimer = SetDelay(APPEND_LOG_TIME_MS);
194
                        appendtimer = SetDelay(APPEND_LOG_TIME_MS);
195
                }
195
                }
196
                else
196
                else
197
                {
197
                {
198
                        if(CheckDelay(appendtimer)) logging_active = 0;
198
                        if(CheckDelay(appendtimer)) logging_active = 0;
199
                }
199
                }
200
 
200
 
201
                if(logging_active)
201
                if(logging_active)
202
                {
202
                {
203
                        switch(logfilestate)
203
                        switch(logfilestate)
204
                        {
204
                        {
205
                                case LOGFILE_IDLE:
205
                                case LOGFILE_IDLE:
206
                                case LOGFILE_CLOSED:
206
                                case LOGFILE_CLOSED:
207
                                        if((GPSData.Status != INVALID) && (SystemTime.Valid) && /*(GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)*/ (FC.StatusFlags & FC_STATUS_FLY))
207
                                        if((GPSData.Status != INVALID) && (SystemTime.Valid) && /*(GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)*/ (FC.StatusFlags & FC_STATUS_FLY))
208
                                        {
208
                                        {
209
                                                logfilestate = LOGFILE_START;
209
                                                logfilestate = LOGFILE_START;
210
                                        }
210
                                        }
211
                                        break;
211
                                        break;
212
                                case LOGFILE_START:
212
                                case LOGFILE_START:
213
                                        // find unused logfile name
213
                                        // find unused logfile name
214
                                        do
214
                                        do
215
                                        {        // try to generate a new logfile name
215
                                        {        // try to generate a new logfile name
216
                                                 logfilename = GenerateKMLLogFileName();
216
                                                 logfilename = GenerateKMLLogFileName();
217
                                        }while((logfilename != NULL) && fexist_(logfilename));
217
                                        }while((logfilename != NULL) && fexist_(logfilename));
218
                                        // if logfilename exist
218
                                        // if logfilename exist
219
                                        if(logfilename != NULL)
219
                                        if(logfilename != NULL)
220
                                        {
220
                                        {
221
                                                // try to create the log file
221
                                                // try to create the log file
222
                                                if(KML_DocumentOpen(logfilename, &logfile))
222
                                                if(KML_DocumentOpen(logfilename, &logfile))
223
                                                {
223
                                                {
224
                                                        flushtimer = SetDelay(LOG_FLUSH_INTERVAL);
224
                                                        flushtimer = SetDelay(LOG_FLUSH_INTERVAL);
225
                                                        logfilestate = LOGFILE_OPENED; // goto next step
225
                                                        logfilestate = LOGFILE_OPENED; // goto next step
226
                                                        UART1_PutString("\r\nOpening kml-file:");
226
                                                        UART1_PutString("\r\nOpening kml-file:");
227
                                                        UART1_PutString(logfilename);
227
                                                        UART1_PutString(logfilename);
228
                                                        UART1_PutString("\r\n");
228
                                                        UART1_PutString("\r\n");
229
                                                }
229
                                                }
230
                                                else // could not be openend
230
                                                else // could not be openend
231
                                                {
231
                                                {
232
                                                        logfilestate = LOGFILE_ERROR;
232
                                                        logfilestate = LOGFILE_ERROR;
233
                                                        UART1_PutString("\r\nError opening kml-file: ");
233
                                                        UART1_PutString("\r\nError opening kml-file: ");
234
                                                        UART1_PutString(logfilename);
234
                                                        UART1_PutString(logfilename);
235
                                                        UART1_PutString("\r\n");
235
                                                        UART1_PutString("\r\n");
236
                                                        logtimer = SetDelay(10);  // try again in open logfile in 10 mili sec
236
                                                        logtimer = SetDelay(10);  // try again in open logfile in 10 mili sec
237
                                                        SD_LoggingError = 1;
237
                                                        SD_LoggingError = 1;
238
                                                }
238
                                                }
239
                                        }
239
                                        }
240
                                        else
240
                                        else
241
                                        {
241
                                        {
242
                                                logfilestate = LOGFILE_ERROR;
242
                                                logfilestate = LOGFILE_ERROR;
243
                                                UART1_PutString("\r\nError getting free kml-file name\r\n");
243
                                                UART1_PutString("\r\nError getting free kml-file name\r\n");
244
                                                SD_LoggingError = 2;
244
                                                SD_LoggingError = 2;
245
                                        }
245
                                        }
246
                                        // else retry in next loop
246
                                        // else retry in next loop
247
                                        break;
247
                                        break;
248
                                case LOGFILE_OPENED:
248
                                case LOGFILE_OPENED:
249
                                        // append new gps log data
249
                                        // append new gps log data
250
                                                if(!KML_LoggGPSCoordinates(&logfile))
250
                                                if(!KML_LoggGPSCoordinates(&logfile))
251
                                                {       // error logging data
251
                                                {       // error logging data
252
                                                        UART1_PutString("\r\nError logging to kml-file\r\n");
252
                                                        UART1_PutString("\r\nError logging to kml-file\r\n");
253
                                                        SD_LoggingError = 3;
253
                                                        SD_LoggingError = 3;
254
                                                        KML_DocumentClose(&logfile);
254
                                                        KML_DocumentClose(&logfile);
255
                                                        logfilestate = LOGFILE_ERROR;
255
                                                        logfilestate = LOGFILE_ERROR;
256
                                                }
256
                                                }
257
                                                else // sucessfully logged
257
                                                else // sucessfully logged
258
                                                {
258
                                                {
259
                                                        SD_LoggingError = 0;
259
                                                        SD_LoggingError = 0;
260
                                                        if(CheckDelay(flushtimer))
260
                                                        if(CheckDelay(flushtimer))
261
                                                        {
261
                                                        {
262
                                                                flushtimer = SetDelay(LOG_FLUSH_INTERVAL);
262
                                                                flushtimer = SetDelay(LOG_FLUSH_INTERVAL);
263
                                                                fflush_(logfile.file);
263
                                                                fflush_(logfile.file);
264
                                                        }
264
                                                        }
265
                                                }
265
                                                }
266
                                        break;
266
                                        break;
267
 
267
 
268
                                case LOGFILE_ERROR:
268
                                case LOGFILE_ERROR:
269
                                        break;
269
                                        break;
270
 
270
 
271
                                default:
271
                                default:
272
                                        logfilestate = LOGFILE_IDLE;
272
                                        logfilestate = LOGFILE_IDLE;
273
                                        break;
273
                                        break;
274
                        }
274
                        }
275
                } // EOF motors are not running
275
                } // EOF motors are not running
276
                else // model is not flying
276
                else // model is not flying
277
                {   // close log file if opened
277
                {   // close log file if opened
278
                        if(logfilestate == LOGFILE_OPENED)
278
                        if(logfilestate == LOGFILE_OPENED)
279
                        {
279
                        {
280
                                if(KML_DocumentClose(&logfile))
280
                                if(KML_DocumentClose(&logfile))
281
                                {
281
                                {
282
                                        UART1_PutString("\r\nClosing kml-file\r\n");
282
                                        UART1_PutString("\r\nClosing kml-file\r\n");
283
                                        logfilestate = LOGFILE_CLOSED;
283
                                        logfilestate = LOGFILE_CLOSED;
284
                                }
284
                                }
285
                                else  // could not be closed
285
                                else  // could not be closed
286
                                {
286
                                {
287
                                        UART1_PutString("\r\nError closing kml-file\r\n");
287
                                        UART1_PutString("\r\nError closing kml-file\r\n");
288
                                        SD_LoggingError = 4;
288
                                        SD_LoggingError = 4;
289
                                        logfilestate =  LOGFILE_ERROR;
289
                                        logfilestate =  LOGFILE_ERROR;
290
                                }
290
                                }
291
                        }
291
                        }
292
                } //EOF motors are not running
292
                } //EOF motors are not running
293
        } // EOF Check LogTimer
293
        } // EOF Check LogTimer
294
 
294
 
295
        return logfilestate;
295
        return logfilestate;
296
}
296
}
297
 
297
 
298
//----------------------------------------------------------------------------------------------------
298
//----------------------------------------------------------------------------------------------------
299
// logs gps and state info to a gpx file
299
// logs gps and state info to a gpx file
300
logfilestate_t Logging_GPX(u32 LogDelay)
300
logfilestate_t Logging_GPX(u32 LogDelay)
301
{
301
{
302
        static  logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate
302
        static  logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate
303
        static  s8* logfilename = NULL;                                         // the pointer to the logfilename
303
        static  s8* logfilename = NULL;                                         // the pointer to the logfilename
304
        static  u32 logtimer = 0, flushtimer = 0, appendtimer = 0;              // the log update timer
304
        static  u32 logtimer = 0, flushtimer = 0, appendtimer = 0;              // the log update timer
305
        static  GPX_Document_t logfile;                                         // the logfilehandle
305
        static  GPX_Document_t logfile;                                         // the logfilehandle
306
        static  u8 part = 0, old_errorcode = 0;
306
        static  u8 part = 0, old_errorcode = 0;
307
//      u32 measure_time;
307
//      u32 measure_time;
308
 
308
 
309
        // initialize if LogDelay is zero
309
        // initialize if LogDelay is zero
310
        if(!LogDelay)
310
        if(!LogDelay)
311
        {
311
        {
312
                switch(logfilestate)
312
                switch(logfilestate)
313
                {
313
                {
314
                        case LOGFILE_OPENED:
314
                        case LOGFILE_OPENED:
315
                                GPX_DocumentClose(&logfile); // try to close it
315
                                GPX_DocumentClose(&logfile); // try to close it
316
                                break;
316
                                break;
317
                        default:
317
                        default:
318
                                break;
318
                                break;
319
                }
319
                }
320
                logfilestate = LOGFILE_IDLE;
320
                logfilestate = LOGFILE_IDLE;
321
                logfilename = NULL;
321
                logfilename = NULL;
322
                GPX_DocumentInit(&logfile);
322
                GPX_DocumentInit(&logfile);
323
                logtimer = SetDelay(0); // set logtimer to now
323
                logtimer = SetDelay(0); // set logtimer to now
324
                return logfilestate;
324
                return logfilestate;
325
        }
325
        }
326
        // no init
326
        // no init
327
        if(CheckDelay(logtimer) || part)
327
        if(CheckDelay(logtimer) || part)
328
        {
328
        {
329
                if(!part) logtimer = SetDelay(LogDelay);        // standard interval
329
                if(!part) logtimer = SetDelay(LogDelay);        // standard interval
330
 
330
 
331
                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN)
331
                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN)
332
                 {
332
                 {
333
                  if(!GPX_logging_active) GPX_logging_active = 1;
333
                  if(!GPX_logging_active) GPX_logging_active = 1;
334
                  appendtimer = SetDelay(APPEND_LOG_TIME_MS);
334
                  appendtimer = SetDelay(APPEND_LOG_TIME_MS);
335
                 }
335
                 }
336
                else
336
                else
337
                 {
337
                 {
338
                  if(CheckDelay(appendtimer)) GPX_logging_active = 0;
338
                  if(CheckDelay(appendtimer)) GPX_logging_active = 0;
339
                 }
339
                 }
340
 
340
 
341
                if(GPX_logging_active || part)
341
                if(GPX_logging_active || part)
342
                {
342
                {
343
                        switch(logfilestate)
343
                        switch(logfilestate)
344
                        {
344
                        {
345
                                case LOGFILE_IDLE:
345
                                case LOGFILE_IDLE:
346
                                case LOGFILE_CLOSED:
346
                                case LOGFILE_CLOSED:
347
                                        if((GPSData.Status != INVALID) && (SystemTime.Valid) &&
347
                                        if((GPSData.Status != INVALID) && (SystemTime.Valid) &&
348
                                        ((FC.StatusFlags & FC_STATUS_FLY) || (LogCfg.StartAtMotorrun && (FC.StatusFlags & FC_STATUS_MOTOR_RUN))))
348
                                        ((FC.StatusFlags & FC_STATUS_FLY) || (LogCfg.StartAtMotorrun && (FC.StatusFlags & FC_STATUS_MOTOR_RUN))))
349
                                        {
349
                                        {
350
                                                logfilestate = LOGFILE_START;
350
                                                logfilestate = LOGFILE_START;
351
                                        }
351
                                        }
352
                                        part = 0;
352
                                        part = 0;
353
                                        break;
353
                                        break;
354
                                case LOGFILE_START:
354
                                case LOGFILE_START:
355
                                        // find unused logfile name
355
                                        // find unused logfile name
356
                                        do
356
                                        do
357
                                        {        // try to generate a new logfile name
357
                                        {        // try to generate a new logfile name
358
                                                 logfilename = GenerateGPXLogFileName();
358
                                                 logfilename = GenerateGPXLogFileName();
359
                                        }while((logfilename != NULL) && fexist_(logfilename));
359
                                        }while((logfilename != NULL) && fexist_(logfilename));
360
                                        // if logfilename exist
360
                                        // if logfilename exist
361
                                        if(logfilename != NULL)
361
                                        if(logfilename != NULL)
362
                                        {
362
                                        {
363
                                                // try to create the log file
363
                                                // try to create the log file
364
                                                if(GPX_DocumentOpen(logfilename, &logfile))
364
                                                if(GPX_DocumentOpen(logfilename, &logfile))
365
                                                {
365
                                                {
366
                                                        flushtimer = SetDelay(LOG_FLUSH_INTERVAL);
366
                                                        flushtimer = SetDelay(LOG_FLUSH_INTERVAL);
367
                                                        logfilestate = LOGFILE_OPENED; // goto next step
367
                                                        logfilestate = LOGFILE_OPENED; // goto next step
368
                                                        UART1_PutString("\r\nOpening gpx-file:");
368
                                                        UART1_PutString("\r\nOpening gpx-file:");
369
                                                        UART1_PutString(logfilename);
369
                                                        UART1_PutString(logfilename);
370
                                                        UART1_PutString("\r\n");
370
                                                        UART1_PutString("\r\n");
371
                                                        GPX_logging_active = 2;
371
                                                        GPX_logging_active = 2;
372
                                                }
372
                                                }
373
                                                else // could not be openend
373
                                                else // could not be openend
374
                                                {
374
                                                {
375
                                                        logfilestate = LOGFILE_ERROR;
375
                                                        logfilestate = LOGFILE_ERROR;
376
                                                        UART1_PutString("\r\nError opening gpx-file: ");
376
                                                        UART1_PutString("\r\nError opening gpx-file: ");
377
                                                        UART1_PutString(logfilename);
377
                                                        UART1_PutString(logfilename);
378
                                                        UART1_PutString("\r\n");
378
                                                        UART1_PutString("\r\n");
379
                                                        SD_LoggingError = 11;
379
                                                        SD_LoggingError = 11;
380
                                                        logtimer = SetDelay(10);  // try again in open logfile in 10 mili sec
380
                                                        logtimer = SetDelay(10);  // try again in open logfile in 10 mili sec
381
                                                }
381
                                                }
382
                                                old_errorcode = ErrorCode;
382
                                                old_errorcode = ErrorCode;
383
                                        }
383
                                        }
384
                                        else
384
                                        else
385
                                        {
385
                                        {
386
                                                logfilestate = LOGFILE_ERROR;
386
                                                logfilestate = LOGFILE_ERROR;
387
                                                UART1_PutString("\r\nError getting free gpx-file name\r\n");
387
                                                UART1_PutString("\r\nError getting free gpx-file name\r\n");
388
                                                SD_LoggingError = 12;
388
                                                SD_LoggingError = 12;
389
                                        }
389
                                        }
390
                                        // else retry in next loop
390
                                        // else retry in next loop
391
                                        part = 0;
391
                                        part = 0;
392
                                        break;
392
                                        break;
393
                                case LOGFILE_OPENED:
393
                                case LOGFILE_OPENED:
394
                                        // append new gps log data
394
                                        // append new gps log data
395
//                                      measure_time = CountMilliseconds;
395
//                                      measure_time = CountMilliseconds;
396
                                        if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))
396
//                                      if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))
397
                                        {
397
                                        {
398
                                                if(!GPX_LoggGPSCoordinates(&logfile,part))
398
                                                if(!GPX_LoggGPSCoordinates(&logfile,part))
399
                                                {       // error logging data
399
                                                {       // error logging data
400
                                                        UART1_PutString("\r\nError logging to gpx-file\r\n");
400
                                                        UART1_PutString("\r\nError logging to gpx-file\r\n");
401
                                                        GPX_DocumentClose(&logfile);
401
                                                        GPX_DocumentClose(&logfile);
402
                                                        SD_LoggingError = 13;
402
                                                        SD_LoggingError = 13;
403
                                                        logfilestate = LOGFILE_ERROR;
403
                                                        logfilestate = LOGFILE_ERROR;
404
                                                }
404
                                                }
405
                                                else // successful log
405
                                                else // successful log
406
                                                {
406
                                                {
407
                                                        if(ErrorCode != old_errorcode || CheckDelay(flushtimer) || part == 8)
407
                                                        if(ErrorCode != old_errorcode || CheckDelay(flushtimer) || part == 8)
408
                                                        {
408
                                                        {
409
                                                                if(ErrorCode) { while(++part < 9) GPX_LoggGPSCoordinates(&logfile,part); }; // close this chapter 
409
                                                                if(ErrorCode) { while(++part < 9) GPX_LoggGPSCoordinates(&logfile,part); }; // close this chapter 
410
                                                                if(ErrorCode != old_errorcode) flushtimer = SetDelay(1000);
410
                                                                if(ErrorCode != old_errorcode) flushtimer = SetDelay(1000);
411
                                                                else flushtimer = SetDelay(LOG_FLUSH_INTERVAL);
411
                                                                else flushtimer = SetDelay(LOG_FLUSH_INTERVAL);
412
                                                                fflush_(logfile.file);
412
                                                                fflush_(logfile.file);
413
                                                                old_errorcode = ErrorCode;
413
                                                                old_errorcode = ErrorCode;
414
                                                        }
414
                                                        }
415
                                                }
415
                                                }
416
                                        }
416
                                        }
417
                                        if(++part >= 9) part = 0;
417
                                        if(++part >= 9) part = 0;
418
//DebugOut.Analog[] = CountMilliseconds - measure_time;
418
//DebugOut.Analog[] = CountMilliseconds - measure_time;
419
                                        break;
419
                                        break;
420
 
420
 
421
                                case LOGFILE_ERROR:
421
                                case LOGFILE_ERROR:
422
                                        part = 0;
422
                                        part = 0;
423
                                        break;
423
                                        break;
424
 
424
 
425
                                default:
425
                                default:
426
                                        part = 0;
426
                                        part = 0;
427
                                        logfilestate = LOGFILE_IDLE;
427
                                        logfilestate = LOGFILE_IDLE;
428
                                        break;
428
                                        break;
429
                        }
429
                        }
430
                } // EOF model is flying
430
                } // EOF model is flying
431
                else // model is not flying
431
                else // model is not flying
432
                {   // close log file if opened
432
                {   // close log file if opened
433
                        if(logfilestate == LOGFILE_OPENED)
433
                        if(logfilestate == LOGFILE_OPENED)
434
                        {
434
                        {
435
                                if(GPX_DocumentClose(&logfile))
435
                                if(GPX_DocumentClose(&logfile))
436
                                {
436
                                {
437
                                        UART1_PutString("\r\nClosing gpx-file\r\n");
437
                                        UART1_PutString("\r\nClosing gpx-file\r\n");
438
                                        logfilestate = LOGFILE_CLOSED;
438
                                        logfilestate = LOGFILE_CLOSED;
439
                                        part = 0;
439
                                        part = 0;
440
                                }
440
                                }
441
                                else  // could not be closed
441
                                else  // could not be closed
442
                                {
442
                                {
443
                                        UART1_PutString("\r\nError closing gpx-file\r\n");
443
                                        UART1_PutString("\r\nError closing gpx-file\r\n");
444
                                        SD_LoggingError = 14;
444
                                        SD_LoggingError = 14;
445
                                        logfilestate =  LOGFILE_ERROR;
445
                                        logfilestate =  LOGFILE_ERROR;
446
                                        part = 0;
446
                                        part = 0;
447
                                }
447
                                }
448
                        }
448
                        }
449
                } //EOF model is not flying
449
                } //EOF model is not flying
450
        } // EOF Check LogTimer
450
        } // EOF Check LogTimer
451
 
451
 
452
        return logfilestate;
452
        return logfilestate;
453
}
453
}
454
 
454
 
455
//----------------------------------------------------------------------------------------------------
455
//----------------------------------------------------------------------------------------------------
456
// initialize logging
456
// initialize logging
457
void Logging_Init(void)
457
void Logging_Init(void)
458
{
458
{
459
        SD_LoggingError = 0;
459
        SD_LoggingError = 0;
460
        LogCfg.KML_Interval = 1000; //default
460
        LogCfg.KML_Interval = 1000; //default
461
        Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value
461
        Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value
462
        if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < MIN_SD_INTERVAL_KML) LogCfg.KML_Interval = MIN_SD_INTERVAL_KML;
462
        if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < MIN_SD_INTERVAL_KML) LogCfg.KML_Interval = MIN_SD_INTERVAL_KML;
463
 
463
 
464
        Logging_KML(0); // initialize
464
        Logging_KML(0); // initialize
465
        LogCfg.GPX_Interval = 0; //default
465
        LogCfg.GPX_Interval = 0; //default
466
        Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value
466
        Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value
467
        Settings_GetParamValue(PID_LOG_AT_MOTORRUN, (u16*)&LogCfg.StartAtMotorrun); // overwrite by settings value
467
        Settings_GetParamValue(PID_LOG_AT_MOTORRUN, (u16*)&LogCfg.StartAtMotorrun); // overwrite by settings value
468
        if(LogCfg.GPX_Interval != 0 && LogCfg.GPX_Interval < MIN_SD_INTERVAL_GPX) LogCfg.GPX_Interval = MIN_SD_INTERVAL_GPX;
468
        if(LogCfg.GPX_Interval != 0 && LogCfg.GPX_Interval < MIN_SD_INTERVAL_GPX) LogCfg.GPX_Interval = MIN_SD_INTERVAL_GPX;
469
        Logging_GPX(0); // initialize
469
        Logging_GPX(0); // initialize
470
}
470
}
471
 
471
 
472
//----------------------------------------------------------------------------------------------------
472
//----------------------------------------------------------------------------------------------------
473
// gobal logging handler
473
// gobal logging handler
474
void Logging_Update(void)
474
void Logging_Update(void)
475
{
475
{
476
        static u8 logmodule = 0;
476
        static u8 logmodule = 0;
477
        static u32 logtimer = 0;
477
        static u32 logtimer = 0;
478
        static logfilestate_t logstate = LOGFILE_IDLE;
478
        static logfilestate_t logstate = LOGFILE_IDLE;
479
 
479
 
480
        if(SD_SWITCH) // a card is in slot
480
        if(SD_SWITCH) // a card is in slot
481
        {
481
        {
482
        if((logstate == LOGFILE_ERROR) && (FC.StatusFlags & FC_STATUS_START)) SD_LoggingError = 100;
482
        if((logstate == LOGFILE_ERROR) && (FC.StatusFlags & FC_STATUS_START)) SD_LoggingError = 100;
483
                if(CheckDelay(logtimer))
483
                if(CheckDelay(logtimer))
484
                {
484
                {
485
                        logtimer = SetDelay(10);  // faster makes no sense
485
                        logtimer = SetDelay(10);  // faster makes no sense
486
                        // call the logger handlers if no error has occured
486
                        // call the logger handlers if no error has occured
487
                        if(logstate != LOGFILE_ERROR)
487
                        if(logstate != LOGFILE_ERROR)
488
                        {  // run only one logging handler per loop
488
                        {  // run only one logging handler per loop
489
                                switch(logmodule++)
489
                                switch(logmodule++)
490
                                {
490
                                {
491
                                        case 0:
491
                                        case 0:
492
                                                logstate = Logging_KML(LogCfg.KML_Interval);
492
                                                logstate = Logging_KML(LogCfg.KML_Interval);
493
                                                break;
493
                                                break;
494
                                        case 1:
494
                                        case 1:
495
                                                logstate = Logging_GPX(LogCfg.GPX_Interval);
495
                                                logstate = Logging_GPX(LogCfg.GPX_Interval);
496
                                                break;
496
                                                break;
497
                                        case 2:
497
                                        case 2:
498
                                            if(UART_VersionInfo.HWMajor >= 30) logstate = LoggingTrigger(200);
498
                                            if(UART_VersionInfo.HWMajor >= 30) logstate = LoggingTrigger(200);
499
                                                logmodule = 0; // resart with first log module
499
                                                logmodule = 0; // resart with first log module
500
                                                break;
500
                                                break;
501
                                        default:
501
                                        default:
502
                                                logmodule = 0;
502
                                                logmodule = 0;
503
                                                break;
503
                                                break;
504
                                }
504
                                }
505
                        }
505
                        }
506
                        else // a logging error has occured
506
                        else // a logging error has occured
507
                        {
507
                        {
508
//                              /*
508
//                              /*
509
                                // try to reinitialize sd-card when motors are not running
509
                                // try to reinitialize sd-card when motors are not running
510
                                if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN))
510
                                if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN))
511
                                {
511
                                {
512
                                        if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside
512
                                        if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside
513
                                        {
513
                                        {
514
                                                Logging_Init(); // initialize the logs
514
                                                Logging_Init(); // initialize the logs
515
                                                logstate = LOGFILE_IDLE;
515
                                                logstate = LOGFILE_IDLE;
516
                                                logtimer = SetDelay(100);       // try next log in 100 mili sec
516
                                                logtimer = SetDelay(100);       // try next log in 100 mili sec
517
                                        }
517
                                        }
518
                                        else
518
                                        else
519
                                        {   // retry in 5 seconds
519
                                        {   // retry in 5 seconds
520
                                                logtimer = SetDelay(5000);  // try again in 5 sec
520
                                                logtimer = SetDelay(5000);  // try again in 5 sec
521
                                        }
521
                                        }
522
                                } // EOF motors are not running
522
                                } // EOF motors are not running
523
//                              */
523
//                              */
524
                        } //EOF logfile error
524
                        } //EOF logfile error
525
                }  // EOF CheckDelay
525
                }  // EOF CheckDelay
526
        }// EOF Card in Slot
526
        }// EOF Card in Slot
527
}
527
}
528
 
528