HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java
@@ -38,6 +38,7 @@ public static final HDLLinkCode HDL_TOPIC_NOT_RIGHT=new HDLLinkCode(-2110,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_TOPIC_NOT_RIGHT)); public static final HDLLinkCode HDL_OBJECT_NOT_SUPPORT=new HDLLinkCode(-2111,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_OBJECT_NOT_SUPPORT)); public static final HDLLinkCode HDL_GATEWAY_REMOTE_NOT_RESPONSE=new HDLLinkCode(-2112,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.HDL_GATEWAY_REMOTE_NOT_RESPONSE)); public static final HDLLinkCode HDL_SUCCESS=new HDLLinkCode(0,HDLLinkLocalSdk.getInstance().getContext().getString(R.string.SUCCESS)); private String msg; private int code; HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java
@@ -34,7 +34,7 @@ public void setByteData(byte []data) { this.byteData = data; this.data = new String(data); // this.data = new String(data); this.length=data.length; } @@ -45,7 +45,7 @@ public void setData(String data) { this.data = data; if (!TextUtils.isEmpty(data)) { this.byteData = data.getBytes(); // this.byteData = data.getBytes(); setLength(data.length()); } else { setLength(0); HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ModbusResponse.java
New file @@ -0,0 +1,88 @@ package com.hdl.sdk.link.core.bean; import androidx.annotation.NonNull; import com.hdl.sdk.link.common.utils.gson.GsonConvert; import java.io.Serializable; /** * Created by hxb on 2021/12/19. */ public class ModbusResponse implements Serializable { /** * 原生主题 */ private String topic; /** * 原生数据 */ private byte []data; /** * 网关Oid */ private String oid; /** * 获取原生主题 * * @return */ public String getTopic() { return topic; } /** * 设置原生主题 * * @param topic */ public void setTopic(String topic) { this.topic = topic; } /** * 获取原生数据 * * @return */ public byte []getData() { return data; } /** * 设置原生数据 * * @param data */ public void setData(byte []data) { this.data = data; } /** * 获取网关主要信息,可能是oid,可能是网关Id,可能是mac * * @return */ public String getOid() { return oid; } /** * 设置Oid * * @param */ public void setOid(String oid) { this.oid = oid; } @NonNull @Override public String toString() { return GsonConvert.getGson().toJson(this); } } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ModbusCallBack.java
@@ -8,5 +8,5 @@ * Created by hxb on 2021/12/15. */ public interface ModbusCallBack extends BaseCallBack { void onSuccess(String msg); void onSuccess(byte []data); } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java
@@ -12,6 +12,7 @@ import com.hdl.sdk.link.common.utils.ThreadToolUtils; import com.hdl.sdk.link.core.bean.LinkRequest; import com.hdl.sdk.link.core.bean.LinkResponse; import com.hdl.sdk.link.core.bean.ModbusResponse; import com.hdl.sdk.link.core.bean.ZigbeeResponse; import com.hdl.sdk.link.core.bean.gateway.GatewayBean; import com.hdl.sdk.link.core.config.HDLLinkConfig; @@ -126,6 +127,14 @@ else{ notifyFailure(HDLLinkCode.HDL_TOPIC_NOT_RIGHT); } }else if(msg instanceof ModbusResponse){ ModbusResponse response = (ModbusResponse) msg; if (replyTopic.equals(response.getTopic())) { notifySucceed(response.getData()); } else{ notifyFailure(HDLLinkCode.HDL_TOPIC_NOT_RIGHT); } } else{ notifyFailure(new HDLLinkCode(HDLLinkCode.HDL_OBJECT_NOT_SUPPORT.getCode(), "Object Name:" + msg)); HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLModBusConnect.java
@@ -11,9 +11,9 @@ import com.hdl.sdk.link.common.utils.LogUtils; import com.hdl.sdk.link.core.bean.LinkRequest; import com.hdl.sdk.link.core.bean.LinkResponse; import com.hdl.sdk.link.core.bean.ModbusResponse; import com.hdl.sdk.link.core.bean.ZigbeeResponse; import com.hdl.sdk.link.core.bean.gateway.GatewayBean; import com.hdl.sdk.link.core.callback.BaseCallBack; import com.hdl.sdk.link.core.callback.ModbusCallBack; import com.hdl.sdk.link.core.callback.ZigbeeCallBack; import com.hdl.sdk.link.core.config.HDLLinkConfig; @@ -28,9 +28,9 @@ private static final String TAG="HDLModbusConnect"; private static HDLModBusConnect instance; /** * 内部用,主要是处理处理掉透传主题及link主题后,还原Zigbee原生数据及主题用 * 内部用,主要是处理处理掉透传主题及link主题后,还原modbus原生数据及主题用 */ private final String zigbeeAllTopic = "/Modbus"; private final String allTopic = "/Modbus"; /** * 返回当前实例,不存在就创建并同时注册监听事件 @@ -54,7 +54,7 @@ if(null==eventListener){ return; } EventDispatcher.getInstance().register(zigbeeAllTopic, eventListener); EventDispatcher.getInstance().register(allTopic, eventListener); } /** @@ -66,7 +66,7 @@ if(null==eventListener){ return; } EventDispatcher.getInstance().remove(zigbeeAllTopic, eventListener); EventDispatcher.getInstance().remove(allTopic, eventListener); } /** @@ -76,44 +76,39 @@ final EventListener eventListener = new EventListener() { @Override public void onMessage(Object msg) { // try { // if (msg instanceof LinkResponse) { // LinkResponse linkResponse = (LinkResponse) msg; // String body = linkResponse.getData(); // int index = body.indexOf("{"); // //zigbee回复的数据前有主题,后面才是数据 // if (index <= 0) // return; // // String zigbeeTopic = body.substring(0, index).trim(); // //zigbee的负载数据 // String bodyData = body.substring(index); // // ZigbeeResponse zigbeeResponse = new ZigbeeResponse(); // zigbeeResponse.setTopic(zigbeeTopic); // zigbeeResponse.setData(bodyData); // String oid = null; // //是否是通过主网关透传主题 // if (linkResponse.getTopic().contains("/slaveoid/")) { // oid = linkResponse.getTopic().split("/")[8]; // } else { // oid = linkResponse.getTopic().split("/")[2]; // } // zigbeeResponse.setOid(oid); // for (GatewayBean gatewayBean : HDLLinkLocalGateway.getInstance().getGatewayList()) { // if (oid.equals(gatewayBean.getGatewayId()) || oid.equals(gatewayBean.getDevice_mac()) || oid.equals(gatewayBean.getOid())) { // //上面的oid可能是网关id或者mac或者是oid,不管是哪个统一使用oid表示方式 // zigbeeResponse.setOid(gatewayBean.getOid()); // break; // } // } // EventDispatcher.getInstance().post(zigbeeTopic, zigbeeResponse); // //发布Zigbee原生主题及数据 // EventDispatcher.getInstance().post(zigbeeAllTopic, zigbeeResponse); // } // } catch (Exception e) { // LogUtils.e(TAG,"LinkResponse转ZigbeeResponse异常:"+ e.getMessage()); // } try { if (msg instanceof LinkResponse) { LinkResponse linkResponse = (LinkResponse) msg; if(linkResponse.getTopic()==null||!linkResponse.getTopic().contains("custom/native/inverter/")) { return; } byte []data = linkResponse.getByteData(); ModbusResponse modbusResponse= new ModbusResponse(); modbusResponse.setTopic("Modbus"+data[0]+data[1]); modbusResponse.setData(data); String oid = null; //是否是通过主网关透传主题 if (linkResponse.getTopic().contains("/slaveoid/")) { oid = linkResponse.getTopic().split("/")[8]; } else { oid = linkResponse.getTopic().split("/")[2]; } modbusResponse.setOid(oid); for (GatewayBean gatewayBean : HDLLinkLocalGateway.getInstance().getGatewayList()) { if (oid.equals(gatewayBean.getGatewayId()) || oid.equals(gatewayBean.getDevice_mac()) || oid.equals(gatewayBean.getOid())) { //上面的oid可能是网关id或者mac或者是oid,不管是哪个统一使用oid表示方式 modbusResponse.setOid(gatewayBean.getOid()); break; } } EventDispatcher.getInstance().post(allTopic, modbusResponse); //发布Zigbee原生主题及数据 // EventDispatcher.getInstance().post(allTopic, zigbeeResponse); } } catch (Exception e) { LogUtils.e(TAG,"LinkResponse转ModbusResponse异常:"+ e.getMessage()); } } }; //注册直接通讯的主题,包括直接和主网关通讯或者直接和从网关通讯 @@ -127,11 +122,10 @@ * 发送原生数据 * * @param gatewayOidOrGatewayId 目标网关的oid或者网关Id * @param responeTopic 回复主题 * @param payload 发送数据 * @param baseCallBack 结果回调 */ public void Send(String gatewayOidOrGatewayId,String responeTopic, String payload, final ModbusCallBack baseCallBack) { public void Send(String gatewayOidOrGatewayId, byte []payload, final ModbusCallBack baseCallBack) { //如果本地有链接这个网关,则用本地连接 GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayByOidOrGatewayId(gatewayOidOrGatewayId); if (null == gatewayBean) { @@ -150,17 +144,19 @@ } else { request.setCloudTopic(String.format(TopicConstant.NATIVE_MODBUS_DOWN_SLAVE, HDLLinkConfig.getInstance().getGatewayId(), gatewayOidOrGatewayId)); } request.setReplyTopic(responeTopic); request.setReplyTopic("Modbus"+payload[0]+payload[1]); long timeout = 2 * 1000; new HDLConnectHelper(timeout, 1, gatewayBean.getIp_address(), 8586, request, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { // if (msg instanceof String) { // if (null != baseCallBack) { // baseCallBack.onSuccess(msg+""); // } // } if (msg instanceof Byte[]) { if (null != baseCallBack) { baseCallBack.onSuccess((byte[])msg); } }else{ LogUtils.e("发送Modbus回调对象类型非数组类型,类型是"+msg.getClass()); } } @Override HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java
@@ -117,9 +117,10 @@ } else { response.setData(new String(linkPacket.getBody(), "utf-8")); } // if (HDLConnectHelper.isLocal()) { LogUtils.i("本地接收到数据:\r\n" + response.getTopic() + "\r\n" + response.getData()); // } response.setByteData(linkPacket.getBody()); // if (HDLConnectHelper.isLocal()) { LogUtils.i("本地接收到数据:\r\n" + response.getTopic() + "\r\n" + response.getData()); // } //解析完成,topic发送一次 EventDispatcher.getInstance().post(response.getTopic(), response); } HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/gateway/HDLLinkLocalGateway.java
@@ -716,25 +716,26 @@ /** * 发送数据到Link网关 * * @param ip 网关IP * @param mac 网关mac * @param isEncrypt 是否加密 * @param topic 请求主题 * @param jObject 负载数据<没有填null></> * @param sendPath 发送路径<类名+方法名>class->methodName</> */ public void sendDataToLinkGateway(String ip, String mac, boolean isEncrypt, public void sendDataToLinkGateway(String mac, boolean isEncrypt, String topic, Object jObject, String sendPath, HDLLinkCallBack callBack) { String topicSend = topic.replace("%s", mac); GatewayBean gatewayBean = this.getLocalGateway(mac); if (gatewayBean == null) { callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); return; } String topicSend = topic.replace("%s", gatewayBean.getOid()); //组装需要发送的数据 String sendStr = createSendData(jObject); // LogUtils.i("sendDataToLinkGateway->" + sendPath + "->本地发送\r\n" + topicSend + "\r\n" + sendStr); LinkRequest message = new LinkRequest(topicSend, sendStr, isEncrypt); GatewayBean gatewayBean = this.getLocalGateway(mac); if (gatewayBean != null) { message.setCloudTopic(topic.replace("%s", gatewayBean.getGatewayId())); } new HDLConnectHelper(ip, message, new HDLConnectHelper.HdlSocketListener() { message.setCloudTopic(topic.replace("%s", gatewayBean.getGatewayId())); new HDLConnectHelper(gatewayBean.getIp_address(), message, new HDLConnectHelper.HdlSocketListener() { @Override public void onSucceed(Object msg) { if (callBack == null) return; HDLLinkLocalSdk/src/main/res/values-zh/strings_code.xml
@@ -24,4 +24,5 @@ <string name="HDL_TOPIC_NOT_RIGHT">主题没有匹配</string> <string name="HDL_OBJECT_NOT_SUPPORT">对象不支持</string> <string name="HDL_GATEWAY_REMOTE_NOT_RESPONSE">网关本地连接失败,通过远程通讯不回复</string> <string name="SUCCESS">成功</string> </resources> HDLLinkLocalSdk/src/main/res/values/strings_code.xml
@@ -24,4 +24,5 @@ <string name="HDL_TOPIC_NOT_RIGHT">Theme does not match</string> <string name="HDL_OBJECT_NOT_SUPPORT">Object not supported</string> <string name="HDL_GATEWAY_REMOTE_NOT_RESPONSE">Gateway local connection failed, unable to reply through remote communication</string> <string name="SUCCESS">success</string> </resources> app/src/main/assets/data/dcloud_control.xml
@@ -1,6 +1,6 @@ <hbuilder version="1.9.9.80110" debug="false" syncDebug ="false"> <hbuilder debug="true" syncDebug="false" version="1.9.9.80110"> <apps> <app appid="unimp" appver="1.0"/> <app appid="unimp" appver="1.0" /> </apps> </hbuilder> app/src/main/java/com/hdl/photovoltaic/bean/ModBusBean.java
New file @@ -0,0 +1,28 @@ package com.hdl.photovoltaic.bean; import java.io.Serializable; /** * Created by hxb on 2023/6/28. */ public class ModBusBean implements Serializable { private String oid;//网关oid private byte []data;//控制命令 public String getOid() { return oid; } public void setOid(String oid) { this.oid = oid; } public byte []getData() { return data; } public void setData(byte []data) { this.data = data; } } app/src/main/java/com/hdl/photovoltaic/internet/TcpClient.java
@@ -1,4 +1,26 @@ package com.hdl.photovoltaic.internet; import com.hdl.sdk.link.core.callback.HDLLinkCallBack; import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; /** * 客户端操作逻辑 */ public class TcpClient { /** * 发送数据到Link网关 * * @param mac 网关mac * @param isEncrypt 是否加密 * @param topic 请求主题 * @param jObject 负载数据<没有填null></> * @param sendPath 发送路径<类名+方法名>class->methodName</> */ public void sendDataToLinkGateway(String mac, boolean isEncrypt, String topic, Object jObject, String sendPath, HDLLinkCallBack callBack) { HDLLinkLocalGateway.getInstance().sendDataToLinkGateway(mac, isEncrypt, topic, jObject, sendPath, callBack); } } app/src/main/java/com/hdl/photovoltaic/internet/api/TopicApi.java
@@ -1,4 +1,312 @@ package com.hdl.photovoltaic.internet.api; public class TopicApi { /* *通知删除并退网子设备拓扑关系 *删除从网关 * */ public static final String DELETING_GATEWAY_SLAVE = "/base/%s/thing/topo/delete/notify"; /* *网关物理退网后上报删除(退网)子设备 * */ public static final String DELETING_GATEWAY_SLAVE_RESULT = "/base/%s/thing/topo/delete/up"; /* 网关数据备份还原 * */ public static final String GATEWAY_BACKUP_RESTORE_DOWN = "/base/%s/device/backup/restore/down"; /* 调试人员主动通知网关备份数据 * */ public static final String GATEWAY_BACKUP_NOTICE_DOWN = "/base/%s/device/backup/notice/down"; /* 备份还原进度获取 * */ public static final String GATEWAY_BACKUP_PROGRESS_GET = "/base/%s/device/backup/restore/progress/get"; /* * 网关编辑命令 * 写远程信息的,例如服务器地址、HomeId、密钥之类 * 与服务器相关的 * */ public static final String GATEWAY_EDIT_REMOTE = "/user/%s/custom/gateway/remote/edit"; /* * 网关恢复出场设置命令 * */ public static final String GATEWAY_INITIALIZE_REMOTE = "/user/%s/custom/gateway/initialize"; public static final String GATEWAY_FIND_REMOTE = "/base/%s/thing/service/mmv_device_find/down"; /** * 红外宝的定位 */ public static final String IR_FIND_REMOTE = "/base/%s/thing/service/irDeviceFind/down"; /** * 红外宝试码 */ public static final String IR_CODE_TEST = "/base/%s/thing/service/irCodeTest/down"; /** * 红外宝遥控器添加 */ public static final String IR_DEVICE_ADD = "/base/%s/thing/service/irDeviceAdd/down"; /** * 红外宝遥控器列表获取 */ public static final String IR_DEVICE_LIST = "/base/%s/thing/service/irDeviceListGet/down"; /** * 红外宝自学码 */ public static final String IR_CODE_STUDY = "/base/%s/thing/service/irCodeStudy/down"; /** * 红外宝自学码删除 */ public static final String IR_CODE_REMOVE = "/base/%s/thing/service/irCodeRemove/down"; /* * 网关编辑命令 * 与服务器无关的 * */ public static final String GATEWAY_SEND_EDIT = "/user/%s/custom/gateway/edit"; /** * 设置网关入网模式 * 入网从机设备使用 * 从网关、红外宝等网络设备 */ public static final String GATEWAY_AUTH = "/user/%s/custom/device/auth_gateway"; //获取网关信息 public static final String GATEWAY_GET = "/user/%s/custom/gateway/remote/get"; //网关广播入网指令 public static final String GATEWAY_AUTH_BROADCAST = "/user/all/custom/device/network_access/broadcast"; //设备入网和认证 public static final String DEIVCE_AUTH_REQUEST = "/user/all/custom/device/network_access/request"; //设备入网和认证响应 public static final String DEIVCE_AUTH_REQUEST_REPLY = "/user/all/custom/device/network_access/request_reply"; /** * 搜索网关 */ public static final String GATEWAY_SEARCH = "/user/all/custom/gateway/search"; /** * 搜索网关响应 */ public static final String GATEWAY_SEARCH_REPLY = "/user/all/custom/gateway/search_reply"; //网关详细信息获取s=gw_id public static final String GATEWAY_INFO = "/user/%s/custom/gateway/get"; //获取物理设备列表 public static final String GET_DEVICE_LIST = "/user/%s/custom/device/list/get"; //获取物理设备列表响应 public static final String GET_DEVICE_LIST_REPLY = "/user/%s/custom/device/list/get_reply"; //获取功能列表 public static final String GET_FUNCTION_LIST = "/user/%s/custom/function/list/get"; //模拟云端ota public static final String OTA_UPGRADE_DOWN = "/base/%s/ota/device/upgrade/down"; /** * 编辑sid */ public static final String EDIT_FUNCTION = "/user/%s/custom/function/attribute/edit"; //获取功能响应 public static final String GET_FUNCTION_LIST_REPLY = "/user/%s/custom/function/list/get_reply"; //功能属性读取 public static final String GET_FUNCTION_ATTRIBUTE = "/user/%s/custom/function/attribute/get"; //功能属性编辑 public static final String EDIT_FUNCTION_ATTRIBUTE = "/user/%s/custom/function/attribute/edit"; //功能属性响应 public static final String GET_FUNCTION_ATTRIBUTE_REPLY = "/user/%s/custom/function/attribute/get_reply"; //控制 public static final String PROPERTY_DOWN = "/base/%s/thing/property/down"; //控制响应 public static final String PROPERTY_DOWN_REPLY = "/base/%s/thing/property/down_reply"; //状态上报 public static final String PROPERTY_UP = "/base/%s/thing/property/up"; //状态上报响应 public static final String PROPERTY_UP_REPLY = "/base/%s/thing/property/up_reply"; //读取状态 public static final String PROPERTY_READ = "/base/%s/thing/property/read"; //读取状态响应 public static final String PROPERTY_READ_REPLY = "/base/%s/thing/property/read_reply"; //更改网关备注名 public static final String GATEWAY_RENAME = "/user/%s/custom/gateway/edit"; //8.1获取场景列表 public static final String SCENE_LIST_GET = "/user/%s/custom/scene/list/get"; //8.2获取场景 public static final String SCENE_GET = "/user/%s/custom/scene/get"; //8.3执行场景 public static final String SCENE_CONTROL = "/user/%s/custom/scene/execute"; //8.4场景增加 public static final String CREATE_SCENE = "/user/%s/custom/scene/add"; //8.5场景编辑 public static final String SCENE_EDIT = "/user/%s/custom/scene/edit"; //8.6场景删除 public static final String SCENE_DELETE = "/user/%s/custom/scene/delete"; //9.1 房间信息列表获取 public static final String ROOM_LIST_GET = "/user/%s/custom/room/list/get"; //9.2 房间信息添加(增量) public static final String ROOM_ADD = "/user/%s/custom/room/add"; //9.2.1 房间信息添加(全量) public static final String ROOM_COVER_ADD = "/user/%s/custom/room/cover/add"; //9.3 房间信息编辑 public static final String ROOM_EDIT = "/user/%s/custom/room/edit"; //9.4 房间信息删除 public static final String ROOM_DELETE = "/user/%s/custom/room/delete"; //9.5 房间绑定关系列表获取 public static final String ROOM_BIND_LIST_GET = "/user/%s/custom/room/bind/list/get"; //9.6 房间绑定关系添加(增量) public static final String ROOM_BIND_ADD = "/user/%s/custom/room/bind/add"; //9.6.1 房间绑定关系添加(全量) public static final String ROOM_BIND_COVER_ADD = "/user/%s/custom/room/bind/cover/add"; //9.7 房间绑定关系删除 public static final String ROOM_BIND_DELETE = "/user/%s/custom/room/bind/delete"; //10.1 自动化列表获取 public static final String LOGIC_LIST_GET = "/user/%s/custom/logic/list/get"; //10.2 自动化手动执行 public static final String LOGIC_execute = "/user/%s/custom/logic/execute"; //10.3 自动化获取 列表一次性读全 public static final String LOGIC_GET = "/user/%s/custom/logic/get"; //10.4 自动化新增/编辑 public static final String LOGIC_EDIT = "/user/%s/custom/logic/edit"; //10.5 自动化删除 public static final String LOGIC_DELETE = "/user/%s/custom/logic/delete"; //10.6 自动化启用禁用 public static final String LOGIC_ENABLE_EDIT = "/user/%s/custom/logic/enable/edit"; //10.7 自动化状态上报 执行结果、本地启用禁用状态上报 public static final String LOGIC_STATUS_UP = "/user/%s/custom/logic/status/up"; //11.1 安防列表获取 public static final String SECURITY_LIST_GET = "/user/%s/custom/security/list/get"; //11.2 安防获取 public static final String SECURITY_GET = "/user/%s/custom/security/get"; //11.3 安防新增/编辑 public static final String SECURITY_EDIT = "/user/%s/custom/security/edit"; //11.4 安防删除 public static final String SECURITY_DELETE = "/user/%s/custom/security/delete"; //11.5 布防设置 public static final String SECURITY_STATUS_SET = "/user/%s/custom/security/status/set"; //11.6 安防防区状态读取 public static final String SECURITY_STATUS_GET = "/user/%s/custom/security/status/get"; //11.7 安防防区报警状态上报 public static final String SECURITY_STATUS_UP = "/user/%s/custom/security/status/up"; //11.8 安防Bypass读取 public static final String SECURITY_BYPASS_GET = "/user/%s/custom/security/bypass/get"; //11.9 安防Bypass设置 public static final String SECURITY_BYPASS_SET = "/user/%s/custom/security/bypass/set"; /** * 设备连接TCP之前广播 */ public static final String BROADCAST = "/user/all/custom/gateway/broadcast"; /** * 主网关回复 */ public static final String BROADCAST_REPLY = "/user/all/custom/gateway/broadcast_reply"; /** * sid绑定房间 */ public static final String SID_BIND_ROOM = "/user/%s/custom/room/bind/add"; /** * sid解绑房间 */ public static final String SID_DELETE_ROOM = "/user/%s/custom/room/bind/delete"; /** * 心跳检测 */ public static final String HEARTBEAT = "/user/%s/custom/gateway/heartbeat"; // public static final String HEARTBEAT="/user/%s/custom/gateway1/qqheartbeat"; /** * 心跳检测回复 */ public static final String HEARTBEAT_REPLY = "/user/%s/custom/gateway/heartbeat_reply"; public static final String NATIVE_ZIGBEE_DOWN = "/user/%s/custom/native/zigbee/down"; public static final String NATIVE_ZIGBEE_DOWN_REPLY = "/user/%s/custom/native/zigbee/down_reply"; public static final String NATIVE_ZIGBEE_UP = "/user/%s/custom/native/zigbee/up"; public static final String NATIVE_ZIGBEE_DOWN_SLAVE = "/user/%s/custom/native/zigbee/down/slaveoid/%s"; public static final String NATIVE_ZIGBEE_DOWN_SLAVE_REPLY = "/user/%s/custom/native/zigbee/down_reply/slaveoid/%s"; public static final String NATIVE_ZIGBEE_UP_SLAVE = "/user/%s/custom/native/zigbee/up/slaveoid/%s"; public static final String NATIVE_LINK_DOWN = "/user/%s/custom/native/a/down"; public static final String NATIVE_LINK_DOWN_REPLY = "/user/%s/custom/native/a/down_reply"; public static final String NATIVE_LINK_UP = "/user/%s/custom/native/a/up"; public static final String NATIVE_LINK_DOWN_SLAVE = "/user/%s/custom/native/a/down/slaveoid/%s"; public static final String NATIVE_LINK_DOWN_SLAVE_REPLY = "/user/%s/custom/native/a/down_reply/slaveoid/%s"; public static final String NATIVE_LINK_UP_SLAVE = "/user/%s/custom/native/a/up/slaveoid/%s"; public static final String GATEWAY_LOCATION_EDIT = "/user/%s/custom/gateway/location/edit"; public static final String GATEWAY_LOCATION_GET = "/user/%s/custom/gateway/location/get"; public static final String NATIVE_MODBUS_DOWN = "/user/%s/custom/native/inverter/down"; public static final String NATIVE_MODBUS_UP = "/user/%s/custom/native/inverter/up"; public static final String NATIVE_MODBUS_DOWN_REPLY = "/user/%s/custom/native/inverter/down_reply"; public static final String NATIVE_MODBUS_DOWN_SLAVE = "/user/%s/custom/native/inverter/down/slaveoid/%s"; public static final String NATIVE_MODBUS_DOWN_SLAVE_REPLY = "/user/%s/custom/native/inverter/down_reply/slaveoid/%s"; } app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java
@@ -511,9 +511,9 @@ */ public void switchHouse(HouseIdBean houseIdBean) { String oidHomeId = UserConfigManage.getInstance().getHomeId(); if (houseIdBean.getHomeId().equals(oidHomeId)) { return; } // if (houseIdBean.getHomeId().equals(oidHomeId)) { // return; // } //删除旧的住宅文件夹 HdlFileLogic.getInstance().deleteDirectory(HdlFileLogic.getInstance().getCurrentHomeRootPath()); //重新设置住宅id app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -8,6 +8,7 @@ import com.google.gson.Gson; import com.hdl.photovoltaic.HDLApp; import com.hdl.photovoltaic.bean.BaseEventBus; import com.hdl.photovoltaic.bean.ModBusBean; import com.hdl.photovoltaic.config.ConstantManage; import com.hdl.photovoltaic.config.UserConfigManage; import com.hdl.photovoltaic.listener.CloudCallBeak; @@ -16,9 +17,12 @@ import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; import com.hdl.photovoltaic.uni.UniToAndroidBean; import com.hdl.photovoltaic.utils.WifiUtils; import com.hdl.sdk.link.common.exception.HDLLinkCode; import com.hdl.sdk.link.common.exception.HDLLinkException; import com.hdl.sdk.link.common.utils.LogUtils; import com.hdl.sdk.link.core.bean.gateway.GatewayBean; import com.hdl.sdk.link.core.callback.GatewayCallBack; import com.hdl.sdk.link.core.callback.ModbusCallBack; import com.hdl.sdk.link.core.connect.HDLModBusConnect; import org.greenrobot.eventbus.EventBus; @@ -51,6 +55,8 @@ } return sHdlUniLogic; } //region ******【原生】和【小程序】通讯的方法 onOtherUniMPEventReceive();openUniMP();sendUni();****** /** * 原生接收到uni发来的数据 @@ -99,28 +105,19 @@ HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { @Override public void onSuccess(List<GatewayBean> gatewayBeanList) { HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); callBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_LIST); callBackBaseBean.setData(gatewayBeanList); sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, callBackBaseBean); uniCallbackData(gatewayBeanList, callback); } @Override public void onError(HDLLinkException e) { //发送失败 HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); callBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_LIST); callBackBaseBean.setCode(e.getCode() + ""); callBackBaseBean.setCode(e.getMsg()); sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, callBackBaseBean); uniCallbackData(null, e.getCode() + "", "", callback); } }); } break; case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND: { //发送modbus协议 // HDLModBusConnect.getInstance().Send(uniToAndroidBean.getGatewayOid(), null, ); sendModBus(data, callback); } } @@ -131,14 +128,14 @@ case HDLUniMP.UNI_EVENT_REPLY_WIFI_LIST: { //获取wifi列表 if (callback != null) { uniCallbackData(wifiUtils.getScanResult(), "0", "", callback); uniCallbackData(wifiUtils.getScanResult(), callback); } } break; case HDLUniMP.UNI_EVENT_REPLY_WIFI_INFO: { //当前wifi详情 if (callback != null) { uniCallbackData(wifiUtils.getCurrentConnectWifiInfo(), "0", "", callback); uniCallbackData(wifiUtils.getCurrentConnectWifiInfo(), callback); } } break; @@ -154,6 +151,38 @@ HdlLogLogic.print("uni===原生接收uni发来的数据", e.getMessage()); } } /** * 发送modbus协议数据 * * @param data modbus数据 * @param callback 回调 */ void sendModBus(Object data, DCUniMPJSCallback callback) { String tempData = getKeyValue("data", data); if (tempData == null) { LogUtils.i("data内容为空"); return; } ModBusBean modBusBean = com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(tempData), ModBusBean.class); if (modBusBean.getOid() == null || modBusBean.getData() == null) { LogUtils.i("内容为空,oid=" + modBusBean.getOid() + " data=" + modBusBean.getData()); return; } //发送modbus协议 HDLModBusConnect.getInstance().Send(modBusBean.getOid(), modBusBean.getData(), new ModbusCallBack() { @Override public void onSuccess(byte[] data) { uniCallbackData(data, callback); } @Override public void onError(HDLLinkException e) { uniCallbackData(null, e.getCode() + "", "失败", callback); } }); } /** @@ -190,6 +219,10 @@ public void checkRemoveOtherUniMPEventCallBack() { HDLUniMPSDKManager.getInstance().checkRemoveOtherUniMPEventCallBack(this); } //endregion //region ******一般方法****** /** * 组装uni发送数据格式 @@ -242,6 +275,10 @@ } private void uniCallbackData(Object obj, DCUniMPJSCallback callback) { uniCallbackData(obj, HDLLinkCode.HDL_SUCCESS + "", HDLLinkCode.HDL_SUCCESS.getMsg(), callback); } /** * 当前对象转 JSONObject * @@ -284,6 +321,7 @@ return ""; } } //endregion }