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