#include <stdbool.h>
uint32_t cmdSendData(const char *pcData, uint32_t ui32ByteCount)
{
uint32_t retCode = SBL_SUCCESS;
bool bSuccess = false;
// Check input arguments
if(ui32ByteCount > SBL_CC2650_MAX_BYTES_PER_TRANSFER)
{
printf("Error: Byte count (%d) exceeds maximum transfer size %d.\n", ui32ByteCount, SBL_CC2650_MAX_BYTES_PER_TRANSFER);
return SBL_ERROR;
}
// Send command
retCode = sendCmd(CMD_SEND_DATA, pcData, ui32ByteCount);
if(retCode != SBL_SUCCESS)
{
return retCode;
}
// Receive command response (ACK/NAK)
retCode = getCmdResponse(&bSuccess, 3);
if(retCode != SBL_SUCCESS)
{
return retCode;
}
if(!bSuccess)
{
return SBL_ERROR;
}
return SBL_SUCCESS;
}
解释:
首先我们包含<stdbool.h>以便我们可以使用bool数据类型。
函数cmdSendData不再是一个类的成员函数,所以我们去掉了类作用域(SblDeviceCC2650::)。
在发送命令和接收命令响应部分,我们使用了常量而不是类静态常量。我们假设这些常量(如SBL_SUCCESS, SBL_ERROR, SBL_CC2650_MAX_BYTES_PER_TRANSFER, CMD_SEND_DATA)已在其他地方定义。
对于getCmdResponse函数,我们假设它接受一个bool指针和一个整数作为参数。我们将bSuccess的地址传递给它,这样它可以更新bSuccess的值。