| | |
| | | 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 |
| | |
| | | initView(); |
| | | //初始化界面监听器 |
| | | initEvent(); |
| | | //注册监听 |
| | | registerAllTopicsListener(); |
| | | } |
| | | |
| | | private void initEvent() { |
| | |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack(); |
| | | //移除监听 |
| | | HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener); |
| | | |
| | | } |
| | | |
| | | private void initView() { |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 注册所有主题数据的监听 |
| | | */ |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |