同時通信確認版

Dependencies:   mbed mbed

Fork of Scarlet_relay_V4 by 航空研究会

Files at this revision

API Documentation at this revision

Comitter:
taknokolat
Date:
Sun Sep 23 16:31:10 2018 +0000
Parent:
4:c08f2e993acc
Commit message:
a

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c08f2e993acc -r 4e6f8015de81 main.cpp
--- a/main.cpp	Sat Sep 22 08:56:53 2018 +0000
+++ b/main.cpp	Sun Sep 23 16:31:10 2018 +0000
@@ -11,11 +11,19 @@
  
 void ISR_Serial_Rx()
 {
-       static char SFbuf[16];
+        static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
         static int bufcounter=0;
         char g_landingcommand;
+        char g_landingcommand_2;
+        char g_landingcommand_3;
         
-            SFbuf[bufcounter] = pc.getc();    
+            if(pc.readable()) {    // 受信確認
+            
+                SFbuf[bufcounter] = pc.getc();    // 1文字取り出し
+                if(SFbuf[0]!='S'){
+                     //pc.printf("x");
+                     return;
+                }      
         
         
         
@@ -23,32 +31,44 @@
             
         if(bufcounter==5 && SFbuf[4]=='F'){
             g_landingcommand = SFbuf[1];
+            g_landingcommand_2 = SFbuf[2];
+            g_landingcommand_3 = SFbuf[3];
+            NVIC_DisableIRQ(USART1_IRQn);
             pc.printf("S");
             pc.printf("%c",g_landingcommand);
-            pc.printf("A");
-            pc.printf("A");
+            pc.printf("%c",g_landingcommand_2);
+            pc.printf("%c",g_landingcommand_3);
             pc.printf("F");
+            NVIC_EnableIRQ(USART1_IRQn);
             wait_ms(31);
             bufcounter = 0;
-            memset(SFbuf, 0, strlen(SFbuf));
+            memset(SFbuf, 0, sizeof(SFbuf));
          }
             else if(bufcounter>=5 ){
                 //pc.printf("Communication Falsed.\r\n");
                 bufcounter = 0;
-                memset(SFbuf, 0, strlen(SFbuf));
+                memset(SFbuf, 0, sizeof(SFbuf));
             } 
-           
+           }
 }
 
 
 void ISR_Serial_Rx_jevois()
 {
-       NVIC_DisableIRQ(USART2_IRQn);
-       static char SFbuf2[16];
+       
+       static char SFbuf2[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
        static int bufcounter2=0;
-       char g_landingcommand2; 
-        
-            SFbuf2[bufcounter2] = pc2.getc();    
+       char g_landingcommand2;
+       char g_landingcommand2_2; 
+       char g_landingcommand2_3;
+        //NVIC_DisableIRQ(USART2_IRQn);
+            if(pc2.readable()) {    // 受信確認
+            
+                SFbuf2[bufcounter2] = pc2.getc();    // 1文字取り出し
+                if(SFbuf2[0]!='S'){
+                     //pc.printf("x");
+                     return;
+              }     
         
         
         
@@ -56,22 +76,25 @@
             
         if(bufcounter2==5 && SFbuf2[4]=='F'){
             g_landingcommand2 = SFbuf2[1];
+            g_landingcommand2_2 = SFbuf2[2];
+            g_landingcommand2_3 = SFbuf2[3];
             pc.printf("S");
             pc.printf("%c",g_landingcommand2);
-            pc.printf("A");
-            pc.printf("A");
+            pc.printf("%c",g_landingcommand2_2);
+            pc.printf("%c",g_landingcommand2_3);
             pc.printf("F");
             wait_ms(31);
             bufcounter2 = 0;
-            memset(SFbuf2, 0, strlen(SFbuf2));
+            memset(SFbuf2, 0, sizeof(SFbuf2));
          }
             else if(bufcounter2>=5 ){
                 //pc.printf("Communication Falsed.\r\n");
                 bufcounter2 = 0;
-                memset(SFbuf2, 0, strlen(SFbuf2));
+                memset(SFbuf2, 0, sizeof(SFbuf2));
             } 
-            NVIC_EnableIRQ(USART2_IRQn);
-           
+            
+           }
+           //NVIC_EnableIRQ(USART2_IRQn);
 }
  
 int main()
@@ -85,8 +108,7 @@
     NVIC_SetPriority(USART2_IRQn,1);
  
     while (1) { 
-        NVIC_SetPriority(USART1_IRQn,0);
-        NVIC_SetPriority(USART2_IRQn,1);
+        
        
        // wait(1.0);