Subversion Repositories NaviCtrl

Rev

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

Rev 496 Rev 497
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"
-
 
Line 65... Line 64...
65
 
64
 
Line 66... Line 65...
66
 
65
 
Line 363... Line 362...
363
{
362
{
364
        File_t *fp;
363
        File_t *fp;
365
        s8 wpline[LINE_MAX];
364
        s8 wpline[LINE_MAX];
366
        u8 retval = WPL_ERROR;
365
        u8 retval = WPL_ERROR;
Line 367... Line -...
367
       
-
 
-
 
366
       
368
 
367
        if(PointCount == 0) return(WPL_NO_WAYPOINTS);
369
        // user absolute path, i.e. leading /   
368
        // user absolute path, i.e. leading /   
370
        if(pWPL_Store->Index == 0)
369
        if(pWPL_Store->Index == 0)
371
        {
370
        {
372
                sprintf(wpline, "/default.wpl");
371
                sprintf(wpline, "/default.wpl");
Line 395... Line 394...
395
                }
394
                }
396
                // Create general section and key entries
395
                // Create general section and key entries
397
                fputs_("[General]\r\n", fp);
396
                fputs_("[General]\r\n", fp);
398
                sprintf(wpline, "Name=%s\r\n",  pWPL_Store->Name);
397
                sprintf(wpline, "Name=%s\r\n",  pWPL_Store->Name);
399
                fputs_(wpline, fp);
398
                fputs_(wpline, fp);
400
                sprintf(wpline, "PositionType=%d\r\n",  pWPL_Store->Type);
-
 
401
                fputs_(wpline, fp);
-
 
402
                sprintf(wpline, "FileVersion=%d\r\n", WP_FILE_VERSION_COMPATIBLE);
399
                sprintf(wpline, "FileVersion=%d\r\n", WP_FILE_VERSION_COMPATIBLE);
403
                fputs_(wpline, fp);
400
                fputs_(wpline, fp);
404
                sprintf(wpline, "NumberOfWaypoints=%d\r\n", PointCount);
401
                sprintf(wpline, "NumberOfWaypoints=%d\r\n", PointCount);
405
                fputs_(wpline, fp);
402
                fputs_(wpline, fp);
406
                // dump all points if existent
403
                // dump all points if existent
Line 465... Line 462...
465
                                fputs_(wpline, fp);
462
                                fputs_(wpline, fp);
466
                                // write point type
463
                                // write point type
467
                                sprintf(wpline, "Type=%d\r\n", PointList[i].Type + 1);
464
                                sprintf(wpline, "Type=%d\r\n", PointList[i].Type + 1);
468
                                fputs_(wpline, fp);    
465
                                fputs_(wpline, fp);    
469
                                // write prefix 
466
                                // write prefix 
470
                                //if(PointList[i].Type == POINT_TYPE_WP) u8_1 = 'P';
-
 
471
                                //else u8_1 = '0';
-
 
472
                                sprintf(wpline, "Prefix=%s\r\n", PointList[i].Name);
467
                                sprintf(wpline, "Prefix=%s\r\n", PointList[i].Name);
473
                                fputs_(wpline, fp);
468
                                fputs_(wpline, fp);
474
                        } // EOF loop over all points
469
                        } // EOF loop over all points
475
                } // EOF if(PointCount)
470
                } // EOF if(PointCount)
476
                if(EOF == fclose_(fp))
471
                if(EOF == fclose_(fp))
Line 481... Line 476...
481
                {
476
                {
482
                        UART1_PutString("ok\r\n");
477
                        UART1_PutString("ok\r\n");
483
                        retval = WPL_OK;
478
                        retval = WPL_OK;
484
                }                                
479
                }                                
485
        } // EOF if(Fat16_IsValid())
480
        } // EOF if(Fat16_IsValid())
-
 
481
        else
-
 
482
        {
486
        else UART1_PutString("no file system found!\r\n");     
483
                UART1_PutString("no file system found!\r\n");
-
 
484
                retval = WPL_NO_SDCARD_FOUND;
-
 
485
        }
487
        return(retval);
486
        return(retval);
488
}
487
}
Line 489... Line 488...
489
 
488
 
490
// load actual point list from SD card
489
// load actual point list from SD card
Line 498... Line 497...
498
        u8 i;
497
        u8 i;
Line 499... Line 498...
499
 
498
 
500
        u8 IsGeneralSection = 0;
499
        u8 IsGeneralSection = 0;
501
        u8 IsPointSection  = 0;
500
        u8 IsPointSection  = 0;
502
        u8 WPNumber = 0;
501
        u8 WPNumber = 0;
503
 
502
 
504
        // user absolute path, i.e. leading /
503
        // user absolute path, i.e. leading /
505
        if(pWPL_Store->Index == 0) // index 0 looks for a default WPL file in the root
504
        if(pWPL_Store->Index == 0) // index 0 looks for a default WPL file in the root
506
        {
505
        {
507
                sprintf(wpline, "/default.wpl");       
506
                sprintf(wpline, "/default.wpl");       
Line 652... Line 651...
652
                                                        if(strcmp(name, "NUMBEROFWAYPOINTS") == 0)
651
                                                        if(strcmp(name, "NUMBEROFWAYPOINTS") == 0)
653
                                                        {      
652
                                                        {      
654
                                                                WPNumber = (u8)atoi(value);
653
                                                                WPNumber = (u8)atoi(value);
655
                                                                if(!WPNumber) // no waypoints in file
654
                                                                if(!WPNumber) // no waypoints in file
656
                                                                {
655
                                                                {
657
                                                                        return(1); // we are done here  
656
                                                                        return(WPL_NO_WAYPOINTS); // we are done here   
658
                                                                }
657
                                                                }
659
                                                                else if(WPNumber > MAX_LIST_LEN) // number o points larger than ram list
658
                                                                else if(WPNumber > MAX_LIST_LEN) // number o points larger than ram list
660
                                                                {
659
                                                                {
661
                                                                        UART1_PutString("To much points!");
660
                                                                        UART1_PutString("To much points!");
662
                                                                        return(0);
661
                                                                        return(WPL_ERROR);
663
                                                                }
662
                                                                }
664
                                                        }
663
                                                        }
665
                                                        else if (strcmp(name, "FILEVERSION") == 0)
664
                                                        else if (strcmp(name, "FILEVERSION") == 0)
666
                                                        {
665
                                                        {
667
                                                                if((u8)atoi(value) != WP_FILE_VERSION_COMPATIBLE)
666
                                                                if((u8)atoi(value) != WP_FILE_VERSION_COMPATIBLE)
Line 676... Line 675...
676
                                                                u8 len = strlen(value);
675
                                                                u8 len = strlen(value);
677
                                                                if(len > 11)
676
                                                                if(len > 11)
678
                                                                value[11] = 0;
677
                                                                value[11] = 0;
679
                                                                memcpy(pWPL_Store->Name, value, 12);
678
                                                                memcpy(pWPL_Store->Name, value, 12);
680
                                                        }
679
                                                        }
681
                                                        else if (strcmp(name, "POSITIONTYPE") == 0)
-
 
682
                                                        {
-
 
683
                                                                pWPL_Store->Type = (u8)atoi(value);
-
 
684
                                                        }
-
 
685
                                                        else
680
                                                        else
686
                                                        {
681
                                                        {
687
                                                                UART1_PutString("Unknown key: ");
682
                                                                UART1_PutString("Unknown key: ");
688
                                                                UART1_PutString(name);
683
                                                                UART1_PutString(name);
689
                                                                UART1_PutString("\r\n");
684
                                                                UART1_PutString("\r\n");
Line 693... Line 688...
693
                                } // EOF key entry line
688
                                } // EOF key entry line
694
                        } // valid line
689
                        } // valid line
695
                } // EOF loop over all lines
690
                } // EOF loop over all lines
696
                fclose_(fp);
691
                fclose_(fp);
697
                NaviData.WaypointNumber = WPCount;
692
                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
-
 
705
                                UART1_PutString("no reference position!\r\n");
-
 
706
                        }
-
 
707
                       
-
 
708
                }
-
 
709
                else
-
 
710
                {       // nothing to do
-
 
711
                        retval = WPL_OK;        
693
                retval = WPL_OK;        
712
                }
-
 
713
                if(retval == WPL_OK) UART1_PutString("ok\r\n");                          
694
                UART1_PutString("ok\r\n");                               
714
        } // EOF if(Fat16_IsValid())
695
        } // EOF if(Fat16_IsValid())
-
 
696
        else
-
 
697
        {
715
        else UART1_PutString("no file system found!\r\n");     
698
                UART1_PutString("no file system found!\r\n");
-
 
699
                retval = WPL_NO_SDCARD_FOUND;
-
 
700
        }      
716
        return(retval);
701
        return(retval);
717
}
702
}
Line 718... Line 703...
718
 
703
 
719
// move actual point list to ref pos., the point in the list marked by index gets the RefPos afterwards
704
// move actual point list to ref pos., the point in the list marked by index gets the RefPos afterwards