From f7c38847b8e00c84c30e51a92c03071d3e9a9da8 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期二, 14 五月 2024 09:08:57 +0800
Subject: [PATCH] 2024年05月14日09:08:49
---
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 149 +++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 135 insertions(+), 14 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 16cf484..d422b52 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -10,6 +10,7 @@
import android.location.Location;
import android.location.LocationManager;
import android.os.IBinder;
+import android.provider.Settings;
import android.text.TextUtils;
import androidx.core.app.ActivityCompat;
@@ -42,6 +43,7 @@
import com.hdl.photovoltaic.ui.bean.Geolocation;
import com.hdl.photovoltaic.ui.bean.LinkBean;
import com.hdl.photovoltaic.ui.bean.OidBean;
+import com.hdl.photovoltaic.ui.bean.UnCountBean;
import com.hdl.photovoltaic.ui.me.AsRegardsActivity;
import com.hdl.photovoltaic.ui.me.PersonalDataActivity;
import com.hdl.photovoltaic.ui.me.SetActivity;
@@ -68,9 +70,13 @@
import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.net.InetSocketAddress;
+import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -231,7 +237,6 @@
case HDLUniMP.UNI_EVENT_REPLY_DEVICE_TIME: {
this.uniGetInverterTime(mode_type, data, callback);
}
-
break;
//閫嗗彉鍣ㄦ椂闂寸紪杈�
case HDLUniMP.UNI_EVENT_REPLY_DEVICE_TIME_EDIT: {
@@ -263,6 +268,11 @@
this.uniGetMessageNumber(mode_type, data, callback);
}
break;
+ //鍒濆鍖栭�嗗彉鍣�
+ case HDLUniMP.UNI_EVENT_REPLY_DEVICE_INITIALIZEINVERTER: {
+ this.setInitializeGateway(mode_type, data, callback);
+ }
+ break;
}
@@ -278,18 +288,29 @@
}
break;
//褰撳墠wifi璇︽儏
- case HDLUniMP.UNI_EVENT_REPLY_WIFI_INFO: {
+ case HDLUniMP.UNI_EVENT_REPLY_WIFI_PHONE_INFO: {
if (callback != null) {
uniCallbackData(mode_type, wifiUtils.getCurrentConnectWifiInfo(), callback);
}
}
break;
- //wifi杩炴帴
- case HDLUniMP.UNI_EVENT_REPLY_WIFI_CONNECT: {
+ //閰嶇疆WiFi淇℃伅缁欓�嗗彉鍣�
+ case HDLUniMP.UNI_EVENT_REPLY_WIFI_SET_DEVICE: {
+ String mac = getKeyValue("mac", getKeyValue("data", data));//
+ String wif_type = getKeyValue("wif_type", getKeyValue("data", data));//1锛氱儹鐐�,2锛氭棤绾縲ifi,3锛氫互澶綉
+ String ssid = getKeyValue("ssid", getKeyValue("data", data));//
+ String password = getKeyValue("password", getKeyValue("data", data));//
+ startTcpThreadSendAccountAndPassword(mode_type, ssid, password, callback);
}
break;
-
+ //鎵撳紑鎵嬫満Wifi璁剧疆鐣岄潰
+ case HDLUniMP.UNI_EVENT_REPLY_OPEN_WIFI_SETTINGS: {
+ Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ HDLApp.getInstance().startActivity(intent);
+ }
+ break;
}
} else if (HDLUniMP.UNI_EVENT_REPLY_OTA_MODEL.equals(topic)) {
//OTA鍗囩骇妯″潡
@@ -412,6 +433,7 @@
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(HDLApp.getInstance(), SetActivity.class);
HDLApp.getInstance().startActivity(intent);
+
}
break;
@@ -640,10 +662,9 @@
String[] ary = path.split("/");
String[] driverInfoAry = ary[ary.length - 1].split("_");
DeviceFirmwareBean deviceFirmwareBean = new DeviceFirmwareBean();
- deviceFirmwareBean.setOid(driverInfoAry[0]);
- deviceFirmwareBean.setImageId(driverInfoAry[1]);
- deviceFirmwareBean.setVersion(driverInfoAry[2].replace(".zip", ""));
- deviceFirmwareBean.setLocalUrl(HdlFileLogic.getInstance().getFirmwarePathFileName(deviceFirmwareBean.getOid(), osImageId, deviceFirmwareBean.getVersion()));
+ deviceFirmwareBean.setImageId(driverInfoAry[0]);
+ deviceFirmwareBean.setVersion(driverInfoAry[1].replace(".zip", ""));
+ deviceFirmwareBean.setLocalUrl(HdlFileLogic.getInstance().getFirmwarePathFileName(osImageId, deviceFirmwareBean.getVersion()));
list.add(deviceFirmwareBean);
}
}
@@ -671,7 +692,7 @@
HdlThreadLogic.runSubThread(new Runnable() {
@Override
public void run() {
- String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(oid, imageId, version);
+ String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(imageId, version);
//涓嶅湪瀛愮嚎绋嬭娴佷細鍗℃涓荤嚎绋�
boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(firmwarePathFileName, responseBody, md5, HdlOtaLogic.firmware_type);
if (isBoolean) {
@@ -725,7 +746,7 @@
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
//鏈湴鍗囩骇鍥轰欢鏂囦欢璺緞
- String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(oid, imageId, version);
+ String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(imageId, version);
byte[] data = HdlFileLogic.getInstance().readFileByte(firmwarePathFileName);
if (data == null || data.length == 0) {
uniCallbackData(type, null, -2, HDLApp.getInstance().getString(R.string.found_locally_firmware_upgrade_file), callback);
@@ -1251,9 +1272,9 @@
*/
private void uniGetMessageNumber(String type, Object data, DCUniMPJSCallback callback) {
String homeId = getKeyValue("homeId", getKeyValue("data", data));
- HdlMessageLogic.getInstance().getMessageUntreatedCount(homeId, new CloudCallBeak<String>() {
+ HdlMessageLogic.getInstance().getMessageUntreatedCount(homeId, new CloudCallBeak<UnCountBean>() {
@Override
- public void onSuccess(String data) {
+ public void onSuccess(UnCountBean data) {
uniCallbackData(type, data, callback);
}
@@ -1630,6 +1651,106 @@
/**
+ * 鍙戦�佽处鍙峰拰瀵嗙爜缁欓�嗗彉鍣�
+ *
+ * @param ssid 璐﹀彿
+ * @param password 瀵嗙爜
+ * @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);
+// 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]);
+// 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
+// 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();
+ }
+
+ /**
+ * 鍒濆鍖栦綘閫嗗彉鍣�
+ *
+ * @param type 璐﹀彿
+ * @param data uni璇锋眰鏁版嵁
+ * @param callback uni鍥炶皟
+ */
+ public void setInitializeGateway(String type, Object data, DCUniMPJSCallback callback) {
+ String mac = getKeyValue("mac", getKeyValue("data", data));
+ HdlDeviceLogic.getInstance().initializeInverter(mac, new LinkCallBack<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+ uniCallbackData(type, obj, callback);
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+ uniCallbackData(type, null, e.getCode(), e.getMsg(), callback);
+ }
+ });
+ }
+
+
+ /**
* 鍙戦�乵odbus鍗忚鏁版嵁
* 閫忎紶鍗忚
* 涓嬪彂涓婚锛�/user/${gw_id}/custom/native/${driver}/down;
@@ -1732,7 +1853,7 @@
HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
try {
uniCallBackBaseBean.setCode(code);
- uniCallBackBaseBean.setMes(msg);
+ uniCallBackBaseBean.setMsg(msg);
uniCallBackBaseBean.setData(obj);
if (callback != null) {
callback.invoke(getJSONObject(uniCallBackBaseBean));
--
Gitblit v1.8.0