bsp_protocol.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /********************** 头文件 *************************/
  2. #include "bsp_protocol.h"
  3. /********************** 变量区 *************************/
  4. /********************** 函数声明区 *************************/
  5. void send_protocol(uint8_t index,uint8_t cmd,uint8_t* dat,uint8_t datLen)
  6. {
  7. uint8_t buf[250];
  8. uint16_t Len = datLen+5;
  9. uint16_t L=0;
  10. uint8_t i;
  11. uint8_t ver = 0;
  12. if(Len>250) return;
  13. buf[L++] = 0xAA; ver += 0xAA; //帧头
  14. buf[L++] = Len; ver += Len; //长度
  15. buf[L++] = ~Len; ver += (~Len);//长度反码
  16. buf[L++] = cmd; ver += cmd; //命令
  17. for(i=0;i<datLen;i++){ buf[L++] = dat[i]; ver += dat[i];} //数据
  18. buf[L++] = ver; //校验
  19. bsp_esb_send(buf,L); //发送出去
  20. }
  21. void send_protocol_game(uint8_t cmd,uint8_t SendTime,uint8_t SendInternal_ms)
  22. {
  23. uint8_t buf[6]={0xAA,0x06,0xF9,0xA2,0x01,0x00};
  24. uint8_t length = 6;
  25. uint8_t i=0,check=0;
  26. uint8_t Esb_sendTime=0;
  27. buf[4] = cmd;
  28. for(i=0;i<5;i++){
  29. check +=buf[i];
  30. }
  31. buf[5] = check;
  32. bsp_esb_send(buf,length);
  33. for(Esb_sendTime=0;Esb_sendTime<SendTime;Esb_sendTime++){
  34. bsp_esb_send(buf,length);
  35. if(SendInternal_ms !=0)nrf_delay_ms(SendInternal_ms);
  36. }
  37. }
  38. #if ESB_RECV_SEND_TEST
  39. void Esb_Test_Send(void)
  40. {
  41. uint8_t buf[50]={0x00,0x01,0x02,0x03,0x04,0x05};
  42. uint8_t length = 50;
  43. send_protocol(1,0xA1,buf,length);
  44. }
  45. #endif