kk
Dependencies: SDFileSystem mbed
Fork of cansat_kk by
main.cpp@1:fa44a6246bcc, 2016-02-29 (annotated)
- Committer:
- mosukro
- Date:
- Mon Feb 29 17:05:54 2016 +0000
- Revision:
- 1:fa44a6246bcc
- Parent:
- 0:649fc30be6ec
- Child:
- 2:be9046fb5859
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nike3221 | 0:649fc30be6ec | 1 | #include "mbed.h" |
Nike3221 | 0:649fc30be6ec | 2 | #include "SDFileSystem.h" |
Nike3221 | 0:649fc30be6ec | 3 | |
Nike3221 | 0:649fc30be6ec | 4 | Ticker timer; |
Nike3221 | 0:649fc30be6ec | 5 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board |
mosukro | 1:fa44a6246bcc | 6 | Serial gps(p28, p27); // tx, rx |
Nike3221 | 0:649fc30be6ec | 7 | Serial pc(USBTX, USBRX); // tx, rx |
Nike3221 | 0:649fc30be6ec | 8 | PwmOut moterl(p21);//左モーター |
Nike3221 | 0:649fc30be6ec | 9 | PwmOut moterr(p22);//右モーター |
Nike3221 | 0:649fc30be6ec | 10 | DigitalOut led1(LED1); |
Nike3221 | 0:649fc30be6ec | 11 | DigitalOut fet3(p23);//ニクロム線 |
Nike3221 | 0:649fc30be6ec | 12 | DigitalOut led2(LED2); |
Nike3221 | 0:649fc30be6ec | 13 | DigitalOut led3(LED3); |
Nike3221 | 0:649fc30be6ec | 14 | DigitalOut led4(LED4); |
Nike3221 | 0:649fc30be6ec | 15 | DigitalOut janpa1(p19);//パラシュートの開きを検知 |
Nike3221 | 0:649fc30be6ec | 16 | DigitalIn janpa2(p20);//パラシュートの開きを検知 |
Nike3221 | 0:649fc30be6ec | 17 | |
mosukro | 1:fa44a6246bcc | 18 | char gps_data[256]; |
mosukro | 1:fa44a6246bcc | 19 | float longitude,latitude,gpstime,knot,angle; |
Nike3221 | 0:649fc30be6ec | 20 | int i=0; |
Nike3221 | 0:649fc30be6ec | 21 | |
mosukro | 1:fa44a6246bcc | 22 | void gps_rx()//GPSデータ受信割り込み |
Nike3221 | 0:649fc30be6ec | 23 | { |
mosukro | 1:fa44a6246bcc | 24 | gps_data[i] = gps.getc(); |
mosukro | 1:fa44a6246bcc | 25 | if( gps_data[i] == '$' ) |
mosukro | 1:fa44a6246bcc | 26 | { |
mosukro | 1:fa44a6246bcc | 27 | //$から受信データを保持する |
mosukro | 1:fa44a6246bcc | 28 | gps_data[0] = '$'; |
mosukro | 1:fa44a6246bcc | 29 | i = 1; |
mosukro | 1:fa44a6246bcc | 30 | } |
mosukro | 1:fa44a6246bcc | 31 | else if( gps_data[i-1] == '\r' && gps_data[i] == '\n' ) |
mosukro | 1:fa44a6246bcc | 32 | { |
mosukro | 1:fa44a6246bcc | 33 | // 改行コードまでのデータを解析する |
mosukro | 1:fa44a6246bcc | 34 | gps_data[i+1] = '\0'; |
mosukro | 1:fa44a6246bcc | 35 | if(memcmp(gps_data, "$GPRMC",6) == 0) |
mosukro | 1:fa44a6246bcc | 36 | { |
mosukro | 1:fa44a6246bcc | 37 | // $GPRMCで始ってればデータを分けて格納 |
mosukro | 1:fa44a6246bcc | 38 | sscanf(gps_data,"$GPRMC,%f,A,%f,N,%f,E,%f,%f",&gpstime,&longitude,&latitude,&knot,&angle); |
mosukro | 1:fa44a6246bcc | 39 | } |
mosukro | 1:fa44a6246bcc | 40 | //データをSDに書き込み |
mosukro | 1:fa44a6246bcc | 41 | mkdir("/sd/mydir", 0777); |
mosukro | 1:fa44a6246bcc | 42 | FILE *fp = fopen("/sd/mydir/gpsdata.txt", "a"); |
mosukro | 1:fa44a6246bcc | 43 | if(fp == NULL) |
mosukro | 1:fa44a6246bcc | 44 | { |
mosukro | 1:fa44a6246bcc | 45 | error("Could not open file for write\n"); |
mosukro | 1:fa44a6246bcc | 46 | } |
mosukro | 1:fa44a6246bcc | 47 | fprintf(fp,"%s \n",gps_data); |
mosukro | 1:fa44a6246bcc | 48 | fclose(fp); |
Nike3221 | 0:649fc30be6ec | 49 | |
mosukro | 1:fa44a6246bcc | 50 | //PCにデータ送信 |
mosukro | 1:fa44a6246bcc | 51 | pc.printf("%s \n",gps_data); |
mosukro | 1:fa44a6246bcc | 52 | i = 0; |
mosukro | 1:fa44a6246bcc | 53 | } |
mosukro | 1:fa44a6246bcc | 54 | else |
mosukro | 1:fa44a6246bcc | 55 | { |
mosukro | 1:fa44a6246bcc | 56 | //改行コードが来るまでカウントを続ける |
mosukro | 1:fa44a6246bcc | 57 | i++; |
mosukro | 1:fa44a6246bcc | 58 | if(i==255){ |
mosukro | 1:fa44a6246bcc | 59 | pc.printf("*** Error! ***\n"); |
mosukro | 1:fa44a6246bcc | 60 | } |
mosukro | 1:fa44a6246bcc | 61 | } |
Nike3221 | 0:649fc30be6ec | 62 | |
Nike3221 | 0:649fc30be6ec | 63 | } |
Nike3221 | 0:649fc30be6ec | 64 | |
mosukro | 1:fa44a6246bcc | 65 | void move() |
Nike3221 | 0:649fc30be6ec | 66 | { |
mosukro | 1:fa44a6246bcc | 67 | //動作 |
Nike3221 | 0:649fc30be6ec | 68 | } |
mosukro | 1:fa44a6246bcc | 69 | |
mosukro | 1:fa44a6246bcc | 70 | int main() |
mosukro | 1:fa44a6246bcc | 71 | { |
mosukro | 1:fa44a6246bcc | 72 | gps.baud(9600); |
mosukro | 1:fa44a6246bcc | 73 | gps.attach(gps_rx, Serial::RxIrq);//GPS割り込み |
mosukro | 1:fa44a6246bcc | 74 | |
Nike3221 | 0:649fc30be6ec | 75 | while(1) |
Nike3221 | 0:649fc30be6ec | 76 | { |
mosukro | 1:fa44a6246bcc | 77 | move(); |
Nike3221 | 0:649fc30be6ec | 78 | } |
mosukro | 1:fa44a6246bcc | 79 | |
Nike3221 | 0:649fc30be6ec | 80 | } |