From 9f9e16bc9b4caecf741339a0699d784558fbc738 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期二, 21 十一月 2023 19:15:31 +0800
Subject: [PATCH] 2023年11月21日19:15:18
---
app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java | 22 +
app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java | 4
app/src/main/java/com/hdl/photovoltaic/codes/CustomCloudCode.java | 4
app/src/main/res/values/strings.xml | 4
app/src/main/java/com/hdl/photovoltaic/internet/api/TopicApi.java | 3
app/src/main/java/com/hdl/photovoltaic/other/HdlCommonLogic.java | 26 ++
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 225 ++++++++++++++++++++++--
app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java | 135 +++++++++++---
app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java | 8
app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java | 12 +
app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpService.java | 20 +
app/src/main/res/values-zh/strings.xml | 4
app/src/main/res/values-en/strings.xml | 4
app/src/main/java/com/hdl/photovoltaic/codes/CustomLocalCode.java | 4
app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java | 15
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java | 33 +++
16 files changed, 449 insertions(+), 74 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/codes/CustomCloudCode.java b/app/src/main/java/com/hdl/photovoltaic/codes/CustomCloudCode.java
new file mode 100644
index 0000000..8c0cdb1
--- /dev/null
+++ b/app/src/main/java/com/hdl/photovoltaic/codes/CustomCloudCode.java
@@ -0,0 +1,4 @@
+package com.hdl.photovoltaic.codes;
+
+public class CustomCloudCode {
+}
diff --git a/app/src/main/java/com/hdl/photovoltaic/codes/CustomLocalCode.java b/app/src/main/java/com/hdl/photovoltaic/codes/CustomLocalCode.java
new file mode 100644
index 0000000..6b17bdd
--- /dev/null
+++ b/app/src/main/java/com/hdl/photovoltaic/codes/CustomLocalCode.java
@@ -0,0 +1,4 @@
+package com.hdl.photovoltaic.codes;
+
+public class CustomLocalCode {
+}
diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java b/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java
index e4f21cd..034fa23 100644
--- a/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java
+++ b/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java
@@ -69,7 +69,7 @@
* @param callBack 鍥炶皟
* @return -
*/
- private Disposable request(String api, String body, CloudCallBeak<String> callBack) {
+ private Disposable requestPost(String api, String body, CloudCallBeak<String> callBack) {
String requestUrl = HDLCloudUserApi.getRequestUrl(api);
@@ -111,7 +111,7 @@
* @param callBack 鍥炶皟
* @return -
*/
- private Disposable requestFile(String api, File body, CloudCallBeak<String> callBack) {
+ private Disposable requestFilePost(String api, File body, CloudCallBeak<String> callBack) {
String requestUrl = HDLCloudUserApi.getRequestUrl(api);
@@ -153,7 +153,7 @@
* @param callBack 鍥炶皟
*/
public Disposable requestHttp(String api, String body, CloudCallBeak<String> callBack) {
- return request(api, body, callBack);
+ return requestPost(api, body, callBack);
}
/**
@@ -164,7 +164,7 @@
* @param callBack 鍥炶皟
*/
public Disposable requestHttpFile(String api, File body, CloudCallBeak<String> callBack) {
- return requestFile(api, body, callBack);
+ return requestFilePost(api, body, callBack);
}
diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java b/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java
index 7653899..7d0b5f3 100644
--- a/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java
+++ b/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java
@@ -20,7 +20,7 @@
public class MyNanoHttpServer extends NanoHTTPD {
//澹版槑鏈嶅姟绔� 绔彛
- private static final Integer HTTP_PORT = 49152;
+ public static final Integer HTTP_PORT = 49152;
public MyNanoHttpServer(String hostname, int port) {
super(hostname, port);
@@ -66,10 +66,14 @@
com.alibaba.fastjson.JSONObject jsonParam = JSON.parseObject(paramStr);
Map<String, Object> result = new HashMap<>();
//TODO 鍐欎綘鐨勪笟鍔¢�昏緫.....
-
- String ss = HdlFileLogic.getInstance().readFile(HdlFileLogic.getInstance().getLogFilePath());
+ //鍗囩骇椹卞姩鏂囦欢璺緞
+ String fileName = ((HTTPSession) session).getUri();
+ String data = "";
+ if (fileName.equals(HdlFileLogic.getInstance().getDriveRootPath())) {
+ data = HdlFileLogic.getInstance().readFile(fileName);
+ }
//鍝嶅簲瀹㈡埛绔�
- return newFixedLengthResponse(ss);
+ return newFixedLengthResponse(data);
// return newFixedLengthResponse("success");
} catch (IOException e) {
e.printStackTrace();
@@ -78,11 +82,15 @@
}
return newFixedLengthResponse("success");
} else if (Method.GET == session.getMethod()) {
-
Map<String, List<String>> parameters = session.getParameters();
- String ss = HdlFileLogic.getInstance().readFile(HdlFileLogic.getInstance().getLogFilePath());
+ //鍗囩骇椹卞姩鏂囦欢璺緞
+ String fileName = ((HTTPSession) session).getUri();
+ String data = "";
+ if (fileName.contains(HdlFileLogic.getInstance().getDriveRootPath())) {
+ data = HdlFileLogic.getInstance().readFile(fileName);
+ }
//鍝嶅簲瀹㈡埛绔�
- return newFixedLengthResponse(ss);
+ return newFixedLengthResponse(data);
// return newFixedLengthResponse("success");
}
diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpService.java b/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpService.java
index 007d757..748140a 100644
--- a/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpService.java
+++ b/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpService.java
@@ -2,6 +2,7 @@
import android.app.Service;
import android.content.Intent;
+import android.os.Binder;
import android.os.IBinder;
import androidx.annotation.Nullable;
@@ -9,11 +10,7 @@
public class MyNanoHttpService extends Service {
private MyNanoHttpServer myNanoHttpServer = MyNanoHttpServer.getInstance(null);
- @Nullable
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
+ private final IBinder mBinder = new LocalBinder();
@Override
public void onCreate() {
@@ -38,4 +35,17 @@
super.onDestroy();
myNanoHttpServer.stop();
}
+
+ @Nullable
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mBinder;
+ }
+
+ public class LocalBinder extends Binder {
+ public MyNanoHttpService getService() {
+ // Return this instance of LocalService so clients can call public methods
+ return MyNanoHttpService.this;
+ }
+ }
}
diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/api/TopicApi.java b/app/src/main/java/com/hdl/photovoltaic/internet/api/TopicApi.java
index 0dd6d34..b26a8f9 100644
--- a/app/src/main/java/com/hdl/photovoltaic/internet/api/TopicApi.java
+++ b/app/src/main/java/com/hdl/photovoltaic/internet/api/TopicApi.java
@@ -43,6 +43,9 @@
public static final String GET_GATEWAY_TIME = "/user/%s/custom/gateway/time/get";
//缃戝叧鏃堕棿淇敼
public static final String SET_GATEWAY_TIME_EDIT = "/user/%s/custom/gateway/time/edit";
+
+ //鏈湴鍗囩骇鍖呮帹閫�(鍛婅瘔缃戝叧涓嬭浇鍗囩骇鍖呭湴鍧�绛変俊鎭�)
+ public static final String SET_GATEWAY_UPGRADE_INFO = "/base/%s/ota/device/upgrade/down";
/*
* 缃戝叧缂栬緫鍛戒护
* 涓庢湇鍔″櫒鏃犲叧鐨�
diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlCommonLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlCommonLogic.java
new file mode 100644
index 0000000..78422a6
--- /dev/null
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlCommonLogic.java
@@ -0,0 +1,26 @@
+package com.hdl.photovoltaic.other;
+
+/**
+ * 鍏叡閫昏緫
+ */
+public class HdlCommonLogic {
+
+ private static volatile HdlCommonLogic sHdlCommonLogic;
+
+ /**
+ * 鑾峰彇褰撳墠瀵硅薄
+ *
+ * @return HdlCommonLogic
+ */
+ public static synchronized HdlCommonLogic getInstance() {
+ if (sHdlCommonLogic == null) {
+ synchronized (HdlCommonLogic.class) {
+ if (sHdlCommonLogic == null) {
+ sHdlCommonLogic = new HdlCommonLogic();
+ }
+ }
+
+ }
+ return sHdlCommonLogic;
+ }
+}
diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
index 0a4b5c0..4a35115 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -835,6 +835,39 @@
return gatewayBean == null;
}
+ /**
+ * 妫�娴嬮�嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
+ *
+ * @param deviceMac 璁惧mac
+ */
+ public void checkInverterConnectedCloud(String deviceMac, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) {
+ this.getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+ @Override
+ public void onSuccess(List<CloudInverterDeviceBean> list) {
+ CloudInverterDeviceBean cloudInverterDeviceBean = null;
+ if (list != null && list.size() > 0) {
+ for (int i = 0; i < list.size(); i++) {
+ if (list.get(i).getOsn().equals(deviceMac)) {
+ cloudInverterDeviceBean = list.get(i);
+ break;
+ }
+
+ }
+ }
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(cloudInverterDeviceBean);
+ }
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+ }
+
/**
* 鍒锋柊閫嗗彉鍣ㄧ紦瀛樹俊鎭�(鍖呮嫭璁剧疆mqtt绉橀挜锛�
diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java
index 69b3e95..10569f4 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java
@@ -107,6 +107,18 @@
return getAPPInternalStoreFilesPath() + "/userConfigManage.txt";
}
+ /**
+ * 鑾峰彇椹卞姩鍗囩骇鏂囦欢鍏ㄨ矾寰�
+ *
+ * @param driverCode 椹卞姩缂栫爜
+ * @param version 椹卞姩鐗堟湰
+ * @return 鍏ㄨ矾寰�
+ */
+ public String getDrivePathFileName(String driverCode, String version) {
+ String driverFileName = driverCode + "_" + version + ".zip";
+ return HdlFileLogic.getInstance().getDriveRootPath() + "/" + driverFileName;
+ }
+
//endregion
//region ---------銆愭枃浠跺す銆戞搷浣�-----------
diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java
index d858f8c..96a2d53 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java
@@ -1,5 +1,10 @@
package com.hdl.photovoltaic.other;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.IBinder;
import android.text.TextUtils;
@@ -13,10 +18,19 @@
import com.hdl.linkpm.sdk.ota.bean.DeviceFirmwareBean;
import com.hdl.linkpm.sdk.ota.bean.DownloadUrlBean;
import com.hdl.linkpm.sdk.ota.bean.GatewayDriverBean;
+import com.hdl.photovoltaic.HDLApp;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.internet.HttpClient;
+import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpServer;
+import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpService;
+import com.hdl.photovoltaic.internet.TcpClient;
import com.hdl.photovoltaic.internet.api.HttpApi;
+import com.hdl.photovoltaic.internet.api.TopicApi;
import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.listener.LinkCallBack;
+import com.hdl.photovoltaic.utils.AppManagerUtils;
+import com.hdl.sdk.link.common.exception.HDLLinkException;
+import com.hdl.sdk.link.core.callback.HDLLinkCallBack;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -45,6 +59,23 @@
}
return sHdlOtaLogic;
}
+
+ /**
+ * Intent涓撻棬鍚姩鏈湴鏈嶅姟
+ *
+ * @return Intent
+ */
+ public Intent getIntent() {
+ return intentServer;
+ }
+
+ public void setIntent(Intent intent) {
+ this.intentServer = intent;
+ }
+
+ private Intent intentServer = null;
+
+ private ServiceConnection mServiceConnection = null;
//region -----鍥轰欢鍗囩骇---------
@@ -381,47 +412,27 @@
*
* @param driverVersionId 椹卞姩鐗堟湰Id
*/
- public void getDeviceDriverDownloadUrl(String driverVersionId, CloudCallBeak<String> callBack) {
-// "driverCode":"029B9988",
-// "driverName":"鏍稿績灞�",
-// "imageId":"12345678",
-// "version":"V01.02.20"
+ public void getDeviceDriverDownloadUrl(String driverVersionId, CloudCallBeak<DownloadUrlBean> callBack) {
+
String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceDriverDownloadUrl;
JsonObject json = new JsonObject();
json.addProperty("driverVersionId", driverVersionId);
HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
@Override
- public void onSuccess(String json) {
-
- if (TextUtils.isEmpty(json)) {
+ public void onSuccess(String s) {
+ if (TextUtils.isEmpty(s)) {
if (callBack != null) {
- callBack.onSuccess("-2");
+ callBack.onSuccess(new DownloadUrlBean());
}
return;
}
Gson gson = new Gson();
Type typeOfT = new TypeToken<DownloadUrlBean>() {
}.getType();
- DownloadUrlBean downloadUrlBean = gson.fromJson(json, typeOfT);
- if (downloadUrlBean == null) {
- if (callBack != null) {
- callBack.onSuccess("-2");
- }
- return;
+ DownloadUrlBean downloadUrlBean = gson.fromJson(s, typeOfT);
+ if (callBack != null) {
+ callBack.onSuccess(downloadUrlBean);
}
- getDeviceDriverDownloadFile(downloadUrlBean.getDownloadUrl(), new CloudCallBeak<DownloadUrlBean>() {
- @Override
- public void onSuccess(DownloadUrlBean obj) {
- String full = HdlFileLogic.getInstance().getDriveRootPath() + "/" + driverVersionId;
- HdlFileLogic.getInstance().writeFile(full, obj.toString());
- }
-
- @Override
- public void onFailure(HDLException e) {
-
- }
- });
-
}
@Override
@@ -446,4 +457,72 @@
//endregion
+
+ /**
+ * 鏈湴鍗囩骇鍖呮帹閫�(鍛婅瘔缃戝叧涓嬭浇鍗囩骇鍖呭湴鍧�绛変俊鎭�)
+ *
+ * @param mac 鐗╃悊璁惧mac
+ * @param oid 鐗╃悊璁惧oid
+ * @param module 妯″潡淇℃伅
+ * @param version 鐗堟湰鍙�
+ * @param size 鍗囩骇鍖呭ぇ灏�
+ * @param url 鍗囩骇鍖呬笅杞藉湴鍧�(瀛樺偍鍦ㄦ湰鍦�)
+ * @param sign_method md5鍔犲瘑瀛楃涓�
+ * @param linkCallBack -
+ */
+ public void pushUpgradePacketInfo(String mac, String oid, String module, String version, String size, String url, String sign_method, LinkCallBack<String> linkCallBack) {
+ String requestUrl = TopicApi.SET_GATEWAY_UPGRADE_INFO;
+ JsonObject json = new JsonObject();
+ json.addProperty("oid", oid);// 鐗╃悊璁惧oid
+ json.addProperty("module", module);//妯″潡淇℃伅
+ json.addProperty("version", version);//鐗堟湰鍙�
+// json.addProperty("is_diff", is_diff);//true=澧為噺鍖咃紝false=鍏ㄩ噺鍖�
+ json.addProperty("size", size);//鍗囩骇鍖呭ぇ灏�
+ json.addProperty("url", url);//鍗囩骇鍖呬笅杞藉湴鍧�
+ json.addProperty("sign_method", sign_method);//鍗囩骇鍖呯鍚嶇被鍨�:md5
+ TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() {
+ @Override
+ public void onSuccess(String msg) {
+ if (linkCallBack != null) {
+ linkCallBack.onSuccess(msg);
+ }
+
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+ if (linkCallBack != null) {
+ linkCallBack.onError(e);
+ }
+ }
+ });
+ }
+
+
+ /**
+ * 鍚姩鏈湴鏈嶅姟
+ */
+ public void startLocalService(ServiceConnection serviceConnection) {
+ //鏈湴
+ //1,寤虹珛鏈湴鏈嶅姟锛�
+ //2锛屽憡璇夌綉鍏虫墜鏈篿p鍜岀鍙o紱
+ //瀹炰緥鍖� 鑾峰彇ip 鍦板潃
+ MyNanoHttpServer.getInstance(AppManagerUtils.getAppManager().getIPAddress(HDLApp.getInstance()));
+ //MyNanoHttpServer.getInstance("127.0.0.1");
+ intentServer = new Intent();
+ intentServer.setClass(HDLApp.getInstance(), MyNanoHttpService.class);
+ this.mServiceConnection = serviceConnection;
+ //鍚姩鏈嶅姟鐩戝惉
+ HDLApp.getInstance().bindService(intentServer, serviceConnection, Context.BIND_AUTO_CREATE);
+ }
+
+ /**
+ * 鍏抽棴鏈湴鏈嶅姟
+ */
+ public void unLocalService() {
+ if (intentServer != null && this.mServiceConnection != null) {
+ HDLApp.getInstance().unbindService(this.mServiceConnection);
+ }
+ }
+
}
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 78ed634..a5be3d4 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -1,6 +1,11 @@
package com.hdl.photovoltaic.other;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
@@ -12,15 +17,21 @@
import com.hdl.linkpm.sdk.ota.bean.DeviceFirmwareBean;
import com.hdl.linkpm.sdk.ota.bean.DownloadUrlBean;
import com.hdl.linkpm.sdk.ota.bean.GatewayDriverBean;
+import com.hdl.linkpm.sdk.utils.HDLMD5Utils;
import com.hdl.photovoltaic.HDLApp;
+import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.bean.ModBusBean;
import com.hdl.photovoltaic.config.UserConfigManage;
+import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpServer;
+import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpService;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.listener.LinkCallBack;
+import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
import com.hdl.photovoltaic.ui.bean.DeviceTimeBean;
import com.hdl.photovoltaic.ui.bean.OidBean;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
+import com.hdl.photovoltaic.utils.AppManagerUtils;
import com.hdl.photovoltaic.utils.WifiUtils;
import com.hdl.sdk.link.common.exception.HDLLinkCode;
import com.hdl.sdk.link.common.exception.HDLLinkException;
@@ -35,8 +46,11 @@
import org.json.JSONObject;
+import java.io.File;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Objects;
import io.dcloud.feature.unimp.DCUniMPJSCallback;
@@ -62,6 +76,7 @@
}
return sHdlUniLogic;
}
+
//region ******銆愬師鐢熴�戝拰銆愬皬绋嬪簭銆戦�氳鐨�3涓柟娉曞悕 onOtherUniMPEventReceive();openUniMP();sendUni();******
@@ -279,7 +294,7 @@
* 娉ㄦ剰锛氶渶瑕佹彁鍓嶅皬绋嬪簭鍦ㄨ繍琛屾墠鍙垚鍔�
*
* @param topic 涓婚澶х被(濡�:UNI_EVENT_REPLY_HOME_MODEL)
- * @param callBackBaseBean 鈥斺��
+ * @param callBackBaseBean 鑷畾涔夊疄浣撶被
*/
public void sendUni(String topic, HDLUniMP.UniCallBackBaseBean callBackBaseBean) {
try {
@@ -362,9 +377,29 @@
* 鑾峰彇銆愯澶囨湰鍦板浐浠躲�戝垪琛�
*/
private void uniGetLocalFirmwares(Object data, DCUniMPJSCallback callback) {
- String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//纭欢鍨嬪彿
- String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//绯荤粺闀滃儚id
- String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//绯荤粺闀滃儚id
+ try {
+ String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//纭欢鍨嬪彿
+ String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//绯荤粺闀滃儚id
+ String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//绯荤粺闀滃儚id
+ List<DeviceFirmwareBean> list = new ArrayList<>();
+ String driverFileList = HdlFileLogic.getInstance().getFirmwareRootPath();
+ File file = new File(driverFileList);
+ if (file.list() != null) {
+ for (int i = 0; i < Objects.requireNonNull(file.list()).length; i++) {
+ String path = Objects.requireNonNull(file.list())[i];
+ String[] ary = path.split("/");
+ String[] driverInfoAry = ary[ary.length - 1].split("_");
+ DeviceFirmwareBean deviceFirmwareBean = new DeviceFirmwareBean();
+ deviceFirmwareBean.setVersion(driverInfoAry[0]);
+ deviceFirmwareBean.setImageId(driverInfoAry[1].replace(".zip", ""));
+ list.add(deviceFirmwareBean);
+ }
+ }
+ if (callback != null) {
+ this.uniCallbackData(list, callback);
+ }
+ } catch (Exception ignored) {
+ }
}
/**
@@ -395,6 +430,8 @@
String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//璁惧id
String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//鍥轰欢鐗堟湰id
+
+ //鍗囩骇鏈湴浼樺厛->浜戠鍗囩骇
boolean isLocalConnect = HdlDeviceLogic.getInstance().isLocalConnect(deviceMac);
if (isLocalConnect) {
//鏈湴
@@ -402,11 +439,32 @@
// 2锛屽憡璇夌綉鍏虫墜鏈篿p鍜岀鍙o紱
} else {
- //浜戠
- HdlOtaLogic.getInstance().upgradeDeviceFirmware(deviceOidId, firmwareVersionId, new CloudCallBeak<Boolean>() {
+ //杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
+ HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
@Override
- public void onSuccess(Boolean obj) {
- uniCallbackData(obj, callback);
+ public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
+ //1:寰呮満,2:杩炴帴涓�,3:鏁呴殰,4:杩愯,5:绂荤嚎,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�)
+ if (cloudInverterDeviceBean == null) {
+ uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback);
+ return;
+ }
+ if (cloudInverterDeviceBean.getDeviceStatus() != 4) {
+ uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), getDeviceStatusString(cloudInverterDeviceBean.getDeviceStatus()), callback);
+ return;
+ }
+ //4:杩愯
+ HdlOtaLogic.getInstance().upgradeDeviceFirmware(deviceOidId, firmwareVersionId, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+ uniCallbackData(obj, callback);
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ uniCallbackData(null, e.getCode(), e.getMsg(), callback);
+ }
+ });
+
}
@Override
@@ -414,7 +472,10 @@
uniCallbackData(null, e.getCode(), e.getMsg(), callback);
}
});
+
}
+
+
}
/**
@@ -460,23 +521,64 @@
* 鑾峰彇銆愯澶囨湰鍦伴┍鍔ㄣ�戝垪琛�
*/
private void uniGetLocalDrivers(Object data, DCUniMPJSCallback callback) {
- String driveCode = getKeyValue("driveCode", getKeyValue("data", data));//椹卞姩缂栧彿鎴栭┍鍔ㄥ悕绉�
- String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//椹卞姩绫诲瀷id
- String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//椹卞姩绫诲瀷id
+ try {
+ String driveCode = getKeyValue("driveCode", getKeyValue("data", data));//椹卞姩缂栧彿鎴栭┍鍔ㄥ悕绉�
+ String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//椹卞姩绫诲瀷id
+ String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//椹卞姩绫诲瀷id
+ List<GatewayDriverBean> list = new ArrayList<>();
+ String driverFileList = HdlFileLogic.getInstance().getDriveRootPath();
+ File file = new File(driverFileList);
+ if (file.list() != null) {
+ for (int i = 0; i < Objects.requireNonNull(file.list()).length; i++) {
+ String path = Objects.requireNonNull(file.list())[i];
+ String[] ary = path.split("/");
+ String[] driverInfoAry = ary[ary.length - 1].split("_");
+ GatewayDriverBean gatewayDriverBean = new GatewayDriverBean();
+ gatewayDriverBean.setDriverCode(driverInfoAry[0]);
+ gatewayDriverBean.setVersion(driverInfoAry[1].replace(".zip", ""));
+ list.add(gatewayDriverBean);
+ }
+ }
+ if (callback != null) {
+ this.uniCallbackData(list, callback);
+ }
+ } catch (Exception exception) {
+ this.uniCallbackData(new ArrayList<>(), callback);
+ }
+
}
/**
* 鍚戜簯绔彂璧枫�愯澶囬┍鍔ㄣ�戜笅杞芥寚浠�
*/
private void uniGatewayDriverDownload(Object data, DCUniMPJSCallback callback) {
-
-
String deviceOid = getKeyValue("oid", getKeyValue("data", data));//缃戝叧璁惧oid
+ String driverCode = getKeyValue("driverCode", getKeyValue("data", data));//椹卞姩缂栫爜
+ String imageId = getKeyValue("imageId", getKeyValue("data", data));//椹卞姩闀滃儚id
+ String version = getKeyValue("version", getKeyValue("data", data));//椹卞姩鐗堟湰
String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//椹卞姩鐗堟湰id
- HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() {
+ HdlOtaLogic.getInstance().getDeviceDriverDownloadUrl(driverVersionId, new CloudCallBeak<DownloadUrlBean>() {
@Override
- public void onSuccess(Boolean obj) {
- uniCallbackData(obj, callback);
+ public void onSuccess(DownloadUrlBean downloadUrlBean) {
+ if (downloadUrlBean == null) {
+ uniCallbackData(null, -2, "涓嬭浇閾炬帴鎵句笉鍒�", callback);
+ return;
+ }
+ HdlOtaLogic.getInstance().getDeviceDriverDownloadFile(downloadUrlBean.getDownloadUrl(), new CloudCallBeak<DownloadUrlBean>() {
+ @Override
+ public void onSuccess(DownloadUrlBean obj) {
+ Gson gson = new Gson();
+ String json = gson.toJson(obj);
+ String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version);
+ HdlFileLogic.getInstance().writeFile(drivePathFileName, json);
+
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+
+ }
+ });
}
@Override
@@ -494,17 +596,72 @@
String deviceMac = getKeyValue("mac", getKeyValue("data", data));//缃戝叧璁惧mac锛堟煡鎵緎ocket锛�
String deviceOid = getKeyValue("oid", getKeyValue("data", data));//缃戝叧璁惧oid
String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//椹卞姩鐗堟湰id
+ String module = getKeyValue("module", getKeyValue("data", data));//妯″潡淇℃伅
+ String version = getKeyValue("version", getKeyValue("data", data));//椹卞姩鐗堟湰鍙�
+ String driverCode = getKeyValue("driverCode", getKeyValue("data", data));//椹卞姩缂栫爜
+ //鍗囩骇鏈湴浼樺厛->浜戠鍗囩骇
boolean isLocalConnect = HdlDeviceLogic.getInstance().isLocalConnect(deviceMac);
if (isLocalConnect) {
//鏈湴
//1,寤虹珛鏈湴鏈嶅姟锛�
// 2锛屽憡璇夌綉鍏虫墜鏈篿p鍜岀鍙o紱
-
- } else {
- HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() {
+ //瀹炰緥鍖� 鑾峰彇ip 鍦板潃
+ HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() {
@Override
- public void onSuccess(Boolean obj) {
- uniCallbackData(obj, callback);
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ //鏈湴鍗囩骇椹卞姩鏂囦欢璺緞
+ String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version);
+ String data = HdlFileLogic.getInstance().readFile(drivePathFileName);
+ String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧椹卞姩闇�瑕�
+ //鍗囩骇椹卞姩鏂囦欢鍦板潃
+ String upgradeFileLocalPathUrl = AppManagerUtils.getAppManager().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + drivePathFileName;
+ //閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�绛変俊鎭�
+ HdlOtaLogic.getInstance().pushUpgradePacketInfo(deviceMac, deviceOid, module, version, data.length() + "", upgradeFileLocalPathUrl, md5, new LinkCallBack<String>() {
+ @Override
+ public void onSuccess(String obj) {
+ HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�鎴愬姛.", false);
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+ HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇.", false);
+ uniCallbackData(null, -2, "閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇,", callback);
+ }
+ });
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ uniCallbackData(null, -2, "鏈湴鏈嶅姟鏈夊紓甯稿け璐�,鏃犳硶鍗囩骇,", callback);
+ }
+ });
+ } else {
+ //杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
+ HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
+ @Override
+ public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
+ //1:寰呮満,2:杩炴帴涓�,3:鏁呴殰,4:杩愯,5:绂荤嚎,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�)
+ if (cloudInverterDeviceBean == null) {
+ uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback);
+ return;
+ }
+ if (cloudInverterDeviceBean.getDeviceStatus() != 4) {
+ uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), getDeviceStatusString(cloudInverterDeviceBean.getDeviceStatus()), callback);
+ return;
+ }
+ //4:杩愯
+ HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+ uniCallbackData(obj, callback);
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ uniCallbackData(null, e.getCode(), e.getMsg(), callback);
+ }
+ });
+
}
@Override
@@ -512,9 +669,35 @@
uniCallbackData(null, e.getCode(), e.getMsg(), callback);
}
});
+
}
}
+
+ /**
+ * @param deviceStatus 閫嗗彉鍣ㄨ繛鎺ヤ簯绔姸鎬佸�硷紙 1:寰呮満,2:杩炴帴涓�,3:鏁呴殰,4:杩愯,5:绂荤嚎锛�
+ * @return 杩斿洖鏂囨湰
+ */
+ public String getDeviceStatusString(int deviceStatus) {
+ switch (deviceStatus) {
+ case 1: {
+ return HDLApp.getInstance().getString(R.string.my_power_station_await);
+ }
+ case 2: {
+ return HDLApp.getInstance().getString(R.string.my_power_station_connecting);
+ }
+ case 3: {
+ return HDLApp.getInstance().getString(R.string.my_power_station_malfunction);
+ }
+ case 5: {
+ return HDLApp.getInstance().getString(R.string.my_power_station_off_line);
+ }
+ default:
+ return "";
+ }
+
+ }
+
/**
* 閫嗗彉鍣ㄦ竻绌轰綇瀹卛d
*
diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java
index bc6dd9c..c895a5a 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java
@@ -14,6 +14,7 @@
import com.google.gson.Gson;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.linkpm.sdk.home.type.HomeType;
+import com.hdl.photovoltaic.HDLApp;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.base.CustomBaseActivity;
import com.hdl.photovoltaic.bean.MqttInfo;
@@ -23,6 +24,7 @@
import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpService;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.other.HdlDeviceLogic;
+import com.hdl.photovoltaic.other.HdlFileLogic;
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlMqttLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
@@ -76,14 +78,13 @@
//鍒濆鍖杕qtt瀹㈡埛绔�
initMqttClient();
+ String path = HdlFileLogic.getInstance().getDriveRootPath() + "/036F6C1B.zip";
+ MyNanoHttpServer.getInstance(AppManagerUtils.getAppManager().getIPAddress(HDLApp.getInstance()));
+ //MyNanoHttpServer.getInstance("127.0.0.1");
+ Intent intentServer = new Intent();
+ intentServer.setClass(HDLApp.getInstance(), MyNanoHttpService.class);
+ startService(intentServer);
- //瀹炰緥鍖� 鑾峰彇ip 鍦板潃
- MyNanoHttpServer.getInstance(AppManagerUtils.getAppManager().getIPAddress(this));
-// MyNanoHttpServer.getInstance("127.0.0.1");
- Intent intent = new Intent();
- intent.setClass(this, MyNanoHttpService.class);
- //鍚姩鏈嶅姟鐩戝惉
- startService(intent);
}
private void initEvent() {
diff --git a/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java b/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java
index 5f5fb54..3e5b1ce 100644
--- a/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java
+++ b/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java
@@ -45,12 +45,16 @@
public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_NEW_LIST = "firmwares_new_list";//璁惧鏂板浐浠跺垪琛�
public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_LOCAL = "firmwares_local_list";//璁惧鏈湴鍥轰欢鍒楄〃
public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_DOWNLOAD = "firmwares_download";//璁惧鍥轰欢涓嬭浇
+ public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_CANCEL_DOWNLOAD = "firmwares_cancel_download";//璁惧鍥轰欢鍙栨秷涓嬭浇
public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_UPGRADE = "firmwares_upgrade";//璁惧鍥轰欢鍗囩骇
+ public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_CANCEL_UPGRADE = "firmwares_cancel_upgrade";//璁惧鍥轰欢鍙栨秷鍗囩骇
public final static String UNI_EVENT_REPLY_OTA_DRIVER_LIST = "driver_current_list";//褰撳墠璁惧椹卞姩鍒楄〃
public final static String UNI_EVENT_REPLY_OTA_DRIVER_NEW = "driver_new_list";//璁惧鏂伴┍鍔ㄥ垪琛�
public final static String UNI_EVENT_REPLY_OTA_DRIVER_LOCAL = "driver_local_list";//璁惧鏈湴椹卞姩鍒楄〃
public final static String UNI_EVENT_REPLY_OTA_DRIVER_DOWNLOAD = "driver_download";//璁惧椹卞姩涓嬭浇
+ public final static String UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD = "driver_cancel_download";//璁惧椹卞姩鍙栨秷涓嬭浇
public final static String UNI_EVENT_REPLY_OTA_DRIVER_UPGRADE = "driver_upgrade";//璁惧椹卞姩鍗囩骇
+ public final static String UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_UPGRADE = "driver_cancel_upgrade";//璁惧椹卞姩鍙栨秷鍗囩骇
/*********Wifi妯″潡*********/ //鍗敠瀹氫箟
diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml
index 4feae6e..7c8521b 100644
--- a/app/src/main/res/values-en/strings.xml
+++ b/app/src/main/res/values-en/strings.xml
@@ -75,6 +75,7 @@
<string name="my_power_station_off_line">绂荤嚎</string>
<string name="my_power_station_malfunction">鏁呴殰</string>
<string name="my_power_station_operation">杩愯</string>
+ <string name="my_power_station_await">寰呮満</string>
<!--璁惧-->
<string name="device_manual_connection">鎵嬪姩杩炴帴</string>
@@ -105,7 +106,8 @@
<string name="set_privacy">闅愮璁剧疆</string>
<string name="set_nickname_modification">鏄电О淇敼</string>
-
+ <!--ota-->
+ <string name="ota_not_cloud_upgrade_fails">閫嗗彉鍣ㄦ病涓婁簯,鍗囩骇澶辫触.</string>
<!--uin-->
<string name="uni_open_error">椤甸潰鍒濆鍖栦腑 璇风瓑寰�5绉掑啀鐐瑰嚮</string>
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 0430569..6e117ef 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -75,6 +75,7 @@
<string name="my_power_station_off_line">绂荤嚎</string>
<string name="my_power_station_malfunction">鏁呴殰</string>
<string name="my_power_station_operation">杩愯</string>
+ <string name="my_power_station_await">寰呮満</string>
<!--璁惧-->
<string name="device_manual_connection">鎵嬪姩杩炴帴</string>
@@ -105,7 +106,8 @@
<string name="set_privacy">闅愮璁剧疆</string>
<string name="set_nickname_modification">鏄电О淇敼</string>
-
+ <!--ota-->
+ <string name="ota_not_cloud_upgrade_fails">閫嗗彉鍣ㄦ病涓婁簯,鍗囩骇澶辫触.</string>
<!--uin-->
<string name="uni_open_error">椤甸潰鍒濆鍖栦腑 璇风瓑寰�5绉掑啀鐐瑰嚮</string>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0430569..e1b913b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -75,6 +75,7 @@
<string name="my_power_station_off_line">绂荤嚎</string>
<string name="my_power_station_malfunction">鏁呴殰</string>
<string name="my_power_station_operation">杩愯</string>
+ <string name="my_power_station_await">寰呮満</string>
<!--璁惧-->
<string name="device_manual_connection">鎵嬪姩杩炴帴</string>
@@ -105,6 +106,9 @@
<string name="set_privacy">闅愮璁剧疆</string>
<string name="set_nickname_modification">鏄电О淇敼</string>
+ <!--ota-->
+ <string name="ota_not_cloud_upgrade_fails">閫嗗彉鍣ㄦ病杩炰笂浜�,鍗囩骇澶辫触.</string>
+
<!--uin-->
<string name="uni_open_error">椤甸潰鍒濆鍖栦腑 璇风瓑寰�5绉掑啀鐐瑰嚮</string>
--
Gitblit v1.8.0