Subversion Repositories NaviCtrl

Rev

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

Rev 79 Rev 82
Line 68... Line 68...
68
#include "timer.h"
68
#include "timer.h"
69
#include "spi_slave.h"
69
#include "spi_slave.h"
70
#include "fat16.h"
70
#include "fat16.h"
71
#include "usb.h"
71
#include "usb.h"
72
#include "sdc.h"
72
#include "sdc.h"
73
#include "kml.h"
73
#include "logging.h"
74
#include "main.h"
74
#include "main.h"
Line 75... Line -...
75
 
-
 
76
 
-
 
77
typedef enum
-
 
78
{
-
 
79
        LOGFILE_IDLE,
-
 
80
        LOGFILE_START,
-
 
81
        LOGFILE_CLOSED,
-
 
82
        LOGFILE_OPENED,
-
 
83
        LOGFILE_ERROR,
-
 
84
} logfilestate_t;
-
 
85
 
75
 
86
u32 TimerCompassUpdate;
76
u32 TimerCompassUpdate;
87
u32 TimerKmlAddPointDelay;
77
u32 TimerLogDelay;
88
u32 TimerCheckError;
78
u32 TimerCheckError;
89
u32 ErrorCode = 0;
79
u32 ErrorCode = 0;
Line 90... Line 80...
90
u16 BeepTime;
80
u16 BeepTime;
Line 221... Line 211...
221
 
211
 
222
 
212
 
223
//----------------------------------------------------------------------------------------------------
213
//----------------------------------------------------------------------------------------------------
224
int main(void)
-
 
225
{
-
 
226
        KML_Document_t gpslogfile;
-
 
227
        logfilestate_t logfilestate = LOGFILE_IDLE;
214
int main(void)
228
        s8* gpslogfilename = NULL;
215
{
229
        /* Configure the system clocks */
-
 
230
        SCU_Config();
216
        /* Configure the system clocks */
231
        KML_DocumentInit(&gpslogfile);                  // Initialize the new kml-document for further use.
217
        SCU_Config();
232
        /* init VIC (Vectored Interrupt Controller)     */
218
        /* init VIC (Vectored Interrupt Controller)     */
233
        SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC
219
        SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC
234
        SCU_AHBPeriphReset(__VIC, DISABLE);             // disable reset state for VIC
220
        SCU_AHBPeriphReset(__VIC, DISABLE);             // disable reset state for VIC
Line 254... Line 240...
254
        I2C1_Init();
240
        I2C1_Init();
255
        // initialize the gps position controller (needs Timer 1)
241
        // initialize the gps position controller (needs Timer 1)
256
        GPS_Init();
242
        GPS_Init();
257
        // initialize fat16 partition on sd card (needs Timer 1)
243
        // initialize fat16 partition on sd card (needs Timer 1)
258
        Fat16_Init();
244
        Fat16_Init();
-
 
245
        // initialize logging
-
 
246
        Logging_Init();
Line 259... Line 247...
259
 
247
 
260
        TimerCompassUpdate = SetDelay(5);
248
        TimerCompassUpdate = SetDelay(5);
261
        TimerKmlAddPointDelay = SetDelay(250);
249
        TimerLogDelay = SetDelay(250);
262
        TimerCheckError = SetDelay(3000);
250
        TimerCheckError = SetDelay(3000);
263
        SerialPutString("\r\n---------------------------------------------");
251
        SerialPutString("\r\n---------------------------------------------");
264
        SerialPutString("\n\r Version information:");
252
        SerialPutString("\n\r Version information:");
265
        GetNaviCtrlVersion();
253
        GetNaviCtrlVersion();
Line 335... Line 323...
335
                        if(FC.MKFlags & MKFLAG_FLY) NaviData.FlyingTime++; // we want to count the battery-time
323
                        if(FC.MKFlags & MKFLAG_FLY) NaviData.FlyingTime++; // we want to count the battery-time
336
//                      else NaviData.FlyingTime = 0;
324
//                      else NaviData.FlyingTime = 0;
337
                        TimerCheckError = SetDelay(1000);
325
                        TimerCheckError = SetDelay(1000);
338
                        Request_SendFollowMe = TRUE;
326
                        Request_SendFollowMe = TRUE;
339
                }
327
                }
340
                // ---------------- KML Timing ------------------------------------
328
                // ---------------- Logging  ---------------------------------------
341
                if(CheckDelay(TimerKmlAddPointDelay))
-
 
342
                {
-
 
343
                        TimerKmlAddPointDelay = SetDelay(500); // every 500 ms
-
 
344
 
-
 
345
                        if(FC.MKFlags & MKFLAG_MOTOR_RUN)
-
 
346
                        {
-
 
347
                                switch(logfilestate)
329
                Logging_Update();
348
                                {
-
 
349
                                        case LOGFILE_IDLE:
-
 
350
                                        case LOGFILE_CLOSED:
-
 
351
                                                if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D) && (FC.MKFlags & MKFLAG_FLY))
-
 
352
                                                {
-
 
353
                                                        logfilestate = LOGFILE_START;
-
 
354
                                                }
-
 
355
                                                break;
-
 
356
                                        case LOGFILE_START:
-
 
357
                                                // find unused logfile name
-
 
358
                                                do
-
 
359
                                                {        // try to generate a new logfile name
-
 
360
                                                         gpslogfilename = GenerateGPSLogFileName();
-
 
361
                                                }while((gpslogfilename != NULL) && fexist_(gpslogfilename));
-
 
362
                                                // if logfilename exist
-
 
363
                                                if(gpslogfilename != NULL)
-
 
364
                                                {
-
 
365
                                                        // try to create the log file
-
 
366
                                                        if(KML_DocumentOpen(gpslogfilename, &gpslogfile))
-
 
367
                                                        {
-
 
368
                                                                logfilestate = LOGFILE_OPENED; // goto next step
-
 
369
                                                                SerialPutString("\r\nOpening kml-file:");
-
 
370
                                                                SerialPutString(gpslogfilename);
-
 
371
                                                                SerialPutString("\r\n");
-
 
372
                                                        }
-
 
373
                                                        else
-
 
374
                                                        {
-
 
375
                                                                logfilestate = LOGFILE_ERROR;
-
 
376
                                                                SerialPutString("\r\nError opening kml-file: ");
-
 
377
                                                                SerialPutString(gpslogfilename);
-
 
378
                                                                SerialPutString("\r\n");
-
 
379
                                                                TimerKmlAddPointDelay = SetDelay(10);  // try again in open logfile in 10 mili sec
-
 
380
                                                        }
-
 
381
                                                }
-
 
382
                                                // else retry in next loop
-
 
383
                                                break;
-
 
384
                                        case LOGFILE_OPENED:
-
 
385
                                                // append new gps log data
-
 
386
                                                if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))
-
 
387
                                                {
-
 
388
                                                        if(!KML_LoggGPSCoordinates(&(GPSData.Position), &gpslogfile))
-
 
389
                                                        {       // error logging data
-
 
390
                                                                SerialPutString("\r\nError Logging GPS data\r\n");
-
 
391
                                                                KML_DocumentClose(&gpslogfile);
-
 
392
                                                                logfilestate = LOGFILE_ERROR;
-
 
393
                                                        }
-
 
394
                                                        else DebugOut.Analog[26]++;     // count SD-Logs
-
 
395
                                                }
-
 
396
                                                break;
-
 
397
 
-
 
398
                                        case LOGFILE_ERROR:
-
 
399
                                                // try to reinitialize the fat16 filesystem
-
 
400
                                                if(0 == Fat16_Init())
-
 
401
                                                {
-
 
402
                                                        logfilestate = LOGFILE_IDLE;
-
 
403
                                                        TimerKmlAddPointDelay = SetDelay(10);  // try again in open logfile in 10 mili sec
-
 
404
                                                }
-
 
405
                                                else
-
 
406
                                                {
-
 
407
                                                        logfilestate = LOGFILE_ERROR;
-
 
408
                                                        TimerKmlAddPointDelay = SetDelay(5000);  // try again in 5 sec
-
 
409
                                                }
-
 
410
                                                break;
-
 
411
 
-
 
412
                                        default:
-
 
413
                                                break;
-
 
414
                                }
-
 
415
                        } // EOF model is flying
-
 
416
                        else // model is not flying
-
 
417
                        {   // close log file if opened
-
 
418
                                if(logfilestate ==  LOGFILE_OPENED)
-
 
419
                                {
-
 
420
                                        if(KML_DocumentClose(&gpslogfile))
-
 
421
                                        {
-
 
422
                                                SerialPutString("\r\nClosing kml-file\r\n");
-
 
423
                                                logfilestate = LOGFILE_CLOSED;
-
 
424
                                        }
-
 
425
                                        else
-
 
426
                                        {
-
 
427
                                                logfilestate =  LOGFILE_ERROR;
-
 
428
                                        }
-
 
429
                                }
-
 
430
                        } //EOF model is not flying
-
 
431
                }
-
 
432
        }
330
        }
433
}
331
}