//package com.hdl.photovoltaic.utils;
|
//
|
//import com.alibaba.fastjson.JSONObject;
|
//import com.hdl.photovoltaic.other.HdlUniLogic;
|
//import com.hdl.photovoltaic.uni.HDLUniMP;
|
//import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
|
//import com.hdl.sdk.link.common.event.EventListener;
|
//import com.hdl.sdk.link.core.bean.ZigbeeResponse;
|
//import com.hdl.sdk.link.core.connect.HDLZigbeeConnect;
|
//
|
///**
|
// * Created by hxb on 2022/1/18.
|
// * 原生透传到uni app
|
// */
|
//public class ThroughUtils {
|
//
|
// final String tag = ThroughUtils.class.getName();
|
//
|
// /**
|
// * 是否uni方式,否则mqtt方式
|
// */
|
// private boolean isUni=true;
|
//
|
//
|
// /**
|
// * instance
|
// */
|
// private volatile static ThroughUtils instance;
|
//
|
// /**
|
// * getInstance
|
// *
|
// * @return Through
|
// */
|
// public static synchronized ThroughUtils getInstance() {
|
// if (instance == null) {
|
// synchronized (ThroughUtils.class) {
|
// if (instance == null) {
|
// instance = new ThroughUtils();
|
// }
|
// }
|
// }
|
// return instance;
|
// }
|
//
|
// EventListener throughEventListener;
|
//
|
// /**
|
// * 注册新设备入网监听
|
// */
|
// public void registerThroughListener() {
|
// //注册监听事件
|
// if (throughEventListener == null) {
|
// throughEventListener = new EventListener() {
|
// @Override
|
// public void onMessage(Object msg) {
|
// if (msg instanceof ZigbeeResponse) {
|
// ZigbeeResponse zigbeeResponse = (ZigbeeResponse) msg;
|
// try {
|
// HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
|
// callBackBaseBean.setTopic(zigbeeResponse.getTopic());
|
// callBackBaseBean.setData(zigbeeResponse.getData());
|
// if (zigbeeResponse.getTopic().startsWith("ZbDataPassthrough")) {
|
// //如果不是使用mqtt方式,就使用uni app推送方式
|
// if (isUni()) {
|
// HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, callBackBaseBean);
|
// HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.UNI_EVENT_ZigBeePassthrough, JSONObject.toJSON(callBackBaseBean));
|
// } else {//使用mqtt方式
|
// //AndroidToPC/唯一标识/uni_event"
|
// UniAppMqtt.getInstance().publish(String.format("AndroidToPC/%s/%s", System.currentTimeMillis(), HDLUniMP.UNI_EVENT_ZigBeePassthrough), JSONObject.toJSON(callBackBaseBean).toString());
|
// }
|
// }
|
// else if(zigbeeResponse.getTopic().contains("DeviceStatusReport/")){
|
// //如果不是使用mqtt方式,就使用uni app推送方式
|
// if (isUni()) {
|
// HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.EVENT_DeviceStatusReportPassthrough, JSONObject.toJSON(callBackBaseBean));
|
// } else {//使用mqtt方式
|
// //AndroidToPC/唯一标识/uni_event"
|
// UniAppMqtt.getInstance().publish(String.format("AndroidToPC/%s/%s", System.currentTimeMillis(), HDLUniMP.EVENT_DeviceStatusReportPassthrough), JSONObject.toJSON(callBackBaseBean).toString());
|
// }
|
// }
|
//
|
// } catch (Exception e) {
|
//
|
// }
|
// }
|
// }
|
// };
|
// HDLZigbeeConnect.getInstance().registerListener(throughEventListener);
|
// }
|
// }
|
//
|
// /**
|
// * 移除全局监听
|
// */
|
// public void removeThroughListener()
|
// {
|
// HDLZigbeeConnect.getInstance().removeListener(throughEventListener);
|
// throughEventListener=null;
|
// }
|
//
|
// /**
|
// * 是否uni方式,否则mqtt方式
|
// * @return
|
// */
|
// public boolean isUni() {
|
// return isUni;
|
// }
|
//
|
// /**
|
// * 是否uni方式,否则mqtt方式
|
// * @param uni
|
// */
|
// public void setUni(boolean uni) {
|
// isUni = uni;
|
// }
|
//}
|