航空研究会
/
Scarlet_relay_V5
同時通信確認版
Fork of Scarlet_relay_V4 by
main.cpp@4:c08f2e993acc, 2018-09-22 (annotated)
- Committer:
- taknokolat
- Date:
- Sat Sep 22 08:56:53 2018 +0000
- Revision:
- 4:c08f2e993acc
- Parent:
- 3:92c039aed84a
- Child:
- 5:4e6f8015de81
a
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:92c039aed84a | 14 | static char SFbuf[16]; |
taknokolat | 3:92c039aed84a | 15 | static int bufcounter=0; |
taknokolat | 4:c08f2e993acc | 16 | char g_landingcommand; |
taknokolat | 3:92c039aed84a | 17 | |
taknokolat | 3:92c039aed84a | 18 | SFbuf[bufcounter] = pc.getc(); |
taknokolat | 3:92c039aed84a | 19 | |
taknokolat | 3:92c039aed84a | 20 | |
taknokolat | 3:92c039aed84a | 21 | |
taknokolat | 3:92c039aed84a | 22 | if(SFbuf[0]=='S'&&bufcounter<5) bufcounter++; |
taknokolat | 3:92c039aed84a | 23 | |
taknokolat | 3:92c039aed84a | 24 | if(bufcounter==5 && SFbuf[4]=='F'){ |
taknokolat | 3:92c039aed84a | 25 | g_landingcommand = SFbuf[1]; |
taknokolat | 3:92c039aed84a | 26 | pc.printf("S"); |
taknokolat | 3:92c039aed84a | 27 | pc.printf("%c",g_landingcommand); |
taknokolat | 3:92c039aed84a | 28 | pc.printf("A"); |
taknokolat | 3:92c039aed84a | 29 | pc.printf("A"); |
taknokolat | 3:92c039aed84a | 30 | pc.printf("F"); |
taknokolat | 3:92c039aed84a | 31 | wait_ms(31); |
taknokolat | 3:92c039aed84a | 32 | bufcounter = 0; |
taknokolat | 3:92c039aed84a | 33 | memset(SFbuf, 0, strlen(SFbuf)); |
taknokolat | 3:92c039aed84a | 34 | } |
taknokolat | 3:92c039aed84a | 35 | else if(bufcounter>=5 ){ |
taknokolat | 3:92c039aed84a | 36 | //pc.printf("Communication Falsed.\r\n"); |
taknokolat | 3:92c039aed84a | 37 | bufcounter = 0; |
taknokolat | 3:92c039aed84a | 38 | memset(SFbuf, 0, strlen(SFbuf)); |
taknokolat | 3:92c039aed84a | 39 | } |
taknokolat | 3:92c039aed84a | 40 | |
taknokolat | 3:92c039aed84a | 41 | } |
TUATBM | 1:e257c3c3f659 | 42 | |
taknokolat | 4:c08f2e993acc | 43 | |
taknokolat | 4:c08f2e993acc | 44 | void ISR_Serial_Rx_jevois() |
taknokolat | 4:c08f2e993acc | 45 | { |
taknokolat | 4:c08f2e993acc | 46 | NVIC_DisableIRQ(USART2_IRQn); |
taknokolat | 4:c08f2e993acc | 47 | static char SFbuf2[16]; |
taknokolat | 4:c08f2e993acc | 48 | static int bufcounter2=0; |
taknokolat | 4:c08f2e993acc | 49 | char g_landingcommand2; |
taknokolat | 4:c08f2e993acc | 50 | |
taknokolat | 4:c08f2e993acc | 51 | SFbuf2[bufcounter2] = pc2.getc(); |
taknokolat | 4:c08f2e993acc | 52 | |
taknokolat | 4:c08f2e993acc | 53 | |
taknokolat | 4:c08f2e993acc | 54 | |
taknokolat | 4:c08f2e993acc | 55 | if(SFbuf2[0]=='S'&&bufcounter2<5) bufcounter2++; |
taknokolat | 4:c08f2e993acc | 56 | |
taknokolat | 4:c08f2e993acc | 57 | if(bufcounter2==5 && SFbuf2[4]=='F'){ |
taknokolat | 4:c08f2e993acc | 58 | g_landingcommand2 = SFbuf2[1]; |
taknokolat | 4:c08f2e993acc | 59 | pc.printf("S"); |
taknokolat | 4:c08f2e993acc | 60 | pc.printf("%c",g_landingcommand2); |
taknokolat | 4:c08f2e993acc | 61 | pc.printf("A"); |
taknokolat | 4:c08f2e993acc | 62 | pc.printf("A"); |
taknokolat | 4:c08f2e993acc | 63 | pc.printf("F"); |
taknokolat | 4:c08f2e993acc | 64 | wait_ms(31); |
taknokolat | 4:c08f2e993acc | 65 | bufcounter2 = 0; |
taknokolat | 4:c08f2e993acc | 66 | memset(SFbuf2, 0, strlen(SFbuf2)); |
taknokolat | 4:c08f2e993acc | 67 | } |
taknokolat | 4:c08f2e993acc | 68 | else if(bufcounter2>=5 ){ |
taknokolat | 4:c08f2e993acc | 69 | //pc.printf("Communication Falsed.\r\n"); |
taknokolat | 4:c08f2e993acc | 70 | bufcounter2 = 0; |
taknokolat | 4:c08f2e993acc | 71 | memset(SFbuf2, 0, strlen(SFbuf2)); |
taknokolat | 4:c08f2e993acc | 72 | } |
taknokolat | 4:c08f2e993acc | 73 | NVIC_EnableIRQ(USART2_IRQn); |
taknokolat | 4:c08f2e993acc | 74 | |
taknokolat | 4:c08f2e993acc | 75 | } |
TUATBM | 0:1f2bac0f6ab8 | 76 | |
TUATBM | 0:1f2bac0f6ab8 | 77 | int main() |
TUATBM | 0:1f2bac0f6ab8 | 78 | { |
taknokolat | 3:92c039aed84a | 79 | |
TUATBM | 0:1f2bac0f6ab8 | 80 | // シリアル通信受信の割り込みイベント登録 |
taknokolat | 2:f975d9cb584d | 81 | pc.attach(ISR_Serial_Rx, Serial::RxIrq); |
taknokolat | 4:c08f2e993acc | 82 | pc2.attach(ISR_Serial_Rx_jevois, Serial::RxIrq); |
taknokolat | 4:c08f2e993acc | 83 | |
taknokolat | 4:c08f2e993acc | 84 | NVIC_SetPriority(USART1_IRQn,0); |
taknokolat | 4:c08f2e993acc | 85 | NVIC_SetPriority(USART2_IRQn,1); |
TUATBM | 0:1f2bac0f6ab8 | 86 | |
TUATBM | 0:1f2bac0f6ab8 | 87 | while (1) { |
taknokolat | 4:c08f2e993acc | 88 | NVIC_SetPriority(USART1_IRQn,0); |
taknokolat | 4:c08f2e993acc | 89 | NVIC_SetPriority(USART2_IRQn,1); |
taknokolat | 4:c08f2e993acc | 90 | |
taknokolat | 2:f975d9cb584d | 91 | // wait(1.0); |
TUATBM | 0:1f2bac0f6ab8 | 92 | |
TUATBM | 0:1f2bac0f6ab8 | 93 | } |
TUATBM | 0:1f2bac0f6ab8 | 94 | |
TUATBM | 0:1f2bac0f6ab8 | 95 | } |