From 083675759bd08c3da20c5cd44c299bf6a6914b1e Mon Sep 17 00:00:00 2001 From: "joy,zhou" Date: Tue, 2 Feb 2021 14:26:33 +0800 Subject: [PATCH] add --- README.md | 4 ++-- iotedgedriverlinksdk/client.py | 4 ++-- iotedgedriverlinksdk/edge.py | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 84c777b..679ae15 100644 --- a/README.md +++ b/README.md @@ -135,10 +135,10 @@ DeviceInfo包括如下信息: --- -### 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'` --- diff --git a/iotedgedriverlinksdk/client.py b/iotedgedriverlinksdk/client.py index 6bb2e09..34c8307 100644 --- a/iotedgedriverlinksdk/client.py +++ b/iotedgedriverlinksdk/client.py @@ -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 { diff --git a/iotedgedriverlinksdk/edge.py b/iotedgedriverlinksdk/edge.py index 4110794..587b23e 100644 --- a/iotedgedriverlinksdk/edge.py +++ b/iotedgedriverlinksdk/edge.py @@ -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)