Jay
2024-11-08 02722a3f9eca857ce7fffea352e9f7ee692a1b71
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
package com.iailab.netsdk.demo.frame.vto;
 
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.iailab.netsdk.common.Res;
import com.iailab.netsdk.lib.NetSDKLib;
import com.iailab.netsdk.lib.ToolKits;
 
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
 
/**
 * @author 47081
 * @version 1.0
 * @description vto监听事件的回调函数, 建议写成单例模式
 * @date 2020/8/15
 */
public class VTOMessageCallBack implements NetSDKLib.fMessCallBack {
    private static VTOMessageCallBack INSTANCE;
    private JTable table;
    private CollectionFingerPrint print;
 
    private VTOMessageCallBack(JTable table) {
        this.table = table;
    }
 
    public static VTOMessageCallBack getINSTANCE(JTable table, CollectionFingerPrint print) {
        if (INSTANCE == null) {
            INSTANCE = new VTOMessageCallBack(table);
        }
        if (table != null) {
            INSTANCE.table = table;
        }
        if (print != null) {
            INSTANCE.print = print;
        }
        return INSTANCE;
    }
 
    @Override
    public boolean invoke(int lCommand, NetSDKLib.LLong lLoginID, Pointer pStuEvent, int dwBufLen, String strDeviceIP, NativeLong nDevicePort, Pointer dwUser) {
        //门禁事件
        if (lCommand == NetSDKLib.NET_ALARM_ACCESS_CTL_EVENT) {
            NetSDKLib.ALARM_ACCESS_CTL_EVENT_INFO info = new NetSDKLib.ALARM_ACCESS_CTL_EVENT_INFO();
            ToolKits.GetPointerDataToStruct(pStuEvent, 0, info);
            //更新列表
            if (table != null) {
                DefaultTableModel model = (DefaultTableModel) table.getModel();
                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()});
 
            }
        }
        //信息事件
        if (lCommand == NetSDKLib.NET_ALARM_FINGER_PRINT) {
            if (print != null) {
                if (lLoginID.longValue() == print.getLoginHandler()) {
                    NetSDKLib.ALARM_CAPTURE_FINGER_PRINT_INFO info = new NetSDKLib.ALARM_CAPTURE_FINGER_PRINT_INFO();
                    ToolKits.GetPointerDataToStruct(pStuEvent, 0, info);
                    print.setCollectionResult(info.bCollectResult == 1);
                    if (info.bCollectResult == 1) {
                        print.setPackageLen(info.nPacketLen * info.nPacketNum);
                        int length = info.nPacketLen * info.nPacketNum;
                        byte[] data = new byte[length];
                        info.szFingerPrintInfo.read(0, data, 0, length);
                        print.setPackageData(data);
                        //显示结果
                        print.setLabelResult(data);
                    }
                    print.stopListen();
                }
            }
        }
        return true;
    }
 
    /**
     * 开门方式
     *
     * @param emOpenMethod
     * @return
     */
    private String openDoorMethod(int emOpenMethod) {
        String method;
        switch (emOpenMethod) {
            case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_CARD:
                method = Res.string().getCard();
                break;
            case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FACE_RECOGNITION:
                method = Res.string().getTargetRecognition();
                break;
            case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FINGERPRINT:
                method = Res.string().getFingerPrint();
                break;
            case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_REMOTE:
                method = Res.string().getRemoteOpenDoor();
                break;
            default:
                method = Res.string().getUnKnow();
                break;
        }
        return method;
    }
}