change2shinsu

Dependencies:   mbed mbedTimer SDFileSystem MU2 GPS

Committer:
takepiyo
Date:
Mon Aug 05 07:44:41 2019 +0000
Revision:
3:4f1bac105598
Parent:
2:d6dc5c2224cc
Child:
4:0d087e3f731d
jazz;

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