你好,
我们有一个外设解决方案,其中DA14580通过UART连接到我们的微控制器。DA14580查询控制器以获取来自中心的GATT读/写请求的特征值。
我们捕获read(atts_read_req_ind)和write(gattc_write_cmd_nind)事件在user_catch_rest_hndl()中
是否有一种机制可以阻止我们可以阻止,直到我们从控制器上从UART获取读取或写入请求的响应,然后从user_catch_rest_hndl()发送响应
简而言之,我们需要从user_catch_rest_hndl()中发送读/写请求并等待接收响应(UART中断),然后从user_catch_rest_hndl()发送响应数据。你能告诉我们这是怎么做的。任何指针,例子都会有所帮助。
Thanks,
hrishikesh.
设备:
嗨Dhrishi,
I dont quite understand the use case, you mention that the 580 is attached to the external MCU (i suppose this is what you mean when you say controller) and the controller provides the values for the characteristics.
那么,上面的情景做出了你想做的事吗?
Thanks MT_dialog
是的。确切地。那是对的。
我们如何做到这一点
嗨Dhrishi,
没有例子你想做什么since the databases values are kept in the internal database of the 580, also i am not quite sure about the block that you mentioned, since as soon as you get the indication (that a central has read or written a characteristic) the SDK will just report that to the application and its up to you what you are going to do. As far as i can tell, regarding what you woulid like to do, most of the commands used in the BLE spec are sequential, that means that most of the commands (including the Read Request and the Write Request) when issued by the central they should be confirmed by the peripheral which means that the central cannnot send an additional request if it doens't get a response from the previous command (this request/response scheme is like a flow control that the BLE protocol implements). So you can get the indication from the read or the write request, catch them in the catch_rest function and start your UART transaction, the central wont issue any additional request until you send a confirmation message, so as soon as your UART transaction is complete you can send the confirm on the other side of the link. Also be aware that not all commands follow the request/response scheme, for example a write command (write with no response) will trigger your indication but the central wont wait for a response and it can still issue an additional command while processing the previous one and that requires an additional flow control scheme.
因此,根据上面,当读取指示来自中心时,可以通过UART写入UART。关于发送你从UART读取的价值,就像我在不同的帖子中提到的那样,你不能只发送你通过UART直接获得的值,但你必须尽快在内部数据库中设置值读取指示,然后发送读取的确认。因此,在读取接收时触发UART事务调用ATTMDB_ATT_SET_VALUE()以便在数据库中设置值,然后在DG_ATTS_READ_CFM()中发送值。
此外,请注意,当您从UART读取时,您将不得不醒来,因此没有睡眠以获得XTAL16。
Thanks MT_dialog
我已经有Attmdb_att_set_value()和dg_atts_read_cfm()在我的实现中。问题是,当在user_catch_rest_hndl()中收到Atts_Read_Req_ind时,我将必须先向外部MCU发送请求,以获得该特征的值在数据接收时,调用上述两个功能。正确的?
现在,来自外部MCU的UART响应将来自中断上下文。因此,如何使当前执行线程在user_catch_rest_hndl()中等待,直到从外部MCU接收到适当的响应。否则它将通过调用以上两个功能来返回,其中垃圾/不正确值以及对中央的读取响应将不正确。
简而言之,我们应该等到接收到UART(从中断上下文)的响应,并且在GATT数据库中保存相同,然后发送读取确认。
嗨Dhrishi,
是的,这是我思考的,获取指示,启动UART事务,获取数据,并通过UART获得的值发送确认。
The 580 its not a thread based system, it just has a scheduler that schedules messages and executing the corresponding callbacks evertime the rwip_schedule() function runs from the main loop. So what you can try is, as soon as you get the reading indication, start the UART transaction or set up the UART for receiving data from the external MCU (that depends on your implementation and how the interaction will be) and either leave the catch_rest handler (by setting up an read interrupt) or stay there (executing the UART transastion, in that case you can't stay as long as you want executing UART transaction since you will start missing BLE event and eventually you will get disconnected since you wont be executing the scheduling function since you wont go through the main loop) as soon as the interaction gets completed. When the UART interrupt hits or the transaction has finished then just send the confirmation message to the client.
Thanks MT_dialog