Rev 516 | Rev 536 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 516 | Rev 530 | ||
---|---|---|---|
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 | 67 | ||
68 | #define MIN_SD_INTERVAL_KML 200 |
68 | #define MIN_SD_INTERVAL_KML 200 |
69 | #define MIN_SD_INTERVAL_GPX 200 |
69 | #define MIN_SD_INTERVAL_GPX 200 |
70 | #define APPEND_LOG_TIME_MS 2510 // log some more time |
70 | #define APPEND_LOG_TIME_MS 2510 // log some more time |
71 | 71 | ||
72 | u8 SD_LoggingError = 0; |
72 | u8 SD_LoggingError = 0; |
73 | 73 | ||
74 | #define LOG_FLUSH_INTERVAL 4000 // 4s // -> and if an Error occures |
74 | #define LOG_FLUSH_INTERVAL 4000 // 4s // -> and if an Error occures |
75 | 75 | ||
76 | typedef enum |
76 | typedef enum |
77 | { |
77 | { |
78 | LOGFILE_IDLE, |
78 | LOGFILE_IDLE, |
79 | LOGFILE_START, |
79 | LOGFILE_START, |
80 | LOGFILE_CLOSED, |
80 | LOGFILE_CLOSED, |
81 | LOGFILE_OPENED, |
81 | LOGFILE_OPENED, |
82 | LOGFILE_ERROR |
82 | LOGFILE_ERROR |
83 | } logfilestate_t; |
83 | } logfilestate_t; |
84 | 84 | ||
85 | // logger handler prototypes |
85 | // logger handler prototypes |
86 | logfilestate_t Logging_KML(u32 LogDelay); |
86 | logfilestate_t Logging_KML(u32 LogDelay); |
87 | logfilestate_t Logging_GPX(u32 LogDelay); |
87 | logfilestate_t Logging_GPX(u32 LogDelay); |
88 | 88 | ||
89 | LogCfg_t LogCfg = {500 , 1000}; |
89 | LogCfg_t LogCfg = {500 , 1000}; |
90 | u32 Logged_GPX_Counter = 0, Logged_KML_Counter = 0; |
90 | u32 Logged_GPX_Counter = 0, Logged_KML_Counter = 0; |
91 | u16 KML_Filenum = 0; |
91 | u16 KML_Filenum = 0; |
92 | 92 | ||
93 | //---------------------------------------------------------------------------------------------------- |
93 | //---------------------------------------------------------------------------------------------------- |
94 | s8* GenerateKMLLogFileName(void) |
94 | s8* GenerateKMLLogFileName(void) |
95 | { |
95 | { |
96 | static u16 filenum = 0; // file name counter |
96 | static u16 filenum = 0; // file name counter |
97 | static s8 filename[35]; |
97 | static s8 filename[35]; |
98 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
98 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
99 | 99 | ||
100 | if(SystemTime.Valid) |
100 | if(SystemTime.Valid) |
101 | { |
101 | { |
102 | // if the day has been changed |
102 | // if the day has been changed |
103 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
103 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
104 | { |
104 | { |
105 | LastTime.Year = SystemTime.Year; |
105 | LastTime.Year = SystemTime.Year; |
106 | LastTime.Month = SystemTime.Month; |
106 | LastTime.Month = SystemTime.Month; |
107 | LastTime.Day = SystemTime.Day; |
107 | LastTime.Day = SystemTime.Day; |
108 | LastTime.Valid = 1; |
108 | LastTime.Valid = 1; |
109 | filenum = 0; // reset file counter |
109 | filenum = 0; // reset file counter |
110 | } |
110 | } |
111 | 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); |
111 | 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); |
112 | else sprintf(filename, "/LOG/%04i%02i%02i/KML/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
112 | else sprintf(filename, "/LOG/%04i%02i%02i/KML/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
113 | filenum++; |
113 | filenum++; |
114 | KML_Filenum = filenum; |
114 | KML_Filenum = filenum; |
115 | return filename; |
115 | return filename; |
116 | } |
116 | } |
117 | else return NULL; |
117 | else return NULL; |
118 | } |
118 | } |
119 | 119 | ||
120 | //---------------------------------------------------------------------------------------------------- |
120 | //---------------------------------------------------------------------------------------------------- |
121 | s8* GenerateGPXLogFileName(void) |
121 | s8* GenerateGPXLogFileName(void) |
122 | { |
122 | { |
123 | static u16 filenum = 0; // file name counter |
123 | static u16 filenum = 0; // file name counter |
124 | static s8 filename[35]; |
124 | static s8 filename[35]; |
125 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
125 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
126 | 126 | ||
127 | if(SystemTime.Valid) |
127 | if(SystemTime.Valid) |
128 | { |
128 | { |
129 | // if the day has been changed |
129 | // if the day has been changed |
130 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
130 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
131 | { |
131 | { |
132 | LastTime.Year = SystemTime.Year; |
132 | LastTime.Year = SystemTime.Year; |
133 | LastTime.Month = SystemTime.Month; |
133 | LastTime.Month = SystemTime.Month; |
134 | LastTime.Day = SystemTime.Day; |
134 | LastTime.Day = SystemTime.Day; |
135 | LastTime.Valid = 1; |
135 | LastTime.Valid = 1; |
136 | filenum = 0; // reset file counter |
136 | filenum = 0; // reset file counter |
137 | } |
137 | } |
138 | 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); |
138 | 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); |
139 | else sprintf(filename, "/LOG/%04i%02i%02i/GPX/GPS%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
139 | else sprintf(filename, "/LOG/%04i%02i%02i/GPX/GPS%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
140 | filenum++; |
140 | filenum++; |
141 | KML_Filenum = filenum; |
141 | KML_Filenum = filenum; |
142 | return filename; |
142 | return filename; |
143 | } |
143 | } |
144 | else return NULL; |
144 | else return NULL; |
145 | } |
145 | } |
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | //---------------------------------------------------------------------------------------------------- |
149 | //---------------------------------------------------------------------------------------------------- |
150 | // logs the current gps position to a kml file |
150 | // logs the current gps position to a kml file |
151 | logfilestate_t Logging_KML(u32 LogDelay) |
151 | logfilestate_t Logging_KML(u32 LogDelay) |
152 | { |
152 | { |
153 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
153 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
154 | static s8* logfilename = NULL; // the pointer to the logfilename |
154 | static s8* logfilename = NULL; // the pointer to the logfilename |
155 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
155 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
156 | static KML_Document_t logfile; // the logfilehandle |
156 | static KML_Document_t logfile; // the logfilehandle |
157 | static u32 appendtimer = 0; // the log update timer |
157 | static u32 appendtimer = 0; // the log update timer |
158 | static u8 logging_active = 0; |
158 | static u8 logging_active = 0; |
159 | 159 | ||
160 | // initialize if LogDelay is zero |
160 | // initialize if LogDelay is zero |
161 | if(!LogDelay) |
161 | if(!LogDelay) |
162 | { |
162 | { |
163 | switch(logfilestate) |
163 | switch(logfilestate) |
164 | { |
164 | { |
165 | case LOGFILE_OPENED: |
165 | case LOGFILE_OPENED: |
166 | KML_DocumentClose(&logfile); // try to close it |
166 | KML_DocumentClose(&logfile); // try to close it |
167 | break; |
167 | break; |
168 | default: |
168 | default: |
169 | break; |
169 | break; |
170 | } |
170 | } |
171 | logfilestate = LOGFILE_IDLE; |
171 | logfilestate = LOGFILE_IDLE; |
172 | logfilename = NULL; |
172 | logfilename = NULL; |
173 | KML_DocumentInit(&logfile); |
173 | KML_DocumentInit(&logfile); |
174 | logtimer = SetDelay(0); // set logtimer to now |
174 | logtimer = SetDelay(0); // set logtimer to now |
175 | return logfilestate; |
175 | return logfilestate; |
176 | } |
176 | } |
177 | // no init |
177 | // no init |
178 | if(CheckDelay(logtimer)) |
178 | if(CheckDelay(logtimer)) |
179 | { |
179 | { |
180 | logtimer = SetDelay(LogDelay); // standard interval |
180 | logtimer = SetDelay(LogDelay); // standard interval |
181 | 181 | ||
182 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
182 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
183 | { |
183 | { |
184 | logging_active = 1; |
184 | logging_active = 1; |
185 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
185 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
186 | } |
186 | } |
187 | else |
187 | else |
188 | { |
188 | { |
189 | if(CheckDelay(appendtimer)) logging_active = 0; |
189 | if(CheckDelay(appendtimer)) logging_active = 0; |
190 | } |
190 | } |
191 | 191 | ||
192 | if(logging_active) |
192 | if(logging_active) |
193 | { |
193 | { |
194 | switch(logfilestate) |
194 | switch(logfilestate) |
195 | { |
195 | { |
196 | case LOGFILE_IDLE: |
196 | case LOGFILE_IDLE: |
197 | case LOGFILE_CLOSED: |
197 | case LOGFILE_CLOSED: |
198 | if((GPSData.Status != INVALID) && (SystemTime.Valid) && /*(GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)*/ (FC.StatusFlags & FC_STATUS_FLY)) |
198 | if((GPSData.Status != INVALID) && (SystemTime.Valid) && /*(GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)*/ (FC.StatusFlags & FC_STATUS_FLY)) |
199 | { |
199 | { |
200 | logfilestate = LOGFILE_START; |
200 | logfilestate = LOGFILE_START; |
201 | } |
201 | } |
202 | break; |
202 | break; |
203 | case LOGFILE_START: |
203 | case LOGFILE_START: |
204 | // find unused logfile name |
204 | // find unused logfile name |
205 | do |
205 | do |
206 | { // try to generate a new logfile name |
206 | { // try to generate a new logfile name |
207 | logfilename = GenerateKMLLogFileName(); |
207 | logfilename = GenerateKMLLogFileName(); |
208 | }while((logfilename != NULL) && fexist_(logfilename)); |
208 | }while((logfilename != NULL) && fexist_(logfilename)); |
209 | // if logfilename exist |
209 | // if logfilename exist |
210 | if(logfilename != NULL) |
210 | if(logfilename != NULL) |
211 | { |
211 | { |
212 | // try to create the log file |
212 | // try to create the log file |
213 | if(KML_DocumentOpen(logfilename, &logfile)) |
213 | if(KML_DocumentOpen(logfilename, &logfile)) |
214 | { |
214 | { |
215 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
215 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
216 | logfilestate = LOGFILE_OPENED; // goto next step |
216 | logfilestate = LOGFILE_OPENED; // goto next step |
217 | UART1_PutString("\r\nOpening kml-file:"); |
217 | UART1_PutString("\r\nOpening kml-file:"); |
218 | UART1_PutString(logfilename); |
218 | UART1_PutString(logfilename); |
219 | UART1_PutString("\r\n"); |
219 | UART1_PutString("\r\n"); |
220 | } |
220 | } |
221 | else // could not be openend |
221 | else // could not be openend |
222 | { |
222 | { |
223 | logfilestate = LOGFILE_ERROR; |
223 | logfilestate = LOGFILE_ERROR; |
224 | UART1_PutString("\r\nError opening kml-file: "); |
224 | UART1_PutString("\r\nError opening kml-file: "); |
225 | UART1_PutString(logfilename); |
225 | UART1_PutString(logfilename); |
226 | UART1_PutString("\r\n"); |
226 | UART1_PutString("\r\n"); |
227 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
227 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
228 | SD_LoggingError = 1; |
228 | SD_LoggingError = 1; |
229 | } |
229 | } |
230 | } |
230 | } |
231 | else |
231 | else |
232 | { |
232 | { |
233 | logfilestate = LOGFILE_ERROR; |
233 | logfilestate = LOGFILE_ERROR; |
234 | UART1_PutString("\r\nError getting free kml-file name\r\n"); |
234 | UART1_PutString("\r\nError getting free kml-file name\r\n"); |
235 | SD_LoggingError = 2; |
235 | SD_LoggingError = 2; |
236 | } |
236 | } |
237 | // else retry in next loop |
237 | // else retry in next loop |
238 | break; |
238 | break; |
239 | case LOGFILE_OPENED: |
239 | case LOGFILE_OPENED: |
240 | // append new gps log data |
240 | // append new gps log data |
241 | if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
241 | if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
242 | { |
242 | { |
243 | if(!KML_LoggGPSCoordinates(&logfile)) |
243 | if(!KML_LoggGPSCoordinates(&logfile)) |
244 | { // error logging data |
244 | { // error logging data |
245 | UART1_PutString("\r\nError logging to kml-file\r\n"); |
245 | UART1_PutString("\r\nError logging to kml-file\r\n"); |
246 | SD_LoggingError = 3; |
246 | SD_LoggingError = 3; |
247 | KML_DocumentClose(&logfile); |
247 | KML_DocumentClose(&logfile); |
248 | logfilestate = LOGFILE_ERROR; |
248 | logfilestate = LOGFILE_ERROR; |
249 | } |
249 | } |
250 | else // sucessfully logged |
250 | else // sucessfully logged |
251 | { |
251 | { |
252 | SD_LoggingError = 0; |
252 | SD_LoggingError = 0; |
253 | if(CheckDelay(flushtimer)) |
253 | if(CheckDelay(flushtimer)) |
254 | { |
254 | { |
255 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
255 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
256 | fflush_(logfile.file); |
256 | fflush_(logfile.file); |
257 | } |
257 | } |
258 | } |
258 | } |
259 | 259 | ||
260 | } |
260 | } |
261 | break; |
261 | break; |
262 | 262 | ||
263 | case LOGFILE_ERROR: |
263 | case LOGFILE_ERROR: |
264 | break; |
264 | break; |
265 | 265 | ||
266 | default: |
266 | default: |
267 | logfilestate = LOGFILE_IDLE; |
267 | logfilestate = LOGFILE_IDLE; |
268 | break; |
268 | break; |
269 | } |
269 | } |
270 | } // EOF motors are not running |
270 | } // EOF motors are not running |
271 | else // model is not flying |
271 | else // model is not flying |
272 | { // close log file if opened |
272 | { // close log file if opened |
273 | if(logfilestate == LOGFILE_OPENED) |
273 | if(logfilestate == LOGFILE_OPENED) |
274 | { |
274 | { |
275 | if(KML_DocumentClose(&logfile)) |
275 | if(KML_DocumentClose(&logfile)) |
276 | { |
276 | { |
277 | UART1_PutString("\r\nClosing kml-file\r\n"); |
277 | UART1_PutString("\r\nClosing kml-file\r\n"); |
278 | logfilestate = LOGFILE_CLOSED; |
278 | logfilestate = LOGFILE_CLOSED; |
279 | } |
279 | } |
280 | else // could not be closed |
280 | else // could not be closed |
281 | { |
281 | { |
282 | UART1_PutString("\r\nError closing kml-file\r\n"); |
282 | UART1_PutString("\r\nError closing kml-file\r\n"); |
283 | SD_LoggingError = 4; |
283 | SD_LoggingError = 4; |
284 | logfilestate = LOGFILE_ERROR; |
284 | logfilestate = LOGFILE_ERROR; |
285 | } |
285 | } |
286 | } |
286 | } |
287 | } //EOF motors are not running |
287 | } //EOF motors are not running |
288 | } // EOF Check LogTimer |
288 | } // EOF Check LogTimer |
289 | 289 | ||
290 | return logfilestate; |
290 | return logfilestate; |
291 | } |
291 | } |
292 | 292 | ||
293 | //---------------------------------------------------------------------------------------------------- |
293 | //---------------------------------------------------------------------------------------------------- |
294 | // logs gps and state info to a gpx file |
294 | // logs gps and state info to a gpx file |
295 | logfilestate_t Logging_GPX(u32 LogDelay) |
295 | logfilestate_t Logging_GPX(u32 LogDelay) |
296 | { |
296 | { |
297 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
297 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
298 | static s8* logfilename = NULL; // the pointer to the logfilename |
298 | static s8* logfilename = NULL; // the pointer to the logfilename |
299 | static u32 logtimer = 0, flushtimer = 0, appendtimer = 0; // the log update timer |
299 | static u32 logtimer = 0, flushtimer = 0, appendtimer = 0; // the log update timer |
300 | static GPX_Document_t logfile; // the logfilehandle |
300 | static GPX_Document_t logfile; // the logfilehandle |
301 | static u8 part = 0, logging_active = 0, old_errorcode = 0; |
301 | static u8 part = 0, logging_active = 0, old_errorcode = 0; |
302 | u32 measure_time; |
302 | u32 measure_time; |
303 | 303 | ||
304 | // initialize if LogDelay is zero |
304 | // initialize if LogDelay is zero |
305 | if(!LogDelay) |
305 | if(!LogDelay) |
306 | { |
306 | { |
307 | switch(logfilestate) |
307 | switch(logfilestate) |
308 | { |
308 | { |
309 | case LOGFILE_OPENED: |
309 | case LOGFILE_OPENED: |
310 | GPX_DocumentClose(&logfile); // try to close it |
310 | GPX_DocumentClose(&logfile); // try to close it |
311 | break; |
311 | break; |
312 | default: |
312 | default: |
313 | break; |
313 | break; |
314 | } |
314 | } |
315 | logfilestate = LOGFILE_IDLE; |
315 | logfilestate = LOGFILE_IDLE; |
316 | logfilename = NULL; |
316 | logfilename = NULL; |
317 | GPX_DocumentInit(&logfile); |
317 | GPX_DocumentInit(&logfile); |
318 | logtimer = SetDelay(0); // set logtimer to now |
318 | logtimer = SetDelay(0); // set logtimer to now |
319 | return logfilestate; |
319 | return logfilestate; |
320 | } |
320 | } |
321 | // no init |
321 | // no init |
322 | if(CheckDelay(logtimer) || part) |
322 | if(CheckDelay(logtimer) || part) |
323 | { |
323 | { |
324 | if(!part) logtimer = SetDelay(LogDelay); // standard interval |
324 | if(!part) logtimer = SetDelay(LogDelay); // standard interval |
325 | 325 | ||
326 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
326 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
327 | { |
327 | { |
328 | logging_active = 1; |
328 | logging_active = 1; |
329 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
329 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
330 | } |
330 | } |
331 | else |
331 | else |
332 | { |
332 | { |
333 | if(CheckDelay(appendtimer)) logging_active = 0; |
333 | if(CheckDelay(appendtimer)) logging_active = 0; |
334 | } |
334 | } |
335 | 335 | ||
336 | if(logging_active || part) |
336 | if(logging_active || part) |
337 | { |
337 | { |
338 | switch(logfilestate) |
338 | switch(logfilestate) |
339 | { |
339 | { |
340 | case LOGFILE_IDLE: |
340 | case LOGFILE_IDLE: |
341 | case LOGFILE_CLOSED: |
341 | case LOGFILE_CLOSED: |
342 | if((GPSData.Status != INVALID) && (SystemTime.Valid) && /*(GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)*/ (FC.StatusFlags & FC_STATUS_FLY)) |
342 | if((GPSData.Status != INVALID) && (SystemTime.Valid) && /*(GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)*/ (FC.StatusFlags & FC_STATUS_FLY)) |
343 | { |
343 | { |
344 | logfilestate = LOGFILE_START; |
344 | logfilestate = LOGFILE_START; |
345 | } |
345 | } |
346 | part = 0; |
346 | part = 0; |
347 | break; |
347 | break; |
348 | case LOGFILE_START: |
348 | case LOGFILE_START: |
349 | // find unused logfile name |
349 | // find unused logfile name |
350 | do |
350 | do |
351 | { // try to generate a new logfile name |
351 | { // try to generate a new logfile name |
352 | logfilename = GenerateGPXLogFileName(); |
352 | logfilename = GenerateGPXLogFileName(); |
353 | }while((logfilename != NULL) && fexist_(logfilename)); |
353 | }while((logfilename != NULL) && fexist_(logfilename)); |
354 | // if logfilename exist |
354 | // if logfilename exist |
355 | if(logfilename != NULL) |
355 | if(logfilename != NULL) |
356 | { |
356 | { |
357 | // try to create the log file |
357 | // try to create the log file |
358 | if(GPX_DocumentOpen(logfilename, &logfile)) |
358 | if(GPX_DocumentOpen(logfilename, &logfile)) |
359 | { |
359 | { |
360 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
360 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
361 | logfilestate = LOGFILE_OPENED; // goto next step |
361 | logfilestate = LOGFILE_OPENED; // goto next step |
362 | UART1_PutString("\r\nOpening gpx-file:"); |
362 | UART1_PutString("\r\nOpening gpx-file:"); |
363 | UART1_PutString(logfilename); |
363 | UART1_PutString(logfilename); |
364 | UART1_PutString("\r\n"); |
364 | UART1_PutString("\r\n"); |
365 | } |
365 | } |
366 | else // could not be openend |
366 | else // could not be openend |
367 | { |
367 | { |
368 | logfilestate = LOGFILE_ERROR; |
368 | logfilestate = LOGFILE_ERROR; |
369 | UART1_PutString("\r\nError opening gpx-file: "); |
369 | UART1_PutString("\r\nError opening gpx-file: "); |
370 | UART1_PutString(logfilename); |
370 | UART1_PutString(logfilename); |
371 | UART1_PutString("\r\n"); |
371 | UART1_PutString("\r\n"); |
372 | SD_LoggingError = 11; |
372 | SD_LoggingError = 11; |
373 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
373 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
374 | } |
374 | } |
375 | old_errorcode = ErrorCode; |
375 | old_errorcode = ErrorCode; |
376 | } |
376 | } |
377 | else |
377 | else |
378 | { |
378 | { |
379 | logfilestate = LOGFILE_ERROR; |
379 | logfilestate = LOGFILE_ERROR; |
380 | UART1_PutString("\r\nError getting free gpx-file name\r\n"); |
380 | UART1_PutString("\r\nError getting free gpx-file name\r\n"); |
381 | SD_LoggingError = 12; |
381 | SD_LoggingError = 12; |
382 | } |
382 | } |
383 | // else retry in next loop |
383 | // else retry in next loop |
384 | part = 0; |
384 | part = 0; |
385 | break; |
385 | break; |
386 | case LOGFILE_OPENED: |
386 | case LOGFILE_OPENED: |
387 | // append new gps log data |
387 | // append new gps log data |
388 | measure_time = CountMilliseconds; |
388 | measure_time = CountMilliseconds; |
389 | if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
389 | if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
390 | { |
390 | { |
391 | if(!GPX_LoggGPSCoordinates(&logfile,part)) |
391 | if(!GPX_LoggGPSCoordinates(&logfile,part)) |
392 | { // error logging data |
392 | { // error logging data |
393 | UART1_PutString("\r\nError logging to gpx-file\r\n"); |
393 | UART1_PutString("\r\nError logging to gpx-file\r\n"); |
394 | GPX_DocumentClose(&logfile); |
394 | GPX_DocumentClose(&logfile); |
395 | SD_LoggingError = 13; |
395 | SD_LoggingError = 13; |
396 | logfilestate = LOGFILE_ERROR; |
396 | logfilestate = LOGFILE_ERROR; |
397 | } |
397 | } |
398 | else // successful log |
398 | else // successful log |
399 | { |
399 | { |
400 | if(ErrorCode != old_errorcode || CheckDelay(flushtimer)) |
400 | if(ErrorCode != old_errorcode || CheckDelay(flushtimer)) |
401 | { |
401 | { |
- | 402 | if(ErrorCode) { while(++part < 9) GPX_LoggGPSCoordinates(&logfile,part); }; // close this chapter |
|
402 | if(ErrorCode != old_errorcode) flushtimer = SetDelay(1000); |
403 | if(ErrorCode != old_errorcode) flushtimer = SetDelay(1000); |
403 | else flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
404 | else flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
404 | fflush_(logfile.file); |
405 | fflush_(logfile.file); |
405 | old_errorcode = ErrorCode; |
406 | old_errorcode = ErrorCode; |
406 | } |
407 | } |
407 | } |
408 | } |
408 | } |
409 | } |
409 | if(++part == 9) part = 0; |
410 | if(++part == 9) part = 0; |
410 | //DebugOut.Analog[19] = CountMilliseconds - measure_time; |
411 | //DebugOut.Analog[19] = CountMilliseconds - measure_time; |
411 | break; |
412 | break; |
412 | 413 | ||
413 | case LOGFILE_ERROR: |
414 | case LOGFILE_ERROR: |
414 | part = 0; |
415 | part = 0; |
415 | break; |
416 | break; |
416 | 417 | ||
417 | default: |
418 | default: |
418 | part = 0; |
419 | part = 0; |
419 | logfilestate = LOGFILE_IDLE; |
420 | logfilestate = LOGFILE_IDLE; |
420 | break; |
421 | break; |
421 | } |
422 | } |
422 | } // EOF model is flying |
423 | } // EOF model is flying |
423 | else // model is not flying |
424 | else // model is not flying |
424 | { // close log file if opened |
425 | { // close log file if opened |
425 | if(logfilestate == LOGFILE_OPENED) |
426 | if(logfilestate == LOGFILE_OPENED) |
426 | { |
427 | { |
427 | if(GPX_DocumentClose(&logfile)) |
428 | if(GPX_DocumentClose(&logfile)) |
428 | { |
429 | { |
429 | UART1_PutString("\r\nClosing gpx-file\r\n"); |
430 | UART1_PutString("\r\nClosing gpx-file\r\n"); |
430 | logfilestate = LOGFILE_CLOSED; |
431 | logfilestate = LOGFILE_CLOSED; |
431 | part = 0; |
432 | part = 0; |
432 | } |
433 | } |
433 | else // could not be closed |
434 | else // could not be closed |
434 | { |
435 | { |
435 | UART1_PutString("\r\nError closing gpx-file\r\n"); |
436 | UART1_PutString("\r\nError closing gpx-file\r\n"); |
436 | SD_LoggingError = 14; |
437 | SD_LoggingError = 14; |
437 | logfilestate = LOGFILE_ERROR; |
438 | logfilestate = LOGFILE_ERROR; |
438 | part = 0; |
439 | part = 0; |
439 | } |
440 | } |
440 | } |
441 | } |
441 | } //EOF model is not flying |
442 | } //EOF model is not flying |
442 | } // EOF Check LogTimer |
443 | } // EOF Check LogTimer |
443 | 444 | ||
444 | return logfilestate; |
445 | return logfilestate; |
445 | } |
446 | } |
446 | 447 | ||
447 | //---------------------------------------------------------------------------------------------------- |
448 | //---------------------------------------------------------------------------------------------------- |
448 | // initialize logging |
449 | // initialize logging |
449 | void Logging_Init(void) |
450 | void Logging_Init(void) |
450 | { |
451 | { |
451 | SD_LoggingError = 0; |
452 | SD_LoggingError = 0; |
452 | LogCfg.KML_Interval = 1000; //default |
453 | LogCfg.KML_Interval = 1000; //default |
453 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
454 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
454 | if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < MIN_SD_INTERVAL_KML) LogCfg.KML_Interval = MIN_SD_INTERVAL_KML; |
455 | if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < MIN_SD_INTERVAL_KML) LogCfg.KML_Interval = MIN_SD_INTERVAL_KML; |
455 | 456 | ||
456 | Logging_KML(0); // initialize |
457 | Logging_KML(0); // initialize |
457 | LogCfg.GPX_Interval = 0; //default |
458 | LogCfg.GPX_Interval = 0; //default |
458 | Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value |
459 | Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value |
459 | if(LogCfg.GPX_Interval != 0 && LogCfg.GPX_Interval < MIN_SD_INTERVAL_GPX) LogCfg.GPX_Interval = MIN_SD_INTERVAL_GPX; |
460 | if(LogCfg.GPX_Interval != 0 && LogCfg.GPX_Interval < MIN_SD_INTERVAL_GPX) LogCfg.GPX_Interval = MIN_SD_INTERVAL_GPX; |
460 | Logging_GPX(0); // initialize |
461 | Logging_GPX(0); // initialize |
461 | } |
462 | } |
462 | 463 | ||
463 | //---------------------------------------------------------------------------------------------------- |
464 | //---------------------------------------------------------------------------------------------------- |
464 | // gobal logging handler |
465 | // gobal logging handler |
465 | void Logging_Update(void) |
466 | void Logging_Update(void) |
466 | { |
467 | { |
467 | static u8 logmodule = 0; |
468 | static u8 logmodule = 0; |
468 | static u32 logtimer = 0; |
469 | static u32 logtimer = 0; |
469 | static logfilestate_t logstate = LOGFILE_IDLE; |
470 | static logfilestate_t logstate = LOGFILE_IDLE; |
470 | 471 | ||
471 | if(SD_SWITCH) // a card is in slot |
472 | if(SD_SWITCH) // a card is in slot |
472 | { |
473 | { |
473 | if((logstate == LOGFILE_ERROR) && (FC.StatusFlags & FC_STATUS_START)) SD_LoggingError = 100; |
474 | if((logstate == LOGFILE_ERROR) && (FC.StatusFlags & FC_STATUS_START)) SD_LoggingError = 100; |
474 | if(CheckDelay(logtimer)) |
475 | if(CheckDelay(logtimer)) |
475 | { |
476 | { |
476 | logtimer = SetDelay(10); // faster makes no sense |
477 | logtimer = SetDelay(10); // faster makes no sense |
477 | // call the logger handlers if no error has occured |
478 | // call the logger handlers if no error has occured |
478 | if(logstate != LOGFILE_ERROR) |
479 | if(logstate != LOGFILE_ERROR) |
479 | { // run only one logging handler per loop |
480 | { // run only one logging handler per loop |
480 | switch(logmodule++) |
481 | switch(logmodule++) |
481 | { |
482 | { |
482 | case 0: |
483 | case 0: |
483 | logstate = Logging_KML(LogCfg.KML_Interval); |
484 | logstate = Logging_KML(LogCfg.KML_Interval); |
484 | break; |
485 | break; |
485 | case 1: |
486 | case 1: |
486 | logstate = Logging_GPX(LogCfg.GPX_Interval); |
487 | logstate = Logging_GPX(LogCfg.GPX_Interval); |
487 | logmodule = 0; // resart with first log module |
488 | logmodule = 0; // resart with first log module |
488 | break; |
489 | break; |
489 | default: |
490 | default: |
490 | logmodule = 0; |
491 | logmodule = 0; |
491 | break; |
492 | break; |
492 | } |
493 | } |
493 | } |
494 | } |
494 | else // a logging error has occured |
495 | else // a logging error has occured |
495 | { |
496 | { |
496 | // /* |
497 | // /* |
497 | // try to reinitialize sd-card when motors are not running |
498 | // try to reinitialize sd-card when motors are not running |
498 | if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) |
499 | if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) |
499 | { |
500 | { |
500 | if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside |
501 | if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside |
501 | { |
502 | { |
502 | Logging_Init(); // initialize the logs |
503 | Logging_Init(); // initialize the logs |
503 | logstate = LOGFILE_IDLE; |
504 | logstate = LOGFILE_IDLE; |
504 | logtimer = SetDelay(100); // try next log in 100 mili sec |
505 | logtimer = SetDelay(100); // try next log in 100 mili sec |
505 | } |
506 | } |
506 | else |
507 | else |
507 | { // retry in 5 seconds |
508 | { // retry in 5 seconds |
508 | logtimer = SetDelay(5000); // try again in 5 sec |
509 | logtimer = SetDelay(5000); // try again in 5 sec |
509 | } |
510 | } |
510 | } // EOF motors are not running |
511 | } // EOF motors are not running |
511 | // */ |
512 | // */ |
512 | } //EOF logfile error |
513 | } //EOF logfile error |
513 | } // EOF CheckDelay |
514 | } // EOF CheckDelay |
514 | }// EOF Card in Slot |
515 | }// EOF Card in Slot |
515 | } |
516 | } |
516 | 517 |