123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /********************** 头文件 *************************/
- #include "bsp_protocol.h"
- /********************** 变量区 *************************/
- /********************** 函数声明区 *************************/
- void send_protocol(uint8_t index,uint8_t cmd,uint8_t* dat,uint8_t datLen)
- {
- uint8_t buf[250];
- uint16_t Len = datLen+5;
- uint16_t L=0;
- uint8_t i;
- uint8_t ver = 0;
- if(Len>250) 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; //校验
- bsp_esb_send(buf,L); //发送出去
- }
- void send_protocol_game(uint8_t cmd,uint8_t SendTime,uint8_t SendInternal_ms)
- {
- uint8_t buf[6]={0xAA,0x06,0xF9,0xA2,0x01,0x00};
- uint8_t length = 6;
- uint8_t i=0,check=0;
- uint8_t Esb_sendTime=0;
- buf[4] = cmd;
- for(i=0;i<5;i++){
- check +=buf[i];
- }
- buf[5] = check;
- bsp_esb_send(buf,length);
- for(Esb_sendTime=0;Esb_sendTime<SendTime;Esb_sendTime++){
- bsp_esb_send(buf,length);
- if(SendInternal_ms !=0)nrf_delay_ms(SendInternal_ms);
- }
- }
- #if ESB_RECV_SEND_TEST
- void Esb_Test_Send(void)
- {
- uint8_t buf[50]={0x00,0x01,0x02,0x03,0x04,0x05};
- uint8_t length = 50;
- send_protocol(1,0xA1,buf,length);
- }
- #endif
|