同時通信確認版

Dependencies:   mbed mbed

Fork of Scarlet_relay_V4 by 航空研究会

main.cpp

Committer:
taknokolat
Date:
2018-09-23
Revision:
5:4e6f8015de81
Parent:
4:c08f2e993acc

File content as of revision 5:4e6f8015de81:

#include "mbed.h"
//#include "Serial.h"

RawSerial pc(PA_2,PA_3,115200);
RawSerial pc2(PB_6,PB_7,115200);
//Serial MySerial1(PA_2,PA_3);




 
void ISR_Serial_Rx()
{
        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;
        
            if(pc.readable()) {    // 受信確認
            
                SFbuf[bufcounter] = pc.getc();    // 1文字取り出し
                if(SFbuf[0]!='S'){
                     //pc.printf("x");
                     return;
                }      
        
        
        
        if(SFbuf[0]=='S'&&bufcounter<5) bufcounter++;
            
        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("%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, sizeof(SFbuf));
         }
            else if(bufcounter>=5 ){
                //pc.printf("Communication Falsed.\r\n");
                bufcounter = 0;
                memset(SFbuf, 0, sizeof(SFbuf));
            } 
           }
}


void ISR_Serial_Rx_jevois()
{
       
       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;
       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;
              }     
        
        
        
        if(SFbuf2[0]=='S'&&bufcounter2<5) bufcounter2++;
            
        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("%c",g_landingcommand2_2);
            pc.printf("%c",g_landingcommand2_3);
            pc.printf("F");
            wait_ms(31);
            bufcounter2 = 0;
            memset(SFbuf2, 0, sizeof(SFbuf2));
         }
            else if(bufcounter2>=5 ){
                //pc.printf("Communication Falsed.\r\n");
                bufcounter2 = 0;
                memset(SFbuf2, 0, sizeof(SFbuf2));
            } 
            
           }
           //NVIC_EnableIRQ(USART2_IRQn);
}
 
int main()
{
     
    // シリアル通信受信の割り込みイベント登録
    pc.attach(ISR_Serial_Rx, Serial::RxIrq);
    pc2.attach(ISR_Serial_Rx_jevois, Serial::RxIrq);
    
    NVIC_SetPriority(USART1_IRQn,0);
    NVIC_SetPriority(USART2_IRQn,1);
 
    while (1) { 
        
       
       // wait(1.0);
 
        }
    
}