void Uart_TxData_Proc(void)
{
u8 tx_buf[128] = {0};
u8 send_flag = 0;
u8 send_len = 0;
u8 content_len = 0;
u16 cmd_value = 0;
tx_buf[0] = 0x55;
tx_buf[1] = 0xAA;
if(sys_info.cmd_connect_status_flag == 1){
sys_info.cmd_connect_status_flag = 0;
cmd_value = CONNCET_STATUS;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
tx_buf[4] = STATUS_OK;
tx_buf[5] = tx_buf[0]+tx_buf[1]+tx_buf[2]+tx_buf[3]+tx_buf[4];
send_flag = 1;
send_len = 6;
}
if(sys_info.cmd_set_timer1_flag == 1){
sys_info.cmd_set_timer1_flag = 0;
cmd_value = SET_SIGLE_TIME;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
memcpy(&tx_buf[4], &store_info.store_timer1, sizeof(store_info.store_timer1));
content_len = sizeof(store_info.store_timer1);
tx_buf[content_len+4] = Check_Crc(tx_buf, content_len+4);
send_flag = 1;
send_len = content_len+5;
}
if(sys_info.cmd_get_timer1_flag == 1){
sys_info.cmd_get_timer1_flag = 0;
cmd_value = GET_SIGLE_TIME;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
memcpy(&tx_buf[4], &store_info.store_timer1, sizeof(store_info.store_timer1));
content_len = sizeof(store_info.store_timer1);
tx_buf[content_len+4] = Check_Crc(tx_buf, content_len+4);
send_flag = 1;
send_len = content_len+5;
}
if(sys_info.cmd_set_timer7_flag == 1){
sys_info.cmd_set_timer7_flag = 0;
cmd_value = SET_SEVEN_TIME;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
memcpy(&tx_buf[4], &store_info.store_timer7, sizeof(store_info.store_timer7));
content_len = sizeof(store_info.store_timer7);
tx_buf[content_len+4] = Check_Crc(tx_buf, content_len+4);
send_flag = 1;
send_len = content_len+5;
}
if(sys_info.cmd_get_timer7_flag == 1){
sys_info.cmd_get_timer7_flag = 0;
cmd_value = GET_SEVEN_TIME;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
memcpy(&tx_buf[4], &store_info.store_timer7, sizeof(store_info.store_timer7));
content_len = sizeof(store_info.store_timer7);
tx_buf[content_len+4] = Check_Crc(tx_buf, content_len+4);
send_flag = 1;
send_len = content_len+5;
}
//激光AB同时亮的命令返回
if(sys_info.cmd_seven_ab_flag == 1){
sys_info.cmd_seven_ab_flag = 0;
cmd_value = SEVEN_MODE_AB;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
tx_buf[4] = STATUS_OK;
tx_buf[5] = tx_buf[0]+tx_buf[1]+tx_buf[2]+tx_buf[3]+tx_buf[4];
send_flag = 1;
send_len = 6;
}
if(sys_info.cmd_seven_ab_one_flag == 1){
sys_info.cmd_seven_ab_one_flag = 0;
cmd_value = SEVEN_MODE_AB_ONE;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
tx_buf[4] = STATUS_OK;
tx_buf[5] = tx_buf[0]+tx_buf[1]+tx_buf[2]+tx_buf[3]+tx_buf[4];
send_flag = 1;
send_len = 6;
}
if(sys_info.cmd_set_seven_flag == 1){
sys_info.cmd_set_seven_flag = 0;
cmd_value = SEVEN_MODE;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
tx_buf[4] = STATUS_OK;
tx_buf[5] = tx_buf[0]+tx_buf[1]+tx_buf[2]+tx_buf[3]+tx_buf[4];
send_flag = 1;
send_len = 6;
}
if(sys_info.cmd_set_seven_one_flag == 1){
sys_info.cmd_set_seven_one_flag = 0;
cmd_value = SEVEN_MODE_ONE;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
tx_buf[4] = STATUS_OK;
tx_buf[5] = tx_buf[0]+tx_buf[1]+tx_buf[2]+tx_buf[3]+tx_buf[4];
send_flag = 1;
send_len = 6;
}
if(sys_info.cmd_set_sigle_flag == 1){
sys_info.cmd_set_sigle_flag = 0;
cmd_value = SIGLE_MODE;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
tx_buf[4] = STATUS_OK;
tx_buf[5] = tx_buf[0]+tx_buf[1]+tx_buf[2]+tx_buf[3]+tx_buf[4];
send_flag = 1;
send_len = 6;
}
if(sys_info.cmd_set_sigle_one_flag == 1){
sys_info.cmd_set_sigle_one_flag = 0;
cmd_value = SIGLE_MODE_ONE;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
tx_buf[4] = STATUS_OK;
tx_buf[5] = tx_buf[0]+tx_buf[1]+tx_buf[2]+tx_buf[3]+tx_buf[4];
send_flag = 1;
send_len = 6;
}
if(sys_info.cmd_holdon_flag == 1){
sys_info.cmd_holdon_flag = 0;
cmd_value = SYS_HOLDON;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
tx_buf[4] = STATUS_OK;
tx_buf[5] = tx_buf[0]+tx_buf[1]+tx_buf[2]+tx_buf[3]+tx_buf[4];
send_flag = 1;
send_len = 6;
}
if(sys_info.cmd_button_mode == 1){
sys_info.cmd_button_mode = 0;
cmd_value = SET_BUTTON_MODE;
tx_buf[2] = (cmd_value>>8);
tx_buf[3] = (cmd_value&0x00ff);
tx_buf[4] = STATUS_OK;
tx_buf[5] = tx_buf[0]+tx_buf[1]+tx_buf[2]+tx_buf[3]+tx_buf[4];
send_flag = 1;
send_len = 6;
}
if(send_flag == 1){
HAL_UART_Transmit(&huart2, tx_buf, send_len, 1000);
send_flag = 0;
send_len = 0;
}
}
/*******************************************************************************
* 函数名: Uart_RxData_Proc
* 输 入: 无
* 输 出: 无
* 功能说明: 处理循环队列里的串口数据
*******************************************************************************/
void Uart_RxData_Proc(void)
{
uint16_t len = 0;
if(st_uart2.queue.WritePtr != st_uart2.queue.ReadPtr)
{
rxdata[rxcount++] = (uint8_t)OD_DeQueue(&st_uart2.queue);
}
if(rxdata[0] != 0x55){
rxcount = 0;
}
if(rxcount == 4){
cmd = (rxdata[2]<<8)+rxdata[3];
}
if(cmd == CONNCET_STATUS){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.cmd_connect_status_flag = 1;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == SET_SIGLE_TIME){
len = sizeof(Store_Timer_1) + 5;
if(rxcount == len){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[rxcount-1]){
memcpy(&store_info.store_timer1, &rxdata[4], sizeof(Store_Timer_1));
EEPROM_Data_Write((uint32_t *)&store_info, sizeof(store_info));
sys_info.cmd_set_timer1_flag = 1;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == GET_SIGLE_TIME){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.cmd_get_timer1_flag = 1;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == SET_SEVEN_TIME){
len = sizeof(Store_Timer_7) + 5;
if(rxcount == len){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[rxcount-1]){
memcpy(&store_info.store_timer7, &rxdata[4], sizeof(Store_Timer_7));
EEPROM_Data_Write((uint32_t *)&store_info, sizeof(store_info));
sys_info.cmd_set_timer7_flag = 1;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == GET_SEVEN_TIME){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.cmd_get_timer7_flag = 1;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == SEVEN_MODE_AB){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.run_mode = MODE_SEVEN_START;
sys_info.cmd_seven_ab_flag = 1; //命令返回标志
sys_info.scan_start_7 = 1;
sys_info.seven_one_flag = 0;
sys_info.seven_ab_one_flag=0;
sys_info.run_seven_ab = 1;
sys_info.button_mode = 0;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == SEVEN_MODE_AB_ONE){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.run_mode = MODE_SEVEN_START;
sys_info.cmd_seven_ab_one_flag = 1;
sys_info.scan_start_7 = 1;
sys_info.run_seven_ab = 1;
sys_info.seven_ab_one_flag=1;
sys_info.button_mode = 0;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == SEVEN_MODE){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.run_mode = MODE_SEVEN_START;
sys_info.cmd_set_seven_flag = 1;//命令返回标志
sys_info.scan_start_7 = 1;
sys_info.seven_one_flag = 0; //取消单次采图
sys_info.seven_ab_one_flag=0;
sys_info.run_seven_ab = 0; //取消AB同时亮
sys_info.button_mode = 0;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == SEVEN_MODE_ONE){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.run_mode = MODE_SEVEN_START;
sys_info.cmd_set_seven_one_flag = 1;
sys_info.scan_start_7 = 1;
sys_info.seven_one_flag = 1;
sys_info.run_seven_ab = 0;
sys_info.button_mode = 0;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == SIGLE_MODE){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.run_mode = MODE_SIGLE_START;
sys_info.cmd_set_sigle_flag = 1;
sys_info.scan_start_1 = 1;
sys_info.sigle_one_flag = 0;
sys_info.button_mode = 0;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == SIGLE_MODE_ONE){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.run_mode = MODE_SIGLE_START;
sys_info.cmd_set_sigle_one_flag = 1;
sys_info.scan_start_1 = 1;
sys_info.sigle_one_flag = 1;
sys_info.button_mode = 0;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == SYS_HOLDON){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.cmd_holdon_flag = 1;
sys_info.sys_holdon_flag = 1;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
if(cmd == SET_BUTTON_MODE){
if(rxcount == 5){
crc = Check_Crc(rxdata, rxcount-1);
if(crc == rxdata[4]){
sys_info.cmd_button_mode = 1;
sys_info.button_mode = 1;
rxcount = 0;
memset(rxdata, 0, UART2_BUFF_SIZE);
}
}
}
//HAL_UART_Transmit(&huart2,&rxdata[rxcount-1],1,100);
}