Commit 8ff9b0d0 authored by 957dd's avatar 957dd

加入了串口控制的设备代码大CHE 0105

parent 22393bcf
No preview for this file type
...@@ -205,7 +205,7 @@ static int process_serial_data(const uint8_t *buffer, int len) { ...@@ -205,7 +205,7 @@ static int process_serial_data(const uint8_t *buffer, int len) {
return -1; return -1;
} }
if(buffer[2]==0xFF||buffer[3]==0xEF){ if(buffer[2]==0xFF||buffer[3]==0xEF){
my_zlog_info("收到串口数据:%02X %02X %02X %02X",buffer[0],buffer[1],buffer[2],buffer[3]); my_zlog_info("收到串口数据");
return 0; return 0;
}else { }else {
my_zlog_info("串口数据大于3字节,但格式不正确"); my_zlog_info("串口数据大于3字节,但格式不正确");
...@@ -274,12 +274,11 @@ int car0105_serial_run(){ ...@@ -274,12 +274,11 @@ int car0105_serial_run(){
static int send_serial_count=0; static int send_serial_count=0;
int n = read(car_serial.fd, rx_buffer, sizeof(rx_buffer)); int n = read(car_serial.fd, rx_buffer, sizeof(rx_buffer));
int serial_index=process_serial_data(rx_buffer, n); int serial_index=process_serial_data(rx_buffer, n);
if(serial_stop_index==false){//接收函数 send_serial_count++;
send_serial_count++;
if(send_serial_count>=55)send_serial_count=55; if(send_serial_count>=55)send_serial_count=55;
}
if(serial_index<0)serial_stop_index=false; if(serial_index==0&&serial_stop_index==true) {
else if(serial_index==0&&serial_stop_index==true) {
send_serial_count=0; send_serial_count=0;
} }
if(send_serial_count==55){ if(send_serial_count==55){
...@@ -302,12 +301,8 @@ void car0105_serial_stop(){ ...@@ -302,12 +301,8 @@ void car0105_serial_stop(){
serial_send(&car_serial, forward_close_command, sizeof(forward_close_command)); serial_send(&car_serial, forward_close_command, sizeof(forward_close_command));
serial_send(&car_serial, left_close_command, sizeof(left_close_command)); serial_send(&car_serial, left_close_command, sizeof(left_close_command));
serial_send(&car_serial, right_close_command, sizeof(right_close_command)); serial_send(&car_serial, right_close_command, sizeof(right_close_command));
static int i=0;
i++; my_zlog_info("串口超时,停止运行");
if(i>5){
my_zlog_info("串口超时,停止运行");
i=0;
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment