12

Dependencies:   mbed-dev_spine

Committer:
panzhan
Date:
Wed Jun 09 01:41:45 2021 +0000
Revision:
0:dd5d4837292c
continuous motion

Who changed what in which revision?

UserRevisionLine numberNew contents of line
panzhan 0:dd5d4837292c 1 #include "data_pc.h"
panzhan 0:dd5d4837292c 2 #include "data_command.h"
panzhan 0:dd5d4837292c 3
panzhan 0:dd5d4837292c 4 Serial pc(PA_2, PA_3); // tx, rx U2 min
panzhan 0:dd5d4837292c 5
panzhan 0:dd5d4837292c 6
panzhan 0:dd5d4837292c 7 int pc_control = 0; // 命令帧标志位
panzhan 0:dd5d4837292c 8 unsigned int flag_A = 0, flag_B = 0;
panzhan 0:dd5d4837292c 9 unsigned int pc_num = 0;
panzhan 0:dd5d4837292c 10
panzhan 0:dd5d4837292c 11 uint16_t mode_flag_get[1] = {0};
panzhan 0:dd5d4837292c 12 uint16_t mode_flag_use[1] = {0};
panzhan 0:dd5d4837292c 13 unsigned int mode_flag = 3;
panzhan 0:dd5d4837292c 14
panzhan 0:dd5d4837292c 15 void pc_decode(){
panzhan 0:dd5d4837292c 16 mode_flag = mode_flag_use[0];
panzhan 0:dd5d4837292c 17 }
panzhan 0:dd5d4837292c 18
panzhan 0:dd5d4837292c 19 void pc_clear(){
panzhan 0:dd5d4837292c 20 mode_flag_use[0] = 0;
panzhan 0:dd5d4837292c 21 }
panzhan 0:dd5d4837292c 22
panzhan 0:dd5d4837292c 23 void serial_pc_isr(){
panzhan 0:dd5d4837292c 24 while(pc.readable()){
panzhan 0:dd5d4837292c 25 uint16_t c=pc.getc();
panzhan 0:dd5d4837292c 26 if(c == 'A'){
panzhan 0:dd5d4837292c 27 flag_A = 1;
panzhan 0:dd5d4837292c 28 flag_B = 0;
panzhan 0:dd5d4837292c 29 pc_num = 0;
panzhan 0:dd5d4837292c 30 mode_flag_get[0] = 0;
panzhan 0:dd5d4837292c 31 break;
panzhan 0:dd5d4837292c 32 }
panzhan 0:dd5d4837292c 33 if(c == 'B'){
panzhan 0:dd5d4837292c 34 flag_B = 1;
panzhan 0:dd5d4837292c 35 }
panzhan 0:dd5d4837292c 36 if(flag_A == 1){
panzhan 0:dd5d4837292c 37 if((flag_B != 1) && (pc_num < 1))
panzhan 0:dd5d4837292c 38 {
panzhan 0:dd5d4837292c 39 mode_flag_get[pc_num] = c;
panzhan 0:dd5d4837292c 40 }
panzhan 0:dd5d4837292c 41 pc_num++;
panzhan 0:dd5d4837292c 42
panzhan 0:dd5d4837292c 43 if((flag_B == 1) && (pc_num != 2))
panzhan 0:dd5d4837292c 44 {
panzhan 0:dd5d4837292c 45 flag_A = 0;
panzhan 0:dd5d4837292c 46 flag_B = 0;
panzhan 0:dd5d4837292c 47 pc_num = 0;
panzhan 0:dd5d4837292c 48 }
panzhan 0:dd5d4837292c 49 if((flag_B == 1) && (pc_num == 2))
panzhan 0:dd5d4837292c 50 {
panzhan 0:dd5d4837292c 51 flag_A = 0;
panzhan 0:dd5d4837292c 52 flag_B = 0;
panzhan 0:dd5d4837292c 53 pc_num = 0;
panzhan 0:dd5d4837292c 54
panzhan 0:dd5d4837292c 55 mode_flag_use[0] = mode_flag_get[0] - '0';
panzhan 0:dd5d4837292c 56 pc_decode();
panzhan 0:dd5d4837292c 57
panzhan 0:dd5d4837292c 58 command.printf("%d", mode_flag); // 命令帧接收成功
panzhan 0:dd5d4837292c 59
panzhan 0:dd5d4837292c 60 pc_clear();
panzhan 0:dd5d4837292c 61
panzhan 0:dd5d4837292c 62 }
panzhan 0:dd5d4837292c 63 pc_control = 1;
panzhan 0:dd5d4837292c 64 }
panzhan 0:dd5d4837292c 65 }
panzhan 0:dd5d4837292c 66 }