TI中文支持网
TI专业的中文技术问题搜集分享网站

CC2340R5: 定时开启和关闭广播状态,同时修改广播参数

Part Number:CC2340R5

为了最大程度降低功耗,我想通过定时器,如一分钟开启一次广播,更改广播参数后,立刻关闭广播,再一分钟后,开启广播。。。往复循环。

已完成内容:可以在BLEAPPUTIL_ADV_END 事件下,进行更新数据

void Peripheral_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
{
bStatus_t status;
switch(event)
{

case BLEAPPUTIL_ADV_END:
{
status = GapAdv_prepareLoadByHandle(peripheralAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE);
// Only update the data when return is successful
if (status == SUCCESS)
{
// Reload buffer to handle
// Here the advDataLen = sizeof(advData1) and it is setup in the app\_peripheral.c
// under advSetInitParamsSet_1
GapAdv_loadByHandle(peripheralAdvHandle_1, GAP_ADV_DATA_TYPE_ADV, sizeof(Manual_advData_Res), Manual_advData_Res);
}
MenuModule_printf(APP_MENU_ADV_EVENT, 0, "BLEAPPUTIL_ADV_END: "
MENU_MODULE_COLOR_YELLOW "%d" MENU_MODULE_COLOR_RESET,
((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);

break;
}

default:
{
break;
}
}
}

遇到的问题:在自定义线程下,在主函数或定时器下使用BLEAppUtil_advStop(),所有程序将会卡死。

void *mainThread(void *arg0)
{
/* 1 second delay */

uint32_t sleep_time = 2;
uint32_t newAdvInt = 2000;
bStatus_t status;
while (1)
{

sleep(sleep_time);
status = BLEAppUtil_advStart(peripheralAdvHandle_1, &advSetStartParamsSet_1);
sleep(sleep_time);
BLEAppUtil_advStop(peripheralAdvHandle_1);
GapAdv_destroy(peripheralAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE);
}
}
void emptyMain(void)
{
pthread_t thread;
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
/* Initialize the attributes structure with default values */
pthread_attr_init(&attrs);
/* Set priority, detach state, and stack size attributes */
priParam.sched_priority = 5; // Lower the priority of this task
retc = pthread_attr_setschedparam(&attrs, &priParam);
retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
retc = pthread_create(&thread, &attrs, mainThread, NULL);
sleep(2);
ADC_init(); // 初始化ADC
ClockP_Init();
ClockP_start(clockHandle); // 定时器开始计时
}

提出问题:如何在任意时刻使用BLEAppUtil_advStop(); 和 BLEAppUtil_advStart(),进行开启/关闭广播,或者说,应该放在哪里使用,是需要满足什么条件的前提下,才能使用BLEAppUtil_advStop(); 和 BLEAppUtil_advStart()吗?

XZP:

补充:项目背景是,读NTC温度传感器ADC的值,当温度小于设定阈值时,关闭广播,并且尽可能的低功耗,当高于阈值时,打开广播。遇到的问题就是,主函数内执行关闭广播:BLEAppUtil_advStop(peripheralAdvHandle_1); 时,整个程序会死机,想问一下,如何关闭广播才合适,或者说BLEAppUtil_advStop(peripheralAdvHandle_1);这个语句应该放在哪里执行

赞(0)
未经允许不得转载:TI中文支持网 » CC2340R5: 定时开启和关闭广播状态,同时修改广播参数
分享到: 更多 (0)