同時通信確認版

Dependencies:   mbed mbed

Fork of Scarlet_relay_V4 by 航空研究会

Committer:
taknokolat
Date:
Sun Sep 23 16:31:10 2018 +0000
Revision:
5:4e6f8015de81
Parent:
4:c08f2e993acc
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TUATBM 0:1f2bac0f6ab8 1 #include "mbed.h"
taknokolat 2:f975d9cb584d 2 //#include "Serial.h"
TUATBM 1:e257c3c3f659 3
taknokolat 3:92c039aed84a 4 RawSerial pc(PA_2,PA_3,115200);
taknokolat 4:c08f2e993acc 5 RawSerial pc2(PB_6,PB_7,115200);
TUATBM 1:e257c3c3f659 6 //Serial MySerial1(PA_2,PA_3);
TUATBM 0:1f2bac0f6ab8 7
TUATBM 1:e257c3c3f659 8
taknokolat 4:c08f2e993acc 9
TUATBM 1:e257c3c3f659 10
TUATBM 0:1f2bac0f6ab8 11
TUATBM 0:1f2bac0f6ab8 12 void ISR_Serial_Rx()
TUATBM 0:1f2bac0f6ab8 13 {
taknokolat 5:4e6f8015de81 14 static char SFbuf[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 3:92c039aed84a 15 static int bufcounter=0;
taknokolat 4:c08f2e993acc 16 char g_landingcommand;
taknokolat 5:4e6f8015de81 17 char g_landingcommand_2;
taknokolat 5:4e6f8015de81 18 char g_landingcommand_3;
taknokolat 3:92c039aed84a 19
taknokolat 5:4e6f8015de81 20 if(pc.readable()) { // 受信確認
taknokolat 5:4e6f8015de81 21
taknokolat 5:4e6f8015de81 22 SFbuf[bufcounter] = pc.getc(); // 1文字取り出し
taknokolat 5:4e6f8015de81 23 if(SFbuf[0]!='S'){
taknokolat 5:4e6f8015de81 24 //pc.printf("x");
taknokolat 5:4e6f8015de81 25 return;
taknokolat 5:4e6f8015de81 26 }
taknokolat 3:92c039aed84a 27
taknokolat 3:92c039aed84a 28
taknokolat 3:92c039aed84a 29
taknokolat 3:92c039aed84a 30 if(SFbuf[0]=='S'&&bufcounter<5) bufcounter++;
taknokolat 3:92c039aed84a 31
taknokolat 3:92c039aed84a 32 if(bufcounter==5 && SFbuf[4]=='F'){
taknokolat 3:92c039aed84a 33 g_landingcommand = SFbuf[1];
taknokolat 5:4e6f8015de81 34 g_landingcommand_2 = SFbuf[2];
taknokolat 5:4e6f8015de81 35 g_landingcommand_3 = SFbuf[3];
taknokolat 5:4e6f8015de81 36 NVIC_DisableIRQ(USART1_IRQn);
taknokolat 3:92c039aed84a 37 pc.printf("S");
taknokolat 3:92c039aed84a 38 pc.printf("%c",g_landingcommand);
taknokolat 5:4e6f8015de81 39 pc.printf("%c",g_landingcommand_2);
taknokolat 5:4e6f8015de81 40 pc.printf("%c",g_landingcommand_3);
taknokolat 3:92c039aed84a 41 pc.printf("F");
taknokolat 5:4e6f8015de81 42 NVIC_EnableIRQ(USART1_IRQn);
taknokolat 3:92c039aed84a 43 wait_ms(31);
taknokolat 3:92c039aed84a 44 bufcounter = 0;
taknokolat 5:4e6f8015de81 45 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 3:92c039aed84a 46 }
taknokolat 3:92c039aed84a 47 else if(bufcounter>=5 ){
taknokolat 3:92c039aed84a 48 //pc.printf("Communication Falsed.\r\n");
taknokolat 3:92c039aed84a 49 bufcounter = 0;
taknokolat 5:4e6f8015de81 50 memset(SFbuf, 0, sizeof(SFbuf));
taknokolat 3:92c039aed84a 51 }
taknokolat 5:4e6f8015de81 52 }
taknokolat 3:92c039aed84a 53 }
TUATBM 1:e257c3c3f659 54
taknokolat 4:c08f2e993acc 55
taknokolat 4:c08f2e993acc 56 void ISR_Serial_Rx_jevois()
taknokolat 4:c08f2e993acc 57 {
taknokolat 5:4e6f8015de81 58
taknokolat 5:4e6f8015de81 59 static char SFbuf2[16]={'Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q','Q'};
taknokolat 4:c08f2e993acc 60 static int bufcounter2=0;
taknokolat 5:4e6f8015de81 61 char g_landingcommand2;
taknokolat 5:4e6f8015de81 62 char g_landingcommand2_2;
taknokolat 5:4e6f8015de81 63 char g_landingcommand2_3;
taknokolat 5:4e6f8015de81 64 //NVIC_DisableIRQ(USART2_IRQn);
taknokolat 5:4e6f8015de81 65 if(pc2.readable()) { // 受信確認
taknokolat 5:4e6f8015de81 66
taknokolat 5:4e6f8015de81 67 SFbuf2[bufcounter2] = pc2.getc(); // 1文字取り出し
taknokolat 5:4e6f8015de81 68 if(SFbuf2[0]!='S'){
taknokolat 5:4e6f8015de81 69 //pc.printf("x");
taknokolat 5:4e6f8015de81 70 return;
taknokolat 5:4e6f8015de81 71 }
taknokolat 4:c08f2e993acc 72
taknokolat 4:c08f2e993acc 73
taknokolat 4:c08f2e993acc 74
taknokolat 4:c08f2e993acc 75 if(SFbuf2[0]=='S'&&bufcounter2<5) bufcounter2++;
taknokolat 4:c08f2e993acc 76
taknokolat 4:c08f2e993acc 77 if(bufcounter2==5 && SFbuf2[4]=='F'){
taknokolat 4:c08f2e993acc 78 g_landingcommand2 = SFbuf2[1];
taknokolat 5:4e6f8015de81 79 g_landingcommand2_2 = SFbuf2[2];
taknokolat 5:4e6f8015de81 80 g_landingcommand2_3 = SFbuf2[3];
taknokolat 4:c08f2e993acc 81 pc.printf("S");
taknokolat 4:c08f2e993acc 82 pc.printf("%c",g_landingcommand2);
taknokolat 5:4e6f8015de81 83 pc.printf("%c",g_landingcommand2_2);
taknokolat 5:4e6f8015de81 84 pc.printf("%c",g_landingcommand2_3);
taknokolat 4:c08f2e993acc 85 pc.printf("F");
taknokolat 4:c08f2e993acc 86 wait_ms(31);
taknokolat 4:c08f2e993acc 87 bufcounter2 = 0;
taknokolat 5:4e6f8015de81 88 memset(SFbuf2, 0, sizeof(SFbuf2));
taknokolat 4:c08f2e993acc 89 }
taknokolat 4:c08f2e993acc 90 else if(bufcounter2>=5 ){
taknokolat 4:c08f2e993acc 91 //pc.printf("Communication Falsed.\r\n");
taknokolat 4:c08f2e993acc 92 bufcounter2 = 0;
taknokolat 5:4e6f8015de81 93 memset(SFbuf2, 0, sizeof(SFbuf2));
taknokolat 4:c08f2e993acc 94 }
taknokolat 5:4e6f8015de81 95
taknokolat 5:4e6f8015de81 96 }
taknokolat 5:4e6f8015de81 97 //NVIC_EnableIRQ(USART2_IRQn);
taknokolat 4:c08f2e993acc 98 }
TUATBM 0:1f2bac0f6ab8 99
TUATBM 0:1f2bac0f6ab8 100 int main()
TUATBM 0:1f2bac0f6ab8 101 {
taknokolat 3:92c039aed84a 102
TUATBM 0:1f2bac0f6ab8 103 // シリアル通信受信の割り込みイベント登録
taknokolat 2:f975d9cb584d 104 pc.attach(ISR_Serial_Rx, Serial::RxIrq);
taknokolat 4:c08f2e993acc 105 pc2.attach(ISR_Serial_Rx_jevois, Serial::RxIrq);
taknokolat 4:c08f2e993acc 106
taknokolat 4:c08f2e993acc 107 NVIC_SetPriority(USART1_IRQn,0);
taknokolat 4:c08f2e993acc 108 NVIC_SetPriority(USART2_IRQn,1);
TUATBM 0:1f2bac0f6ab8 109
TUATBM 0:1f2bac0f6ab8 110 while (1) {
taknokolat 5:4e6f8015de81 111
taknokolat 4:c08f2e993acc 112
taknokolat 2:f975d9cb584d 113 // wait(1.0);
TUATBM 0:1f2bac0f6ab8 114
TUATBM 0:1f2bac0f6ab8 115 }
TUATBM 0:1f2bac0f6ab8 116
TUATBM 0:1f2bac0f6ab8 117 }