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 | 273 +++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 197 insertions(+), 76 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 201f261..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,13 +10,11 @@
import android.location.Location;
import android.location.LocationManager;
import android.os.IBinder;
+import android.provider.Settings;
import android.text.TextUtils;
-import android.view.View;
-import android.widget.TextView;
import androidx.core.app.ActivityCompat;
-import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@@ -45,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;
@@ -54,7 +53,6 @@
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
import com.hdl.photovoltaic.utils.NetworkUtils;
import com.hdl.photovoltaic.utils.WifiUtils;
-import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
import com.hdl.sdk.link.common.exception.HDLLinkCode;
import com.hdl.sdk.link.common.exception.HDLLinkException;
import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
@@ -72,11 +70,14 @@
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.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
@@ -236,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: {
@@ -268,6 +268,11 @@
this.uniGetMessageNumber(mode_type, data, callback);
}
break;
+ //鍒濆鍖栭�嗗彉鍣�
+ case HDLUniMP.UNI_EVENT_REPLY_DEVICE_INITIALIZEINVERTER: {
+ this.setInitializeGateway(mode_type, data, callback);
+ }
+ break;
}
@@ -283,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鍗囩骇妯″潡
@@ -376,6 +392,53 @@
break;
}
+ } else if (HDLUniMP.UNI_EVENT_REPLY_MINE_MODEL.equals(topic)) {
+ //鎴戠殑妯″潡
+ switch (type) {
+ //璧勬枡缂栬緫
+ case HDLUniMP.UNI_EVENT_REPLY_MINE_EDIT_USER_INFO: {
+ Intent intent = new Intent();
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setClass(HDLApp.getInstance(), PersonalDataActivity.class);
+ HDLApp.getInstance().startActivity(intent);
+ }
+ break;
+ //鐢电珯閫夋嫨
+ case HDLUniMP.UNI_EVENT_REPLY_MINE_SELECTED_POWERSTATION: {
+ Intent intent = new Intent();
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setClass(HDLApp.getInstance(), PowerStationsListEdit.class);
+ HDLApp.getInstance().startActivity(intent);
+ }
+ break;
+ //娑堟伅涓績
+ case HDLUniMP.UNI_EVENT_REPLY_MINE_MESSAGE_CENTER: {
+ Intent intent = new Intent();
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setClass(HDLApp.getInstance(), MessageCenterList.class);
+ HDLApp.getInstance().startActivity(intent);
+ }
+ break;
+ //鍏充簬
+ case HDLUniMP.UNI_EVENT_REPLY_MINE_ABOUT: {
+ Intent intent = new Intent();
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setClass(HDLApp.getInstance(), AsRegardsActivity.class);
+ HDLApp.getInstance().startActivity(intent);
+ }
+ break;
+ //璁剧疆
+ case HDLUniMP.UNI_EVENT_REPLY_MINE_SETTING: {
+ Intent intent = new Intent();
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.setClass(HDLApp.getInstance(), SetActivity.class);
+ HDLApp.getInstance().startActivity(intent);
+
+ }
+ break;
+
+
+ }
} else if (HDLUniMP.UNI_EVENT_REPLY_OTHER_MODEL.equals(topic)) {
//鍏跺畠妯″潡
switch (type) {
@@ -418,52 +481,11 @@
}
break;
- }
- } else if (HDLUniMP.UNI_EVENT_REPLY_MINE_MODEL.equals(topic)) {
- //鎴戠殑妯″潡
- switch (type) {
- //璧勬枡缂栬緫
- case HDLUniMP.UNI_EVENT_REPLY_MINE_EDIT_USER_INFO: {
- Intent intent = new Intent();
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setClass(HDLApp.getInstance(), PersonalDataActivity.class);
- HDLApp.getInstance().startActivity(intent);
+ //uni閫氱煡鍘熺敓閫�鍑虹櫥褰�
+ case HDLUniMP.UNI_EVENT_REPLY_OTHER_LOGOUT: {
+ HDLLinkPMUser.getInstance().logout(0);
}
break;
- //鐢电珯閫夋嫨
- case HDLUniMP.UNI_EVENT_REPLY_MINE_SELECTED_POWERSTATION: {
- Intent intent = new Intent();
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setClass(HDLApp.getInstance(), PowerStationsListEdit.class);
- HDLApp.getInstance().startActivity(intent);
- }
- break;
- //娑堟伅涓績
- case HDLUniMP.UNI_EVENT_REPLY_MINE_MESSAGE_CENTER: {
- Intent intent = new Intent();
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setClass(HDLApp.getInstance(), MessageCenterList.class);
- HDLApp.getInstance().startActivity(intent);
- }
- break;
- //鍏充簬
- case HDLUniMP.UNI_EVENT_REPLY_MINE_ABOUT: {
- Intent intent = new Intent();
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setClass(HDLApp.getInstance(), AsRegardsActivity.class);
- HDLApp.getInstance().startActivity(intent);
- }
- break;
- //璁剧疆
- case HDLUniMP.UNI_EVENT_REPLY_MINE_SETTING: {
- Intent intent = new Intent();
- 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) {
@@ -681,9 +702,9 @@
}
if (isBoolean) {
- uniCallbackData(type, null, 0, "鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛", callback);
+ uniCallbackData(type, null, 0, HDLApp.getInstance().getString(R.string.writing_firmware_upgrade_memory_succeeded), callback);
} else {
- uniCallbackData(type, null, -2, "涓嬭浇鍥轰欢鍗囩骇鏂囦欢澶辫触", callback);
+ uniCallbackData(type, null, -2, HDLApp.getInstance().getString(R.string.download_firmware_upgrade_file_failed), callback);
}
}
});
@@ -725,10 +746,10 @@
@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, "鏈湴鎵句笉鍒板崌绾у浐浠舵枃浠�,璇蜂笅杞藉ソ鍥轰欢鏂囦欢,鍐嶉噸鏂板崌绾�.", callback);
+ uniCallbackData(type, null, -2, HDLApp.getInstance().getString(R.string.found_locally_firmware_upgrade_file), callback);
return;
}
String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧鍥轰欢闇�瑕�
@@ -743,14 +764,14 @@
@Override
public void onError(HDLLinkException e) {
- uniCallbackData(type, null, -2, "閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇,", callback);
+ uniCallbackData(type, null, -2, HDLApp.getInstance().getString(R.string.notify_gateway_firmware_upgrade_failed), callback);
}
});
}
@Override
public void onServiceDisconnected(ComponentName name) {
- uniCallbackData(type, null, -2, "鏈湴鏈嶅姟鏈夊紓甯稿け璐�,鏃犳硶鍗囩骇,", callback);
+ uniCallbackData(type, null, -2, HDLApp.getInstance().getString(R.string.local_service_fails), callback);
}
});
} else {
@@ -934,9 +955,9 @@
HdlFileLogic.getInstance().deleteFile(drivePathFileName);//涓嬭浇澶辫触锛屽垹闄や笉瀹屾暣椹卞姩鏂囦欢;
}
if (isBoolean) {
- uniCallbackData(type, null, 0, "鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛", callback);
+ uniCallbackData(type, null, 0, HDLApp.getInstance().getString(R.string.writing_drive_memory_succeeded), callback);
} else {
- uniCallbackData(type, null, -2, "涓嬭浇椹卞姩鍗囩骇鏂囦欢澶辫触", callback);
+ uniCallbackData(type, null, -2, HDLApp.getInstance().getString(R.string.download_drive_file_failed), callback);
}
}
});
@@ -980,7 +1001,7 @@
String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version);
byte[] data = HdlFileLogic.getInstance().readFileByte(drivePathFileName);
if (data == null || data.length == 0) {
- uniCallbackData(type, null, -2, "鏈湴鎵句笉鍒板崌绾ч┍鍔ㄦ枃浠�,璇蜂笅杞藉ソ椹卞姩鏂囦欢,鍐嶉噸鏂板崌绾�.", callback);
+ uniCallbackData(type, null, -2, HDLApp.getInstance().getString(R.string.found_locally_drive_file), callback);
return;
}
String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧椹卞姩闇�瑕�
@@ -995,14 +1016,14 @@
@Override
public void onError(HDLLinkException e) {
- uniCallbackData(type, null, -2, "閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇,", callback);
+ uniCallbackData(type, null, -2, HDLApp.getInstance().getString(R.string.notify_gateway_drive_failed), callback);
}
});
}
@Override
public void onServiceDisconnected(ComponentName name) {
- uniCallbackData(type, null, -2, "鏈湴鏈嶅姟鏈夊紓甯稿け璐�,鏃犳硶鍗囩骇,", callback);
+ uniCallbackData(type, null, -2, HDLApp.getInstance().getString(R.string.local_service_fails), callback);
}
});
} else {
@@ -1089,7 +1110,7 @@
*/
private void uniCancelDownloadingUpgradeFile(String type, Object data, DCUniMPJSCallback callback) {
HdlOtaLogic.getInstance().stopDownloadUpgradeFile();
- uniCallbackData(type, null, 0, "鍙栨秷涓嬭浇鎴愬姛.", callback);
+ uniCallbackData(type, null, 0, HDLApp.getInstance().getString(R.string.cancel_download_successfully), 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,15 +1853,15 @@
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));
// callback.invoke(uniCallBackBaseBean);
- HdlLogLogic.print("uni--->鎺ユ敹--->" + type + "--->" + new Gson().toJson(uniCallBackBaseBean), true);
+ HdlLogLogic.print("uni--->鍥炲--->" + type + "--->" + new Gson().toJson(uniCallBackBaseBean), true);
}
} catch (Exception e) {
- HdlLogLogic.print("uni--->鎺ユ敹--->" + type + "--->" + e.getMessage(), true);
+ HdlLogLogic.print("uni--->鍥炲--->" + type + "--->" + e.getMessage(), true);
}
--
Gitblit v1.8.0