Subversion Repositories NaviCtrl

Rev

Rev 838 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 838 Rev 867
Line 299... Line 299...
299
// logs gps and state info to a gpx file
299
// logs gps and state info to a gpx file
300
logfilestate_t Logging_GPX(u32 LogDelay)
300
logfilestate_t Logging_GPX(u32 LogDelay)
301
{
301
{
302
        static  logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate
302
        static  logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate
303
        static  s8* logfilename = NULL;                                         // the pointer to the logfilename
303
        static  s8* logfilename = NULL;                                         // the pointer to the logfilename
304
        static  u32 logtimer = 0, flushtimer = 0, appendtimer = 0;              // the log update timer
304
        static  u32 logtimer = 0, flushtimer = 0, appendtimer = 0, errortimer = 0;              // the log update timer
305
        static  GPX_Document_t logfile;                                         // the logfilehandle
305
        static  GPX_Document_t logfile;                                         // the logfilehandle
306
        static  u8 part = 0, old_errorcode = 0;
306
        static  u8 part = 0, old_errorcode = 0, cnt_retry = 0;
307
//      u32 measure_time;
307
//      u32 measure_time;
Line 308... Line 308...
308
 
308
 
309
        // initialize if LogDelay is zero
309
        // initialize if LogDelay is zero
310
        if(!LogDelay)
310
        if(!LogDelay)
Line 371... Line 371...
371
                                                        GPX_logging_active = 2;
371
                                                        GPX_logging_active = 2;
372
                                                }
372
                                                }
373
                                                else // could not be openend
373
                                                else // could not be openend
374
                                                {
374
                                                {
375
                                                        logfilestate = LOGFILE_ERROR;
375
                                                        logfilestate = LOGFILE_ERROR;
-
 
376
                                                        errortimer = SetDelay(2000); // retry in 2 sec
376
                                                        UART1_PutString("\r\nError opening gpx-file: ");
377
                                                        UART1_PutString("\r\nError opening gpx-file: ");
377
                                                        UART1_PutString(logfilename);
378
                                                        UART1_PutString(logfilename);
378
                                                        UART1_PutString("\r\n");
379
                                                        UART1_PutString("\r\n");
379
                                                        SD_LoggingError = 11;
380
                                                        SD_LoggingError = 11;
380
                                                        logtimer = SetDelay(10);  // try again in open logfile in 10 mili sec
381
                                                        logtimer = SetDelay(10);  // try again in open logfile in 10 mili sec
Line 383... Line 384...
383
                                        }
384
                                        }
384
                                        else
385
                                        else
385
                                        {
386
                                        {
386
                                                logfilestate = LOGFILE_ERROR;
387
                                                logfilestate = LOGFILE_ERROR;
387
                                                UART1_PutString("\r\nError getting free gpx-file name\r\n");
388
                                                UART1_PutString("\r\nError getting free gpx-file name\r\n");
-
 
389
                                                errortimer = SetDelay(2000); // retry in 2 sec
388
                                                SD_LoggingError = 12;
390
                                                SD_LoggingError = 12;
389
                                        }
391
                                        }
390
                                        // else retry in next loop
392
                                        // else retry in next loop
391
                                        part = 0;
393
                                        part = 0;
392
                                        break;
394
                                        break;
393
                                case LOGFILE_OPENED:
395
                                case LOGFILE_OPENED:
394
                                        // append new gps log data
396
                                        // append new gps log data
395
//                                      measure_time = CountMilliseconds;
397
//                                      measure_time = CountMilliseconds;
396
//                                      if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))
398
//                                      if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))
397
                                        {
399
                                        {
398
                                                if(!GPX_LoggGPSCoordinates(&logfile,part))
400
                                                if(!GPX_LoggGPSCoordinates(&logfile,part)/* || (Parameter.User5 > 100)*/)
399
                                                {       // error logging data
401
                                                {       // error logging data
400
                                                        UART1_PutString("\r\nError logging to gpx-file\r\n");
402
                                                        UART1_PutString("\r\nError logging to gpx-file\r\n");
401
                                                        GPX_DocumentClose(&logfile);
403
                                                        GPX_DocumentClose(&logfile);
402
                                                        SD_LoggingError = 13;
404
                                                        SD_LoggingError = 13;
403
                                                        logfilestate = LOGFILE_ERROR;
405
                                                        logfilestate = LOGFILE_ERROR;
-
 
406
                                                        errortimer = SetDelay(2000); // retry in 2 sec
404
                                                }
407
                                                }
405
                                                else // successful log
408
                                                else // successful log
406
                                                {
409
                                                {
407
                                                        if(ErrorCode != old_errorcode || CheckDelay(flushtimer) || part == 8)
410
                                                        if(ErrorCode != old_errorcode || CheckDelay(flushtimer) || part == 8)
408
                                                        {
411
                                                        {
Line 417... Line 420...
417
                                        if(++part >= 9) part = 0;
420
                                        if(++part >= 9) part = 0;
418
//DebugOut.Analog[] = CountMilliseconds - measure_time;
421
//DebugOut.Analog[] = CountMilliseconds - measure_time;
419
                                        break;
422
                                        break;
Line 420... Line 423...
420
 
423
 
-
 
424
                                case LOGFILE_ERROR:
-
 
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++;
421
                                case LOGFILE_ERROR:
431
                                          }
422
                                        part = 0;
432
                                        part = 0;
Line 423... Line 433...
423
                                        break;
433
                                        break;
424
 
434
 
Line 440... Line 450...
440
                                }
450
                                }
441
                                else  // could not be closed
451
                                else  // could not be closed
442
                                {
452
                                {
443
                                        UART1_PutString("\r\nError closing gpx-file\r\n");
453
                                        UART1_PutString("\r\nError closing gpx-file\r\n");
444
                                        SD_LoggingError = 14;
454
                                        SD_LoggingError = 14;
445
                                        logfilestate =  LOGFILE_ERROR;
455
                                        logfilestate = LOGFILE_ERROR;
446
                                        part = 0;
456
                                        part = 0;
447
                                }
457
                                }
448
                        }
458
                        }
-
 
459
                        else
-
 
460
                        {
-
 
461
                          if(logfilestate == LOGFILE_ERROR) logfilestate = LOGFILE_IDLE;
-
 
462
                          cnt_retry = 0;
-
 
463
                        }
449
                } //EOF model is not flying
464
                } //EOF model is not flying
450
        } // EOF Check LogTimer
465
        } // EOF Check LogTimer
Line 451... Line 466...
451
 
466
 
452
        return logfilestate;
467
        return logfilestate;
Line 471... Line 486...
471
 
486
 
472
//----------------------------------------------------------------------------------------------------
487
//----------------------------------------------------------------------------------------------------
473
// gobal logging handler
488
// gobal logging handler
474
void Logging_Update(void)
489
void Logging_Update(void)
475
{
490
{
476
        static u8 logmodule = 0;
491
        static u8 logmodule = 0, retry_in_flight_cnt = 0;
477
        static u32 logtimer = 0;
492
        static u32 logtimer = 0;
Line 478... Line 493...
478
        static logfilestate_t logstate = LOGFILE_IDLE;
493
        static logfilestate_t logstate = LOGFILE_IDLE;
479
 
494
 
Line 517... Line 532...
517
                                        }
532
                                        }
518
                                        else
533
                                        else
519
                                        {   // retry in 5 seconds
534
                                        {   // retry in 5 seconds
520
                                                logtimer = SetDelay(5000);  // try again in 5 sec
535
                                                logtimer = SetDelay(5000);  // try again in 5 sec
521
                                        }
536
                                        }
-
 
537
                                 retry_in_flight_cnt = 0;
522
                                } // EOF motors are not running
538
                                } // EOF motors are not running
-
 
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
 
523
//                              */
557
//                              */
524
                        } //EOF logfile error
558
                        } //EOF logfile error
525
                }  // EOF CheckDelay
559
                }  // EOF CheckDelay
526
        }// EOF Card in Slot
560
        }// EOF Card in Slot
527
}
561
}