刘卫锦
2023-08-14 bd80ca98ffb4f483ca2eba47051281fa69e790ac
app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java
@@ -8,16 +8,26 @@
import android.os.Bundle;
import android.view.View;
import com.google.gson.Gson;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.base.CustomBaseActivity;
import com.hdl.photovoltaic.databinding.ActivityMyPowerStationBinding;
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlUniLogic;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.utils.PermissionUtils;
import com.hdl.sdk.link.HDLLinkLocalSdk;
import com.hdl.sdk.link.common.event.EventListener;
import com.hdl.sdk.link.core.bean.LinkResponse;
import com.hdl.sdk.link.core.bean.ModbusResponse;
public class MyPowerStationActivity extends CustomBaseActivity {
    private ActivityMyPowerStationBinding viewBinding;
    private int currentFragmentIndex = 0;
    private EventListener allTopicsListener;
    @Override
@@ -28,11 +38,13 @@
    @Override
    public void onBindView(Bundle savedInstanceState) {
        getWindow().setStatusBarColor(getColor(R.color.text_245EC3));
        //初始化
        initView();
        //初始化界面监听器
        initEvent();
        //注册监听
        registerAllTopicsListener();
    }
    private void initEvent() {
@@ -53,6 +65,14 @@
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack();
        //移除监听
        HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener);
    }
    private void initView() {
        viewBinding.myPowerStationBottomIl1.titleTv.setText(R.string.my_power_station_电站);
@@ -124,4 +144,32 @@
    }
    /**
     * 注册所有主题数据的监听
     */
    private void registerAllTopicsListener() {
        allTopicsListener = new EventListener() {
            @Override
            public void onMessage(Object msg) {
                if (msg instanceof ModbusResponse) {
                    ModbusResponse response = (ModbusResponse) msg;
                    if (response.getTopic() == null) {
                        return;
                    }
                    HdlLogLogic.print("监听到的数据===========" + new Gson().toJson(response));
//                    if (response.getTopic().endsWith("custom/native/inverter/up")) {
                    HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
                    uniCallBackBaseBean.setType(response.getTopic());
                    uniCallBackBaseBean.setData(response.getData());
                    HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
//                    }
                }
            }
        };
        HDLLinkLocalSdk.getInstance().registerAllTopicsListener(allTopicsListener);
    }
}