1
zhanghua
2024-09-26 c775c6953d9759e70f08acbfa8f6d7490aaae3d1
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com.netsdk.demo.customize;
 
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.structure.*;
import com.netsdk.lib.utils.Initialization;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;
 
/**
 * @author 291189
 * @version 1.0
 * @description ERR220629200 
 * @date 2022/7/4 10:45
 */
public class PollingConfigDemo extends Initialization {
 
    /**
     * 平台下发轮询配置,规则和场景字段见附件
     */
 
    public void setPollingConfig() {
 
        NET_IN_SET_POLLING_CONFIG input = new NET_IN_SET_POLLING_CONFIG();
 
        input.nConfigCnt = 1;
 
        NET_SET_POLLING_CONFIG_INFO info = new NET_SET_POLLING_CONFIG_INFO();
        info.bEnable = 1;
 
        NET_SET_POLLING_CONFIG_INFO setInfo = new NET_SET_POLLING_CONFIG_INFO();
 
        setInfo.bEnable = 1;
 
        setInfo.nChannel = 0;
 
        /**
         * 规则配置个数
         */
        setInfo.nRulelTypeCnt = 2;
        /**
         * 规则配置
         */
        ToolKits.StringToByteArray("ObjectRemoval", setInfo.szRulelType[0].arr);
        ToolKits.StringToByteArray("ObjectPlacement", setInfo.szRulelType[1].arr);
        /**
         * 全局配置列表
         */
        ToolKits.StringToByteArray("ObjectMonitor", setInfo.szGlobalTypeList[0].arr);
        /**
         * 全局配置列表个数
         */
        setInfo.nGlobalTypeListNum = 1;
 
        input.stuConfigInfos[0] = setInfo;
 
        Pointer pointerInput = new Memory(input.size());
 
        pointerInput.clear(input.size());
 
        ToolKits.SetStructDataToPointer(input, pointerInput, 0);
 
        NET_OUT_SET_POLLING_CONFIG outPut = new NET_OUT_SET_POLLING_CONFIG();
 
        Pointer pointerOutput = new Memory(outPut.size());
        pointerOutput.clear(outPut.size());
        ToolKits.SetStructDataToPointer(outPut, pointerOutput, 0);
 
        boolean b = netSdk.CLIENT_SetPollingConfig(loginHandle, pointerInput, pointerOutput, 3000);
 
        if (b) {
            System.out.println("CLIENT_SetPollingConfig success");
        } else {
            System.out.println("CLIENT_SetPollingConfig fail:" + ToolKits.getErrorCode());
 
        }
 
    }
 
    /**
     * 按通道获取设备智能业务的运行状态
     */
    public void getChannelState() {
        NET_IN_GET_CHANNEL_STATE input = new NET_IN_GET_CHANNEL_STATE();
        input.nChannelNum = 0;
        //input.nChannel[0] = 0;
        //input.nChannel[1] = 1;
        Pointer pointerInput = new Memory(input.size());
        pointerInput.clear(input.size());
        ToolKits.SetStructDataToPointer(input, pointerInput, 0);
 
        NET_OUT_GET_CHANNEL_STATE outPut = new NET_OUT_GET_CHANNEL_STATE();
 
        outPut.nMaxStateNum = 10;
 
        NET_CHANNEL_STATE_INFO_EX[] infos = new NET_CHANNEL_STATE_INFO_EX[outPut.nMaxStateNum];
 
        for (int i = 0; i < infos.length; i++) {
            infos[i] = new NET_CHANNEL_STATE_INFO_EX();
        }
 
        outPut.pstuStateEx = new Memory(infos[0].size() * infos.length);
 
        outPut.pstuStateEx.clear(infos[0].size() * infos.length);
 
        ToolKits.SetStructArrToPointerData(infos, outPut.pstuStateEx);
 
        Pointer pointerOutput = new Memory(outPut.size());
        pointerOutput.clear(outPut.size());
        ToolKits.SetStructDataToPointer(outPut, pointerOutput, 0);
 
        boolean b = netSdk.CLIENT_GetChannelState(loginHandle, pointerInput, pointerOutput, 3000);
 
        if (b) {
            System.out.println("CLIENT_GetChannelState success");
 
            ToolKits.GetPointerData(pointerOutput, outPut);
 
            int nMaxStateNum = outPut.nMaxStateNum;
            // 用户申请智能业务状态信息最大个数
            System.out.println("用户申请智能业务状态信息最大个数:" + nMaxStateNum);
            System.out.println("智能业务状态信息实际个数:" + outPut.nStateNum);
 
            NET_CHANNEL_STATE_INFO_EX[] stateInfos = new NET_CHANNEL_STATE_INFO_EX[outPut.nMaxStateNum];
            for (int i = 0; i < stateInfos.length; i++) {
                stateInfos[i] = new NET_CHANNEL_STATE_INFO_EX();
            }
 
            ToolKits.GetPointerDataToStructArr(outPut.pstuStateEx, stateInfos);
 
            for (int i = 0; i < outPut.nStateNum; i++) {
 
                NET_CHANNEL_STATE_INFO_EX info = stateInfos[i];
 
                /**
                 * 通道号
                 */
                int nChannel = info.nChannel;
                System.out.println("通道号:" + nChannel);
                /**
                 * 已开启的智能规则信息个数
                 */
 
                int nIntelliInfoNum = info.nIntelliInfoNum;
                System.out.println("已开启的智能规则信息个数:" + nIntelliInfoNum);
 
                NET_INTELLI_INFO[] stuIntelliInfo = info.stuIntelliInfo;
 
                for (int j = 0; j < nIntelliInfoNum; j++) {
 
                    NET_INTELLI_INFO net_intelli_info = stuIntelliInfo[j];
 
                    int nTypeNum = net_intelli_info.nTypeNum;
                    System.out.println("智能规则类型个数:" + nTypeNum);
 
                    /**
                     * 智能规则类型
                     */
                    Byte64Arr[] szType = net_intelli_info.szType;
 
                    for (int m = 0; m < nTypeNum; m++) {
                        Byte64Arr byte64Arr = szType[m];
                        // 智能规则类型
                        try {
                            System.out.println("智能规则类型:" + new String(byte64Arr.arr, encode));
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
 
                    }
                    /**
                     * 智能场景类型
                     */
 
                    byte[] szClass = net_intelli_info.szClass;
                    try {
                        System.out.println("智能场景类型:" + new String(szClass, encode));
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
 
                }
 
            }
 
        } else {
            System.out.println("CLIENT_GetChannelState fail:" + ToolKits.getErrorCode());
 
        }
 
    }
 
    public static void main(String[] args) {
        PollingConfigDemo pollingConfigDemo = new PollingConfigDemo();
        InitTest("10.172.160.239", 37777, "admin", "admin123");
 
        Scanner sc = new Scanner(System.in);
 
        while (true) {
            System.out.println("0 退出");
            System.out.println("1 平台下发轮询配置");
            System.out.println("2 按通道获取设备智能业务的运行状态");
            int nextInt = sc.nextInt();
 
            if (nextInt == 0) {
                break;
            } else if (nextInt == 1) {
                pollingConfigDemo.setPollingConfig();
            } else if (nextInt == 2) {
                pollingConfigDemo.getChannelState();
            }
        }
 
        LoginOut();
 
    }
}