Subversion Repositories NaviCtrl

Rev

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

Rev 495 Rev 496
Line 59... Line 59...
59
#include <string.h>
59
#include <string.h>
60
#include "91x_lib.h"
60
#include "91x_lib.h"
61
#include "waypoints.h"
61
#include "waypoints.h"
62
#include "uart1.h"
62
#include "uart1.h"
63
#include "fat16.h"
63
#include "fat16.h"
-
 
64
#include "spi_slave.h"
-
 
65
 
-
 
66
 
-
 
67
WPL_Store_t WPL_Store;
Line 64... Line 68...
64
 
68
 
65
// the waypoints list
69
// the waypoints list
Line 66... Line 70...
66
#define MAX_LIST_LEN 101
70
#define MAX_LIST_LEN 101
Line 358... Line 362...
358
u8 PointList_SaveToFile(WPL_Store_t * pWPL_Store)
362
u8 PointList_SaveToFile(WPL_Store_t * pWPL_Store)
359
{
363
{
360
        File_t *fp;
364
        File_t *fp;
361
        s8 wpline[LINE_MAX];
365
        s8 wpline[LINE_MAX];
362
        u8 retval = WPL_ERROR;
366
        u8 retval = WPL_ERROR;
363
        // user absolute path, i.e. leading /
-
 
Line 364... Line -...
364
       
-
 
Line -... Line 367...
-
 
367
       
-
 
368
 
-
 
369
        // user absolute path, i.e. leading /   
-
 
370
        if(pWPL_Store->Index == 0)
-
 
371
        {
-
 
372
                sprintf(wpline, "/default.wpl");
-
 
373
        }
-
 
374
        else
-
 
375
        {
365
        sprintf(wpline, "/list_%03d.wpl", pWPL_Store->Index);
376
                sprintf(wpline, "/WPL/list_%03d.wpl", pWPL_Store->Index);
Line 366... Line 377...
366
 
377
        }
367
        UART1_PutString("\n\r Save WPL...");
378
        UART1_PutString("\n\r Save WPL...");
368
 
379
 
Line 478... Line 489...
478
 
489
 
479
// load actual point list from SD card
490
// load actual point list from SD card
480
u8 PointList_ReadFromFile(WPL_Store_t * pWPL_Store)
491
u8 PointList_ReadFromFile(WPL_Store_t * pWPL_Store)
481
{
492
{
482
        File_t *fp;
493
        File_t *fp;
-
 
494
        s8 wpline[LINE_MAX];
Line 483... Line 495...
483
        s8 wpline[LINE_MAX], retval = 0;
495
        u8 retval = WPL_ERROR;
484
       
496
       
Line 485... Line 497...
485
        s8 *name, *value;
497
        s8 *name, *value;
486
        u8 i;
498
        u8 i;
487
 
499
 
Line 488... Line 500...
488
        u8 IsGeneralSection = 0;
500
        u8 IsGeneralSection = 0;
-
 
501
        u8 IsPointSection  = 0;
-
 
502
        u8 WPNumber = 0;
-
 
503
 
-
 
504
        // user absolute path, i.e. leading /
-
 
505
        if(pWPL_Store->Index == 0) // index 0 looks for a default WPL file in the root
-
 
506
        {
489
        u8 IsPointSection  = 0;
507
                sprintf(wpline, "/default.wpl");       
-
 
508
        }
Line 490... Line 509...
490
        u8 WPNumber = 0;
509
        else
491
 
510
        {
492
        // user absolute path, i.e. leading /
511
                sprintf(wpline, "/WPL/list_%03d.wpl", pWPL_Store->Index);
Line 500... Line 519...
500
        {       // check if wpl file is existing
519
        {       // check if wpl file is existing
501
                fp = fopen_(wpline, 'r');               // try to open the file
520
                fp = fopen_(wpline, 'r');               // try to open the file
502
                if(fp == NULL)
521
                if(fp == NULL)
503
                {
522
                {
504
                        UART1_PutString("ERROR: Reading waypoint file!\r\n");
523
                        UART1_PutString("ERROR: Reading waypoint file!\r\n");
505
                        return(0);
524
                        return(retval);
506
                }
525
                }
507
                // clear point list first
526
                // clear point list first
508
                PointList_Clear();
527
                PointList_Clear();
509
                // read all lines from file
528
                // read all lines from file
510
                while(fgets_(wpline, LINE_MAX, fp) != 0)
529
                while(fgets_(wpline, LINE_MAX, fp) != 0)
Line 645... Line 664...
645
                                                        }
664
                                                        }
646
                                                        else if (strcmp(name, "FILEVERSION") == 0)
665
                                                        else if (strcmp(name, "FILEVERSION") == 0)
647
                                                        {
666
                                                        {
648
                                                                if((u8)atoi(value) != WP_FILE_VERSION_COMPATIBLE)
667
                                                                if((u8)atoi(value) != WP_FILE_VERSION_COMPATIBLE)
649
                                                                {
668
                                                                {
-
 
669
                                                                        PointList_Clear();
650
                                                                        UART1_PutString("Bad file version!\r\n");
670
                                                                        UART1_PutString("Bad file version!\r\n");
651
                                                                        return(0);     
671
                                                                        return(WPL_ERROR);     
652
                                                                }
672
                                                                }
653
                                                        }
673
                                                        }
654
                                                        else if (strcmp(name, "NAME") == 0)
674
                                                        else if (strcmp(name, "NAME") == 0)
655
                                                        {
675
                                                        {
656
                                                                u8 len = strlen(value);
676
                                                                u8 len = strlen(value);
Line 673... Line 693...
673
                                } // EOF key entry line
693
                                } // EOF key entry line
674
                        } // valid line
694
                        } // valid line
675
                } // EOF loop over all lines
695
                } // EOF loop over all lines
676
                fclose_(fp);
696
                fclose_(fp);
677
                NaviData.WaypointNumber = WPCount;
697
                NaviData.WaypointNumber = WPCount;
-
 
698
                // if the WPS data are relative to home position
-
 
699
                if(pWPL_Store->Type == WPL_STORE_TYPE_REL)
-
 
700
                {       // try to shift the wp list 
-
 
701
                        if(PointList_Move(1, &(NaviData.HomePosition))) retval = WPL_OK;
-
 
702
                        else
-
 
703
                        {
-
 
704
                                PointList_Clear(); // to avoid wrong absolute positions
678
                UART1_PutString("ok\r\n");
705
                                UART1_PutString("no reference position!\r\n");
-
 
706
                        }
-
 
707
                       
-
 
708
                }
-
 
709
                else
-
 
710
                {       // nothing to do
679
                retval = 1;                              
711
                        retval = WPL_OK;        
-
 
712
                }
-
 
713
                if(retval == WPL_OK) UART1_PutString("ok\r\n");                          
680
        } // EOF if(Fat16_IsValid())
714
        } // EOF if(Fat16_IsValid())
681
        else UART1_PutString("no file system found!\r\n");     
715
        else UART1_PutString("no file system found!\r\n");     
682
        return(retval);
716
        return(retval);
683
}
717
}