完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,我正在使用CYBLY-012011-00,而且我有麻烦编程我的BLE停止扫描,即使在遵循所需的步骤。请看下面我的代码。它是一个广告商的观察员。
无效StackEventHandler(UIT32事件,ValueEndoPARAM) { /*局部变量*/ CYBLY-GAPCL 开关(事件) { 案例CyLeLayEvtStaskon:/*Buffer-Loop** *开始扫描* 如果(CyByrErrOrthOK==CyByLyGAPcStistSCAN(CyByLyScNangIn FAST)) { PrTNF(“开始扫描rn”); } 断裂; 结果: AdvReals= *(CyByLyGAPcAdvdRePtRoTyt**)EvestPARAM; 断裂; CyBeLyEvtggpcSCANLYSTARGSTESTSTOP: UARTH2H2BuUARTPUSTSHIPE(“R nCyBuryEVTGGAPCX SCANLYSTARGSTESTORRN”); 断裂; 违约: 断裂; } } 三、***************************************************************************************** *函数名:BLE(); ***************************************************************************************************************************************************************************************** int(空) { 聚伞花序; CyBLY状态; 囊状的; 连接端=0; 而(连接项==0) { APIREST=CyBLYSTART(STACKEVENDEANDER); CyBLY-GAPCSTARSTCAN(CysLySCAN); 聚伞花序; } 当(CybulyStand)!= CyBytStayex断开) { CyBLY-GAPCSTOCTSCAN(); 聚伞花序; CyByLySt= CyByLyGETSTATE(); } } 基本上保持在CysLySt=胞浆扫描。 1)有没有其他人有类似的问题,如果是这样的话,有解决办法吗? 2)我可以使用CyByLyStStEATE()来获得CyByLySt= CyByLyStayex断开连接。然而,当我进入深度睡眠时,我醒来时没有其他的中断,所以我怀疑它可能还没有真正发挥作用。 任何帮助将不胜感激! 以上来自于百度翻译 以下为原文 HI there, I am using the CYBLE-012011-00 and I am having trouble programming my BLE to stop scanning even after following the required steps. Please see below my code. It is acting as an observer to an advertiser. void StackEventHandler(uint32 event, void* eventParam) { /*local variables*/ CYBLE_GAPC_ADV_REPORT_T advReport; switch(event) { case CYBLE_EVT_STACK_ON: /*BLE stack ON*/ /*Start Scanning*/ if(CYBLE_ERROR_OK==CyBle_GapcStartScan(CYBLE_SCANNING_FAST)) { printf("Started to Scanrn"); } break; case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT: advReport=*(CYBLE_GAPC_ADV_REPORT_T *)eventParam; break; case CYBLE_EVT_GAPC_SCAN_START_STOP: UART_H2B_UartPutString("rnCYBLE_EVT_GAPC_SCAN_START_STOPrn"); break; default: break; } } /******************************************************************************************************** * Function Name : BLE(); ********************************************************************************************************/ int BLE(void) { CYBLE_API_RESULT_T apiResult; CYBLE_STATE_T CYBLE_State; CyGlobalIntEnable; Connection_end = 0; while(Connection_end == 0) { apiResult = CyBle_Start(StackEventHandler); CyBle_GapcStartScan(CYBLE_SCANNING_FAST); CyBle_ProcessEvents(); } while(CYBLE_State != CYBLE_STATE_DISCONNECTED) { CyBle_GapcStopScan(); CyBle_ProcessEvents(); CYBLE_State = CyBle_GetState(); } } Essentially it remains in CYBLE_State = CYBLE_SCANNING 1) Has anyone else had a similar problem and if so is there a solution? 2) I can use CYBLE_SetState() to get to CYBLE_State = CYBLE_STATE_DISCONNECTED. However when I go into deepsleep I am waking up with no other interrupts, So I suspect it may still not be actually functioning correctly. Any help would be greatly appreciated! |
|
相关推荐
2个回答
|
|
嗨,帕特里克
按邮政编码: { 连接端=0; 而(连接项==0) { APIREST=CyBLYSTART(STACKEVENDEANDER); CyBLY-GAPCSTARSTCAN(CysLySCAN); 聚伞花序; } } 作为变量:连接端是init到0,所以条件(连接项=0=0)总是为1。这意味着CyByLyGAPCSTARTSCAN(CyByLyScNangGIN FAST);在(1)循环中被调用。这是你设计的功能吗? 感谢和问候 詹森 以上来自于百度翻译 以下为原文 Hi Patrick Per the post code: { Connection_end = 0; while(Connection_end == 0) { apiResult = CyBle_Start(StackEventHandler); CyBle_GapcStartScan(CYBLE_SCANNING_FAST); CyBle_ProcessEvents(); } } As the variable: Connection_end is init to 0, so the condition while(Connection_end == 0) is always 1. Which means the CyBle_GapcStartScan(CYBLE_SCNANING_FAST); is called in while(1) loop. Does this your designed function? Thanks & Regards Jenson |
|
|
|
当调用CyByStayScor()时,堆栈没有完全结束,直到返回CyByLyEvtGAPCXSCANEXSTARJSTEL回调事件。
因此,我建议您的代码调用CyByLyGAPcStCurthSo()函数,然后等待事件发生,而不是试图调用CyByLyGAPcStScor(),直到BLE状态改变。因为在停止扫描和停止扫描之间有一个抽象层/层,可能您调用CyByLyGAPcStCurthSo();在堆栈中成功停止扫描和停止事件发生,这可能导致停止事件再次发生(因为您调用停止)。再次扫描,这可能是唤醒的原因。 我建议对代码进行修改,使其看起来像这样: 无效StackEventHandler(UIT32事件,ValueEndoPARAM) { /*局部变量*/ CYBLY-GAPCL 开关(事件) { 案例CyLeLayEvtStaskon:/*Buffer-Loop** *开始扫描* 如果(CyByrErrOrthOK==CyByLyGAPcStistSCAN(CyByLyScNangIn FAST)) { PrTNF(“开始扫描rn”); } 断裂; 结果: AdvReals= *(CyByLyGAPcAdvdRePtRoTyt**)EvestPARAM; 断裂; CyBeLyEvtggpcSCANLYSTARGSTESTSTOP: UARTH2H2BuUARTPUSTSHIPE(“R nCyBuryEVTGGAPCX SCANLYSTARGSTESTORRN”); 断裂; 违约: 断裂; } } 三、***************************************************************************************** *函数名:BLE(); ***************************************************************************************************************************************************************************************** int(空) { 聚伞花序; CyBLY状态; 囊状的; 连接端=0; APIREST=CyBLYSTART(STACKEVENDEANDER); /Staskon事件发生时被调用,所以我们不需要在这里调用它。 /CyBLY-GAPCSTARSTCAN(CyBysSCAN); 而(CalnDeNeXORD=0)/假设这被设置为!0至少跑一次 { 聚伞花序; 当准备停止扫描时,//设置连接结束=1 } CyBLY-GAPCSTOCTSCAN(); 当(CybulyStand)!= CyBytStayex断开) { 聚伞花序; CyByLySt= CyByLyGETSTATE(); } } 关于代码的一些注释: 看起来你在调用while循环中的CyByLyStad(),这只需要在BLE使用之前调用一次,而不是轮询/连续调用。 与CyByLyGAPCSTECKSCAN()和CyByLyGAPCSTARTSCAN()函数相同。 CyByLePraceSeVScript()基本上应该运行每个XMS以符合BLE处理时间要求,其中X是BLE设置(在BLE组件下)的连接间隔。一般来说,我会把它放在我的代码的主循环中,然后只使用主标志循环回以触发一次性操作,作为一个“基于事件的”代码体系结构。这也简化了为循环和检查状态编写代码所需的代码。然而,它使得标志和信令成比例复杂。 以上来自于百度翻译 以下为原文 When you call the CybleStopScan(), the stack isn't fully finished stopping until it returns the CYBLE_EVT_GAPC_SCAN_START_STOP callback event. Thus, I would suggest having your code call the CyBle_GapcStopScan(); function, and then wait until the event occurrs, rather than attempting to call the CyBle_GapcStopScan(); over and over until the BLE state changes. Because there is an abstraction/layer between the stop scan, and the scan being stopped, possibly you are calling the CyBle_GapcStopScan(); between the stack successfully stopping scanning and the stop event occurring, which then could lead to the stop event occurring again (since you call the stop scan again), which could be the cause of the wakeup. I would suggest a change to your code to look like this: void StackEventHandler(uint32 event, void* eventParam) { /*local variables*/ CYBLE_GAPC_ADV_REPORT_T advReport; switch(event) { case CYBLE_EVT_STACK_ON: /*BLE stack ON*/ /*Start Scanning*/ if(CYBLE_ERROR_OK==CyBle_GapcStartScan(CYBLE_SCANNING_FAST)) { printf("Started to Scanrn"); } break; case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT: advReport=*(CYBLE_GAPC_ADV_REPORT_T *)eventParam; break; case CYBLE_EVT_GAPC_SCAN_START_STOP: UART_H2B_UartPutString("rnCYBLE_EVT_GAPC_SCAN_START_STOPrn"); break; default: break; } } /******************************************************************************************************** * Function Name : BLE(); ********************************************************************************************************/ int BLE(void) { CYBLE_API_RESULT_T apiResult; CYBLE_STATE_T CYBLE_State; CyGlobalIntEnable; Connection_end = 0; apiResult = CyBle_Start(StackEventHandler); //scanstart is being called when the stack_on event occurs, so we don't need to call it up here //CyBle_GapcStartScan(CYBLE_SCANNING_FAST); while(Connection_end == 0) //Assuming this is getting set to !0 after running at least once { CyBle_ProcessEvents(); //Set Connection_end = 1 when ready to stop scanning } CyBle_GapcStopScan(); while(CYBLE_State != CYBLE_STATE_DISCONNECTED) { CyBle_ProcessEvents(); CYBLE_State = CyBle_GetState(); } } Some notes on your code: It seems like you are calling the Cyble_Start() inside a while loop; This only needs to be called once before BLE usage, not polling/continuously Same with the CyBle_GapcStopScan() and the CyBle_GapcStartScan() functions. CyBle_ProcessEvents() should basically be run every x ms to comply with the BLE processing time requirements where x is the connection interval of the BLE settings (under the BLE component). Generally I would put it in the main loop of my code, and then just loop back to main using flags to trigger one-time operations as an "event based" architecture of code. This also simplifies the code you need to write for loops and checking states. It does however make the flags and signaling more complicated proportionally. |
|
|
|
只有小组成员才能发言,加入小组>>
750个成员聚集在这个小组
加入小组2055 浏览 1 评论
1811 浏览 1 评论
3622 浏览 1 评论
请问可以直接使用来自FX2LP固件的端点向主机FIFO写入数据吗?
1747 浏览 6 评论
1499 浏览 1 评论
CY8C4025LQI在程序中调用函数,通过示波器观察SCL引脚波形,无法将pin0.4(SCL)下拉是什么原因导致?
484浏览 2评论
CYUSB3065焊接到USB3.0 TYPE-B口的焊接触点就无法使用是什么原因导致的?
339浏览 2评论
CX3连接Camera修改分辨率之后,播放器无法播出camera的画面怎么解决?
401浏览 2评论
343浏览 2评论
使用stm32+cyw43438 wifi驱动whd,WHD驱动固件加载失败的原因?
836浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-10 16:15 , Processed in 0.603903 second(s), Total 47, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号