看了小宋老師的課嘗試著寫的,拋磚引玉。
#if UART_SELFTEST&UART_BUFF_EN
os_timer_t buff_timer_t;
void ICACHE_FLASH_ATTR
uart_test_rx()
{
uint8 uart_buf[128]={0};
uint16 len = 0;
len = rx_buff_deq(uart_buf, 128 );
tx_buff_enq(uart_buf,len);
crc = GetCRC16(uart_buf, len-2);
crch = crc >> 8;
crcl = crc & 0xFF;
char *PA;
CHAR *PB;
if(uart_buf[0]=='0' && uart_buf[1]=='1' && uart_buf[2]=='0' && uart_buf[3]=='3')
{ char buf[0]=0x01;
buf[1]=0x03;
int cnt;
memset(CCC,0,sizeof(CCC));
memset(DDD,0,sizeof(DDD));
memset(CRCL,0,sizeof(CRCL));
memset(CRCH,0,sizeof(CRCH));
uart0_sendStr("modbus讀本機狀態(tài)模式");
PA=uart_buf;
PA=PA+4;
PB=PA+4;
memcpy(CCC,PA,strlen(PA)-strlen(PB));
buf[3]=CCC;
PA=PB;
PB=PA+4;
memcpy(DDD,PA,strlen(PA)-strlen(PB));
buf[4]=DDD;
cnt=atoi(DDD);
PA=PB;
PB=PA=2;
memcpy(CRCH,PA,strlen(PA)-strlen(PB));
PA=PB;
PB=PA=2;
memcpy(CRCL,PA,strlen(PA)-strlen(PB));
if ((CRCH!=crch) || (CRCL!=crcl))
{
return;
os_sprintf(buf[2],cnt*2);
buf[5]=0;//或1,表示某個設備的狀態(tài)
buf=buf[0]+buf[1]+buf[2]+buf[5]+crch+crcl;
uart0_sendStr(buf);
}
else if(uart_buf[0]=='0' && uart_buf[1]=='1' && uart_buf[2]=='0' && uart_buf[3]=='6')
{
uart0_sendStr("modbus寫本機狀態(tài)模式");
}
}
#endif
|