zxl
15 小时以前 3b0516a2959e25576e4f3fda697a3b025d06c8c9
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
package com.ycl.api.YS.vca.accesscontrol;
 
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_DEVICE_TYPE_E;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_LAPI_SUB_INFO_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_SUBSCRIBE_SUCC_INFO_S;
 
import javax.swing.*;
 
/**
 * @description To subscribe alarm and close subscribing alarm.
 * @introduction Only support VMS.
 */
public class DataReport {
    /**
     * @description To subscribe alarm.
     * @introduction Calling the interface of NETDEV_SubscibeLapiAlarm NETDEV_SetAlarmFGCallBack
     */
    public static void subscribeAlarm() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        
        if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_IPC_ACS) 
        {
            boolean bRet = NetDemo.netdevsdk.NETDEV_SetAlarmFGCallBack(NetDemo.lpUserID, NetDemo.pfAlarmMessFGCB, NetDemo.lpUserID);
               if(true != bRet)
               {
                   JOptionPane.showMessageDialog(null, "SubscribeAlarm failed error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                   System.out.println("NETDEV_SetAlarmFGCallBack fail:" + NetDemo.netdevsdk.NETDEV_GetLastError());
                   return;
               }
               NETDEV_LAPI_SUB_INFO_S stSubInfo = new NETDEV_LAPI_SUB_INFO_S();
               NETDEV_SUBSCRIBE_SUCC_INFO_S stSubSuccInfo = new NETDEV_SUBSCRIBE_SUCC_INFO_S();
               stSubInfo.udwType = 1024;
               stSubInfo.udwLibIDNum=0xffff;
               boolean bRet2 = NetDemo.netdevsdk.NETDEV_SubscibeLapiAlarm(NetDemo.lpUserID, stSubInfo, stSubSuccInfo);
               if(true != bRet2)
               {
                   JOptionPane.showMessageDialog(null, "SubscribeAlarm failed error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                   System.out.println("NETDEV_SubscibeLapiAlarm fail:" + NetDemo.netdevsdk.NETDEV_GetLastError());
               }
               else
               {
                   JOptionPane.showMessageDialog(null, "SubscribeAlarm success");
                   System.out.println("SubscribeLapiAlarm success");
                   NetDemo.dwAccessControlFGMointerID = stSubSuccInfo.udwID;    
               }   
        }
        else if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_VMS) 
        {
            boolean bRet2 = NetDemo.netdevsdk.NETDEV_SetAlarmFGCallBack(NetDemo.lpUserID, NetDemo.pfAlarmMessFGCB, NetDemo.lpUserID);
               if(true != bRet2)
               {
                   JOptionPane.showMessageDialog(null, "SubscribeAlarm failed error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                   System.out.println("NETDEV_SetAlarmFGCallBack fail:" + NetDemo.netdevsdk.NETDEV_GetLastError());
                   return;
               }
               NETDEV_LAPI_SUB_INFO_S stSubInfo = new NETDEV_LAPI_SUB_INFO_S();
               NETDEV_SUBSCRIBE_SUCC_INFO_S stSubSuccInfo = new NETDEV_SUBSCRIBE_SUCC_INFO_S();
       
               stSubInfo.udwType = 1024;
               stSubInfo.udwLibIDNum=0xffff;
               boolean bRet3 = NetDemo.netdevsdk.NETDEV_SubscibeLapiAlarm(NetDemo.lpUserID, stSubInfo, stSubSuccInfo);
               if(true != bRet3)
               {
                   JOptionPane.showMessageDialog(null, "SubscribeAlarm failed error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                   System.out.println("NETDEV_SubscibeLapiAlarm fail:" + NetDemo.netdevsdk.NETDEV_GetLastError());
               }
               else
               {
                   JOptionPane.showMessageDialog(null, "SubscribeAlarm success");
                   System.out.println("SubscibeLapiAlarm success");
                   NetDemo.dwAccessControlFGMointerID = stSubSuccInfo.udwID;       
               } 
        }
        else 
        {
               JOptionPane.showMessageDialog(null, "Not support ");
               return;
        }
    }
    /**
     * @description To cancel subscribing alarm.
     * @introduction Calling the interface of NETDEV_UnSubLapiAlarm and NETDEV_SetAlarmFGCallBack.
     */
    public static void unsubscribeAlarm() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        
        if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_IPC_ACS){
            boolean flag = NetDemo.netdevsdk.NETDEV_SetAlarmFGCallBack(NetDemo.lpUserID, null, NetDemo.lpUserID);
            if(true != flag)
            {
                JOptionPane.showMessageDialog(null, "SubscribeAlarm failed error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.println("NETDEV_SetAlarmFGCallBack fail:" + NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            boolean bRet = NetDemo.netdevsdk.NETDEV_UnSubLapiAlarm(NetDemo.lpUserID, NetDemo.dwAccessControlFGMointerID);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_UnSubLapiAlarm failed error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.println("NETDEV_UnSubLapiAlarm failed:" + NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            else 
            {
                JOptionPane.showMessageDialog(null, "UnSubscribeAlarm success");
            }
            NetDemo.dwAccessControlFGMointerID = -1;
        }
        else if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_VMS)
        {   
            boolean flag=NetDemo.netdevsdk.NETDEV_SetAlarmFGCallBack(NetDemo.lpUserID, null, NetDemo.lpUserID);
        if(true != flag)
        {
            JOptionPane.showMessageDialog(null, "SubscribeAlarm failed error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.println("NETDEV_SetAlarmFGCallBack fail:" + NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        boolean bRet = NetDemo.netdevsdk.NETDEV_UnSubLapiAlarm(NetDemo.lpUserID, NetDemo.dwAccessControlFGMointerID);
        if(false == bRet){
            JOptionPane.showMessageDialog(null, "NETDEV_UnSubLapiAlarm failed error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.println("NETDEV_UnSubLapiAlarm failed:" + NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }else {
            JOptionPane.showMessageDialog(null, "UnSubscribeAlarm success");
        }
        NetDemo.dwAccessControlFGMointerID = -1;
        }
        else 
        {
            JOptionPane.showMessageDialog(null, "Not support ");
            return;
        }
    }
    
}