123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #include "bsp_uart.h"
- #include "bsp_protocol.h"
- void send_to_uart_AABBCC(uint8_t index,uint8_t cmd,uint8_t* dat,uint8_t datLen)
- {
- uint8_t buf[255];
- uint16_t Len = datLen+5;
- uint16_t L=0;
- uint8_t i;
- uint8_t ver = 0;
- if(Len>255) return;
- buf[L++] = 0xAA; ver += 0xAA; //帧头
- buf[L++] = Len; ver += Len; //长度
- buf[L++] = ~Len; ver += (~Len);//长度反码
- buf[L++] = cmd; ver += cmd; //命令
- for(i=0;i<datLen;i++){ buf[L++] = dat[i]; ver += dat[i];} //数据
- buf[L++] = ver; //校验
-
- for(i=0;i<L;i++) app_uart_put(buf[i]); //串口输出数据
- app_uart_put(0x0d);
- }
- struct pm_type pm;
- struct pm_other_type pm_other;
- void send_uart_data_UPDATE_BASEINFO(void)
- {
- uint8_t buf[100];
- uint8_t L=0;
- int i=0;
- buf[L++]=UPDATE_BASEINFO;
-
- buf[L++]=pm.power;
- buf[L++]=pm.inner_temperature;
- buf[L++]=pm.pressure[0];
- buf[L++]=pm.pressure[1];
- buf[L++]=pm.pressure[2];
- buf[L++]=pm.pressure[3];
-
- buf[L++]=pm_other.power;
- buf[L++]=pm_other.inner_temperature;
- buf[L++]=pm_other.pressure[0];
- buf[L++]=pm_other.pressure[1];
- buf[L++]=pm_other.pressure[2];
- buf[L++]=pm_other.pressure[3];
-
- // SEGGER_RTT_printf(0,"buff= 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++]);
- send_to_uart_AABBCC(DEX_NUM,CMD_UPDATE,buf,L);
- }
- void load_pm_other(unsigned char* buf)
- {
- int i=8;
- pm_other.power = buf[i++];
- pm_other.inner_temperature = buf[i++];
- pm_other.pressure[0]=buf[i++];
- pm_other.pressure[1]=buf[i++];
- pm_other.pressure[2]=buf[i++];
- pm_other.pressure[3]=buf[i++];
- // SEGGER_RTT_printf(0,"buff= 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",buf[i++],buf[i++],buf[i++],buf[i++],buf[i++],buf[i++]);
- // SEGGER_RTT_printf(0,"output power= %d%% ,temperature= %d ,pressure= 0x%x 0x%x 0x%x 0x%x\n",pm_other.power,pm_other.inner_temperature,pm_other.pressure[0],pm_other.pressure[1],pm_other.pressure[2],pm_other.pressure[3]);
- send_uart_data_UPDATE_BASEINFO();
- }
- //命令处理函数
- void AABBCC_callback(unsigned char* data,char len)
- {
- switch(data[3])//看命令号
- {
- case CMD_UPDATE: //查询基本信息
- switch(data[4])//看子命令
- {
- case UPDATE_BASEINFO:
- SEGGER_RTT_printf(0,"AABBCC_callback -> UPDATE_BASEINFO\n");
- send_uart_data_UPDATE_BASEINFO();//发送设备基本信息
- break;
- }
- //printf("AABBCC_callback -> UPDATE_BASEINFO\n");
- break;
- default:
- break;
- }
- }
- unsigned char AABBCC_buff[50];
- void AABBCC_REC(unsigned char data)
- {
- static char len=0;
- static char crc=0;
- if(((len==0)&&(data==0xAA))
- || ( len==1)
- || ((len==2)&&(AABBCC_buff[1] + data==0xFF))
- || ((len >2)&&(AABBCC_buff[1]-1 > len))
- )
- {
- AABBCC_buff[len++]=data;
- crc+=data;
- }
- else if((AABBCC_buff[1]-1 == len) && ( crc==data ))
- {
- AABBCC_buff[len]=data;
- AABBCC_callback(AABBCC_buff,len);//接收完成,回调事件函数
- }
- else
- {
- len=0;
- crc=0;
- }
- }
- //。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
|