From 23d38b1e7374c20698702b6ab3feb1e92e82c4d3 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 04 十二月 2024 19:22:17 +0800
Subject: [PATCH] 2024年12月04日19:22:16

---
 app/src/main/java/com/hdl/photovoltaic/ui/test/TestMainActivity.java |  271 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 235 insertions(+), 36 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/test/TestMainActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/test/TestMainActivity.java
index 40455f8..73496fe 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/test/TestMainActivity.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/test/TestMainActivity.java
@@ -2,27 +2,31 @@
 
 import androidx.recyclerview.widget.LinearLayoutManager;
 
-import android.content.Context;
 import android.os.Bundle;
 import android.text.TextUtils;
-import android.util.Log;
 import android.view.View;
 
+
 import com.google.gson.Gson;
-import com.hdl.photovoltaic.R;
+import com.hdl.linkpm.sdk.core.exception.HDLException;
 import com.hdl.photovoltaic.base.CustomBaseActivity;
+import com.hdl.photovoltaic.bean.InverterBean;
 import com.hdl.photovoltaic.config.UserConfigManage;
 import com.hdl.photovoltaic.databinding.ActivityTestMainBinding;
 import com.hdl.photovoltaic.enums.ShowErrorMode;
+import com.hdl.photovoltaic.internet.TcpClient;
+import com.hdl.photovoltaic.listener.CloudCallBeak;
 import com.hdl.photovoltaic.listener.LinkCallBack;
 import com.hdl.photovoltaic.other.HdlDeviceLogic;
 import com.hdl.photovoltaic.other.HdlThreadLogic;
+import com.hdl.photovoltaic.ui.bean.CloudInverterChildDeviceBean;
 import com.hdl.photovoltaic.ui.bean.OidBean;
+import com.hdl.photovoltaic.ui.test.dialogs.DialogDeviceList;
 import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
-import com.hdl.photovoltaic.widget.ConfirmationExceptionDialog;
 import com.hdl.sdk.link.common.exception.HDLLinkException;
 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 java.util.ArrayList;
 import java.util.List;
@@ -34,6 +38,11 @@
 
     private ActivityTestMainBinding viewBinding;
     private TestTitleAdapter testTitleAdapter;
+
+    private List<OidBean> mOidList;
+
+    private GatewayBean mGatewayBean;
+    private String s = "";
 
     @Override
     public Object getContentView() {
@@ -57,34 +66,34 @@
      * 鍒濆鍖�
      */
     private void initView() {
-        viewBinding.toolbarTopFragmentHouseListRl.topBarView.setBackgroundColor(getResources().getColor(R.color.text_FFFFFFFF, null));
-        viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText("閫嗗彉鍣ㄦ寚浠ゆ祴璇�");
-        viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setTextColor(getResources().getColor(R.color.text_030D1C, null));
-        viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setVisibility(View.VISIBLE);
 
+        String homeId = "鐢电珯Id=" + UserConfigManage.getInstance().getHomeId();
+        String homeName = "鐢电珯鍚嶇О=" + UserConfigManage.getInstance().getHomeName();
+        viewBinding.homeIdTv.setText(homeId);
+        viewBinding.homeNameTv.setText(homeName);
 
     }
 
     private void initEvent() {
-        viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setOnClickListener(this);
+        viewBinding.topBackLl.setOnClickListener(this);
+        viewBinding.topLogBtn.setOnClickListener(this);
+        viewBinding.clickCommandTv.setOnClickListener(this);
+        viewBinding.clickSelectDeviceTv.setOnClickListener(this);
         testTitleAdapter.setItemOnClickListener(new TestTitleAdapter.OnClickListener() {
             @Override
-            public void OnClick(int position) {
-
-
+            public void OnClick(int position, String title) {
                 if (TextUtils.isEmpty(UserConfigManage.getInstance().getHomeId())) {
                     // TODO: 10/30/23 璇峰厛閫夋嫨浣忓畢杩涜娴嬭瘯,鍚﹀垯鏃犳硶杩涜閫嗗彉鍣ㄦ寚浠ゆ祴璇�;
-                    TipDialog("璇峰厛閫夋嫨浣忓畢杩涜娴嬭瘯,鍚﹀垯鏃犳硶杩涜閫嗗彉鍣ㄦ寚浠ゆ祴璇�.");
+                    TipDialog("璇峰厛閫夋嫨涓�涓�愮數绔欍�戣繘琛屾祴璇�,鍚﹀垯鏃犳硶杩涜閫嗗彉鍣ㄦ寚浠ゆ祴璇�.", null);
                     return;
                 }
-                GatewayBean gatewayBean = HdlDeviceLogic.getInstance().getCurrentHomeMainGateway();
-                if (gatewayBean == null) {
-                    // TODO: 10/30/23 鎵句笉鍒颁綇瀹呯殑涓婚�嗗彉鍣�,璇峰厛纭鏄惁缁戝畾閫嗗彉鍣紝鍐嶈繘琛岄�嗗彉鍣ㄦ寚浠ゆ祴璇�;
-                    TipDialog("鎵句笉鍒颁綇瀹呯殑涓婚�嗗彉鍣�,璇峰厛纭鏄惁缁戝畾杩囬�嗗彉鍣紝鍐嶈繘琛岄�嗗彉鍣ㄦ寚浠ゆ祴璇�.");
+                if (mGatewayBean == null && !title.equals("鎼滅储銆愭墍鏈夈�戦�嗗彉鍣ㄥ垪琛�(0)")) {
+                    TipDialog("鎵句笉鍒颁綇瀹呯殑銆愰�嗗彉鍣ㄣ��,璇峰厛纭鏄惁缁戝畾杩囬�嗗彉鍣紝鍐嶈繘琛岄�嗗彉鍣ㄦ寚浠ゆ祴璇�.", null);
                     return;
                 }
-                showLoading();
-                startRequest(position, gatewayBean);
+
+
+                startRequest(position, mGatewayBean);
             }
         });
     }
@@ -93,8 +102,16 @@
     @Override
     public void onClick(View v) {
         int id = v.getId();
-        if (id == viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.getId()) {
+        if (id == viewBinding.topBackLl.getId()) {
             finish();
+        } else if (id == viewBinding.topLogBtn.getId()) {
+            startActivity(TestLogActivity.class);
+
+        } else if (id == viewBinding.clickCommandTv.getId()) {
+
+        } else if (id == viewBinding.clickSelectDeviceTv.getId()) {
+            selectDevice();
+
         }
     }
 
@@ -105,9 +122,15 @@
      */
     private List<String> getTitleList() {
         List<String> s = new ArrayList<>();
-        s.add("鎼滅储閫嗗彉鍣ㄥ垪琛�");
-        s.add("鑾峰彇閫嗗彉鍣╫id鍒楄〃");
-        s.add("璇诲彇閫嗗彉鍣ㄨ鎯�");
+        s.add("鎼滅储銆愭墍鏈夈�戦�嗗彉鍣ㄥ垪琛�(0)");
+        s.add("鎼滅储銆愪綇瀹呫�戦�嗗彉鍣ㄥ垪琛�(1)");
+        s.add("鑾峰彇閫嗗彉鍣╫id鍒楄〃(2)");
+        s.add("璇诲彇閫嗗彉鍣ㄨ鎯�(3)");
+        s.add("瑙g粦閫嗗彉鍣�(4)");
+        s.add("涓婁紶oid鍒楄〃缁欎簯绔�(5)");
+        s.add("鑾峰彇閫嗗彉鍣ㄤ笅鎸傝澶囧垪琛�(6)");
+        s.add("鑾峰彇閫嗗彉鍣ㄧ殑淇℃伅(7)");
+        s.add("鎭㈠鍑哄巶璁剧疆(8)");
         return s;
     }
 
@@ -117,58 +140,201 @@
      * @param position 绱㈠紩鍊�
      */
     private void startRequest(int position, GatewayBean gatewayBean) {
+        showLoading();
         String title = getTitleList().get(position);
         switch (title) {
-            case "鎼滅储閫嗗彉鍣ㄥ垪琛�": {
-                HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() {
+            case "鎼滅储銆愭墍鏈夈�戦�嗗彉鍣ㄥ垪琛�(0)": {
+                HdlDeviceLogic.getInstance().searchAllNetworkGateway(new GatewayCallBack() {
                     @Override
                     public void onSuccess(List<GatewayBean> gatewayBeanList) {
-                        gsonConvertJsonStr(gatewayBeanList);
+                        List<GatewayBean> newGatewayBeanList = new ArrayList<>();
+                        for (int i = 0; i < gatewayBeanList.size(); i++) {
+                            if (HdlDeviceLogic.getInstance().isGatewaySpk(gatewayBeanList.get(i).getGatewayType())) {
+                                newGatewayBeanList.add(gatewayBeanList.get(i));
+                            }
+                        }
+                        gsonConvertJsonStr(newGatewayBeanList);
                     }
 
                     @Override
                     public void onError(HDLLinkException e) {
-                        setError(e);
+                        setError(e.getMsg(), e.getCode());
                     }
                 });
             }
             break;
+            case "鎼滅储銆愪綇瀹呫�戦�嗗彉鍣ㄥ垪琛�(1)": {
+                List<GatewayBean> gatewayBeanList = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId());
+                gsonConvertJsonStr(gatewayBeanList);
+            }
+            break;
 
-            case "鑾峰彇閫嗗彉鍣╫id鍒楄〃": {
+            case "鑾峰彇閫嗗彉鍣╫id鍒楄〃(2)": {
                 HdlDeviceLogic.getInstance().getInverterOidList(gatewayBean.getDevice_mac(), new LinkCallBack<List<OidBean>>() {
                     @Override
                     public void onSuccess(List<OidBean> obj) {
+                        mOidList = obj;
                         gsonConvertJsonStr(obj);
                     }
 
                     @Override
                     public void onError(HDLLinkException e) {
-                        setError(e);
+                        setError(e.getMsg(), e.getCode());
                     }
                 });
             }
             break;
 
-            case "璇诲彇閫嗗彉鍣ㄨ鎯�": {
-                HdlDeviceLogic.getInstance().getGatewayInfo(gatewayBean.getDevice_mac(), new LinkCallBack<GatewayBean>() {
+            case "璇诲彇閫嗗彉鍣ㄨ鎯�(3)": {
+                HdlDeviceLogic.getInstance().getGatewayInfo(gatewayBean.getDevice_mac(), new LinkCallBack<InverterBean>() {
                     @Override
-                    public void onSuccess(GatewayBean obj) {
+                    public void onSuccess(InverterBean obj) {
                         gsonConvertJsonStr(obj);
                     }
 
                     @Override
                     public void onError(HDLLinkException e) {
-                        setError(e);
+                        setError(e.getMsg(), e.getCode());
                     }
                 });
             }
             break;
+            case "瑙g粦閫嗗彉鍣�(4)": {
+                TipDialog("涓�鏃︽竻闄ゆ帀閫嗗彉鍣ㄤ綇瀹卛d,閫嗗彉鍣ㄩ渶瑕侀噸鏂扮粦瀹氫綇瀹咃紝鍚﹀垯鏃犳硶娴嬭瘯閫嗗彉鍣ㄦ寚浠�;", new Listener() {
+                    @Override
+                    public void Confirmation() {
+
+                        HdlDeviceLogic.getInstance().clearInverterHomeId(gatewayBean.getDevice_mac(), new LinkCallBack<Boolean>() {
+                            @Override
+                            public void onSuccess(Boolean obj) {
+                                s += "瑙g粦銆愭湰鍦般�戞垚鍔�--->";
+                                HdlDeviceLogic.getInstance().delInverterDevice(UserConfigManage.getInstance().getHomeId(), gatewayBean.getDeviceId(), new CloudCallBeak<Boolean>() {
+                                    @Override
+                                    public void onSuccess(Boolean obj) {
+                                        s += "瑙g粦銆愪簯绔�戞垚鍔�";
+                                        gsonConvertJsonStr(s);
+                                    }
+
+                                    @Override
+                                    public void onFailure(HDLException e) {
+                                        setError(e.getMsg(), e.getCode());
+                                    }
+                                });
+                            }
+
+                            @Override
+                            public void onError(HDLLinkException e) {
+                                setError(e.getMsg(), e.getCode());
+                            }
+                        });
+                    }
+                });
+            }
+            break;
+            case "涓婁紶oid鍒楄〃缁欎簯绔�(5)": {
+                if (this.mOidList == null || this.mOidList.size() == 0) {
+                    hideLoading();
+                    HdlThreadLogic.toast(this, "娌℃湁oid鍒楄〃鏁版嵁锛岃鍏堣幏鍙栭�嗗彉鍣╫id鍒楄〃鏁版嵁锛屽啀閲嶆柊涓婁紶.");
+                    return;
+                }
+                HdlDeviceLogic.getInstance().fullUpdateOid(UserConfigManage.getInstance().getHomeId(), this.mOidList, new CloudCallBeak<Boolean>() {
+                    @Override
+                    public void onSuccess(Boolean obj) {
+                        gsonConvertJsonStr(obj);
+                    }
+
+                    @Override
+                    public void onFailure(HDLException e) {
+                        setError(e.getMsg(), e.getCode());
+                    }
+                });
+            }
+            break;
+            case "鑾峰彇閫嗗彉鍣ㄤ笅鎸傝澶囧垪琛�(6)": {
+                HdlDeviceLogic.getInstance().getInverterDeviceChildDeviceList(UserConfigManage.getInstance().getHomeId(), gatewayBean.getOid(), new CloudCallBeak<List<CloudInverterChildDeviceBean>>() {
+                    @Override
+                    public void onSuccess(List<CloudInverterChildDeviceBean> obj) {
+                        gsonConvertJsonStr(obj);
+                    }
+
+                    @Override
+                    public void onFailure(HDLException e) {
+                        setError(e.getMsg(), e.getCode());
+                    }
+                });
+            }
+            break;
+            case "鑾峰彇閫嗗彉鍣ㄧ殑淇℃伅(7)": {
+                if (TextUtils.isEmpty(mGatewayBean.getAddresses())) {
+                    TipDialog("閫嗗彉鍣╝ddresses鍦板潃涓簄ull.", null);
+                    return;
+                }
+                TcpClient.getInstance().sendModBusDataToLinkGateway(gatewayBean.getDevice_mac(), mGatewayBean.getAddresses(), TcpClient.FunctionCode.ReadMultipleRegisters, 550, "8", new ModbusCallBack() {
+                    @Override
+                    public void onSuccess(int[] data) {
+                        gsonConvertJsonStr(data);
+                    }
+
+                    @Override
+                    public void onError(HDLLinkException e) {
+                        setError(e.getMsg(), e.getCode());
+                    }
+                });
+            }
+            break;
+            case "鎭㈠鍑哄巶璁剧疆(8)": {
+                ConfirmationCancelDialog confirmationCancelDialog = new ConfirmationCancelDialog(_mActivity);
+                confirmationCancelDialog.show();
+                confirmationCancelDialog.setTitle("鎻愮ず!");
+                confirmationCancelDialog.setContent("鏄惁瑕佽В缁慭"" + mGatewayBean.getDevice_name() + "\"?");
+                confirmationCancelDialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() {
+                    @Override
+                    public void Confirm() {
+                        confirmationCancelDialog.dismiss();
+                        showLoading("瑙g粦涓�...");
+                        HdlDeviceLogic.getInstance().initializeInverter(gatewayBean.getDevice_mac(), new LinkCallBack<Boolean>() {
+                            @Override
+                            public void onSuccess(Boolean obj) {
+                                hideLoading();
+                                gsonConvertJsonStr(obj);
+                                HdlDeviceLogic.getInstance().removeLocalCacheMemoryGatewayToMac(UserConfigManage.getInstance().getHomeId(), mGatewayBean.getDevice_mac());
+                                HdlDeviceLogic.getInstance().delInverterDevice(UserConfigManage.getInstance().getHomeId(), mGatewayBean.getDeviceId(), null);
+                            }
+
+                            @Override
+                            public void onError(HDLLinkException e) {
+                                hideLoading();
+                                setError(e.getMsg(), e.getCode());
+                            }
+                        });
+                    }
+                });
+                confirmationCancelDialog.setNoOnclickListener(new ConfirmationCancelDialog.onNoOnclickListener() {
+                    @Override
+                    public void Cancel() {
+                        hideLoading();
+                        confirmationCancelDialog.dismiss();
+                    }
+                });
+
+            }
+            break;
+            default: {
+                HdlThreadLogic.runMainThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        hideLoading();
+                    }
+                }, this, ShowErrorMode.YES);
+                break;
+            }
+
         }
 
     }
 
-    private void setError(HDLLinkException hdlLinkException) {
-        String error = hdlLinkException.getMsg() + "(" + hdlLinkException.getCode() + ")";
+    private void setError(String msg, int code) {
+        String error = msg + "(" + code + ")";
         showText(error);
     }
 
@@ -198,7 +364,7 @@
     /**
      * @param s 閿欒淇℃伅
      */
-    private void TipDialog(String s) {
+    private void TipDialog(String s, Listener listener) {
         ConfirmationCancelDialog confirmationCancelDialog = new ConfirmationCancelDialog(this);
         confirmationCancelDialog.setTitle("鎻愮ず");
         confirmationCancelDialog.setContent(s);
@@ -209,16 +375,49 @@
             @Override
             public void Cancel() {
                 confirmationCancelDialog.dismiss();
+                hideLoading();
+
             }
         });
         confirmationCancelDialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() {
             @Override
             public void Confirm() {
+                hideLoading();
                 confirmationCancelDialog.dismiss();
+                if (listener != null) {
+                    listener.Confirmation();
+                }
 
             }
         });
     }
 
+    /**
+     * 閫夋嫨閫嗗彉鍣ㄨ皟璇�
+     */
+    public void selectDevice() {
+        List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId());
+        DialogDeviceList dialogDeviceList = new DialogDeviceList(_mActivity, list);
+        dialogDeviceList.show();
+        dialogDeviceList.DeviceOnclickListener(new DialogDeviceList.OnclickListener() {
+            @Override
+            public void onClick(int position, GatewayBean gatewayBean) {
+                dialogDeviceList.dismiss();
+                if (gatewayBean == null) {
+                    return;
+                }
+                mGatewayBean = gatewayBean;
+                String str = "閫嗗彉鍣ㄥ悕绉�=" + gatewayBean.getDevice_name() + "_" + gatewayBean.getDevice_mac();
+                viewBinding.deviceNameTv.setText(str);
+
+            }
+        });
+
+    }
+
+    public interface Listener {
+        void Confirmation();
+    }
+
 
 }
\ No newline at end of file

--
Gitblit v1.8.0