1
DATA_PC/data_pc.cpp@0:d80c66cb1b3a, 2020-11-10 (annotated)
- Committer:
- panzhan
- Date:
- Tue Nov 10 09:09:58 2020 +0000
- Revision:
- 0:d80c66cb1b3a
panzhan_main_controller_copy2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
panzhan | 0:d80c66cb1b3a | 1 | #include "data_pc.h" |
panzhan | 0:d80c66cb1b3a | 2 | |
panzhan | 0:d80c66cb1b3a | 3 | Serial pc(PA_2, PA_3); // tx, rx U2 min |
panzhan | 0:d80c66cb1b3a | 4 | |
panzhan | 0:d80c66cb1b3a | 5 | |
panzhan | 0:d80c66cb1b3a | 6 | int pc_control = 0; // 命令帧标志位 |
panzhan | 0:d80c66cb1b3a | 7 | unsigned int flag_A = 0, flag_B = 0; |
panzhan | 0:d80c66cb1b3a | 8 | unsigned int pc_num = 0; |
panzhan | 0:d80c66cb1b3a | 9 | |
panzhan | 0:d80c66cb1b3a | 10 | uint16_t phase_flag_get[1] = {0}; |
panzhan | 0:d80c66cb1b3a | 11 | uint16_t phase_flag_use[1] = {0}; |
panzhan | 0:d80c66cb1b3a | 12 | unsigned int phase_flag = 0; |
panzhan | 0:d80c66cb1b3a | 13 | |
panzhan | 0:d80c66cb1b3a | 14 | void pc_decode(){ |
panzhan | 0:d80c66cb1b3a | 15 | phase_flag = phase_flag_use[0]; |
panzhan | 0:d80c66cb1b3a | 16 | } |
panzhan | 0:d80c66cb1b3a | 17 | |
panzhan | 0:d80c66cb1b3a | 18 | void pc_clear(){ |
panzhan | 0:d80c66cb1b3a | 19 | phase_flag_use[0] = 0; |
panzhan | 0:d80c66cb1b3a | 20 | } |
panzhan | 0:d80c66cb1b3a | 21 | |
panzhan | 0:d80c66cb1b3a | 22 | void serial_pc_isr(){ |
panzhan | 0:d80c66cb1b3a | 23 | while(pc.readable()){ |
panzhan | 0:d80c66cb1b3a | 24 | uint16_t c=pc.getc(); |
panzhan | 0:d80c66cb1b3a | 25 | if(c == 'A'){ |
panzhan | 0:d80c66cb1b3a | 26 | flag_A = 1; |
panzhan | 0:d80c66cb1b3a | 27 | flag_B = 0; |
panzhan | 0:d80c66cb1b3a | 28 | pc_num = 0; |
panzhan | 0:d80c66cb1b3a | 29 | phase_flag_get[0] = 0; |
panzhan | 0:d80c66cb1b3a | 30 | break; |
panzhan | 0:d80c66cb1b3a | 31 | } |
panzhan | 0:d80c66cb1b3a | 32 | if(c == 'B'){ |
panzhan | 0:d80c66cb1b3a | 33 | flag_B = 1; |
panzhan | 0:d80c66cb1b3a | 34 | } |
panzhan | 0:d80c66cb1b3a | 35 | if(flag_A == 1){ |
panzhan | 0:d80c66cb1b3a | 36 | if((flag_B != 1) && (pc_num < 1)) |
panzhan | 0:d80c66cb1b3a | 37 | { |
panzhan | 0:d80c66cb1b3a | 38 | phase_flag_get[pc_num] = c; |
panzhan | 0:d80c66cb1b3a | 39 | } |
panzhan | 0:d80c66cb1b3a | 40 | pc_num++; |
panzhan | 0:d80c66cb1b3a | 41 | |
panzhan | 0:d80c66cb1b3a | 42 | if((flag_B == 1) && (pc_num != 2)) |
panzhan | 0:d80c66cb1b3a | 43 | { |
panzhan | 0:d80c66cb1b3a | 44 | flag_A = 0; |
panzhan | 0:d80c66cb1b3a | 45 | flag_B = 0; |
panzhan | 0:d80c66cb1b3a | 46 | pc_num = 0; |
panzhan | 0:d80c66cb1b3a | 47 | } |
panzhan | 0:d80c66cb1b3a | 48 | if((flag_B == 1) && (pc_num == 2)) |
panzhan | 0:d80c66cb1b3a | 49 | { |
panzhan | 0:d80c66cb1b3a | 50 | flag_A = 0; |
panzhan | 0:d80c66cb1b3a | 51 | flag_B = 0; |
panzhan | 0:d80c66cb1b3a | 52 | pc_num = 0; |
panzhan | 0:d80c66cb1b3a | 53 | |
panzhan | 0:d80c66cb1b3a | 54 | phase_flag_use[0] = phase_flag_get[0] - '0'; |
panzhan | 0:d80c66cb1b3a | 55 | pc_decode(); |
panzhan | 0:d80c66cb1b3a | 56 | |
panzhan | 0:d80c66cb1b3a | 57 | pc.printf("%d", phase_flag); // 命令帧接收成功 |
panzhan | 0:d80c66cb1b3a | 58 | |
panzhan | 0:d80c66cb1b3a | 59 | pc_clear(); |
panzhan | 0:d80c66cb1b3a | 60 | |
panzhan | 0:d80c66cb1b3a | 61 | } |
panzhan | 0:d80c66cb1b3a | 62 | pc_control = 1; |
panzhan | 0:d80c66cb1b3a | 63 | } |
panzhan | 0:d80c66cb1b3a | 64 | } |
panzhan | 0:d80c66cb1b3a | 65 | } |