change2shinsu

Dependencies:   mbed mbedTimer SDFileSystem MU2 GPS

main.cpp

Committer:
Nerosho
Date:
2019-08-03
Revision:
2:d6dc5c2224cc
Parent:
1:a8772ca26d1b
Child:
3:4f1bac105598

File content as of revision 2:d6dc5c2224cc:

#include "mbed.h"
#include "MU2.h"
#include "SDFileSystem.h"
//#include "GPS.h"

MU2 MuPort(p9,p10);
SDFileSystem sd(p5, p6, p7, p8, "sd");
//GPS gps(p13,p14);
Serial gps(p13,p14); //tx, rx


DigitalIn flight(p21);    //フライトピン
DigitalOut FIRE(p26);    //溶断

DigitalOut myled(LED1);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);

int main()
{

    wait(3);

    //FILE* fp1= fopen("/sd/cansat/log3.txt", "w");
    FILE* fp2= fopen("/sd/cansat/gpsdata10.csv", "w");
    
    /*if(fp1 == NULL || fp2 == NULL)
{
    (fp1 == NULL) ? fprintf(stderr, "fname1 open error.\n") : fclose(fp1);
    (fp2 == NULL) ? fprintf(stderr, "fname2 open error.\n") : fclose(fp2);
    return -1;
}*/

    

    //fprintf(fp1, "CanSat start!\r\n");

    while(1) { //溶断機構
        if (flight==1) {
            wait(2);
        }

        else {
            //fprintf(fp1, "Fire!!\r\n");
            //FIRE=1;
            myled=1;//テストようにLED光らせてる
            wait(5);//溶断にかかる時間TBD秒
            //FIRE=0;
            myled=0;
            break;
        }
    }



    gps.baud(9600);
    char recvGPS=0;
    char getGPS[128];
    int i=0;
    
    //fprintf(fp1, "GPS start!\r\n");




    while(1) {
        if(gps.readable()) {


            recvGPS=gps.getc();
            getGPS[i]=recvGPS;

            if(getGPS[i]=='\n') {

                if((getGPS[5]=='G')&&(getGPS[6]=='A')) {

                    MuPort.send(getGPS);

                    /*if(fp == NULL) {
                        error("Could not open file for write\n");
                    }*/
                    
                    fprintf(fp2, "%s\n",getGPS);
                    //fclose(fp);
                    wait(1);

                }

                i=0;

            }

            i++;

        }

        // wait(1);
        //fclose(fp);
    }
    //fclose(fp1);
    fclose(fp2);

}