Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
82 | killagreg | 1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
||
3 | /*#######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + www.MikroKopter.com |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
360 | holgerb | 7 | // + Software Nutzungsbedingungen (english version: see below) |
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 |
||
489 | killagreg | 10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
360 | holgerb | 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. |
||
82 | killagreg | 13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 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. |
||
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. |
||
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. |
||
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
||
489 | killagreg | 21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
360 | holgerb | 22 | // + des Mitverschuldens offen. |
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. |
||
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 |
||
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. |
||
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. |
||
82 | killagreg | 31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 32 | // + Software LICENSING TERMS |
82 | killagreg | 33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
489 | killagreg | 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 |
360 | holgerb | 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. |
||
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 |
||
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 |
||
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 |
||
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 |
||
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. |
||
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. |
||
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. |
||
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
||
53 | // + #### END OF LICENSING TERMS #### |
||
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
||
82 | killagreg | 55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include <stdio.h> |
||
57 | #include "91x_lib.h" |
||
58 | #include "main.h" |
||
119 | killagreg | 59 | #include "timer1.h" |
82 | killagreg | 60 | #include "uart1.h" |
61 | #include "kml.h" |
||
85 | killagreg | 62 | #include "gpx.h" |
86 | killagreg | 63 | #include "ssc.h" |
88 | killagreg | 64 | #include "settings.h" |
378 | holgerb | 65 | #include "led.h" |
380 | holgerb | 66 | #include "logging.h" |
721 | holgerb | 67 | #include "triggerlog.h" |
82 | killagreg | 68 | |
380 | holgerb | 69 | #define MIN_SD_INTERVAL_KML 200 |
456 | holgerb | 70 | #define MIN_SD_INTERVAL_GPX 200 |
378 | holgerb | 71 | |
351 | holgerb | 72 | u8 SD_LoggingError = 0; |
92 | killagreg | 73 | |
74 | |||
82 | killagreg | 75 | |
722 | ingob | 76 | |
82 | killagreg | 77 | // logger handler prototypes |
78 | logfilestate_t Logging_KML(u32 LogDelay); |
||
79 | logfilestate_t Logging_GPX(u32 LogDelay); |
||
80 | |||
101 | holgerb | 81 | LogCfg_t LogCfg = {500 , 1000}; |
489 | killagreg | 82 | u32 Logged_GPX_Counter = 0, Logged_KML_Counter = 0; |
705 | holgerb | 83 | u16 KML_Filenum = 0, GPX_Filenum = 0, GPX_logging_active = 0; |
82 | killagreg | 84 | |
85 | //---------------------------------------------------------------------------------------------------- |
||
86 | s8* GenerateKMLLogFileName(void) |
||
87 | { |
||
88 | static u16 filenum = 0; // file name counter |
||
705 | holgerb | 89 | static s8 filename[40]; |
82 | killagreg | 90 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
91 | |||
92 | if(SystemTime.Valid) |
||
93 | { |
||
94 | // if the day has been changed |
||
95 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
||
96 | { |
||
97 | LastTime.Year = SystemTime.Year; |
||
98 | LastTime.Month = SystemTime.Month; |
||
99 | LastTime.Day = SystemTime.Day; |
||
100 | LastTime.Valid = 1; |
||
101 | filenum = 0; // reset file counter |
||
102 | } |
||
565 | holgerb | 103 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
104 | { |
||
515 | killagreg | 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); |
429 | holgerb | 106 | else sprintf(filename, "/LOG/%04i%02i%02i/KML/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
565 | holgerb | 107 | } |
108 | else |
||
109 | { |
||
573 | holgerb | 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); |
565 | holgerb | 111 | else sprintf(filename, "/SIMULATE/%04i%02i%02i/KML/SIM%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
112 | } |
||
113 | |||
82 | killagreg | 114 | filenum++; |
516 | holgerb | 115 | KML_Filenum = filenum; |
82 | killagreg | 116 | return filename; |
117 | } |
||
118 | else return NULL; |
||
119 | } |
||
120 | |||
121 | //---------------------------------------------------------------------------------------------------- |
||
122 | s8* GenerateGPXLogFileName(void) |
||
123 | { |
||
124 | static u16 filenum = 0; // file name counter |
||
705 | holgerb | 125 | static s8 filename[40]; |
82 | killagreg | 126 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
127 | |||
128 | if(SystemTime.Valid) |
||
129 | { |
||
130 | // if the day has been changed |
||
131 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
||
132 | { |
||
133 | LastTime.Year = SystemTime.Year; |
||
134 | LastTime.Month = SystemTime.Month; |
||
135 | LastTime.Day = SystemTime.Day; |
||
136 | LastTime.Valid = 1; |
||
137 | filenum = 0; // reset file counter |
||
138 | } |
||
565 | holgerb | 139 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
140 | { |
||
515 | killagreg | 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); |
429 | holgerb | 142 | else sprintf(filename, "/LOG/%04i%02i%02i/GPX/GPS%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
565 | holgerb | 143 | } |
144 | else |
||
145 | { |
||
573 | holgerb | 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); |
565 | holgerb | 147 | else sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/SIM%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
148 | } |
||
705 | holgerb | 149 | GPX_Filenum = filenum; |
82 | killagreg | 150 | filenum++; |
151 | return filename; |
||
152 | } |
||
153 | else return NULL; |
||
154 | } |
||
155 | |||
156 | |||
157 | |||
158 | //---------------------------------------------------------------------------------------------------- |
||
159 | // logs the current gps position to a kml file |
||
160 | logfilestate_t Logging_KML(u32 LogDelay) |
||
161 | { |
||
162 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
||
163 | static s8* logfilename = NULL; // the pointer to the logfilename |
||
92 | killagreg | 164 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
82 | killagreg | 165 | static KML_Document_t logfile; // the logfilehandle |
432 | holgerb | 166 | static u32 appendtimer = 0; // the log update timer |
167 | static u8 logging_active = 0; |
||
82 | killagreg | 168 | |
146 | killagreg | 169 | // initialize if LogDelay is zero |
82 | killagreg | 170 | if(!LogDelay) |
171 | { |
||
172 | switch(logfilestate) |
||
173 | { |
||
88 | killagreg | 174 | case LOGFILE_OPENED: |
82 | killagreg | 175 | KML_DocumentClose(&logfile); // try to close it |
176 | break; |
||
177 | default: |
||
178 | break; |
||
179 | } |
||
180 | logfilestate = LOGFILE_IDLE; |
||
181 | logfilename = NULL; |
||
182 | KML_DocumentInit(&logfile); |
||
183 | logtimer = SetDelay(0); // set logtimer to now |
||
88 | killagreg | 184 | return logfilestate; |
82 | killagreg | 185 | } |
186 | // no init |
||
187 | if(CheckDelay(logtimer)) |
||
188 | { |
||
189 | logtimer = SetDelay(LogDelay); // standard interval |
||
88 | killagreg | 190 | |
489 | killagreg | 191 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
515 | killagreg | 192 | { |
193 | logging_active = 1; |
||
194 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
||
195 | } |
||
489 | killagreg | 196 | else |
515 | killagreg | 197 | { |
198 | if(CheckDelay(appendtimer)) logging_active = 0; |
||
199 | } |
||
432 | holgerb | 200 | |
201 | if(logging_active) |
||
82 | killagreg | 202 | { |
203 | switch(logfilestate) |
||
204 | { |
||
205 | case LOGFILE_IDLE: |
||
206 | case LOGFILE_CLOSED: |
||
429 | holgerb | 207 | if((GPSData.Status != INVALID) && (SystemTime.Valid) && /*(GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)*/ (FC.StatusFlags & FC_STATUS_FLY)) |
82 | killagreg | 208 | { |
209 | logfilestate = LOGFILE_START; |
||
210 | } |
||
211 | break; |
||
212 | case LOGFILE_START: |
||
213 | // find unused logfile name |
||
214 | do |
||
215 | { // try to generate a new logfile name |
||
216 | logfilename = GenerateKMLLogFileName(); |
||
378 | holgerb | 217 | }while((logfilename != NULL) && fexist_(logfilename)); |
82 | killagreg | 218 | // if logfilename exist |
219 | if(logfilename != NULL) |
||
220 | { |
||
221 | // try to create the log file |
||
222 | if(KML_DocumentOpen(logfilename, &logfile)) |
||
223 | { |
||
92 | killagreg | 224 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
82 | killagreg | 225 | logfilestate = LOGFILE_OPENED; // goto next step |
110 | killagreg | 226 | UART1_PutString("\r\nOpening kml-file:"); |
227 | UART1_PutString(logfilename); |
||
228 | UART1_PutString("\r\n"); |
||
82 | killagreg | 229 | } |
230 | else // could not be openend |
||
231 | { |
||
232 | logfilestate = LOGFILE_ERROR; |
||
110 | killagreg | 233 | UART1_PutString("\r\nError opening kml-file: "); |
234 | UART1_PutString(logfilename); |
||
235 | UART1_PutString("\r\n"); |
||
82 | killagreg | 236 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
351 | holgerb | 237 | SD_LoggingError = 1; |
82 | killagreg | 238 | } |
239 | } |
||
240 | else |
||
241 | { |
||
242 | logfilestate = LOGFILE_ERROR; |
||
110 | killagreg | 243 | UART1_PutString("\r\nError getting free kml-file name\r\n"); |
351 | holgerb | 244 | SD_LoggingError = 2; |
82 | killagreg | 245 | } |
246 | // else retry in next loop |
||
247 | break; |
||
248 | case LOGFILE_OPENED: |
||
249 | // append new gps log data |
||
85 | killagreg | 250 | if(!KML_LoggGPSCoordinates(&logfile)) |
82 | killagreg | 251 | { // error logging data |
110 | killagreg | 252 | UART1_PutString("\r\nError logging to kml-file\r\n"); |
351 | holgerb | 253 | SD_LoggingError = 3; |
82 | killagreg | 254 | KML_DocumentClose(&logfile); |
255 | logfilestate = LOGFILE_ERROR; |
||
256 | } |
||
92 | killagreg | 257 | else // sucessfully logged |
258 | { |
||
351 | holgerb | 259 | SD_LoggingError = 0; |
92 | killagreg | 260 | if(CheckDelay(flushtimer)) |
261 | { |
||
262 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
||
263 | fflush_(logfile.file); |
||
264 | } |
||
265 | } |
||
82 | killagreg | 266 | break; |
88 | killagreg | 267 | |
82 | killagreg | 268 | case LOGFILE_ERROR: |
269 | break; |
||
88 | killagreg | 270 | |
82 | killagreg | 271 | default: |
272 | logfilestate = LOGFILE_IDLE; |
||
273 | break; |
||
274 | } |
||
92 | killagreg | 275 | } // EOF motors are not running |
82 | killagreg | 276 | else // model is not flying |
277 | { // close log file if opened |
||
278 | if(logfilestate == LOGFILE_OPENED) |
||
279 | { |
||
280 | if(KML_DocumentClose(&logfile)) |
||
281 | { |
||
110 | killagreg | 282 | UART1_PutString("\r\nClosing kml-file\r\n"); |
82 | killagreg | 283 | logfilestate = LOGFILE_CLOSED; |
284 | } |
||
285 | else // could not be closed |
||
286 | { |
||
110 | killagreg | 287 | UART1_PutString("\r\nError closing kml-file\r\n"); |
351 | holgerb | 288 | SD_LoggingError = 4; |
82 | killagreg | 289 | logfilestate = LOGFILE_ERROR; |
290 | } |
||
291 | } |
||
92 | killagreg | 292 | } //EOF motors are not running |
82 | killagreg | 293 | } // EOF Check LogTimer |
294 | |||
295 | return logfilestate; |
||
296 | } |
||
88 | killagreg | 297 | |
82 | killagreg | 298 | //---------------------------------------------------------------------------------------------------- |
299 | // logs gps and state info to a gpx file |
||
300 | logfilestate_t Logging_GPX(u32 LogDelay) |
||
301 | { |
||
85 | killagreg | 302 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
303 | static s8* logfilename = NULL; // the pointer to the logfilename |
||
867 | holgerb | 304 | static u32 logtimer = 0, flushtimer = 0, appendtimer = 0, errortimer = 0; // the log update timer |
85 | killagreg | 305 | static GPX_Document_t logfile; // the logfilehandle |
867 | holgerb | 306 | static u8 part = 0, old_errorcode = 0, cnt_retry = 0; |
582 | holgerb | 307 | // u32 measure_time; |
82 | killagreg | 308 | |
218 | killagreg | 309 | // initialize if LogDelay is zero |
85 | killagreg | 310 | if(!LogDelay) |
311 | { |
||
515 | killagreg | 312 | switch(logfilestate) |
85 | killagreg | 313 | { |
88 | killagreg | 314 | case LOGFILE_OPENED: |
85 | killagreg | 315 | GPX_DocumentClose(&logfile); // try to close it |
316 | break; |
||
515 | killagreg | 317 | default: |
85 | killagreg | 318 | break; |
319 | } |
||
320 | logfilestate = LOGFILE_IDLE; |
||
321 | logfilename = NULL; |
||
322 | GPX_DocumentInit(&logfile); |
||
323 | logtimer = SetDelay(0); // set logtimer to now |
||
88 | killagreg | 324 | return logfilestate; |
85 | killagreg | 325 | } |
326 | // no init |
||
345 | holgerb | 327 | if(CheckDelay(logtimer) || part) |
85 | killagreg | 328 | { |
378 | holgerb | 329 | if(!part) logtimer = SetDelay(LogDelay); // standard interval |
88 | killagreg | 330 | |
489 | killagreg | 331 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
432 | holgerb | 332 | { |
705 | holgerb | 333 | if(!GPX_logging_active) GPX_logging_active = 1; |
489 | killagreg | 334 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
432 | holgerb | 335 | } |
489 | killagreg | 336 | else |
432 | holgerb | 337 | { |
705 | holgerb | 338 | if(CheckDelay(appendtimer)) GPX_logging_active = 0; |
432 | holgerb | 339 | } |
340 | |||
705 | holgerb | 341 | if(GPX_logging_active || part) |
85 | killagreg | 342 | { |
343 | switch(logfilestate) |
||
344 | { |
||
345 | case LOGFILE_IDLE: |
||
346 | case LOGFILE_CLOSED: |
||
581 | holgerb | 347 | if((GPSData.Status != INVALID) && (SystemTime.Valid) && |
348 | ((FC.StatusFlags & FC_STATUS_FLY) || (LogCfg.StartAtMotorrun && (FC.StatusFlags & FC_STATUS_MOTOR_RUN)))) |
||
85 | killagreg | 349 | { |
350 | logfilestate = LOGFILE_START; |
||
351 | } |
||
345 | holgerb | 352 | part = 0; |
85 | killagreg | 353 | break; |
354 | case LOGFILE_START: |
||
355 | // find unused logfile name |
||
356 | do |
||
357 | { // try to generate a new logfile name |
||
358 | logfilename = GenerateGPXLogFileName(); |
||
378 | holgerb | 359 | }while((logfilename != NULL) && fexist_(logfilename)); |
85 | killagreg | 360 | // if logfilename exist |
361 | if(logfilename != NULL) |
||
362 | { |
||
363 | // try to create the log file |
||
364 | if(GPX_DocumentOpen(logfilename, &logfile)) |
||
365 | { |
||
92 | killagreg | 366 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
85 | killagreg | 367 | logfilestate = LOGFILE_OPENED; // goto next step |
110 | killagreg | 368 | UART1_PutString("\r\nOpening gpx-file:"); |
369 | UART1_PutString(logfilename); |
||
370 | UART1_PutString("\r\n"); |
||
705 | holgerb | 371 | GPX_logging_active = 2; |
85 | killagreg | 372 | } |
373 | else // could not be openend |
||
374 | { |
||
375 | logfilestate = LOGFILE_ERROR; |
||
867 | holgerb | 376 | errortimer = SetDelay(2000); // retry in 2 sec |
110 | killagreg | 377 | UART1_PutString("\r\nError opening gpx-file: "); |
378 | UART1_PutString(logfilename); |
||
379 | UART1_PutString("\r\n"); |
||
351 | holgerb | 380 | SD_LoggingError = 11; |
85 | killagreg | 381 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
382 | } |
||
515 | killagreg | 383 | old_errorcode = ErrorCode; |
85 | killagreg | 384 | } |
385 | else |
||
386 | { |
||
387 | logfilestate = LOGFILE_ERROR; |
||
515 | killagreg | 388 | UART1_PutString("\r\nError getting free gpx-file name\r\n"); |
867 | holgerb | 389 | errortimer = SetDelay(2000); // retry in 2 sec |
351 | holgerb | 390 | SD_LoggingError = 12; |
85 | killagreg | 391 | } |
392 | // else retry in next loop |
||
345 | holgerb | 393 | part = 0; |
85 | killagreg | 394 | break; |
395 | case LOGFILE_OPENED: |
||
396 | // append new gps log data |
||
581 | holgerb | 397 | // measure_time = CountMilliseconds; |
808 | holgerb | 398 | // if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
85 | killagreg | 399 | { |
867 | holgerb | 400 | if(!GPX_LoggGPSCoordinates(&logfile,part)/* || (Parameter.User5 > 100)*/) |
85 | killagreg | 401 | { // error logging data |
110 | killagreg | 402 | UART1_PutString("\r\nError logging to gpx-file\r\n"); |
515 | killagreg | 403 | GPX_DocumentClose(&logfile); |
351 | holgerb | 404 | SD_LoggingError = 13; |
85 | killagreg | 405 | logfilestate = LOGFILE_ERROR; |
867 | holgerb | 406 | errortimer = SetDelay(2000); // retry in 2 sec |
85 | killagreg | 407 | } |
92 | killagreg | 408 | else // successful log |
409 | { |
||
581 | holgerb | 410 | if(ErrorCode != old_errorcode || CheckDelay(flushtimer) || part == 8) |
92 | killagreg | 411 | { |
530 | holgerb | 412 | if(ErrorCode) { while(++part < 9) GPX_LoggGPSCoordinates(&logfile,part); }; // close this chapter |
489 | killagreg | 413 | if(ErrorCode != old_errorcode) flushtimer = SetDelay(1000); |
485 | holgerb | 414 | else flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
92 | killagreg | 415 | fflush_(logfile.file); |
485 | holgerb | 416 | old_errorcode = ErrorCode; |
92 | killagreg | 417 | } |
418 | } |
||
85 | killagreg | 419 | } |
536 | holgerb | 420 | if(++part >= 9) part = 0; |
610 | holgerb | 421 | //DebugOut.Analog[] = CountMilliseconds - measure_time; |
85 | killagreg | 422 | break; |
88 | killagreg | 423 | |
85 | killagreg | 424 | case LOGFILE_ERROR: |
867 | holgerb | 425 | if((cnt_retry < 3) && CheckDelay(errortimer) ) |
426 | { |
||
427 | logfilestate = LOGFILE_IDLE; |
||
428 | errortimer = SetDelay(2000); |
||
429 | UART1_PutString("\r\nRetry gpx-file\r\n"); |
||
430 | cnt_retry++; |
||
431 | } |
||
345 | holgerb | 432 | part = 0; |
85 | killagreg | 433 | break; |
88 | killagreg | 434 | |
85 | killagreg | 435 | default: |
345 | holgerb | 436 | part = 0; |
85 | killagreg | 437 | logfilestate = LOGFILE_IDLE; |
438 | break; |
||
439 | } |
||
440 | } // EOF model is flying |
||
441 | else // model is not flying |
||
442 | { // close log file if opened |
||
443 | if(logfilestate == LOGFILE_OPENED) |
||
444 | { |
||
445 | if(GPX_DocumentClose(&logfile)) |
||
446 | { |
||
110 | killagreg | 447 | UART1_PutString("\r\nClosing gpx-file\r\n"); |
85 | killagreg | 448 | logfilestate = LOGFILE_CLOSED; |
345 | holgerb | 449 | part = 0; |
85 | killagreg | 450 | } |
451 | else // could not be closed |
||
452 | { |
||
110 | killagreg | 453 | UART1_PutString("\r\nError closing gpx-file\r\n"); |
351 | holgerb | 454 | SD_LoggingError = 14; |
867 | holgerb | 455 | logfilestate = LOGFILE_ERROR; |
345 | holgerb | 456 | part = 0; |
85 | killagreg | 457 | } |
458 | } |
||
867 | holgerb | 459 | else |
460 | { |
||
461 | if(logfilestate == LOGFILE_ERROR) logfilestate = LOGFILE_IDLE; |
||
462 | cnt_retry = 0; |
||
463 | } |
||
85 | killagreg | 464 | } //EOF model is not flying |
465 | } // EOF Check LogTimer |
||
466 | |||
82 | killagreg | 467 | return logfilestate; |
468 | } |
||
469 | |||
470 | //---------------------------------------------------------------------------------------------------- |
||
471 | // initialize logging |
||
472 | void Logging_Init(void) |
||
473 | { |
||
351 | holgerb | 474 | SD_LoggingError = 0; |
378 | holgerb | 475 | LogCfg.KML_Interval = 1000; //default |
88 | killagreg | 476 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
380 | holgerb | 477 | if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < MIN_SD_INTERVAL_KML) LogCfg.KML_Interval = MIN_SD_INTERVAL_KML; |
310 | holgerb | 478 | |
92 | killagreg | 479 | Logging_KML(0); // initialize |
146 | killagreg | 480 | LogCfg.GPX_Interval = 0; //default |
88 | killagreg | 481 | Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value |
581 | holgerb | 482 | Settings_GetParamValue(PID_LOG_AT_MOTORRUN, (u16*)&LogCfg.StartAtMotorrun); // overwrite by settings value |
380 | holgerb | 483 | if(LogCfg.GPX_Interval != 0 && LogCfg.GPX_Interval < MIN_SD_INTERVAL_GPX) LogCfg.GPX_Interval = MIN_SD_INTERVAL_GPX; |
515 | killagreg | 484 | Logging_GPX(0); // initialize |
82 | killagreg | 485 | } |
486 | |||
487 | //---------------------------------------------------------------------------------------------------- |
||
488 | // gobal logging handler |
||
489 | void Logging_Update(void) |
||
490 | { |
||
867 | holgerb | 491 | static u8 logmodule = 0, retry_in_flight_cnt = 0; |
82 | killagreg | 492 | static u32 logtimer = 0; |
493 | static logfilestate_t logstate = LOGFILE_IDLE; |
||
86 | killagreg | 494 | |
838 | holgerb | 495 | // if(SD_SWITCH) // a card is in slot |
84 | killagreg | 496 | { |
351 | holgerb | 497 | if((logstate == LOGFILE_ERROR) && (FC.StatusFlags & FC_STATUS_START)) SD_LoggingError = 100; |
92 | killagreg | 498 | if(CheckDelay(logtimer)) |
84 | killagreg | 499 | { |
92 | killagreg | 500 | logtimer = SetDelay(10); // faster makes no sense |
501 | // call the logger handlers if no error has occured |
||
115 | killagreg | 502 | if(logstate != LOGFILE_ERROR) |
176 | killagreg | 503 | { // run only one logging handler per loop |
115 | killagreg | 504 | switch(logmodule++) |
505 | { |
||
506 | case 0: |
||
507 | logstate = Logging_KML(LogCfg.KML_Interval); |
||
508 | break; |
||
509 | case 1: |
||
510 | logstate = Logging_GPX(LogCfg.GPX_Interval); |
||
705 | holgerb | 511 | break; |
512 | case 2: |
||
513 | if(UART_VersionInfo.HWMajor >= 30) logstate = LoggingTrigger(200); |
||
115 | killagreg | 514 | logmodule = 0; // resart with first log module |
515 | break; |
||
516 | default: |
||
517 | logmodule = 0; |
||
518 | break; |
||
519 | } |
||
520 | } |
||
521 | else // a logging error has occured |
||
489 | killagreg | 522 | { |
351 | holgerb | 523 | // /* |
176 | killagreg | 524 | // try to reinitialize sd-card when motors are not running |
351 | holgerb | 525 | if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) |
92 | killagreg | 526 | { |
159 | killagreg | 527 | if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside |
528 | { |
||
529 | Logging_Init(); // initialize the logs |
||
530 | logstate = LOGFILE_IDLE; |
||
351 | holgerb | 531 | logtimer = SetDelay(100); // try next log in 100 mili sec |
159 | killagreg | 532 | } |
533 | else |
||
534 | { // retry in 5 seconds |
||
535 | logtimer = SetDelay(5000); // try again in 5 sec |
||
536 | } |
||
867 | holgerb | 537 | retry_in_flight_cnt = 0; |
159 | killagreg | 538 | } // EOF motors are not running |
867 | holgerb | 539 | else |
540 | { |
||
541 | if(retry_in_flight_cnt < 5) |
||
542 | { |
||
543 | logtimer = SetDelay(2000); // try again in 2 sec |
||
544 | logstate = LOGFILE_IDLE; |
||
545 | retry_in_flight_cnt++; |
||
546 | } |
||
547 | else |
||
548 | if(retry_in_flight_cnt < 8) |
||
549 | { |
||
550 | Logging_Init(); // initialize the logs |
||
551 | logtimer = SetDelay(5000); // try again in 5 sec |
||
552 | logstate = LOGFILE_IDLE; |
||
553 | retry_in_flight_cnt++; |
||
554 | } |
||
555 | } |
||
556 | |||
351 | holgerb | 557 | // */ |
92 | killagreg | 558 | } //EOF logfile error |
559 | } // EOF CheckDelay |
||
560 | }// EOF Card in Slot |
||
88 | killagreg | 561 | } |