From 51bd5829118714be826ab9de93d822615ef48a4f Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期三, 29 五月 2024 14:50:14 +0800
Subject: [PATCH] Merge branch 'wjc_new' into wxw_new
---
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 187 +++++++++++++++++++++++++++++-----------------
1 files changed, 117 insertions(+), 70 deletions(-)
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 6b3d883..e66c575 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -202,6 +202,11 @@
} else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODEL.equals(topic)) {
//璁惧妯″潡
switch (type) {
+ //modBus鍗忚涓撶敤
+ case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND: {
+ sendModBus(mode_type, data, callback);
+ }
+ break;
//娣诲姞閫嗗彉鍣ㄥ埌浜戠
case HDLUniMP.UNI_EVENT_REPLY_DEVICE_ADD: {
this.uniAddInverterDeviceToCloud(mode_type, data, callback);
@@ -225,11 +230,6 @@
//鑾峰彇閫嗗彉鍣ㄥ垪琛�
case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: {
this.uniGetCurrentHomeLocalAndCloudGatewayList(mode_type, data, callback);
- }
- break;
- //modBus鍗忚涓撶敤
- case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND: {
- sendModBus(mode_type, data, callback);
}
break;
//鑾峰彇oid鍒楄〃
@@ -275,6 +275,11 @@
//鍒濆鍖栭�嗗彉鍣�
case HDLUniMP.UNI_EVENT_REPLY_DEVICE_INITIALIZEINVERTER: {
this.setInitializeGateway(mode_type, data, callback);
+ }
+ break;
+ //璇诲彇璁惧杩滅▼淇℃伅
+ case HDLUniMP.UNI_EVENT_REPLY_DEVICE_REMOTEINFO: {
+ this.setInverterDeviceRemoteInfo(mode_type, data, callback);
}
break;
@@ -498,10 +503,7 @@
//uni涓婚〉鐐瑰嚮杩斿洖閫氱煡
case HDLUniMP.UNI_EVENT_REPLY_OTHER_BACK: {
//EventBus浜嬩欢鍒嗗彂
- BaseEventBus baseEventBus = new BaseEventBus();
- baseEventBus.setTopic(HDLUniMP.UNI_EVENT_REPLY_OTHER_MODEL);
- baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_OTHER_BACK);
- EventBus.getDefault().post(baseEventBus);
+ HdlCommonLogic.getInstance().postEventBus(HDLUniMP.UNI_EVENT_REPLY_OTHER_MODEL, HDLUniMP.UNI_EVENT_REPLY_OTHER_BACK);
}
break;
@@ -1719,77 +1721,75 @@
* @param callback uni鍥炶皟
*/
public void startTcpThreadSendAccountAndPassword(String type, String ssid, String password, DCUniMPJSCallback callback) {
- new Thread(
- () -> {
- Socket socket = null;
- OutputStream outputStreamTcp = null;
- InputStream inputStreamTcp = null;
- try {
- socket = new Socket();
- socket.setTcpNoDelay(true);
- socket.setSoTimeout(10 * 1000);//10绉掕秴鏃�
- socket.connect(new InetSocketAddress("192.168.8.1", 8586));
- socket.setKeepAlive(true);
+ new Thread(() -> {
+ Socket socket = null;
+ OutputStream outputStreamTcp = null;
+ InputStream inputStreamTcp = null;
+ try {
+ socket = new Socket();
+ socket.setTcpNoDelay(true);
+ socket.setSoTimeout(10 * 1000);//10绉掕秴鏃�
+ socket.connect(new InetSocketAddress("192.168.8.1", 8586));
+ socket.setKeepAlive(true);
// logMessage("tcp杩炴帴鐘舵�佹垚鍔�", 0, "");
- outputStreamTcp = socket.getOutputStream();
- JsonObject jsonObject = new JsonObject();
- jsonObject.addProperty("id", "102030");
- jsonObject.addProperty("ssid", ssid);
- jsonObject.addProperty("password", password);
- jsonObject.addProperty("server_addr", HDLLinkPMUser.getInstance().getHomeRegionUrl());
- jsonObject.addProperty("homeId", UserConfigManage.getInstance().getHomeId());
- String sendData = "Topic:/user/id/custom/wifi/set\r\n";
- sendData += "Length:" + jsonObject.toString().getBytes().length + "\r\n\r\n";
- sendData += jsonObject.toString();
- outputStreamTcp.write(sendData.getBytes());
- outputStreamTcp.flush();
- Thread.sleep(200);
- inputStreamTcp = socket.getInputStream();
- byte[] bytes = new byte[1204 * 2];
- int len = inputStreamTcp.read(bytes);
- if (len != -1) {
- String str = new String(bytes, 0, bytes.length);
- String[] strings = str.split("\r\n\r\n");
- String[] topicAndLength = strings[0].split("\r\n");
- String topic = topicAndLength[0];
- JSONObject json = new JSONObject(strings[1]);
+ outputStreamTcp = socket.getOutputStream();
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("id", "102030");
+ jsonObject.addProperty("ssid", ssid);
+ jsonObject.addProperty("password", password);
+ jsonObject.addProperty("server_addr", HDLLinkPMUser.getInstance().getHomeRegionUrl());
+ jsonObject.addProperty("homeId", UserConfigManage.getInstance().getHomeId());
+ String sendData = "Topic:/user/id/custom/wifi/set\r\n";
+ sendData += "Length:" + jsonObject.toString().getBytes().length + "\r\n\r\n";
+ sendData += jsonObject.toString();
+ outputStreamTcp.write(sendData.getBytes());
+ outputStreamTcp.flush();
+ Thread.sleep(200);
+ inputStreamTcp = socket.getInputStream();
+ byte[] bytes = new byte[1204 * 2];
+ int len = inputStreamTcp.read(bytes);
+ if (len != -1) {
+ String str = new String(bytes, 0, bytes.length);
+ String[] strings = str.split("\r\n\r\n");
+ String[] topicAndLength = strings[0].split("\r\n");
+ String topic = topicAndLength[0];
+ JSONObject json = new JSONObject(strings[1]);
// logMessage("tcp鍥炲鏁版嵁", 0, strings[0] + "\r\n" + json.toString());
- if (topic.endsWith("wifi/set_reply") || topic.endsWith("wifi/result/notify")) {
- if (callback != null) {
- uniCallbackData(type, json, callback);
- }
- if (json.has("mac")) { //鍥炲鎴愬姛鍐嶆嬁璁惧mac
+ if (topic.endsWith("wifi/set_reply") || topic.endsWith("wifi/result/notify")) {
+ if (callback != null) {
+ uniCallbackData(type, json, callback);
+ }
+ if (json.has("mac")) { //鍥炲鎴愬姛鍐嶆嬁璁惧mac
// this.device_mac = json.getString("mac");
// this.isSucceedTcp = true;//琛ㄧず鎴愬姛
- }
- }
- }
-
- } catch (Exception ignored) {
- } finally {
- try {
- if (outputStreamTcp != null) {
- outputStreamTcp.close();
- outputStreamTcp = null;
- }
- if (inputStreamTcp != null) {
- inputStreamTcp.close();
- inputStreamTcp = null;
- }
- if (socket != null) {
- socket.close();
- socket = null;
- }
-
- } catch (Exception ignored) {
}
}
}
- ).start();
+
+ } catch (Exception ignored) {
+ } finally {
+ try {
+ if (outputStreamTcp != null) {
+ outputStreamTcp.close();
+ outputStreamTcp = null;
+ }
+ if (inputStreamTcp != null) {
+ inputStreamTcp.close();
+ inputStreamTcp = null;
+ }
+ if (socket != null) {
+ socket.close();
+ socket = null;
+ }
+
+ } catch (Exception ignored) {
+ }
+ }
+ }).start();
}
/**
- * 鍒濆鍖栦綘閫嗗彉鍣�
+ * 鍒濆鍖栭�嗗彉鍣�
*
* @param type 璐﹀彿
* @param data uni璇锋眰鏁版嵁
@@ -1810,6 +1810,53 @@
});
}
+ /**
+ * 鍒濆鍖栭�嗗彉鍣�
+ *
+ * @param type 璐﹀彿
+ * @param data uni璇锋眰鏁版嵁
+ * @param callback uni鍥炶皟
+ */
+ public void setInverterDeviceRemoteInfo(String type, Object data, DCUniMPJSCallback callback) {
+ String homeId = getKeyValue("homeId", getKeyValue("data", data));
+ String json = getKeyValue("list", getKeyValue("data", data));
+ List<CloudInverterDeviceBean> newList = new ArrayList<>();
+ try {
+ List<GatewayBean> list = new Gson().fromJson(json, new TypeToken<List<GatewayBean>>() {
+ }.getType());
+ if (list != null && list.size() > 0) {
+ for (int i = 0; i < list.size(); i++) {
+ GatewayBean gatewayBean = list.get(i);
+ CloudInverterDeviceBean inverterDeviceBean = new CloudInverterDeviceBean();
+ inverterDeviceBean.setCategorySecondName(gatewayBean.getCategorySecondName());
+ inverterDeviceBean.setOsn(gatewayBean.getDevice_mac());
+ inverterDeviceBean.setOmodel(gatewayBean.getDevice_model());
+ inverterDeviceBean.setOid(gatewayBean.getOid());
+ inverterDeviceBean.setAddresses(gatewayBean.getAddresses());
+ inverterDeviceBean.setSid(gatewayBean.getSid());
+ inverterDeviceBean.setDeviceId(gatewayBean.getDeviceId());
+ inverterDeviceBean.setName(gatewayBean.getDevice_name());
+ inverterDeviceBean.setDeviceStatus(gatewayBean.getDeviceStatus());
+ inverterDeviceBean.setSpk(gatewayBean.getSpk());
+ inverterDeviceBean.setDeviceType(gatewayBean.getDeviceType());
+ newList.add(inverterDeviceBean);
+ }
+ }
+ } catch (Exception ignored) {
+ }
+ HdlDeviceLogic.getInstance().setDeviceRemoteInfo(newList, homeId, new CloudCallBeak<List<GatewayBean>>() {
+ @Override
+ public void onSuccess(List<GatewayBean> obj) {
+ uniCallbackData(type, obj, callback);
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ uniCallbackData(type, null, e.getCode(), e.getMsg(), callback);
+ }
+ });
+ }
+
/**
* 鍙戦�乵odbus鍗忚鏁版嵁
--
Gitblit v1.8.0