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
package com.netsdk.demo.example;
 
import java.io.File;
import com.netsdk.demo.util.CaseMenu;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.enumeration.NET_EM_CFG_OPERATE_TYPE;
import com.netsdk.lib.NetSDKLib.LLong;
import com.netsdk.lib.NetSDKLib.NET_DEVICEINFO_Ex;
import com.netsdk.lib.NetSDKLib.NET_FIREWARNING_MODE_INFO;
import com.netsdk.lib.NetSDKLib.NET_FIRE_WARNING_INFO;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
 
public class FireWarning {
    public static final NetSDKLib netSdk = NetSDKLib.NETSDK_INSTANCE;
    // 登陆句柄
    private static LLong loginHandle = new LLong(0);
        
    
    // 设备信息扩展
    private NET_DEVICEINFO_Ex deviceInfo = new NET_DEVICEINFO_Ex();
    
    
    public void InitTest(){
        // 初始化SDK库
        netSdk.CLIENT_Init(DisConnectCallBack.getInstance(), null);
 
        // 设置断线重连成功回调函数
        netSdk.CLIENT_SetAutoReconnect(HaveReConnectCallBack.getInstance(), null);
 
        //打开日志,可选
        NetSDKLib.LOG_SET_PRINT_INFO setLog = new NetSDKLib.LOG_SET_PRINT_INFO();
        String logPath = new File(".").getAbsoluteFile().getParent() + File.separator + "sdk_log" + File.separator + "sdk.log";
        setLog.bSetFilePath = 1;
        System.arraycopy(logPath.getBytes(), 0, setLog.szLogFilePath, 0, logPath.getBytes().length);
        setLog.bSetPrintStrategy = 1;
        setLog.nPrintStrategy = 0;
        if (!netSdk.CLIENT_LogOpen(setLog)){
            System.err.println("Open SDK Log Failed!!!");
        }
        
        Login();
    }
    
    public void Login(){
        
         // 登陆设备
        int nSpecCap = NetSDKLib.EM_LOGIN_SPAC_CAP_TYPE.EM_LOGIN_SPEC_CAP_TCP;    // TCP登入
        IntByReference nError = new IntByReference(0);
        loginHandle = netSdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser,
                m_strPassword ,nSpecCap, null, deviceInfo, nError);
        if (loginHandle.longValue() != 0) {
            System.out.printf("Login Device[%s] Success!\n", m_strIp);
        }
        else {
            System.err.printf("Login Device[%s] Fail.Error[%s]\n", m_strIp, ToolKits.getErrorCode());
            LoginOut();
        }
    }
    
    
    public void LoginOut(){
        System.out.println("End Test");
        if( loginHandle.longValue() != 0)
        {
            netSdk.CLIENT_Logout(loginHandle);
        }
        System.out.println("See You...");
        
        netSdk.CLIENT_Cleanup();
        System.exit(0);
    }
    
////////////////////////////////////////////////////////////////
private String m_strIp                     = "172.32.104.15";
private int    m_nPort                     = 37777;
private String m_strUser                 = "admin";
private String m_strPassword             = "admin123";
////////////////////////////////////////////////////////////////
 
public void FireWarningMode() {
    int emCfgOpType=NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_FIRE_WARNINGMODE;
    
    NET_FIREWARNING_MODE_INFO msg=new NET_FIREWARNING_MODE_INFO();
    //szOut.emFireWarningMode=1;
    int dwOutBufferSize=msg.size();
    Pointer szOutBuffer =new Memory(dwOutBufferSize);
    ToolKits.SetStructDataToPointer(msg, szOutBuffer, 0);
    boolean ret=netSdk.CLIENT_GetConfig(loginHandle, emCfgOpType, 1, szOutBuffer, dwOutBufferSize, 3000, null);
    if(!ret) {
        System.err.printf("getconfig  failed, ErrCode=%x\n", netSdk.CLIENT_GetLastError());
        return;
    }
    ToolKits.GetPointerData(szOutBuffer, msg);
    System.out.println(msg.emFireWarningMode);
    
    msg.emFireWarningMode=0;
    IntByReference restart = new IntByReference(0);
    int dwInBufferSize=msg.size();
    Pointer szInBuffer =new Memory(dwInBufferSize);
    ToolKits.SetStructDataToPointer(msg, szInBuffer, 0);
    boolean result=netSdk.CLIENT_SetConfig(loginHandle, emCfgOpType, 1, szInBuffer, dwInBufferSize, 3000, restart, null);
    if(!result) {
        System.err.printf("setconfig  failed, ErrCode=%x\n", netSdk.CLIENT_GetLastError());
    }else {
        System.out.println("setconfig success");
    }
}
 
public void Fire_Warning() {
    int emCfgOpType=NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_FIRE_WARNING;
    NET_FIRE_WARNING_INFO msg=new NET_FIRE_WARNING_INFO();
    
    int dwOutBufferSize=msg.size();
    Pointer szOutBuffer =new Memory(dwOutBufferSize);
    ToolKits.SetStructDataToPointer(msg, szOutBuffer, 0);
    boolean ret=netSdk.CLIENT_GetConfig(loginHandle, emCfgOpType, 1, szOutBuffer, dwOutBufferSize, 3000, null);
    if(!ret) {
        System.err.printf("getconfig  failed, ErrCode=%x\n", netSdk.CLIENT_GetLastError());
        return;
    }
    ToolKits.GetPointerData(szOutBuffer, msg);
    System.out.println("火灾预警配置个数"+msg.nFireWarnRuleNum+
                       "\n使能"+msg.stuFireWarnRule[0].bEnable);
    
    msg.nFireWarnRuleNum=1;
    msg.stuFireWarnRule[0].bEnable=1;
    msg.stuFireWarnRule[0].nPresetId=0;
    msg.stuFireWarnRule[0].nRow=32;
    msg.stuFireWarnRule[0].nCol=40;
    msg.stuFireWarnRule[0].emFireWarningDetectMode=0;
    msg.stuFireWarnRule[0].emFireWarningDetectTragetType=0;
    msg.stuFireWarnRule[0].bTimeDurationEnable=0;
    msg.stuFireWarnRule[0].nFireDuration=60;
    msg.stuFireWarnRule[0].nDetectWindowNum=1;
    msg.stuFireWarnRule[0].stuDetectWnd[0].nRgnNum=1;
    msg.stuFireWarnRule[0].stuDetectWnd[0].nRegions[0]=123456789;
    msg.stuFireWarnRule[0].stuDetectWnd[0].stuPostion.fHorizontalAngle=0;
    msg.stuFireWarnRule[0].stuDetectWnd[0].stuPostion.fMagnification=0;
    msg.stuFireWarnRule[0].stuDetectWnd[0].stuPostion.fVerticalAngle=1;
    msg.stuFireWarnRule[0].stuDetectWnd[0].nTargetSize=3;
    msg.stuFireWarnRule[0].stuDetectWnd[0].nSensitivity=5;
    msg.stuFireWarnRule[0].stuDetectWnd[0].nWindowsID=33;
    msg.stuFireWarnRule[0].stuDetectWnd[0].szName="Region1".getBytes();
    
    IntByReference restart = new IntByReference(0);
    int dwInBufferSize=msg.size();
    Pointer szInBuffer =new Memory(dwInBufferSize);
    ToolKits.SetStructDataToPointer(msg, szInBuffer, 0);
    boolean result=netSdk.CLIENT_SetConfig(loginHandle, emCfgOpType, 1, szInBuffer, dwInBufferSize, 3000, restart, null);
    if(!result) {
        System.err.printf("setconfig  failed, ErrCode=%x\n", netSdk.CLIENT_GetLastError());
    }else {
        System.out.println("setconfig success");
    }
}
 
/**
 * 设备断线回调
 */
private static class DisConnectCallBack implements NetSDKLib.fDisConnect {
 
    private DisConnectCallBack() {
    }
 
    private static class CallBackHolder {
        private static DisConnectCallBack instance = new DisConnectCallBack();
    }
 
    public static DisConnectCallBack getInstance() {
        return CallBackHolder.instance;
    }
 
    public void invoke(NetSDKLib.LLong lLoginID, String pchDVRIP, int nDVRPort, Pointer dwUser) {
        System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort);
    }
}
 
/**
 * 设备重连回调
 */
private static class HaveReConnectCallBack implements NetSDKLib.fHaveReConnect {
    private HaveReConnectCallBack() {
    }
 
    private static class CallBackHolder {
        private static HaveReConnectCallBack instance = new HaveReConnectCallBack();
    }
 
    public static HaveReConnectCallBack getInstance() {
        return CallBackHolder.instance;
    }
 
    public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
        System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort);
 
    }
}
 
public void RunTest(){
    CaseMenu menu=new CaseMenu();
    menu.addItem((new CaseMenu.Item(this , "FireWarningMode" , "FireWarningMode")));
    menu.addItem((new CaseMenu.Item(this , "Fire_Warning" , "Fire_Warning")));
    menu.run();
}
 
public static void  main(String []args){
    FireWarning XM=new FireWarning();
    XM.InitTest();
    XM.RunTest();
    XM.LoginOut();
}
}