This commit is contained in:
joy,zhou 2021-02-02 14:26:33 +08:00
parent 6bf7291552
commit 083675759b
3 changed files with 9 additions and 5 deletions

View File

@ -135,10 +135,10 @@ DeviceInfo包括如下信息
--- ---
<a name="set_rrpc_callback"></a> <a name="set_rrpc_callback"></a>
### SubDevice.set_rrpc_callback(msg_callback) ### SubDevice.set_rrpc_callback(msg_callback)->bytes
设置子设备的接收RRPC的回调函数 设置子设备的接收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'`
--- ---

View File

@ -38,8 +38,8 @@ class SubDevice(object):
def set_msg_callback(self, msg_callback): def set_msg_callback(self, msg_callback):
self.callback = msg_callback self.callback = msg_callback
def set_rrpc_callback(self, msg_callback): def set_rrpc_callback(self, rrpc_callback):
self.rrpc = msg_callback self.rrpc = rrpc_callback
def get_device_info(self): def get_device_info(self):
return { return {

View File

@ -398,7 +398,11 @@ def _on_message(message):
sub_dev = _connect_map[identify] sub_dev = _connect_map[identify]
if isinstance(topic, str) and topic.startswith("/$system/") and topic.find("/rrpc/request/") > 0: if isinstance(topic, str) and topic.startswith("/$system/") and topic.find("/rrpc/request/") > 0:
if sub_dev.rrpc: 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: if sub_dev.callback:
sub_dev.callback(topic, msg) sub_dev.callback(topic, msg)