潘志宝
2024-11-07 7ef5c8881725f221fdf70b62a03c6b2128f47f12
提交 | 用户 | 时间
149dd0 1 package com.iailab.netsdk.demo.frame.vto;
H 2
3 import com.sun.jna.NativeLong;
4 import com.sun.jna.Pointer;
5 import com.iailab.netsdk.common.Res;
6 import com.iailab.netsdk.lib.NetSDKLib;
7 import com.iailab.netsdk.lib.ToolKits;
8
9 import javax.swing.*;
10 import javax.swing.table.DefaultTableModel;
11
12 /**
13  * @author 47081
14  * @version 1.0
15  * @description vto监听事件的回调函数, 建议写成单例模式
16  * @date 2020/8/15
17  */
18 public class VTOMessageCallBack implements NetSDKLib.fMessCallBack {
19     private static VTOMessageCallBack INSTANCE;
20     private JTable table;
21     private CollectionFingerPrint print;
22
23     private VTOMessageCallBack(JTable table) {
24         this.table = table;
25     }
26
27     public static VTOMessageCallBack getINSTANCE(JTable table, CollectionFingerPrint print) {
28         if (INSTANCE == null) {
29             INSTANCE = new VTOMessageCallBack(table);
30         }
31         if (table != null) {
32             INSTANCE.table = table;
33         }
34         if (print != null) {
35             INSTANCE.print = print;
36         }
37         return INSTANCE;
38     }
39
40     @Override
41     public boolean invoke(int lCommand, NetSDKLib.LLong lLoginID, Pointer pStuEvent, int dwBufLen, String strDeviceIP, NativeLong nDevicePort, Pointer dwUser) {
42         //门禁事件
43         if (lCommand == NetSDKLib.NET_ALARM_ACCESS_CTL_EVENT) {
44             NetSDKLib.ALARM_ACCESS_CTL_EVENT_INFO info = new NetSDKLib.ALARM_ACCESS_CTL_EVENT_INFO();
45             ToolKits.GetPointerDataToStruct(pStuEvent, 0, info);
46             //更新列表
47             if (table != null) {
48                 DefaultTableModel model = (DefaultTableModel) table.getModel();
49                 model.addRow(new Object[]{new String(info.szUserID).trim(), new String(info.szCardNo).trim(), info.stuTime.toStringTime(), openDoorMethod(info.emOpenMethod), info.bStatus == 1 ? Res.string().getSucceed() : Res.string().getFailed()});
50
51             }
52         }
53         //信息事件
54         if (lCommand == NetSDKLib.NET_ALARM_FINGER_PRINT) {
55             if (print != null) {
56                 if (lLoginID.longValue() == print.getLoginHandler()) {
57                     NetSDKLib.ALARM_CAPTURE_FINGER_PRINT_INFO info = new NetSDKLib.ALARM_CAPTURE_FINGER_PRINT_INFO();
58                     ToolKits.GetPointerDataToStruct(pStuEvent, 0, info);
59                     print.setCollectionResult(info.bCollectResult == 1);
60                     if (info.bCollectResult == 1) {
61                         print.setPackageLen(info.nPacketLen * info.nPacketNum);
62                         int length = info.nPacketLen * info.nPacketNum;
63                         byte[] data = new byte[length];
64                         info.szFingerPrintInfo.read(0, data, 0, length);
65                         print.setPackageData(data);
66                         //显示结果
67                         print.setLabelResult(data);
68                     }
69                     print.stopListen();
70                 }
71             }
72         }
73         return true;
74     }
75
76     /**
77      * 开门方式
78      *
79      * @param emOpenMethod
80      * @return
81      */
82     private String openDoorMethod(int emOpenMethod) {
83         String method;
84         switch (emOpenMethod) {
85             case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_CARD:
86                 method = Res.string().getCard();
87                 break;
88             case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FACE_RECOGNITION:
89                 method = Res.string().getTargetRecognition();
90                 break;
91             case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FINGERPRINT:
92                 method = Res.string().getFingerPrint();
93                 break;
94             case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_REMOTE:
95                 method = Res.string().getRemoteOpenDoor();
96                 break;
97             default:
98                 method = Res.string().getUnKnow();
99                 break;
100         }
101         return method;
102     }
103 }