Rev 350 | Rev 357 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 350 | Rev 351 | ||
---|---|---|---|
Line 62... | Line 62... | ||
62 | #include "kml.h" |
62 | #include "kml.h" |
63 | #include "gpx.h" |
63 | #include "gpx.h" |
64 | #include "ssc.h" |
64 | #include "ssc.h" |
65 | #include "settings.h" |
65 | #include "settings.h" |
Line -... | Line 66... | ||
- | 66 | ||
Line 66... | Line 67... | ||
66 | 67 | u8 SD_LoggingError = 0; |
|
Line 67... | Line 68... | ||
67 | 68 | ||
68 | #define LOG_FLUSH_INTERVAL 20000 // 20s |
69 | #define LOG_FLUSH_INTERVAL 20000 // 20s |
Line 206... | Line 207... | ||
206 | logfilestate = LOGFILE_ERROR; |
207 | logfilestate = LOGFILE_ERROR; |
207 | UART1_PutString("\r\nError opening kml-file: "); |
208 | UART1_PutString("\r\nError opening kml-file: "); |
208 | UART1_PutString(logfilename); |
209 | UART1_PutString(logfilename); |
209 | UART1_PutString("\r\n"); |
210 | UART1_PutString("\r\n"); |
210 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
211 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
- | 212 | SD_LoggingError = 1; |
|
211 | } |
213 | } |
212 | } |
214 | } |
213 | else |
215 | else |
214 | { |
216 | { |
215 | logfilestate = LOGFILE_ERROR; |
217 | logfilestate = LOGFILE_ERROR; |
216 | UART1_PutString("\r\nError getting free kml-file name\r\n"); |
218 | UART1_PutString("\r\nError getting free kml-file name\r\n"); |
- | 219 | SD_LoggingError = 2; |
|
217 | } |
220 | } |
218 | // else retry in next loop |
221 | // else retry in next loop |
219 | break; |
222 | break; |
220 | case LOGFILE_OPENED: |
223 | case LOGFILE_OPENED: |
221 | // append new gps log data |
224 | // append new gps log data |
222 | if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
225 | if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
223 | { |
226 | { |
224 | if(!KML_LoggGPSCoordinates(&logfile)) |
227 | if(!KML_LoggGPSCoordinates(&logfile)) |
225 | { // error logging data |
228 | { // error logging data |
226 | UART1_PutString("\r\nError logging to kml-file\r\n"); |
229 | UART1_PutString("\r\nError logging to kml-file\r\n"); |
- | 230 | SD_LoggingError = 3; |
|
227 | KML_DocumentClose(&logfile); |
231 | KML_DocumentClose(&logfile); |
228 | logfilestate = LOGFILE_ERROR; |
232 | logfilestate = LOGFILE_ERROR; |
229 | } |
233 | } |
230 | else // sucessfully logged |
234 | else // sucessfully logged |
231 | { |
235 | { |
- | 236 | SD_LoggingError = 0; |
|
232 | if(CheckDelay(flushtimer)) |
237 | if(CheckDelay(flushtimer)) |
233 | { |
238 | { |
234 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
239 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
235 | fflush_(logfile.file); |
240 | fflush_(logfile.file); |
236 | } |
241 | } |
Line 257... | Line 262... | ||
257 | logfilestate = LOGFILE_CLOSED; |
262 | logfilestate = LOGFILE_CLOSED; |
258 | } |
263 | } |
259 | else // could not be closed |
264 | else // could not be closed |
260 | { |
265 | { |
261 | UART1_PutString("\r\nError closing kml-file\r\n"); |
266 | UART1_PutString("\r\nError closing kml-file\r\n"); |
- | 267 | SD_LoggingError = 4; |
|
262 | logfilestate = LOGFILE_ERROR; |
268 | logfilestate = LOGFILE_ERROR; |
263 | } |
269 | } |
264 | } |
270 | } |
265 | } //EOF motors are not running |
271 | } //EOF motors are not running |
266 | } // EOF Check LogTimer |
272 | } // EOF Check LogTimer |
Line 335... | Line 341... | ||
335 | { |
341 | { |
336 | logfilestate = LOGFILE_ERROR; |
342 | logfilestate = LOGFILE_ERROR; |
337 | UART1_PutString("\r\nError opening gpx-file: "); |
343 | UART1_PutString("\r\nError opening gpx-file: "); |
338 | UART1_PutString(logfilename); |
344 | UART1_PutString(logfilename); |
339 | UART1_PutString("\r\n"); |
345 | UART1_PutString("\r\n"); |
- | 346 | SD_LoggingError = 11; |
|
340 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
347 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
341 | } |
348 | } |
342 | } |
349 | } |
343 | else |
350 | else |
344 | { |
351 | { |
345 | logfilestate = LOGFILE_ERROR; |
352 | logfilestate = LOGFILE_ERROR; |
346 | UART1_PutString("\r\nError getting free gpx-file name\r\n"); |
353 | UART1_PutString("\r\nError getting free gpx-file name\r\n"); |
- | 354 | SD_LoggingError = 12; |
|
347 | } |
355 | } |
348 | // else retry in next loop |
356 | // else retry in next loop |
349 | part = 0; |
357 | part = 0; |
350 | break; |
358 | break; |
351 | case LOGFILE_OPENED: |
359 | case LOGFILE_OPENED: |
Line 355... | Line 363... | ||
355 | { |
363 | { |
356 | if(!GPX_LoggGPSCoordinates(&logfile,part)) |
364 | if(!GPX_LoggGPSCoordinates(&logfile,part)) |
357 | { // error logging data |
365 | { // error logging data |
358 | UART1_PutString("\r\nError logging to gpx-file\r\n"); |
366 | UART1_PutString("\r\nError logging to gpx-file\r\n"); |
359 | GPX_DocumentClose(&logfile); |
367 | GPX_DocumentClose(&logfile); |
- | 368 | SD_LoggingError = 13; |
|
360 | logfilestate = LOGFILE_ERROR; |
369 | logfilestate = LOGFILE_ERROR; |
361 | } |
370 | } |
362 | else // successful log |
371 | else // successful log |
363 | { |
372 | { |
364 | if(CheckDelay(flushtimer)) |
373 | if(CheckDelay(flushtimer)) |
Line 393... | Line 402... | ||
393 | part = 0; |
402 | part = 0; |
394 | } |
403 | } |
395 | else // could not be closed |
404 | else // could not be closed |
396 | { |
405 | { |
397 | UART1_PutString("\r\nError closing gpx-file\r\n"); |
406 | UART1_PutString("\r\nError closing gpx-file\r\n"); |
- | 407 | SD_LoggingError = 14; |
|
398 | logfilestate = LOGFILE_ERROR; |
408 | logfilestate = LOGFILE_ERROR; |
399 | part = 0; |
409 | part = 0; |
400 | } |
410 | } |
401 | } |
411 | } |
402 | } //EOF model is not flying |
412 | } //EOF model is not flying |
Line 407... | Line 417... | ||
407 | 417 | ||
408 | //---------------------------------------------------------------------------------------------------- |
418 | //---------------------------------------------------------------------------------------------------- |
409 | // initialize logging |
419 | // initialize logging |
410 | void Logging_Init(void) |
420 | void Logging_Init(void) |
- | 421 | { |
|
411 | { |
422 | SD_LoggingError = 0; |
412 | LogCfg.KML_Interval = 500; //default |
423 | LogCfg.KML_Interval = 500; //default |
413 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
424 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
Line 414... | Line 425... | ||
414 | if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < 500) LogCfg.KML_Interval = 500; |
425 | if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < 500) LogCfg.KML_Interval = 500; |
Line 428... | Line 439... | ||
428 | static u32 logtimer = 0; |
439 | static u32 logtimer = 0; |
429 | static logfilestate_t logstate = LOGFILE_IDLE; |
440 | static logfilestate_t logstate = LOGFILE_IDLE; |
Line 430... | Line 441... | ||
430 | 441 | ||
431 | if(SD_SWITCH) // a card is in slot |
442 | if(SD_SWITCH) // a card is in slot |
- | 443 | { |
|
432 | { |
444 | if((logstate == LOGFILE_ERROR) && (FC.StatusFlags & FC_STATUS_START)) SD_LoggingError = 100; |
433 | if(CheckDelay(logtimer)) |
445 | if(CheckDelay(logtimer)) |
434 | { |
446 | { |
435 | logtimer = SetDelay(10); // faster makes no sense |
447 | logtimer = SetDelay(10); // faster makes no sense |
436 | // call the logger handlers if no error has occured |
448 | // call the logger handlers if no error has occured |
Line 450... | Line 462... | ||
450 | break; |
462 | break; |
451 | } |
463 | } |
452 | } |
464 | } |
453 | else // a logging error has occured |
465 | else // a logging error has occured |
454 | { |
466 | { |
455 | /* |
467 | // /* |
456 | // try to reinitialize sd-card when motors are not running |
468 | // try to reinitialize sd-card when motors are not running |
457 | if(!(FC.Flags & FCFLAG_MOTOR_RUN)) |
469 | if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) |
458 | { |
470 | { |
459 | if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside |
471 | if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside |
460 | { |
472 | { |
461 | Logging_Init(); // initialize the logs |
473 | Logging_Init(); // initialize the logs |
462 | logstate = LOGFILE_IDLE; |
474 | logstate = LOGFILE_IDLE; |
463 | logtimer = SetDelay(10); // try next log in 10 mili sec |
475 | logtimer = SetDelay(100); // try next log in 100 mili sec |
464 | } |
476 | } |
465 | else |
477 | else |
466 | { // retry in 5 seconds |
478 | { // retry in 5 seconds |
467 | logtimer = SetDelay(5000); // try again in 5 sec |
479 | logtimer = SetDelay(5000); // try again in 5 sec |
468 | } |
480 | } |
469 | } // EOF motors are not running |
481 | } // EOF motors are not running |
470 | */ |
482 | // */ |
471 | } //EOF logfile error |
483 | } //EOF logfile error |
472 | } // EOF CheckDelay |
484 | } // EOF CheckDelay |
473 | }// EOF Card in Slot |
485 | }// EOF Card in Slot |
474 | } |
486 | } |