From ab4fde3dd12361b4092fd52060a66017a060236b Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期四, 29 六月 2023 15:34:20 +0800 Subject: [PATCH] Merge branch 'hxb' into wjc --- HDLLinkLocalSdk/src/main/res/values/strings_code.xml | 49 ++++---- app/src/main/java/com/hdl/photovoltaic/bean/ModBusBean.java | 28 ++++ HDLLinkLocalSdk/src/main/res/values-zh/strings_code.xml | 1 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java | 9 + HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLModBusConnect.java | 98 +++++++-------- HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java | 4 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java | 1 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java | 7 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ModbusCallBack.java | 2 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ModbusResponse.java | 88 ++++++++++++++ app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 59 +++++++-- 11 files changed, 253 insertions(+), 93 deletions(-) diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java index a041d71..fbdfecd 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/common/exception/HDLLinkCode.java +++ b/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; diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java index ad2f655..5a58a0d 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkResponse.java +++ b/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); diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ModbusResponse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ModbusResponse.java new file mode 100644 index 0000000..cc54c11 --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/ModbusResponse.java @@ -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); + } +} diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ModbusCallBack.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ModbusCallBack.java index 7e58147..bfff2ff 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/callback/ModbusCallBack.java +++ b/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); } diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java index 18967d5..47e5363 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLConnectHelper.java +++ b/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)); diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLModBusConnect.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLModBusConnect.java index e38c3ad..241fee5 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/connect/HDLModBusConnect.java +++ b/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; /** - * 鍐呴儴鐢紝涓昏鏄鐞嗗鐞嗘帀閫忎紶涓婚鍙妉ink涓婚鍚庯紝杩樺師Zigbee鍘熺敓鏁版嵁鍙婁富棰樼敤 + * 鍐呴儴鐢紝涓昏鏄鐞嗗鐞嗘帀閫忎紶涓婚鍙妉ink涓婚鍚庯紝杩樺師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())) { -// //涓婇潰鐨刼id鍙兘鏄綉鍏砳d鎴栬�卪ac鎴栬�呮槸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杞琙igbeeResponse寮傚父:"+ 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())) { + //涓婇潰鐨刼id鍙兘鏄綉鍏砳d鎴栬�卪ac鎴栬�呮槸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杞琈odbusResponse寮傚父:"+ e.getMessage()); + } } }; //娉ㄥ唽鐩存帴閫氳鐨勪富棰橈紝鍖呮嫭鐩存帴鍜屼富缃戝叧閫氳鎴栬�呯洿鎺ュ拰浠庣綉鍏抽�氳 @@ -127,11 +122,10 @@ * 鍙戦�佸師鐢熸暟鎹� * * @param gatewayOidOrGatewayId 鐩爣缃戝叧鐨刼id鎴栬�呯綉鍏矷d - * @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("鍙戦�丮odbus鍥炶皟瀵硅薄绫诲瀷闈炴暟缁勭被鍨嬶紝绫诲瀷鏄�"+msg.getClass()); + } } @Override diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java index dcc7ffc..2d0e0ea 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/QueueUtils.java +++ b/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()); + // } //瑙f瀽瀹屾垚,topic鍙戦�佷竴娆� EventDispatcher.getInstance().post(response.getTopic(), response); } diff --git a/HDLLinkLocalSdk/src/main/res/values-zh/strings_code.xml b/HDLLinkLocalSdk/src/main/res/values-zh/strings_code.xml index 25f17da..d842ea7 100644 --- a/HDLLinkLocalSdk/src/main/res/values-zh/strings_code.xml +++ b/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> \ No newline at end of file diff --git a/HDLLinkLocalSdk/src/main/res/values/strings_code.xml b/HDLLinkLocalSdk/src/main/res/values/strings_code.xml index 00a28c6..8cc9e3e 100644 --- a/HDLLinkLocalSdk/src/main/res/values/strings_code.xml +++ b/HDLLinkLocalSdk/src/main/res/values/strings_code.xml @@ -1,27 +1,28 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <string name="HDL_DATA_ERROR">Parameter exception</string> - <string name="HDL_DATA_NULL_ERROR">Parameter cannot be empty</string> - <string name="HDL_AUTH_ERROR">Authentication failed</string> - <string name="HDL_SEND_ERROR">fail in send</string> - <string name="HDL_TIMEOUT_ERROR">timeout,gateway no response</string> - <string name="HDL_UNAUTHORIZED_ERROR">Not certified, please authenticate first</string> - <string name="HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED">Authentication failed. The gateway is not registered to the cloud</string> - <string name="HDL_SEARCH_GATEWAY_TIMEOUT_ERROR">Failed to search gateway, timeout</string> - <string name="HDL_AUTH_MAC_KEY_ERROR">Authentication failed. The device key corresponding to the MAC does not exist</string> - <string name="HDL_DATA_PARSING_ERROR">Data parsing error</string> - <string name="HDL_GET_DEVICE_LIST_ERROR">Failed to get device list</string> - <string name="HDL_GET_FUNCTION_LIST_ERROR">Failed to get function list</string> - <string name="HDL_GET_FUNCTION_PROPERTIES_ERROR">Failed to get function attribute</string> - <string name="HDL_CONTROL_FAILURE_ERROR">Control failure</string> - <string name="HDL_GET_GATEWAY_FAILURE_ERROR">Failed to get gateway list</string> - <string name="HDL_GET_Zigbee_FAILURE_ERROR">Sending timeout, no response from gateway</string> - <string name="HDL_GATEWAY_NOT_EXIST">Gateway does not exist</string> - <string name="HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR">Failed to get the device list</string> - <string name="HDL_MILLIMETER_NOT_EXIST">Millimeter does not exist</string> - <string name="HDL_UNKOWN_CODE">Unkown Error</string> - <string name="HDL_APPLICATION_EXCEPTION">System Exception</string> - <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="HDL_DATA_ERROR">Parameter exception</string> +<string name="HDL_DATA_NULL_ERROR">Parameter cannot be empty</string> +<string name="HDL_AUTH_ERROR">Authentication failed</string> +<string name="HDL_SEND_ERROR">fail in send</string> +<string name="HDL_TIMEOUT_ERROR">timeout,gateway no response</string> +<string name="HDL_UNAUTHORIZED_ERROR">Not certified, please authenticate first</string> +<string name="HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED">Authentication failed. The gateway is not registered to the cloud</string> +<string name="HDL_SEARCH_GATEWAY_TIMEOUT_ERROR">Failed to search gateway, timeout</string> +<string name="HDL_AUTH_MAC_KEY_ERROR">Authentication failed. The device key corresponding to the MAC does not exist</string> +<string name="HDL_DATA_PARSING_ERROR">Data parsing error</string> +<string name="HDL_GET_DEVICE_LIST_ERROR">Failed to get device list</string> +<string name="HDL_GET_FUNCTION_LIST_ERROR">Failed to get function list</string> +<string name="HDL_GET_FUNCTION_PROPERTIES_ERROR">Failed to get function attribute</string> +<string name="HDL_CONTROL_FAILURE_ERROR">Control failure</string> +<string name="HDL_GET_GATEWAY_FAILURE_ERROR">Failed to get gateway list</string> +<string name="HDL_GET_Zigbee_FAILURE_ERROR">Sending timeout, no response from gateway</string> +<string name="HDL_GATEWAY_NOT_EXIST">Gateway does not exist</string> +<string name="HDL_GET_Zigbee_DEVICE_LIST_FAILURE_ERROR">Failed to get the device list</string> +<string name="HDL_MILLIMETER_NOT_EXIST">Millimeter does not exist</string> +<string name="HDL_UNKOWN_CODE">Unkown Error</string> +<string name="HDL_APPLICATION_EXCEPTION">System Exception</string> +<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> \ No newline at end of file diff --git a/app/src/main/java/com/hdl/photovoltaic/bean/ModBusBean.java b/app/src/main/java/com/hdl/photovoltaic/bean/ModBusBean.java new file mode 100644 index 0000000..fed6b01 --- /dev/null +++ b/app/src/main/java/com/hdl/photovoltaic/bean/ModBusBean.java @@ -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; + } +} diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java index e49931a..b0e1592 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java +++ b/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; @@ -101,28 +105,23 @@ 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); -// uniCallbackData(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, "", "", callBackBaseBean); + 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(callBackBaseBean, 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: { - - //鍙戦�乵odbus鍗忚 -// HDLModBusConnect.getInstance().Send(uniToAndroidBean.getGatewayOid(), null, ); + sendModBus(data,callback); } } @@ -156,6 +155,38 @@ HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�", e.getMessage()); } + } + + /** + * 鍙戦�乵odbus鍗忚鏁版嵁 + * @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; + } + + //鍙戦�乵odbus鍗忚 + 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); + } + }); } /** @@ -248,6 +279,10 @@ } + private void uniCallbackData(Object obj, DCUniMPJSCallback callback) { + uniCallbackData(obj,HDLLinkCode.HDL_SUCCESS+"",HDLLinkCode.HDL_SUCCESS.getMsg(),callback); + } + /** * 褰撳墠瀵硅薄杞� JSONObject * -- Gitblit v1.8.0