T Umezawa
/
light9
Check Uplink
main.cpp@0:16b8e1c4d8ac, 2020-12-29 (annotated)
- Committer:
- umezawa
- Date:
- Tue Dec 29 07:06:55 2020 +0000
- Revision:
- 0:16b8e1c4d8ac
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
umezawa | 0:16b8e1c4d8ac | 1 | #include "mbed.h" |
umezawa | 0:16b8e1c4d8ac | 2 | Serial pc(USBTX, USBRX); |
umezawa | 0:16b8e1c4d8ac | 3 | Serial com(D1,D0); |
umezawa | 0:16b8e1c4d8ac | 4 | DigitalOut NRST(A5); |
umezawa | 0:16b8e1c4d8ac | 5 | char msg[256]; |
umezawa | 0:16b8e1c4d8ac | 6 | char data[256]; |
umezawa | 0:16b8e1c4d8ac | 7 | |
umezawa | 0:16b8e1c4d8ac | 8 | char rcmd = 0; |
umezawa | 0:16b8e1c4d8ac | 9 | int cmdflag = 0; |
umezawa | 0:16b8e1c4d8ac | 10 | |
umezawa | 0:16b8e1c4d8ac | 11 | void commandget() |
umezawa | 0:16b8e1c4d8ac | 12 | { |
umezawa | 0:16b8e1c4d8ac | 13 | wait(0.5); |
umezawa | 0:16b8e1c4d8ac | 14 | rcmd=com.getc(); |
umezawa | 0:16b8e1c4d8ac | 15 | cmdflag = 1; |
umezawa | 0:16b8e1c4d8ac | 16 | } |
umezawa | 0:16b8e1c4d8ac | 17 | |
umezawa | 0:16b8e1c4d8ac | 18 | void initialize() |
umezawa | 0:16b8e1c4d8ac | 19 | { |
umezawa | 0:16b8e1c4d8ac | 20 | rcmd = NULL; |
umezawa | 0:16b8e1c4d8ac | 21 | cmdflag = 0; |
umezawa | 0:16b8e1c4d8ac | 22 | } |
umezawa | 0:16b8e1c4d8ac | 23 | |
umezawa | 0:16b8e1c4d8ac | 24 | int main() |
umezawa | 0:16b8e1c4d8ac | 25 | { |
umezawa | 0:16b8e1c4d8ac | 26 | com.baud(115200); |
umezawa | 0:16b8e1c4d8ac | 27 | pc.baud(115200); |
umezawa | 0:16b8e1c4d8ac | 28 | //初期化 |
umezawa | 0:16b8e1c4d8ac | 29 | NRST = 1; |
umezawa | 0:16b8e1c4d8ac | 30 | NRST = 0; |
umezawa | 0:16b8e1c4d8ac | 31 | wait(2); |
umezawa | 0:16b8e1c4d8ac | 32 | NRST = 1; |
umezawa | 0:16b8e1c4d8ac | 33 | com.scanf("%s",msg); |
umezawa | 0:16b8e1c4d8ac | 34 | pc.printf("%s\r\n",msg); |
umezawa | 0:16b8e1c4d8ac | 35 | if (strstr(msg,"Select")!=NULL) { |
umezawa | 0:16b8e1c4d8ac | 36 | com.printf("2\r\n"); |
umezawa | 0:16b8e1c4d8ac | 37 | wait(0.5); |
umezawa | 0:16b8e1c4d8ac | 38 | com.printf("q 2\r\n"); |
umezawa | 0:16b8e1c4d8ac | 39 | wait(0.5); |
umezawa | 0:16b8e1c4d8ac | 40 | com.printf("start\r\n"); |
umezawa | 0:16b8e1c4d8ac | 41 | com.scanf("%s",msg); |
umezawa | 0:16b8e1c4d8ac | 42 | for(int i = 0; i<4; i++) { |
umezawa | 0:16b8e1c4d8ac | 43 | com.getc(); |
umezawa | 0:16b8e1c4d8ac | 44 | } |
umezawa | 0:16b8e1c4d8ac | 45 | } |
umezawa | 0:16b8e1c4d8ac | 46 | pc.printf("Setting OK\r\n"); |
umezawa | 0:16b8e1c4d8ac | 47 | com.attach(commandget,Serial::RxIrq); |
umezawa | 0:16b8e1c4d8ac | 48 | while(1) { |
umezawa | 0:16b8e1c4d8ac | 49 | pc.printf("HEPTA\r\n"); |
umezawa | 0:16b8e1c4d8ac | 50 | wait(1.0); |
umezawa | 0:16b8e1c4d8ac | 51 | if (cmdflag == 1) { |
umezawa | 0:16b8e1c4d8ac | 52 | if (rcmd == 'a') { |
umezawa | 0:16b8e1c4d8ac | 53 | com.printf("UPLINK\r\n"); |
umezawa | 0:16b8e1c4d8ac | 54 | } |
umezawa | 0:16b8e1c4d8ac | 55 | initialize(); |
umezawa | 0:16b8e1c4d8ac | 56 | } |
umezawa | 0:16b8e1c4d8ac | 57 | } |
umezawa | 0:16b8e1c4d8ac | 58 | } |