ProtocolSender.cpp 902 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * ProtocolSender.cpp
  3. *
  4. * Created on: Sep 8, 2017
  5. * Author: guoxs
  6. */
  7. #include "uart/ProtocolSender.h"
  8. #include "uart/UartContext.h"
  9. #include "utils/Log.h"
  10. #include <stdio.h>
  11. extern BYTE getCheckSum(const BYTE *pData, int len);
  12. /**
  13. * 需要根据协议格式进行拼接,以下只是个模板
  14. * Need to be spliced ​​according to the agreement format, the following is just a template
  15. */
  16. // uart是串口,pData是发送的内容,len发送内容的长度
  17. bool sendProtocolTo(int uart, const BYTE *pData, BYTE len) {
  18. BYTE dataBuf[256];
  19. //起始
  20. dataBuf[0] = 0x24;
  21. UINT frameLen = 1;
  22. // 数据
  23. for (int i = 0; i < len; ++i) { // 通过循环,判断数据的长度
  24. dataBuf[frameLen] = pData[i];
  25. frameLen++;
  26. }
  27. //LOGD("send msg len = %d, frameLen = %d", len, frameLen);
  28. //结束
  29. dataBuf[frameLen] = 0x23;
  30. return UartContext::sendTo(uart, dataBuf, frameLen+1);
  31. }