asdf

Dependencies:   SDFileSystem mbed

Fork of All_Combined_Real by JanPaul Bergeson

main.cpp

Committer:
jphbergeson
Date:
2016-03-10
Revision:
0:26713d1db198
Child:
1:5fa445bd14a6

File content as of revision 0:26713d1db198:

#include "mbed.h"
#include "nmea.h"
#include "SDFileSystem.h"

#define BUF_SIZE 1024

DigitalOut gpo(D0);
DigitalOut led(LED_RED);

Serial duino(PTC4, PTC3);
Serial pc(USBTX, USBRX);

/**************************************************
 **          SD FILE SYSTEM                       **
 **************************************************/
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
FILE *fpData;

int main()
{
    pc.baud(115200); // make sure to set computer TERA Term or whatever to 115200 baud!!!
    duino.baud(9600);
    pc.printf("Initializing ...\r\n");
    char buffer[BUF_SIZE];
    
    while (true) {
        
        led = !led;
        
        get_nmea(&duino, buffer, BUF_SIZE);
        
        struct NMEA_data nmea = parse_line(buffer);
            
        // determine whether there's a lock
        char lock_str[BUF_SIZE];
        if ( nmea.lock_flag == 'A' )
            sprintf(lock_str, "Has lock");
        else 
            sprintf(lock_str, "No lock");
            
        // assemble data into summary string
        char status_str[BUF_SIZE];
        sprintf(status_str, "%02d:%02d:%02d, %d/%d/%d, %dd %lf' %c %dd %lf' %c, %s\r\n", 
            nmea.hours, nmea.minutes, nmea.seconds, 
            nmea.month, nmea.day, nmea.year,
            nmea.latitude, nmea.latitude_minutes, nmea.latitude_direction,
            nmea.longitude, nmea.longitude_minutes, nmea.longitude_direction, lock_str);
        
        // print to pc, sd card
        pc.printf("%s", status_str);
        
        fpData = fopen("/sd/data.txt", "a");
        fprintf(fpData, "%s", status_str);
        fclose(fpData);
        wait(0.5f);
    }
}