I'm still struggling with my gps logger. I want to save the gps data from a NEO-6M and save it to an SD card as a .gpx. I can save the content without error:
<trkpt lat="48.191566" lon="15.202584"> <ele>246.1</ele> <time>2019-11-08T12:09:53Z</time> </trkpt>
But the GPX file itself needs a header, which would be this:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <gpx version="1.1" creator="GPS Visualizer https://www.gpsvisualizer.com/" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"> <trk> <name>Logging</name> <trkseg>
When I try to write the header before the endless loop cycle, something goes wrong, because the avr keeps resetting. At this case the only thing has been written on the card is the header string. I'm using the FatFs ( http://elm-chan.org/fsw/ff/00index_e.html ). I know that many things can goes wrong, but at first glance do you have any idea what can be the problem? Maybe I'm just simply using the FatFs wrong. Here is the code:
const char header[] = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n" "<gpx version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n<trk>\n" " <name>Logging</name>\n" " <trkseg>"; const char ending[] = " </trkseg>\n</trk>\n</gpx>"; void FormatGPXData(char* input, float lat, float lon, char* alt, char* speed, char* time, char* date) { float intpart = 0; float latitude = modff(lat / 100.0 , &intpart) / 60 * 100 + intpart; float longitude = modff(lon / 100.0 , &intpart) / 60 * 100 + intpart; sprintf(input, " <trkpt lat=\"%f\" lon=\"%f\">\n <ele>%s</ele>\n <time>%sT%sZ</time>\n <speed>%s</speed>\n </trkpt>\n", latitude, longitude, alt, date, time, speed); } int main(void) { uint8_t i = 0; uint8_t status = D_ERROR; char sentence[100U]; char sd_data[160U]; char c = '\0'; FRESULT fr; FATFS fs; FIL fil; UART_Init(9600); RingBuffer_InitBuffer(&Buffer); LCDInit(LS_NONE); LCDClear(); LCDWriteStringXY(0, 0, "Welcome"); f_mount(&fs, "", 0); fr = open_append(&fil, "logfile.gpx"); if(fr == FR_OK) { f_printf(&fil, header); f_close(&fil); } sei(); while(1) { while (c != '$') { while(RingBuffer_IsEmpty(&Buffer)); // wait until chars arrive { c = RingBuffer_Remove(&Buffer); } } sentence[i++] = c; while (c != '\n') { while(RingBuffer_IsEmpty(&Buffer)); // wait until chars arrive { c = RingBuffer_Remove(&Buffer); sentence[i++] = c; } } sentence[i] = '\0'; i = 0; status = proc_sentence(sentence); if(status == OK) { f_mount(&fs, "", 0); fr = open_append(&fil, "logfile.gpx"); if (fr == FR_OK) { if(gpgll_datas.data_arrive == TRUE) { FormatGPXData(sd_data, gprmc_datas.latitude, gprmc_datas.longitude, gpgga_datas.altitude, gpvtg_datas.speed_kmh, gprmc_datas.time, gprmc_datas.date); f_printf(&fil, sd_data); fr = f_close(&fil); LCDClear(); LCDWriteStringXY(0, 0, gpgga_datas.satellites); LCDWriteStringXY(8, 0, gpgga_datas.altitude); LCDWriteStringXY(0, 1, gpvtg_datas.speed_kmh); gpgll_datas.data_arrive = FALSE; } } status = D_ERROR; } else { LCDClear(); LCDWriteStringXY(0, 0, "StatErr"); }