Rev 494 | Rev 496 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 494 | Rev 495 | ||
---|---|---|---|
Line 353... | Line 353... | ||
353 | } |
353 | } |
Line 354... | Line 354... | ||
354 | 354 | ||
355 | #define LINE_MAX 70 |
355 | #define LINE_MAX 70 |
356 | #define WP_FILE_VERSION_COMPATIBLE 3 |
356 | #define WP_FILE_VERSION_COMPATIBLE 3 |
357 | // save actual point list to SD card |
357 | // save actual point list to SD card |
358 | u8 PointList_SaveToFile(u8 place, s8 * name) |
358 | u8 PointList_SaveToFile(WPL_Store_t * pWPL_Store) |
359 | { |
359 | { |
360 | File_t *fp; |
360 | File_t *fp; |
- | 361 | s8 wpline[LINE_MAX]; |
|
361 | s8 wpline[LINE_MAX], retval = 0; |
362 | u8 retval = WPL_ERROR; |
362 | // user absolute path, i.e. leading / |
363 | // user absolute path, i.e. leading / |
363 | 364 | ||
364 | sprintf(wpline, "/list_%03d.wpl", place); |
- | |
365 | - | ||
366 | UART1_PutString("\n\r Write "); |
- | |
367 | UART1_PutString(wpline); |
- | |
Line 368... | Line 365... | ||
368 | UART1_PutString("..."); |
365 | sprintf(wpline, "/list_%03d.wpl", pWPL_Store->Index); |
Line 369... | Line 366... | ||
369 | 366 | ||
370 | UART1_PutString("\n\r Save WPL..."); |
367 | UART1_PutString("\n\r Save WPL..."); |
- | 368 | ||
- | 369 | if(Fat16_IsValid()) |
|
- | 370 | { // check if wpl file is existing |
|
- | 371 | if(fexist_(wpline)) |
|
- | 372 | { //file is existent |
|
- | 373 | if(!(pWPL_Store->OverwriteFile)) |
|
- | 374 | { |
|
- | 375 | UART1_PutString("Error: file exist!\r\n"); |
|
371 | 376 | return(WPL_FILEEXIST); |
|
372 | if(Fat16_IsValid()) |
377 | } |
373 | { // check if wpl file is existing |
378 | } |
374 | fp = fopen_(wpline, 'w'); // try to open the file |
379 | fp = fopen_(wpline, 'w'); // try to open the file |
375 | if(fp == NULL) |
380 | if(fp == NULL) |
376 | { |
381 | { |
377 | UART1_PutString("ERROR: Creating waypoint file!\r\n"); |
382 | UART1_PutString("ERROR: Creating waypoint file!\r\n"); |
378 | return(retval); |
383 | return(retval); |
379 | } |
384 | } |
- | 385 | // Create general section and key entries |
|
- | 386 | fputs_("[General]\r\n", fp); |
|
380 | // Create general section and key entries |
387 | sprintf(wpline, "Name=%s\r\n", pWPL_Store->Name); |
381 | fputs_("[General]\r\n", fp); |
388 | fputs_(wpline, fp); |
382 | sprintf(wpline, "Name=%s\r\n", name); |
389 | sprintf(wpline, "PositionType=%d\r\n", pWPL_Store->Type); |
383 | fputs_(wpline, fp); |
390 | fputs_(wpline, fp); |
384 | sprintf(wpline, "FileVersion=%d\r\n", WP_FILE_VERSION_COMPATIBLE); |
391 | sprintf(wpline, "FileVersion=%d\r\n", WP_FILE_VERSION_COMPATIBLE); |
Line 460... | Line 467... | ||
460 | UART1_PutString("failed!\r\n"); |
467 | UART1_PutString("failed!\r\n"); |
461 | } |
468 | } |
462 | else |
469 | else |
463 | { |
470 | { |
464 | UART1_PutString("ok\r\n"); |
471 | UART1_PutString("ok\r\n"); |
465 | retval = 1; |
472 | retval = WPL_OK; |
466 | } |
473 | } |
467 | } // EOF if(Fat16_IsValid()) |
474 | } // EOF if(Fat16_IsValid()) |
468 | else UART1_PutString("no file system found!\r\n"); |
475 | else UART1_PutString("no file system found!\r\n"); |
469 | return(retval); |
476 | return(retval); |
470 | } |
477 | } |
Line 471... | Line 478... | ||
471 | 478 | ||
472 | // load actual point list from SD card |
479 | // load actual point list from SD card |
473 | u8 PointList_ReadFromFile(u8 place) |
480 | u8 PointList_ReadFromFile(WPL_Store_t * pWPL_Store) |
474 | { |
481 | { |
475 | File_t *fp; |
482 | File_t *fp; |
Line 476... | Line 483... | ||
476 | s8 wpline[LINE_MAX], retval = 0; |
483 | s8 wpline[LINE_MAX], retval = 0; |
Line 481... | Line 488... | ||
481 | u8 IsGeneralSection = 0; |
488 | u8 IsGeneralSection = 0; |
482 | u8 IsPointSection = 0; |
489 | u8 IsPointSection = 0; |
483 | u8 WPNumber = 0; |
490 | u8 WPNumber = 0; |
Line 484... | Line 491... | ||
484 | 491 | ||
485 | // user absolute path, i.e. leading / |
492 | // user absolute path, i.e. leading / |
Line 486... | Line 493... | ||
486 | sprintf(wpline, "/list_%03d.wpl", place); |
493 | sprintf(wpline, "/list_%03d.wpl", pWPL_Store->Index); |
487 | 494 | ||
488 | UART1_PutString("\n\r Read "); |
495 | UART1_PutString("\n\r Read "); |
Line 642... | Line 649... | ||
642 | { |
649 | { |
643 | UART1_PutString("Bad file version!\r\n"); |
650 | UART1_PutString("Bad file version!\r\n"); |
644 | return(0); |
651 | return(0); |
645 | } |
652 | } |
646 | } |
653 | } |
- | 654 | else if (strcmp(name, "NAME") == 0) |
|
- | 655 | { |
|
- | 656 | u8 len = strlen(value); |
|
- | 657 | if(len > 11) |
|
- | 658 | value[11] = 0; |
|
- | 659 | memcpy(pWPL_Store->Name, value, 12); |
|
- | 660 | } |
|
- | 661 | else if (strcmp(name, "POSITIONTYPE") == 0) |
|
- | 662 | { |
|
- | 663 | pWPL_Store->Type = (u8)atoi(value); |
|
- | 664 | } |
|
647 | else |
665 | else |
648 | { |
666 | { |
649 | UART1_PutString("Unknown key: "); |
667 | UART1_PutString("Unknown key: "); |
650 | UART1_PutString(name); |
668 | UART1_PutString(name); |
651 | UART1_PutString("\r\n"); |
669 | UART1_PutString("\r\n"); |