fuliqi
2025-02-21 64efb660b2c119c00432434c0f651f8996483f18
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
package com.ycl.api.YS.alarm;
 
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.util.Common;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_ALARM_RELATED_DATA_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_LAPI_SUB_INFO_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_STRUCT_IMAGE_INFO_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_SUBSCRIBE_SUCC_INFO_S;
 
import javax.swing.*;
 
/**
 * @description This section includes subscribing alarm,closing subscribe alarm and clearing alarm.
 * @introduction Support IPC/NVR/VMS.
 */
public class Alarm {
    /**
     * @description To subscribe alarm.
     * @introduction Calling the interface of NETDEV_SetAlarmCallBack_V30.
     */
    public static void SubscribeAlarm() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
 
        //IPC��nvr�赥������15,bit13(8192)����ע��V40�ص���ͼƬ�ص�
        if(NetDemo.jComboBoxDeviceType.getSelectedIndex() == 0) {
            //ע��澯�ص�
            boolean bRet = NetDemo.netdevsdk.NETDEV_SetAlarmCallBack_V40(NetDemo.lpUserID, NetDemo.cbAlarmMessCallBackV40, null);
            if(false == bRet) {
                System.out.printf("NETDEV_SetAlarmCallBack_V40 failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
            }
            else{
                System.out.printf("NETDEV_SetAlarmCallBack_V40 success");
            }
            //ע��ͼƬ�ص�
            bRet = NetDemo.netdevsdk.NETDEV_SetPicAlarmCallBack(NetDemo.lpUserID, NetDemo.cbPicMessCallBack, NetDemo.lpUserID);
            if(false == bRet) {
                System.out.printf("NETDEV_SetPicAlarmCallBack failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
            }
            else{
                System.out.printf("NETDEV_SetPicAlarmCallBack success");
            }
 
            //���ĸ澯
            NETDEV_LAPI_SUB_INFO_S stSubInfo = new NETDEV_LAPI_SUB_INFO_S();
            stSubInfo.udwType = 15;
            NETDEV_SUBSCRIBE_SUCC_INFO_S stSubSuccInfo = new NETDEV_SUBSCRIBE_SUCC_INFO_S();
            bRet = NetDemo.netdevsdk.NETDEV_SubscibeLapiAlarm(NetDemo.lpUserID, stSubInfo, stSubSuccInfo);
            if(false == bRet){
                System.out.printf("NETDEV_SubscibeLapiAlarm failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                //JOptionPane.showMessageDialog(null, "NETDEV_SubscibeLapiAlarm 15 failed");
                return;
            }
            else{
                NetDemo.udwAlarmSubID = stSubSuccInfo.udwID;
                System.out.printf("NETDEV_SubscibeLapiAlarm 15 succ\n");
                //JOptionPane.showMessageDialog(null, "NETDEV_SubscibeLapiAlarm 15 success");
            }
            //����ͼƬ
            stSubInfo.udwType = 8192;
            bRet = NetDemo.netdevsdk.NETDEV_SubscibeLapiAlarm(NetDemo.lpUserID, stSubInfo, stSubSuccInfo);
            if(false == bRet){
                System.out.printf("NETDEV_SubscibeLapiAlarm failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                //JOptionPane.showMessageDialog(null, "NETDEV_SubscibeLapiAlarm bit13 failed");
                return;
            }
            else{
                NetDemo.udwPicSubID = stSubSuccInfo.udwID;
                System.out.printf("NETDEV_SubscibeLapiAlarm bit13 succ\n");
                //JOptionPane.showMessageDialog(null, "NETDEV_SubscibeLapiAlarm bit13 success");
            }
        }
 
        //vms�� NETDEV_SetAlarmCallBack_V30 �ڲ�����
        boolean bRet = NetDemo.netdevsdk.NETDEV_SetAlarmCallBack_V30(NetDemo.lpUserID, NetDemo.cbAlarmMessCallBack, null);
        if(bRet) {
            JOptionPane.showMessageDialog(null, "Subscribe success");
        }else {
            JOptionPane.showMessageDialog(null, "NETDEV_SetAlarmCallBack_V30 failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
        }
    }
    /**
     * @description To close subscribe alarm.
     * @introduction Calling the interface of NETDEV_SetAlarmCallBack_V30.
     */
    public static void UnSubscribeAlarm() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
 
        //IPC��nvr�赥������15����ע��V40�ص�
        if(NetDemo.jComboBoxDeviceType.getSelectedIndex() == 0) {
            //ȡ���澯�ص�
            boolean bRet = NetDemo.netdevsdk.NETDEV_SetAlarmCallBack_V40(NetDemo.lpUserID, null, null);
            if(false == bRet) {
                System.out.printf("NETDEV_SetAlarmCallBack_V40 failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
            }
            else{
                System.out.printf("NETDEV_SetAlarmCallBack_V40 success");
            }
            //ȡ��ͼƬ�ص�
            bRet = NetDemo.netdevsdk.NETDEV_SetPicAlarmCallBack(NetDemo.lpUserID, null, NetDemo.lpUserID);
            if(false == bRet) {
                System.out.printf("NETDEV_SetPicAlarmCallBack failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
            }
            else{
                System.out.printf("NETDEV_SetPicAlarmCallBack success");
            }
            //ȡ���澯����
            bRet = NetDemo.netdevsdk.NETDEV_UnSubLapiAlarm(NetDemo.lpUserID, NetDemo.udwAlarmSubID);
            if(false == bRet){
                System.out.printf("NETDEV_SubscibeLapiAlarm failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                //JOptionPane.showMessageDialog(null, "NETDEV_UnSubLapiAlarm failed");
            }
            else{
                System.out.printf("NETDEV_UnSubLapiAlarm 15 success");
                //JOptionPane.showMessageDialog(null, "NETDEV_UnSubLapiAlarm success");
            }
            //ȡ��ͼƬ����
            bRet = NetDemo.netdevsdk.NETDEV_UnSubLapiAlarm(NetDemo.lpUserID, NetDemo.udwPicSubID);
            if(false == bRet){
                System.out.printf("NETDEV_SubscibeLapiAlarm failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                //JOptionPane.showMessageDialog(null, "NETDEV_UnSubLapiAlarm failed");
            }
            else{
                System.out.printf("NETDEV_UnSubLapiAlarm bit13 success");
                //JOptionPane.showMessageDialog(null, "NETDEV_UnSubLapiAlarm success");
            }
        }
 
        boolean bRet = NetDemo.netdevsdk.NETDEV_SetAlarmCallBack_V30(NetDemo.lpUserID, null, null);
        if(bRet==false) {
            JOptionPane.showMessageDialog(null, "NETDEV_SetAlarmCallBack_V30 failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }else {
            JOptionPane.showMessageDialog(null, "UnSubscribe success");
        }
    }
    /**
     * @description To clear alarm.
     */
    public static void ClearAlarm() {
        NetDemo.AlarmTableModel.setRowCount(0);
    }
 
    /**
     * @description Get the related data of the selected alarm in alarm table
     * support fall_object_detection
     */
    public static void getRelatedData() {
        if(null == NetDemo.lpUserID) {
            JOptionPane.showMessageDialog(null, "Please Login device first.");
            return;
            }
        if(NetDemo.SubAlarmID == -1) {
            JOptionPane.showMessageDialog(null, "Please select an AlarmID.");
            return;
            }
 
        Pointer lpFindHandle = NetDemo.netdevsdk.NETDEV_FindAlarmRelatedDataList(NetDemo.lpUserID,NetDemo.SubAlarmID);
        if(null == lpFindHandle) {
            System.out.printf("NETDEV_FindAlarmRelatedDataList failed: "+ NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
            }
 
        NETDEV_ALARM_RELATED_DATA_S pstAlarmRelatedData = new NETDEV_ALARM_RELATED_DATA_S();
 
        pstAlarmRelatedData.stStructDataInfo.udwImageNum = 2;
        NETDEV_STRUCT_IMAGE_INFO_S[] pstImageInfo = new NETDEV_STRUCT_IMAGE_INFO_S[pstAlarmRelatedData.stStructDataInfo.udwImageNum];
        for(int j = 0; j < pstAlarmRelatedData.stStructDataInfo.udwImageNum; j++) {
            pstImageInfo[j] = new NETDEV_STRUCT_IMAGE_INFO_S();
            pstImageInfo[j].udwSize = Common.NETDEMO_PICTURE_SIZE;
            pstImageInfo[j].pszData = new Memory(Common.NETDEMO_PICTURE_SIZE);
            }
        pstAlarmRelatedData.stStructDataInfo.pstImageInfo= new Memory(pstImageInfo[0].size()*pstAlarmRelatedData.stStructDataInfo.udwImageNum);
        Common.SetStructArrToPointerData(pstImageInfo, pstAlarmRelatedData.stStructDataInfo.pstImageInfo);
        pstAlarmRelatedData.write();
 
        boolean bRet = NetDemo.netdevsdk.NETDEV_FindNextAlarmRelatedDataInfo(lpFindHandle, pstAlarmRelatedData);
        if(bRet != true) {
            System.out.printf("NETDEV_FindNextAlarmRelatedDataInfo failed: "+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
            }else {
                pstAlarmRelatedData.read();
                //pstImageInfo =  Common.pointerToStructureArray(pstAlarmRelatedData.stStructDataInfo.udwImageNum,pstAlarmRelatedData.stStructDataInfo.pstImageInfo, NETDEV_STRUCT_IMAGE_INFO_S.class);
                Common.GetPointerDataToStructArr(pstAlarmRelatedData.stStructDataInfo.pstImageInfo, pstImageInfo);
                if(0 < pstAlarmRelatedData.stStructDataInfo.udwImageNum) {
                    //ͼƬ��Ϣ
                    for(int j = 0; j < pstAlarmRelatedData.stStructDataInfo.udwImageNum; j++ ) {
                        String curTime = Common.getDate();
                        String strImageName = NetDemo.strPicturePath  + "RelatedAlarmPic_" +  NetDemo.SubAlarmID + "_" + curTime +"_"+ j+".jpg";
                        if(0 != pstImageInfo[j].udwSize) {
                            Common.savePicture(pstImageInfo[j].pszData, pstImageInfo[j].udwSize, strImageName);
                            JOptionPane.showMessageDialog(null, "The " + (j+1) + " picture was saved successfully");
                            }else {
                                JOptionPane.showMessageDialog(null, "The Size of the "+ (j+1) + " picture is 0");
                                }
                        }
                    }else {
                        JOptionPane.showMessageDialog(null, "Image Num is 0");
                        }
                }
        bRet = NetDemo.netdevsdk.NETDEV_FindCloseAlarmRelatedDataList(lpFindHandle);
        if(bRet != true) {
            System.out.printf("NETDEV_FindCloseAlarmRelatedDataList failed: "+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
            }
        }
    }