更新时间:2024-06-14 GMT+08:00
分享

DriverClient方法说明

ModuleSDK中,客户端类DriverClient提供多个方法供客户开发应用时使用,使用时可参考每个函数的功能定义。

表1 DriverClient方法说明

接口

说明

createFromEnv

根据环境变量创建客户端,相关配置参数从环境变量获取。

setGatewayCallback

设置网关回调,实现对子设备下行请求、网关下行事件的处理。

sendDeviceMessage

发送设备消息。

sendDeviceEvent

发送设备事件。

getDeviceShadow

获取设备影子。

reportSubDevicesProperties

批量上报子设备属性。

reportSubDevicesPropertiesAndDiscovery

上报子设备发现属性。

syncSubDevices

发送子设备同步请求事件。

updateSubDevicesStatus

发送更新子设备状态事件。

getProducts

发送获取产品事件。

reportScanResult

上报子设备扫描结果。

DriverClient::createFromEnv

根据环境变量创建客户端,相关配置参数从环境变量获取。

函数描述

public static DriverClient createFromEnv()throws GeneraException

DriverClient::setGatewayCallback

设置网关回调,实现对子设备下行请求、网关下行事件的处理。

函数描述

public void setGatewayCallback(GatewayCallback gatewayCallback)
表2 参数说明

参数名称

类型

参数描述

gatewayCallback

GatewayCallback

网关回调类实例

表3 GatewayCallback需要实现的回调接口

回调接口

参数描述

void onDeviceMessageReceived(Message message)

收到子设备消息回调

CommandRsp onDeviceCommandCalled(String requestId, Command command)

收到子设备命令回调

IotResult onDevicePropertiesSet(String requestId, PropsSet propsSet)

收到子设备属性设置回调

PropsGetRsp onDevicePropertiesGet(String requestId, PropsGet propsGet)

收到子设备属性获取回调

void onDeviceShadowReceived(String requestId, ShadowGetRsp shadowGetRsp)

收到子设备影子回调

void onDeviceEventReceived(Event event)

收到子设备事件回调

void onSubDevicesAdded(String eventId, AddSubDevicesEvent addSubDevicesEvent)

收到新增子设备事件回调

void onSubDevicesDeleted(String eventId, DeleteSubDevicesEvent deleteSubDevicesEvent)

收到新增子设备事件回调

void onGetProductsResponse(String eventId, GetProductsRspEvent response)

收到获取产品应答回调

void onStartScan(String eventId, StartScanEvent startScanEvent)

收到启动子设备扫描回调

DriverClient::sendDeviceMessage

发送设备消息。

函数描述

public void sendDeviceMessage(Message message) throws IllegalArgumentException, JsonException
表4 参数说明

参数名称

类型

参数描述

message

Message

设备消息

DriverClient::sendDeviceEvent

发送设备消息。

函数描述

public void sendDeviceEvent(Event event) throws IllegalArgumentException, JsonException
表5 参数说明

参数名称

类型

参数描述

event

Event

设备事件

DriverClient::getDeviceShadow

获取设备影子。

函数描述

public void getDeviceShadow(String requestId, ShadowGet shadowGet) throws IllegalArgumentException, JsonException
表6 参数说明

参数名称

类型

参数描述

requestId

String

请求ID

shadowGet

ShadowGet

应获取请求

DriverClient::reportSubDevicesProperties

批量上报子设备属性。

函数描述

public void reportSubDevicesProperties(SubDevicesPropsReport report)
表7 参数说明

参数名称

类型

参数描述

report

SubDevicesPropsReport

子设备属性上报消息体

DriverClient::reportSubDevicesPropertiesAndDiscovery

上报子设备发现属性。

函数描述

public void reportSubDevicesPropertiesAndDiscovery(SubDevicesDiscoveryPropsReport report)
表8 参数说明

参数名称

类型

参数描述

report

SubDevicesDiscoveryPropsReport

子设备发现属性数据消息体

DriverClient::syncSubDevices

发送子设备同步请求事件。

函数描述

public void syncSubDevices(String eventId, SyncSubDevicesEvent syncSubDevicesEvent) throws IllegalArgumentException, JsonException
表9 参数说明

参数名称

类型

参数描述

eventId

String

事件ID

syncSubDevicesEvent

SyncSubDevicesEvent

同步子设备请求事件

DriverClient::updateSubDevicesStatus

发送更新子设备状态事件。

函数描述

public void updateSubDevicesStatus(String eventId, UpdateSubDevicesStatusEvent statusEvent) throws JsonException
表10 参数说明

参数名称

类型

参数描述

eventId

String

事件ID

statusEvent

UpdateSubDevicesStatusEvent

更新子设备状态事件

DriverClient::getProducts

发送获取产品事件。

函数描述

public void getProducts(String eventId, GetProductsEvent getProductsEvent) throws IllegalArgumentException, JsonException
表11 参数说明

参数名称

类型

参数描述

eventId

String

事件ID

getProductsEvent

GetProductsEvent

获取产品事件

DriverClient::reportScanResult

上报子设备扫描结果。

函数描述

public void reportScanResult(String eventId, ScanResultEvent scanResultEvent) throws JsonException
表12 参数说明

参数名称

类型

参数描述

eventId

String

事件ID

scanResultEvent

ScanResultEvent

子设备扫描结果事件

分享:

    相关文档

    相关产品