mac
2024-01-11 dbff6d6f9200417ea60e2fe507b79cbe2eb7ea32
app/src/main/java/com/hdl/photovoltaic/ui/test/TestMainActivity.java
@@ -2,28 +2,36 @@
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.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.base.CustomBaseActivity;
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.internet.api.TopicApi;
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.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.bean.response.BaseLocalResponse;
import com.hdl.sdk.link.core.callback.GatewayCallBack;
import com.hdl.sdk.link.core.callback.HDLLinkCallBack;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
@@ -34,6 +42,8 @@
    private ActivityTestMainBinding viewBinding;
    private TestTitleAdapter testTitleAdapter;
    private List<OidBean> mOidList;
    @Override
    public Object getContentView() {
@@ -69,6 +79,7 @@
    private void initEvent() {
        viewBinding.topBackBtn.setOnClickListener(this);
        viewBinding.topLogBtn.setOnClickListener(this);
        viewBinding.clickCommandTv.setOnClickListener(this);
        testTitleAdapter.setItemOnClickListener(new TestTitleAdapter.OnClickListener() {
            @Override
            public void OnClick(int position, String title) {
@@ -79,8 +90,8 @@
                    TipDialog("请先选择住宅进行测试,否则无法进行逆变器指令测试.", null);
                    return;
                }
                GatewayBean gatewayBean = HdlDeviceLogic.getInstance().getCurrentHomeMainGateway();
                if (gatewayBean == null && !title.equals("搜索逆变器列表")) {
                GatewayBean gatewayBean = HdlDeviceLogic.getInstance().getCurrentHomeMainGateway(UserConfigManage.getInstance().getHomeId());
                if (gatewayBean == null && !title.equals("搜索逆变器列表(0)") && !title.equals("搜索【住宅】逆变器列表(1)")) {
                    // TODO: 10/30/23 找不到住宅的主逆变器,请先确认是否绑定逆变器,再进行逆变器指令测试;
                    TipDialog("找不到住宅的【主逆变器】,请先确认是否绑定过逆变器,再进行逆变器指令测试.", null);
                    return;
@@ -100,6 +111,8 @@
        } else if (id == viewBinding.topLogBtn.getId()) {
            startActivity(TestLogActivity.class);
        } else if (id == viewBinding.clickCommandTv.getId()) {
        }
    }
@@ -110,10 +123,13 @@
     */
    private List<String> getTitleList() {
        List<String> s = new ArrayList<>();
        s.add("搜索逆变器列表");
        s.add("获取逆变器oid列表");
        s.add("读取逆变器详情");
        s.add("清除逆变器住宅Id");
        s.add("搜索逆变器列表(0)");
        s.add("搜索【住宅】逆变器列表(1)");
        s.add("获取逆变器oid列表(2)");
        s.add("读取逆变器详情(3)");
        s.add("清除逆变器住宅Id(4)");
        s.add("上传oid列表给云端(5)");
        s.add("获取逆变器下挂设备列表(6)");
        return s;
    }
@@ -125,8 +141,28 @@
    private void startRequest(int position, GatewayBean gatewayBean) {
        String title = getTitleList().get(position);
        switch (title) {
            case "搜索逆变器列表": {
                HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() {
            case "搜索逆变器列表(0)": {
                HdlDeviceLogic.getInstance().searchAllGateway(new GatewayCallBack() {
                    @Override
                    public void onSuccess(List<GatewayBean> 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.getMsg(), e.getCode());
                    }
                });
            }
            break;
            case "搜索【住宅】逆变器列表(1)": {
                HdlDeviceLogic.getInstance().searchCurrentHomeGateway(new GatewayCallBack() {
                    @Override
                    public void onSuccess(List<GatewayBean> gatewayBeanList) {
                        gsonConvertJsonStr(gatewayBeanList);
@@ -134,28 +170,29 @@
                    @Override
                    public void onError(HDLLinkException e) {
                        setError(e);
                        setError(e.getMsg(), e.getCode());
                    }
                });
            }
            break;
            case "获取逆变器oid列表": {
            case "获取逆变器oid列表(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 "读取逆变器详情": {
            case "读取逆变器详情(3)": {
                HdlDeviceLogic.getInstance().getGatewayInfo(gatewayBean.getDevice_mac(), new LinkCallBack<GatewayBean>() {
                    @Override
                    public void onSuccess(GatewayBean obj) {
@@ -164,12 +201,12 @@
                    @Override
                    public void onError(HDLLinkException e) {
                        setError(e);
                        setError(e.getMsg(), e.getCode());
                    }
                });
            }
            break;
            case "清除逆变器住宅Id": {
            case "清除逆变器住宅Id(4)": {
                TipDialog("一旦清除掉逆变器住宅id,逆变器需要重新绑定住宅,否则无法测试逆变器指令;", new Listener() {
                    @Override
                    public void Confirmation() {
@@ -181,19 +218,62 @@
                            @Override
                            public void onError(HDLLinkException e) {
                                setError(e);
                                setError(e.getMsg(), e.getCode());
                            }
                        });
                    }
                });
            }
            break;
            case "上传oid列表给云端(5)": {
                if (this.mOidList == null || this.mOidList.size() == 0) {
                    hideLoading();
                    HdlThreadLogic.toast(this, "没有oid列表数据,请先获取逆变器oid列表数据,再重新上传.");
                    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;
            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);
    }