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
package com.netsdk.demo.customize;
 
import com.netsdk.demo.util.CaseMenu;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.structure.DEV_EVENT_TRAFFIC_DRIVER_ABNORMAL_INFO;
import com.netsdk.lib.structure.NET_TIME_EX;
import com.netsdk.lib.utils.Initialization;
import com.sun.jna.Pointer;
import java.io.File;
import java.io.UnsupportedEncodingException;
 
/**
 * @author 291189
 * @version 1.0
 * @description ERR211022043
 * @date 2021/11/4 9:22
 */
public class TrafficDriverAbnormalDemo  extends Initialization {
 
    int channel=-1;
    NetSDKLib.LLong    attachHandle=new NetSDKLib.LLong(0);
    /**
     * 订阅智能任务
     */
    public NetSDKLib.LLong AttachEventRealLoadPic() {
        // 先退订,设备不会对重复订阅作校验,重复订阅后会有重复的事件返回
        if(attachHandle.longValue()!=0){
            this.DetachEventRealLoadPic();
        }
 
        // 需要图片
        int bNeedPicture = 1;
        attachHandle = netSdk.CLIENT_RealLoadPictureEx(loginHandle, channel, NetSDKLib.EVENT_IVS_TRAFFIC_DRIVER_ABNORMAL, bNeedPicture, AnalyzerDataCB.getInstance(), null, null);
        // attachHandle = netSdk.CLIENT_RealLoadPictureEx(loginHandle, channel, NetSDKLib.EVENT_IVS_ALL, bNeedPicture, AnalyzerDataCB.getInstance(), null, null);
 
        if (attachHandle.longValue() != 0) {
            System.out.printf("Chn[%d] CLIENT_RealLoadPictureEx Success\n", channel);
        } else {
            System.out.printf("Ch[%d] CLIENT_RealLoadPictureEx Failed!LastError = %s\n", channel,
                    ToolKits.getErrorCode());
        }
 
        return attachHandle;
    }
    /**
     * 报警事件(智能)回调
     */
    private static class AnalyzerDataCB implements NetSDKLib.fAnalyzerDataCallBack {
        private final File picturePath;
        private static AnalyzerDataCB instance;
 
        private AnalyzerDataCB() {
            picturePath = new File("./AnalyzerPicture/");
            if (!picturePath.exists()) {
                picturePath.mkdirs();
            }
        }
 
        public static AnalyzerDataCB getInstance() {
            if (instance == null) {
                synchronized (AnalyzerDataCB.class) {
                    if (instance == null) {
                        instance = new AnalyzerDataCB();
                    }
                }
            }
            return instance;
        }
 
        public int invoke(NetSDKLib.LLong lAnalyzerHandle, int dwAlarmType, Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize,
                          Pointer dwUser, int nSequence, Pointer reserved) {
            if (lAnalyzerHandle == null || lAnalyzerHandle.longValue() == 0) {
                return -1;
            }
 
 
            switch (dwAlarmType) {
                case NetSDKLib.EVENT_IVS_TRAFFIC_DRIVER_ABNORMAL: //   驾驶员异常报警事件(对应 DEV_EVENT_TRAFFIC_DRIVER_ABNORMAL_INFO)
 
 
                    DEV_EVENT_TRAFFIC_DRIVER_ABNORMAL_INFO msg=new DEV_EVENT_TRAFFIC_DRIVER_ABNORMAL_INFO();
 
                    ToolKits.GetPointerData(pAlarmInfo, msg);
 
                    /** 通道号*/
                    int nChannelID = msg.nChannelID;
 
                    System.out.println("nChannelID:"+nChannelID);
 
                    /** 事件动作, 0表示脉冲事件, 1表示持续性事件开始, 2表示持续性事件结束*/
                    int nAction = msg.nAction;
                    System.out.println("nAction:"+nAction);
 
                    /** GPS信息*/
                    NetSDKLib.NET_GPS_STATUS_INFO stuGPSStatusInfo = msg.stuGPSStatusInfo;
                        //定位时间
                        NetSDKLib.NET_TIME revTime = stuGPSStatusInfo.revTime;
 
                        System.out.println("revTime:"+revTime);
 
                    byte[] dvrSerial = stuGPSStatusInfo.DvrSerial;
 
                    String serial = new String(dvrSerial);// 设备序列号
                             System.out.println("serial:"+serial);
 
                    double longitude = stuGPSStatusInfo.longitude;//经度(单位是百万分之度,范围0-360度)
                    System.out.println("longitude:"+longitude);
 
                    double  latidude = stuGPSStatusInfo.latidude; // 纬度(单位是百万分之度,范围0-180度)
                    System.out.println("latidude:"+latidude);
 
                    double height=stuGPSStatusInfo.height;        // 高度(米)
                    System.out.println("height:"+height);
 
                    double  angle=stuGPSStatusInfo.angle;         // 方向角(正北方向为原点,顺时针为正)
                    System.out.println("angle:"+angle);
 
                    double   speed=stuGPSStatusInfo.speed;       // 速度(单位km/H)
                    System.out.println("speed:"+speed);
 
                    /** 事件发生的时间*/
                     NET_TIME_EX UTC= msg.UTC;
                    System.out.println("UTC:"+UTC);
                    /**  违章关联视频FTP上传路径 */
                    try {
                        String videoPath = new String(msg.szVideoPath, "GBK");
 
                        System.out.println("videoPath:"+videoPath);
 
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
 
 
                    break;
                default:
                    System.out.println("其他事件--------------------"+ dwAlarmType);
                    break;
            }
 
            return 0;
        }
    }
 
    /**
     * 停止侦听智能事件
     */
    public void DetachEventRealLoadPic() {
        if (this.attachHandle.longValue() != 0) {
            netSdk.CLIENT_StopLoadPic(this.attachHandle);
        }
    }
 
 
    /**
     * 加载测试内容
     */
    public void RunTest() {
        CaseMenu menu = new CaseMenu();
        menu.addItem(new CaseMenu.Item(this, "订阅智能事件", "AttachEventRealLoadPic"));
        menu.addItem(new CaseMenu.Item(this, "停止侦听智能事件", "DetachEventRealLoadPic"));
        menu.run();
    }
 
    public static void main(String[] args) {
 
 
        Initialization.InitTest("10.35.221.232", 37777, "admin", "admin123");
        new TrafficDriverAbnormalDemo().RunTest();
        Initialization.LoginOut();
    }
}