2021千草のl432(センサー)側プログラム

Dependencies:   BufferedSerial SDFileSystem mbed

Revision:
3:c1456d673aaf
Parent:
2:4c7d64e27929
Child:
4:5bc7cddcc1cd
--- a/main.cpp	Tue Aug 30 23:19:42 2022 +0000
+++ b/main.cpp	Fri Sep 09 13:31:55 2022 +0000
@@ -2,9 +2,9 @@
  * Copyright (c) 2019 ARM Limited
  * SPDX-License-Identifier: Apache-2.0
  */
- 
- /*センサーにコマンドを送信するのはとりあえず後回し
- GPSのデータを受信するのも後回し*/
+
+/*センサーにコマンドを送信するのはとりあえず後回し
+GPSのデータを受信するのも後回し*/
 
 #include "mbed.h"
 #include "SDFileSystem.h"
@@ -14,7 +14,10 @@
 Serial jy901(PA_9,PA_10);
 SDFileSystem sd(PA_7, PA_6, PA_5, PA_4, "sd");  //mosi, miso, sck, cs
 //BufferedSerial f303(PA_2,PA_3,38400);
-Serial f303(PA_2,PA_3,38400);
+//Serial f303(PA_2,PA_3,38400);
+DigitalIn F2L_1(PA_3);
+DigitalIn F2L_2(PA_2);
+
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 //Serial pc(USBTX, USBRX,38400);//ボーレートを落とすと,USB側からのデータが正確に出力されない.
@@ -28,50 +31,52 @@
 void getGPS();  //GPSデータを取得し、f303に送信する関数
 void StandbyCommand();
 void MakeFile();
- 
+
 int main()
 {
     comm.attach(StandbyCommand,1);    //割り込みで1秒ごとにf303からのコマンドを取得
-    
+
     /**********************
     //センサーのsleepモードを終わらせて、キャリブレーションを開始する関数
     *****************/
-    
+
     /*while(sig==1){//次のシグナルがくるまでの間
         JY901();
     }
-    
+
     while(sig==2){
         getGPS();
     }*/
 }
 
-void StandbyCommand(){
+void StandbyCommand()
+{
     //printf("StandbyCommand start\r\n");
     sig=getSignal();
-    switch(sig){
-      case 1:
-      //comm.detach();
-      MakeFile();
-      break;
-      
-      case 2:
-      comm.detach();
-      while(1){
-          getGPS();
-      }
-      break;
+    switch(sig) {
+        case 2:
+            //comm.detach();
+            MakeFile();
+            break;
+
+        case 3:
+            comm.detach();
+            while(1) {
+                getGPS();
+            }
+            break;
     }
 }
 
-void MakeFile(){
-    mkdir("/sd/2021MR", 0777);   
+void MakeFile()
+{
+    mkdir("/sd/2021MR", 0777);
     FILE *fp = fopen("/sd/2021MR/chigusa.bin", "w");
     if(fp == NULL) {
         error("Could not open file for write\n");
     }
-    
-    while(sig!=2){
+
+    while(sig!=3) {
         fputc(jy901.getc(),fp);
         //JY901();
     }
@@ -79,11 +84,11 @@
 }
 
 /*void JY901(){
-    
-}*/
 
+}*/
+/*
 int getSignal(){    //センサー起動のタイミングで1を返し、センサー終了してGPS送信するタイミングで2を返す関数。
-    
+
     //while(1){   //s:撮影終了、p:フライトピン作動,c:撮影終了・GPS送信
     //printf("getSignal start\r\n");
     int i=0;
@@ -94,8 +99,8 @@
                 //printf("readable\r\n");
                 led1=1;
                 wait(0.1);
-                led1=0;                
-                
+                led1=0;
+
                 char temp = f303.getc();//一文字読み込む
                 //printf("%c\r\n",temp);
                 str[i++] = temp;
@@ -113,19 +118,19 @@
                     //printf("get p\r\n");
                     led2=1;
                     wait(0.1);
-                    led2=0;  
-                    wait(0.1);                  
+                    led2=0;
+                    wait(0.1);
                     led2=1;
                     wait(0.1);
                     led2=0;
                     return 2;
                 }
                 else if(str[i-1]=='c'){ //ブザー作動後、センサー記録を停止
-                    //printf("get c\r\n");     
+                    //printf("get c\r\n");
                     led2=1;
                     wait(0.1);
-                    led2=0;  
-                    wait(0.1);                  
+                    led2=0;
+                    wait(0.1);
                     led2=1;
                     wait(0.1);
                     led2=0;
@@ -134,10 +139,53 @@
                     wait(0.1);
                     led2=0;
                     return 3;
-                }  
+                }
+}*/
+
+int getSignal()     //センサー起動のタイミングで2を返し、センサー終了のタイミングで3を返す関数。
+{
+
+    //printf("get Command\r\n");
+    if(F2L_1 == 1) {
+        if(F2L_2 == 1) {  //手動でカメラの動作が停止された場合
+            //printf("get s!!\r\n");
+            led2=1;
+            wait(0.1);
+            led2=0;
+            return 1;
+        } else { //フライトピンが作動した場合
+            //printf("get p\r\n");
+            led2=1;
+            wait(0.1);
+            led2=0;
+            wait(0.1);
+            led2=1;
+            wait(0.1);
+            led2=0;
+            return 2;
+        }
+    } else {
+        if(F2L_2 == 1) { //地上に降着しブザーが作動した場合
+            //printf("get c\r\n");
+            led2=1;
+            wait(0.1);
+            led2=0;
+            wait(0.1);
+            led2=1;
+            wait(0.1);
+            led2=0;
+            wait(0.1);
+            led2=1;
+            wait(0.1);
+            led2=0;
+            return 3;
+        }
+    }
+
 }
 
-void getGPS(){
+void getGPS()
+{
     char buf[10000],data[10000];
     int ucRxCnt,j=0;
     //string GPSStatus="";
@@ -145,48 +193,46 @@
     if(fp == NULL) {
         error("Could not open file for write\n");
     }*/
-    
-    for(int i=0;i<10000;i++){
+
+    for(int i=0; i<10000; i++) {
         buf[i]=jy901.getc();
     }
-    
-    while(j<=int(sizeof(buf)/sizeof(buf[0]))){        
+
+    while(j<=int(sizeof(buf)/sizeof(buf[0]))) {
         data[ucRxCnt++]=buf[j];  //Store the received data in the buffer
-        if (data[0]!=0x55){ //The data header is not correct, then restart to find the 0x55 data header
+        if (data[0]!=0x55) { //The data header is not correct, then restart to find the 0x55 data header
             ucRxCnt=0;
-           // printf("not start sig\n");
-        }
-        else if(ucRxCnt<11) {
-           //printf("data is less than 11\n\r");
+            // printf("not start sig\n");
+        } else if(ucRxCnt<11) {
+            //printf("data is less than 11\n\r");
         }//If the data is less than 11, alert.
-        else{
+        else {
             //printf("switch\n\r");
-            switch(data[1])//Determine what kind of data the data is, and then copy it to the corresponding structure. Some data packets need to open the corresponding output through the upper computer before receiving the data of this data packet.
-            {
-               /* case 0x50:    memcpy(&stcTime,&ucRxBuffer[2],8);break;//memcpy is a memory copy function that comes with the compiler. You need to reference "string.h" to copy the characters of the receive buffer into the data structure to achieve data parsing.
-                case 0x51:  
-                    printf("case 0x51 worked!");
-                    memcpy(&stcAcc,&data[2],8);
-                    fprintf(facc,"Acc,%.3f,%.3f,%.3f\r\n",(float)stcAcc.a[0]/32768*16,(float)stcAcc.a[1]/32768*16,(float)stcAcc.a[2]/32768*16);
+            switch(data[1]) { //Determine what kind of data the data is, and then copy it to the corresponding structure. Some data packets need to open the corresponding output through the upper computer before receiving the data of this data packet.
+                /* case 0x50:    memcpy(&stcTime,&ucRxBuffer[2],8);break;//memcpy is a memory copy function that comes with the compiler. You need to reference "string.h" to copy the characters of the receive buffer into the data structure to achieve data parsing.
+                 case 0x51:
+                     printf("case 0x51 worked!");
+                     memcpy(&stcAcc,&data[2],8);
+                     fprintf(facc,"Acc,%.3f,%.3f,%.3f\r\n",(float)stcAcc.a[0]/32768*16,(float)stcAcc.a[1]/32768*16,(float)stcAcc.a[2]/32768*16);
+                     break;
+                 case 0x52:  memcpy(&stcGyro,&ucRxBuffer[2],8);break;
+                 case 0x53:  memcpy(&stcAngle,&ucRxBuffer[2],8);break;
+                 case 0x54:  memcpy(&stcMag,&ucRxBuffer[2],8);break;
+                 case 0x55:  memcpy(&stcDStatus,&ucRxBuffer[2],8);break;
+                 case 0x56:  memcpy(&stcPress,&ucRxBuffer[2],8);break;
+                 case 0x57:  memcpy(&stcLonLat,&ucRxBuffer[2],8);break;*/
+                case 0x58:
+                    //memcpy(&stcGPSV,&data[2],8);
+                    //sprintf(GPSStatus,"GPSHeight:%.1fm GPSYaw:%.1fDeg GPSV:%.3fkm/h\r\n",(float)stcGPSV.sGPSHeight/10,(float)stcGPSV.sGPSYaw/10,(float)stcGPSV.lGPSVelocity/1000);
+                    //f303.printf("%s",GPSStatus);
+                    //printf("come a GPS data!!");
                     break;
-                case 0x52:  memcpy(&stcGyro,&ucRxBuffer[2],8);break;
-                case 0x53:  memcpy(&stcAngle,&ucRxBuffer[2],8);break;
-                case 0x54:  memcpy(&stcMag,&ucRxBuffer[2],8);break;
-                case 0x55:  memcpy(&stcDStatus,&ucRxBuffer[2],8);break;
-                case 0x56:  memcpy(&stcPress,&ucRxBuffer[2],8);break;
-                case 0x57:  memcpy(&stcLonLat,&ucRxBuffer[2],8);break;*/
-                case 0x58:  
-                //memcpy(&stcGPSV,&data[2],8);
-                //sprintf(GPSStatus,"GPSHeight:%.1fm GPSYaw:%.1fDeg GPSV:%.3fkm/h\r\n",(float)stcGPSV.sGPSHeight/10,(float)stcGPSV.sGPSYaw/10,(float)stcGPSV.lGPSVelocity/1000);
-                //f303.printf("%s",GPSStatus);
-                //printf("come a GPS data!!");
-                break;
-                //case 0x59:  memcpy(&stcQ,&ucRxBuffer[2],8);break;
+                    //case 0x59:  memcpy(&stcQ,&ucRxBuffer[2],8);break;
             }
             ucRxCnt=0;//Clear the cache area
         }
         j++;
     }
-    
-    
+
+
 }
\ No newline at end of file