更新时间:2024-07-01 GMT+08:00
分享

观察者模式

Java版本Agent Lite采用了观察者模式,用来实现Agent Lite上报的消息。

第三方通过实现Agent Lite提供的public void update (IotaMessage arg0)接口来接收数据。

通过registerObserver(MyObserver o)来注册观察者,removeObserver(MyObserver o)来移除观察者。

IotaMessage类说明:

1
2
3
4
bind后接收响应获取appiddeviceidsecret
String appId = iotaMsg.getString(BindService.BIND_IE_APPID);
String deviceId = iotaMsg.getString(BindService.BIND_IE_DEVICEID);
String secret = iotaMsg.getString(BindService.BIND_IE_DEVICESECRET);
1
2
3
4
上报数据收到响应
String deviceId = iotaMsg.getString(DataTransService.DATATRANS_IE_DEVICEID);
int retcode = iotaMsg.getUint(DataTransService.DATATRANS_IE_RESULT, 0);
intcookie = iotaMsg.getUint(DataTransService.DATATRANS_IE_COOKIE, 0);
1
2
3
4
5
6
命令接收
String deviceId = iotaMsg.getString(DataTransService.DATATRANS_IE_DEVICEID);
String requestId = iotaMsg.getString(DataTransService.DATATRANS_IE_REQUSTID);
String serviceId = iotaMsg.getString(DataTransService.DATATRANS_IE_SERVICEID);
String method = iotaMsg.getString(DataTransService.DATATRANS_IE_METHOD);
String cmd = iotaMsg.getString(DataTransService.DATATRANS_IE_CMDCONTENT);
1
2
3
设备添加收到响应ret = 0表示成功):
String deviceId =iotaMsg.getString(HubService.HUB_IE_DEVICEID);
int ret = iotaMsg.getUint(HubService.HUB_IE_RESULT, HubService.HUB_RESULT_FAILED);
1
2
3
设备删除收到响应result = 0表示成功):
int result = iotaMsg.getUint(HubService.HUB_IE_RESULT, 0);
int cookie = iotaMsg.getUint(HubService.HUB_IE_COOKIE, 0);
1
2
3
更新设备状态收到响应result = 0表示成功):
int result = iotaMsg.getUint(HubService.HUB_IE_RESULT, 0);
int cookie = iotaMsg.getUint(HubService.HUB_IE_COOKIE, 0);
1
2
收到设备登出 (错误码信息对照loginService定义)
int reason = iotaMsg.getUint(LoginService.LOGIN_IE_RESULT, -1);

相关文档