add
This commit is contained in:
parent
6bf7291552
commit
083675759b
|
@ -135,10 +135,10 @@ DeviceInfo包括如下信息:
|
|||
|
||||
---
|
||||
<a name="set_rrpc_callback"></a>
|
||||
### SubDevice.set_rrpc_callback(msg_callback)
|
||||
### SubDevice.set_rrpc_callback(msg_callback)->bytes
|
||||
设置子设备的接收RRPC的回调函数
|
||||
|
||||
* set_RRPC_callback`func`: 子设备收消息回调,例如:` def callbacl(topic:str, msg:b''): print(str(msg,'utf-8')`
|
||||
* set_RRPC_callback`func`: 子设备收消息回调,例如:` def callback(topic:str, msg:b''): return b 'hello'`
|
||||
|
||||
|
||||
---
|
||||
|
|
|
@ -38,8 +38,8 @@ class SubDevice(object):
|
|||
def set_msg_callback(self, msg_callback):
|
||||
self.callback = msg_callback
|
||||
|
||||
def set_rrpc_callback(self, msg_callback):
|
||||
self.rrpc = msg_callback
|
||||
def set_rrpc_callback(self, rrpc_callback):
|
||||
self.rrpc = rrpc_callback
|
||||
|
||||
def get_device_info(self):
|
||||
return {
|
||||
|
|
|
@ -398,7 +398,11 @@ def _on_message(message):
|
|||
sub_dev = _connect_map[identify]
|
||||
if isinstance(topic, str) and topic.startswith("/$system/") and topic.find("/rrpc/request/") > 0:
|
||||
if sub_dev.rrpc:
|
||||
sub_dev.rrpc(topic, msg)
|
||||
resp = sub_dev.rrpc(topic, msg)
|
||||
if not resp:
|
||||
topic = topic.replace(
|
||||
"/rrpc/request/", "/rrpc/response/", 1)
|
||||
sub_dev.publish(topic, resp)
|
||||
|
||||
if sub_dev.callback:
|
||||
sub_dev.callback(topic, msg)
|
||||
|
|
Loading…
Reference in New Issue