change2shinsu

Dependencies:   mbed mbedTimer SDFileSystem MU2 GPS

Committer:
Nerosho
Date:
Wed Aug 07 10:05:17 2019 +0000
Revision:
5:6d0de80387cf
Parent:
4:0d087e3f731d
Child:
7:c94dd56226a1
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nerosho 0:d0f3991839ec 1 #include "mbed.h"
Nerosho 0:d0f3991839ec 2 #include "MU2.h"
Nerosho 0:d0f3991839ec 3 #include "SDFileSystem.h"
takepiyo 3:4f1bac105598 4 #include "inletclose.h"
Nerosho 2:d6dc5c2224cc 5 //#include "GPS.h"
Nerosho 1:a8772ca26d1b 6
Nerosho 5:6d0de80387cf 7
takepiyo 4:0d087e3f731d 8 MU2 MuPort(p28,p27);
takepiyo 3:4f1bac105598 9 SDFileSystem sd(p11, p12, p13, p14, "sd");
Nerosho 2:d6dc5c2224cc 10 //GPS gps(p13,p14);
takepiyo 3:4f1bac105598 11 Serial gps(p9,p10); //tx, rx
takepiyo 3:4f1bac105598 12
takepiyo 3:4f1bac105598 13 Inlet inlet(p26,p15,p16);//モーター出力,感圧センサー1入力,感圧センサー2入力
Nerosho 2:d6dc5c2224cc 14
Nerosho 0:d0f3991839ec 15
takepiyo 3:4f1bac105598 16 //DigitalIn flight(p21); //フライトピン
takepiyo 3:4f1bac105598 17 DigitalOut FIRE(p24); //溶断
Nerosho 1:a8772ca26d1b 18
Nerosho 1:a8772ca26d1b 19 DigitalOut myled(LED1);
takepiyo 4:0d087e3f731d 20 DigitalOut myled2(LED2);
Nerosho 1:a8772ca26d1b 21 DigitalOut myled3(LED3);
Nerosho 1:a8772ca26d1b 22 DigitalOut myled4(LED4);
Nerosho 0:d0f3991839ec 23
Nerosho 5:6d0de80387cf 24
Nerosho 0:d0f3991839ec 25 int main()
Nerosho 0:d0f3991839ec 26 {
Nerosho 2:d6dc5c2224cc 27
Nerosho 5:6d0de80387cf 28 wait(0.5);//フライトピン抜けてから溶断までの時間
Nerosho 0:d0f3991839ec 29
Nerosho 2:d6dc5c2224cc 30 //FILE* fp1= fopen("/sd/cansat/log3.txt", "w");
Nerosho 5:6d0de80387cf 31 FILE* fp2= fopen("/sd/cansat/gpsdata0806_2.csv", "w");
takepiyo 3:4f1bac105598 32
Nerosho 2:d6dc5c2224cc 33 /*if(fp1 == NULL || fp2 == NULL)
takepiyo 3:4f1bac105598 34 {
Nerosho 2:d6dc5c2224cc 35 (fp1 == NULL) ? fprintf(stderr, "fname1 open error.\n") : fclose(fp1);
Nerosho 2:d6dc5c2224cc 36 (fp2 == NULL) ? fprintf(stderr, "fname2 open error.\n") : fclose(fp2);
Nerosho 2:d6dc5c2224cc 37 return -1;
takepiyo 3:4f1bac105598 38 }*/
Nerosho 5:6d0de80387cf 39
Nerosho 5:6d0de80387cf 40 //fprintf(fp2, "CanSat Start!\n");
Nerosho 2:d6dc5c2224cc 41
takepiyo 3:4f1bac105598 42 //溶断機構部分
Nerosho 2:d6dc5c2224cc 43
Nerosho 2:d6dc5c2224cc 44 //fprintf(fp1, "CanSat start!\r\n");
Nerosho 0:d0f3991839ec 45
takepiyo 3:4f1bac105598 46 //fprintf(fp1, "Fire!!\r\n");
takepiyo 3:4f1bac105598 47 //FIRE=1;
takepiyo 3:4f1bac105598 48 myled=1;//テストようにLED光らせてる
Nerosho 5:6d0de80387cf 49 wait(3);//溶断にかかる時間TBD秒
takepiyo 3:4f1bac105598 50 //FIRE=0;
takepiyo 3:4f1bac105598 51 myled=0;
takepiyo 3:4f1bac105598 52
takepiyo 3:4f1bac105598 53 //溶断機構終わり
Nerosho 0:d0f3991839ec 54
Nerosho 2:d6dc5c2224cc 55 gps.baud(9600);
Nerosho 2:d6dc5c2224cc 56 char recvGPS=0;
Nerosho 2:d6dc5c2224cc 57 char getGPS[128];
Nerosho 2:d6dc5c2224cc 58 int i=0;
takepiyo 3:4f1bac105598 59 int timer=0;
takepiyo 3:4f1bac105598 60
Nerosho 5:6d0de80387cf 61 //fprintf(fp2, "GPS start!!\n");
Nerosho 2:d6dc5c2224cc 62
takepiyo 3:4f1bac105598 63 while(1)
takepiyo 3:4f1bac105598 64 {
takepiyo 4:0d087e3f731d 65 myled3=1;
takepiyo 4:0d087e3f731d 66 myled2=0;
takepiyo 3:4f1bac105598 67 if(gps.readable())
takepiyo 3:4f1bac105598 68 {
Nerosho 2:d6dc5c2224cc 69 recvGPS=gps.getc();
Nerosho 2:d6dc5c2224cc 70 getGPS[i]=recvGPS;
Nerosho 2:d6dc5c2224cc 71
takepiyo 3:4f1bac105598 72 if(getGPS[i]=='\n')
takepiyo 3:4f1bac105598 73 {
Nerosho 2:d6dc5c2224cc 74
takepiyo 3:4f1bac105598 75 if((getGPS[5]=='G')&&(getGPS[6]=='A'))
takepiyo 3:4f1bac105598 76 {
takepiyo 4:0d087e3f731d 77
takepiyo 3:4f1bac105598 78 MuPort.send(getGPS);
takepiyo 3:4f1bac105598 79
Nerosho 2:d6dc5c2224cc 80 /*if(fp == NULL) {
Nerosho 2:d6dc5c2224cc 81 error("Could not open file for write\n");
Nerosho 2:d6dc5c2224cc 82 }*/
takepiyo 3:4f1bac105598 83
Nerosho 5:6d0de80387cf 84
Nerosho 2:d6dc5c2224cc 85 fprintf(fp2, "%s\n",getGPS);
Nerosho 2:d6dc5c2224cc 86 //fclose(fp);
takepiyo 3:4f1bac105598 87
takepiyo 3:4f1bac105598 88 wait(0.1);
takepiyo 4:0d087e3f731d 89 timer++;
Nerosho 2:d6dc5c2224cc 90 }
Nerosho 2:d6dc5c2224cc 91
Nerosho 2:d6dc5c2224cc 92 i=0;
Nerosho 2:d6dc5c2224cc 93 }
Nerosho 5:6d0de80387cf 94
Nerosho 2:d6dc5c2224cc 95 i++;
takepiyo 4:0d087e3f731d 96 if(timer>10)//落下開始してからTBD秒後whileを抜ける.
takepiyo 3:4f1bac105598 97 {
takepiyo 3:4f1bac105598 98 break;
takepiyo 3:4f1bac105598 99 }
Nerosho 2:d6dc5c2224cc 100 }
Nerosho 2:d6dc5c2224cc 101
Nerosho 2:d6dc5c2224cc 102 // wait(1);
Nerosho 2:d6dc5c2224cc 103 //fclose(fp);
Nerosho 0:d0f3991839ec 104 }
takepiyo 3:4f1bac105598 105
takepiyo 3:4f1bac105598 106 while(1)
takepiyo 3:4f1bac105598 107 {
takepiyo 4:0d087e3f731d 108 myled3=0;
takepiyo 4:0d087e3f731d 109 myled2=1;
takepiyo 3:4f1bac105598 110 if(gps.readable())
takepiyo 3:4f1bac105598 111 {
takepiyo 3:4f1bac105598 112 recvGPS=gps.getc();
takepiyo 3:4f1bac105598 113 getGPS[i]=recvGPS;
takepiyo 3:4f1bac105598 114
takepiyo 3:4f1bac105598 115 if(getGPS[i]=='\n')
takepiyo 3:4f1bac105598 116 {
takepiyo 3:4f1bac105598 117
takepiyo 3:4f1bac105598 118 if((getGPS[5]=='G')&&(getGPS[6]=='A'))
takepiyo 3:4f1bac105598 119 {
takepiyo 4:0d087e3f731d 120 MuPort.send(getGPS);
takepiyo 3:4f1bac105598 121
takepiyo 3:4f1bac105598 122 /*if(fp == NULL) {
takepiyo 3:4f1bac105598 123 error("Could not open file for write\n");
takepiyo 3:4f1bac105598 124 }*/
takepiyo 3:4f1bac105598 125
takepiyo 3:4f1bac105598 126 fprintf(fp2, "%s\n",getGPS);
takepiyo 3:4f1bac105598 127 //fclose(fp);
takepiyo 3:4f1bac105598 128 wait(0.1);
takepiyo 3:4f1bac105598 129 }
takepiyo 3:4f1bac105598 130
takepiyo 3:4f1bac105598 131 i=0;
takepiyo 3:4f1bac105598 132 }
takepiyo 3:4f1bac105598 133 i++;
takepiyo 3:4f1bac105598 134 inlet.Close(0.9);
takepiyo 3:4f1bac105598 135 }
takepiyo 3:4f1bac105598 136
takepiyo 3:4f1bac105598 137 // wait(1);
takepiyo 3:4f1bac105598 138 //fclose(fp);
takepiyo 3:4f1bac105598 139 }
takepiyo 3:4f1bac105598 140
takepiyo 3:4f1bac105598 141
Nerosho 2:d6dc5c2224cc 142 //fclose(fp1);
Nerosho 2:d6dc5c2224cc 143 fclose(fp2);
Nerosho 2:d6dc5c2224cc 144
Nerosho 2:d6dc5c2224cc 145 }
Nerosho 2:d6dc5c2224cc 146
Nerosho 2:d6dc5c2224cc 147
Nerosho 2:d6dc5c2224cc 148