#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) */
-/* 0x08 - nema interval */
-#define M_NEMAINTERVAL 0x08
+/* 0x08 - nmea interval */
+#define M_NMEAINTERVAL 0x08
typedef struct {
uint8_t gga;
uint8_t gsa;
1 - flash
*/
-} m_nemainterval_t;
+} m_nmeainterval_t;
/* 0x09 - Query Software Version */
typedef struct {
uint8_t msg_type; /*
00 = no output
- 01 = nema output
+ 01 = nmea output
02 = binary output
*/
} m_output_t;
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;
return;
}
-
+/* Tell we are a car instead of a pedestrian */
void venus634_navmode(void)
{
m_navmode_t navmode;
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;
}
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);
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;
}
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)
+void gps_get_pos(struct gps_pos *pos)
{
- 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) {
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 (fat_write_file(fd, (unsigned char *)buf, len) != len) {
+
+ if (sd_log_enabled()) {
+
+ if (sd_log_write(buf, len) != len) {
printf_P(PSTR("error writing to file\n"));
return -1;
}
}
+ else
+ printf("%s", buf);
+
}
return 0;