123456789101112131415161718192021222324252627282930313233343536 |
- /*
- * ProtocolSender.cpp
- *
- * Created on: Sep 8, 2017
- * Author: guoxs
- */
- #include "uart/ProtocolSender.h"
- #include "uart/UartContext.h"
- #include "utils/Log.h"
- #include <stdio.h>
- extern BYTE getCheckSum(const BYTE *pData, int len);
- /**
- * 需要根据协议格式进行拼接,以下只是个模板
- * Need to be spliced according to the agreement format, the following is just a template
- */
- // uart是串口,pData是发送的内容,len发送内容的长度
- bool sendProtocolTo(int uart, const BYTE *pData, BYTE len) {
- BYTE dataBuf[256];
- //起始
- dataBuf[0] = 0x24;
- UINT frameLen = 1;
- // 数据
- for (int i = 0; i < len; ++i) { // 通过循环,判断数据的长度
- dataBuf[frameLen] = pData[i];
- frameLen++;
- }
- //LOGD("send msg len = %d, frameLen = %d", len, frameLen);
- //结束
- dataBuf[frameLen] = 0x23;
- return UartContext::sendTo(uart, dataBuf, frameLen+1);
- }
|