ProtocolSender.cpp 976 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. #include <string>
  12. #include <string.h>
  13. #include "service/BusinessConfig.h"
  14. extern BYTE getCheckSum(const BYTE *pData, int len);
  15. /**
  16. * 需要根据协议格式进行拼接,以下只是个模板
  17. * Need to be spliced ​​according to the agreement format, the following is just a template
  18. */
  19. // uart是串口,pData是发送的内容,len发送内容的长度
  20. bool sendProtocolTo(int uart, const BYTE *pData, BYTE len) {
  21. BYTE dataBuf[256];
  22. //起始
  23. dataBuf[0] = 0x24;
  24. UINT frameLen = 1;
  25. // 数据
  26. for (int i = 0; i < len; ++i) { // 通过循环,判断数据的长度
  27. dataBuf[frameLen] = pData[i];
  28. frameLen++;
  29. }
  30. //LOGD("send msg len = %d, frameLen = %d", len, frameLen);
  31. //结束
  32. dataBuf[frameLen] = 0x23;
  33. return UartContext::sendTo(uart, dataBuf, frameLen+1);
  34. }