用戶(hù)接口實(shí)現(xiàn)細(xì)節(jié)
/*
*函數(shù)功能:?jiǎn)?dòng)串口數(shù)據(jù)發(fā)送功能
* des:要寫(xiě)入?yún)?shù)的地址
* len:要寫(xiě)入?yún)?shù)的長(zhǎng)度
* port:要寫(xiě)入的串口號(hào)
* 返回值:實(shí)際寫(xiě)入的數(shù)據(jù)長(zhǎng)度,這個(gè)參數(shù)有點(diǎn)雞肋啊。。。
*/
int write_serial(unsigned char *des,int len,int port)
{
int i,temp_len=0;
SERIAL_STR *serial_snd = &serial_snd_g[port -1];
if(serial_snd!=0)
{
for(i=0;i
{
*serial_snd->write_pointer = des[temp_len++];
serial_snd->write_pointer++;
if((serial_snd->write_pointer-serial_snd->datas_buffer)>MAX_REC_SIZE-1)
{
serial_snd->write_pointer=serial_snd->datas_buffer;
serial_snd->write_full_flag=1;
}
}
if(port==1)
{
USART_ITConfig( USART1, USART_IT_TC, ENABLE );
}
else if(port==2)
{
USART_ITConfig( USART2, USART_IT_TXE, ENABLE );
}
else if(port==3)
{
USART_ITConfig( USART3, USART_IT_TXE, ENABLE );
}
}
return temp_len;
}
int rcv_deal_datas(void *datas, void *param, void *flag)
{
struct rcv_deal_pro_st *pro = (struct rcv_deal_pro_st *)datas;
int len = 0;
int type = 0;
len=read_serial( (unsigned char *)(pro->rcv_buff+pro->total_len), sizeof(pro->rcv_buff)-len-1, pro->port);
if(len)
{
pro->total_len += len;
}
else if(pro->total_len)
{
unsigned char *point = (unsigned char *)pro->rcv_buff;
while(point < pro->rcv_buff + pro->total_len)
{
type = pro->resolve_pro_func(pro->rcv_buff, pro->total_len, pro->result);
//清除緩存數(shù)據(jù)
if(type && pro->deal_pro_func)
{
pro->deal_pro_func(type, pro->result);
}
point = (unsigned char *)&pro->result;
memset(pro->rcv_buff,0,1024);
}
pro->total_len=0;
}
return 1;
}