X-Git-Url: http://git.droids-corp.org/?p=protos%2Fimu.git;a=blobdiff_plain;f=gps_venus.c;h=01551a68d2a7529e2521a29d85e253854dbba688;hp=7119f8ccca504ec79758594c5c0a34ee6a7411c8;hb=f8d665eef7b761e3b769af6b8dd9711754711cdd;hpb=80d45bc2bf74e4f2833ec9427d145ecd7d8c13b7 diff --git a/gps_venus.c b/gps_venus.c index 7119f8c..01551a6 100644 --- a/gps_venus.c +++ b/gps_venus.c @@ -16,6 +16,7 @@ #include "partition.h" #include "sd_raw.h" #include "sd_raw_config.h" +#include "sd_log.h" #define debug_printf(args...) do { } while (0) /* #define debug_printf(args...) printf(args) */ @@ -533,138 +534,18 @@ int gps_venus_init(void) return 0; } -static uint8_t find_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry) +void gps_get_pos(struct gps_pos *pos) { - (void)fs; - - while(fat_read_dir(dd, dir_entry)) - { - if(strcmp(dir_entry->long_name, name) == 0) - { - fat_reset_dir(dd); - return 1; - } - } - - return 0; -} - -static struct fat_file_struct* open_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name) -{ - struct fat_dir_entry_struct file_entry; - if(!find_file_in_dir(fs, dd, name, &file_entry)) - return 0; - - return fat_open_file(fs, &file_entry); -} - -static struct fat_file_struct *open_log_file(void) -{ - struct fat_file_struct *fd; - struct fat_fs_struct *fs; - struct partition_struct *partition ; - struct fat_dir_struct *dd; - struct fat_dir_entry_struct directory; - struct fat_dir_entry_struct file_entry; - int16_t i = 0; - char name[16]; - - /* setup sd card slot */ - if (!sd_raw_init()) { -#if SD_DEBUG - printf_P(PSTR("MMC/SD initialization failed\n")); -#endif - return NULL; - } - - /* open first partition */ - partition = partition_open(sd_raw_read, - sd_raw_read_interval, -#if SD_RAW_WRITE_SUPPORT - sd_raw_write, sd_raw_write_interval, -#else - 0, 0, -#endif - 0); - - if (!partition) { - /* If the partition did not open, assume the storage device - * is a "superfloppy", i.e. has no MBR. - */ - partition = partition_open(sd_raw_read, - sd_raw_read_interval, -#if SD_RAW_WRITE_SUPPORT - sd_raw_write, - sd_raw_write_interval, -#else - 0, - 0, -#endif - -1); - if (!partition) { -#if SD_DEBUG - printf_P(PSTR("opening partition failed\n")); -#endif - return NULL; - } - } - - /* open file system */ - fs = fat_open(partition); - if (!fs) { -#if SD_DEBUG - printf_P(PSTR("opening filesystem failed\n")); -#endif - return NULL; - } - - /* open root directory */ - fat_get_dir_entry_of_path(fs, "/", &directory); - dd = fat_open_dir(fs, &directory); - if (!dd) { -#if SD_DEBUG - printf_P(PSTR("opening root directory failed\n")); -#endif - return NULL; - } - - /* print some card information as a boot message */ - //print_disk_info(fs); - - printf("choose log file name\n"); - while (1) { - snprintf(name, sizeof(name), "log%.4d", i++); - if (!find_file_in_dir(fs, dd, name, &file_entry)) - break; - } - - printf("create log file %s\n", name); - if (!fat_create_file(dd, name, &file_entry)) { - printf_P(PSTR("error creating file: ")); - } - - fd = open_file_in_dir(fs, dd, name); - if (!fd) { - printf_P(PSTR("error opening ")); - return NULL; - } - - return fd; + memcpy(pos, &gps_pos, sizeof(*pos)); } int gps_loop(void) { - struct fat_file_struct *fd = NULL; uint32_t ms; - uint8_t flags; + uint8_t flags, prio; int16_t len; char buf[128]; - - if (1) { - fd = open_log_file(); - if (fd == NULL) - printf("open log failed\r\n"); - } + struct gps_pos pos; while (1) { @@ -672,20 +553,26 @@ int gps_loop(void) ms = global_ms; IRQ_UNLOCK(flags); - if (fd != NULL) { + /* get position (prevent modification of gps pos during copy) */ + prio = callout_mgr_set_prio(&imuboard.intr_cm, GPS_PRIO); + gps_get_pos(&pos); + callout_mgr_restore_prio(&imuboard.intr_cm, prio); + + /* XXX copy */ + len = snprintf(buf, sizeof(buf), + "%"PRIu32" " + "svnum %.2X lat %3.5f long %3.5f " + "alt %3.5f sea_alt %3.5f\n", + ms, gps_pos.sv_num, + (double)gps_pos.latitude/10000000., + (double)gps_pos.longitude/10000000., + (double)gps_pos.altitude/100., + (double)gps_pos.sea_altitude/100.); + - /* XXX copy */ - len = snprintf(buf, sizeof(buf), - "%"PRIu32" " - "svnum %.2X lat %3.5f long %3.5f " - "alt %3.5f sea_alt %3.5f\n", - ms, gps_pos.sv_num, - (double)gps_pos.latitude/10000000., - (double)gps_pos.longitude/10000000., - (double)gps_pos.altitude/100., - (double)gps_pos.sea_altitude/100.); + if (sd_log_enabled()) { - if (fat_write_file(fd, (unsigned char *)buf, len) != len) { + if (sd_log_write(buf, len) != len) { printf_P(PSTR("error writing to file\n")); return -1; }