mac
2024-05-30 7e79979359bf5d3438afac05458e454c4786d50b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//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;
//    }
//}