X-Git-Url: http://git.droids-corp.org/?p=protos%2Fimu.git;a=blobdiff_plain;f=gps_venus.c;h=22e2076ca0312c6c6532e770f437aa033c429999;hp=7150ef2fcadbb575fd2b91c9993584a67e5c160a;hb=9976bc2b818f3cb985e83509d01141fb95b4533a;hpb=b80b5b2fa35d632456556f9940314b565a60e802 diff --git a/gps_venus.c b/gps_venus.c index 7150ef2..22e2076 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) */ @@ -96,8 +97,8 @@ typedef struct { -/* 0x08 - nema interval */ -#define M_NEMAINTERVAL 0x08 +/* 0x08 - nmea interval */ +#define M_NMEAINTERVAL 0x08 typedef struct { uint8_t gga; uint8_t gsa; @@ -111,7 +112,7 @@ typedef struct { 1 - flash */ -} m_nemainterval_t; +} m_nmeainterval_t; /* 0x09 - Query Software Version */ @@ -119,7 +120,7 @@ typedef struct { typedef struct { uint8_t msg_type; /* 00 = no output - 01 = nema output + 01 = nmea output 02 = binary output */ } m_output_t; @@ -237,13 +238,15 @@ void venus634_rate(void) memset(&rate,0,sizeof(m_rate_t)); rate.rate = 20; - //rate.rate = 0; /* ram */ + rate.attributes = 0; /* ram */ venus634_send(M_RATE,&rate,sizeof(m_rate_t)); return; } +/* Wide Area Augmentation System: use ground stations to increase the precision + * of gps position */ void venus634_waas(void) { m_waas_t waas; @@ -257,7 +260,7 @@ void venus634_waas(void) return; } - +/* Tell we are a car instead of a pedestrian */ void venus634_navmode(void) { m_navmode_t navmode; @@ -271,23 +274,26 @@ void venus634_navmode(void) return; } - -void venus634_nema_interval(void) +/* frequency of NMEA messages */ +void venus634_nmea_interval(void) { - m_nemainterval_t nemainterval; + m_nmeainterval_t nmeainterval; + + memset(&nmeainterval,0,sizeof(m_nmeainterval_t)); - memset(&nemainterval,0,sizeof(m_nemainterval_t)); - nemainterval.gga = 1; - nemainterval.gsa = 1; - nemainterval.gsv = 1; - nemainterval.gll = 1; - nemainterval.rmc = 1; - nemainterval.vtg = 1; - nemainterval.zda = 1; + /* set frequency for nmea: 1 = once every one position fix, 2 = once + * every two position fix, ... */ + nmeainterval.gga = 1; /* GPGGA interval - GPS Fix Data*/ + nmeainterval.gsa = 1; /* GNSS DOPS and Active Satellites */ + nmeainterval.gsv = 1; /* GNSS Satellites in View */ + nmeainterval.gll = 1; /* Geographic Position - Latitude longitude */ + nmeainterval.rmc = 1; /* Recomended Minimum Specific GNSS Sentence */ + nmeainterval.vtg = 1; /* Course Over Ground and Ground Speed */ + nmeainterval.zda = 1; /* Time & Date*/ - nemainterval.attributes = 1; /* ram flash */ + nmeainterval.attributes = 1; /* ram flash */ - venus634_send(M_NEMAINTERVAL,&nemainterval,sizeof(m_nemainterval_t)); + venus634_send(M_NMEAINTERVAL,&nmeainterval,sizeof(m_nmeainterval_t)); return; } @@ -407,10 +413,14 @@ int wait_ack(int msg_type) static int decode_gps_pos(uint8_t *buf, uint16_t len) { struct gps_pos *pos = (struct gps_pos *)buf; + uint8_t irq_flags; if (len != sizeof(*pos)) return -1; + if (pos->msg_id != 0xA8) /* XXX not tested */ + return -1; + gps_pos.gps_week = ntohs(pos->gps_week); gps_pos.tow = ntohl(pos->tow); @@ -430,6 +440,11 @@ static int decode_gps_pos(uint8_t *buf, uint16_t len) gps_pos.ecef_vy = ntohl(pos->ecef_vy); gps_pos.ecef_vz = ntohl(pos->ecef_vz); + /* update global structure */ + IRQ_LOCK(irq_flags); + memcpy(&gps_pos, pos, sizeof(gps_pos)); + IRQ_UNLOCK(irq_flags); + return 0; } @@ -533,125 +548,6 @@ 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)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; -} - void gps_get_pos(struct gps_pos *pos) { memcpy(pos, &gps_pos, sizeof(*pos)); @@ -659,19 +555,12 @@ void gps_get_pos(struct gps_pos *pos) int gps_loop(void) { - struct fat_file_struct *fd = NULL; uint32_t ms; uint8_t flags, prio; int16_t len; char buf[128]; struct gps_pos pos; - if (1) { - fd = open_log_file(); - if (fd == NULL) - printf("open log failed\r\n"); - } - while (1) { IRQ_LOCK(flags); @@ -695,13 +584,16 @@ int gps_loop(void) (double)gps_pos.sea_altitude/100.); - if (fd != NULL) { + 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; } } + else + printf("%s", buf); + } return 0;