This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CC2340R5:影响配对的 UART 回调实现

Guru**** 2589280 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1385597/cc2340r5-uart-callback-implementation-affecting-pairing

器件型号:CC2340R5

工具与软件:

您好!

在  basic_ble OAD 外围设备项目中、我们将根据 UART 回调实现观察配对过程中的不同行为。

以下 是两种不同的实现方式:

观察结果:

实施1:我们没有在远程设备(移动电话)上收到 PASSKEY 输入弹出窗口、最终每次配对都失败、而且我们也没有收到 BLEAPPUTIL_PAIRING_STATE_COMPLETE 事件。

实施2:配对成功。  

我们需要使用实施 1来正确处理 UART 交换、但配对失败、最好建议解决方案。

SDK 版本:simplelink_lowpower_f3_sdk_8_10_01_02  

CCS 版本:CCS 12.7.1

//Global variables
uint8_t uartReadBuffer[100] = {0};
uint8_t uartPacketSize = 0;



//Implemention 1:

void HandlingFunction(char *pData)
{
	uint8_t *pDataBase = NULL;
    pDataBase = pData;
    uint8_t len = *pData;
    pData++;
    UART2_write(uart, pDataBase,len+1, 0);
	UART2_read(uart, &uartReadBuffer, UART_MAX_READ_SIZE,0);
}

void UARTCallback(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
   
	uint8_t *idx = NULL;
	uint8_t *data = BLEAppUtil_malloc(count);
	idx = data;
	*idx = count;
	idx++;
	memcpy(idx, buffer, count);
	BLEAppUtil_invokeFunction(HandlingFunction, data);
	memset(uartReadBuffer,0,sizeof(uartReadBuffer));
}

//Implemention 2:

void HandlingFunction(char *pData)
{
	UART2_write(uart, uartReadBuffer,uartPacketSize, 0);
	memset(uartReadBuffer,0,sizeof(uartReadBuffer));
	UART2_read(uart, &uartReadBuffer, UART_MAX_READ_SIZE,0);
}

void UARTCallback(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
    uartPacketSize = count;
    BLEAppUtil_invokeFunction(HandlingFunction, NULL);
}

谢谢!

Vignesh。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Vignesh:  

    感谢您的咨询。  

    在执行1的代码中、对于第23行、你可以尝试在 count 之后添加+1、如下所示:

    uint8_t *data = BLEAppUtil_malloc(count+1);

    如果可行、请告诉我。  

    选项2:您是否也可以尝试在不进行以上任何更改的情况下将以下内容用于第28行:  

    BLEAppUtil_invokeFunctionNoData(HandlingFunction);

    此函数接收回调和数据并切换环境、以便从 BLE App Util 模块环境来调用此回调。 如果您仍然收到错误、请告诉我?

    此外、我们还有一个完整的 UART over BLE 示例、您可以查看:  BLE 上的数据流 UART 示例

    此致

    Ivan